4
$\begingroup$

If I have a list, say $\{\frac{1}{36},\frac{1}{36},\frac{1}{18},\frac{1}{18},\frac{1}{12},\frac{1}{12},\frac{1}{12},\frac{1}{12},\frac{1}{12},\frac{1}{12},\frac{1}{12},\frac{1}{12},\frac{1}{18},\frac{1}{18},\frac{1}{36},\frac{1}{36}\}$, how can I make it so that all the elements of the list have the same denominator (using the smallest one possible) ?

$\endgroup$
4
  • 1
    $\begingroup$ The real problem is how to get that numbers printed.Mathematica will simplify them on the fly. There are several related question to this on this site. Search for them $\endgroup$ Commented Nov 26, 2015 at 20:00
  • 2
    $\begingroup$ Try multiplying the list by the LCM of the denominators; that will give you the list of numerators. $\endgroup$ Commented Nov 26, 2015 at 20:08
  • 2
    $\begingroup$ LCM@@Denominator[list]] might be what you want. $\endgroup$ Commented Nov 26, 2015 at 20:38
  • 1
    $\begingroup$ Related: How to prevent simplification?, How to NOT simplify fraction. $\endgroup$
    – jkuczm
    Commented Nov 26, 2015 at 22:59

4 Answers 4

4
$\begingroup$
l = {1/36, 1/36, 1/18, 1/12, 1/18};
lcm = LCM @@ (Denominator@l);
ToString[#]/lcm & /@ (l lcm);
$\endgroup$
5
$\begingroup$

If it is only for printing you could do something like this

list = {1/36, 1/36, 1/18, 1/12, 1/18};

max = Max@Denominator@list;
p1 = ToString /@ max/Denominator@list;
p2 = Array[ToString@max &, Length@list;

Column[#, Center, Spacings -> 1, Dividers -> Center] & /@ Transpose[{p1, p2}]

enter image description here

$\endgroup$
3
$\begingroup$

Not only for printing. One more option is to use HoldForm[] (or Defer[] suggested by J.M.):

Clear[list, den, print];    
list = {1/36, 1/36, 1/18, 1/12, 1/18};

HoldForm:

den = Denominator@list;
print = HoldForm /@ (Max[den]/den)/Max[den]

To evaluate the expression:

ReleaseHold@print

PS. One may olso use Inactivate[]

$\endgroup$
2
  • $\begingroup$ I would prefer Defer[] (or Inactivate[] in newer versions) myself. $\endgroup$ Commented Nov 26, 2015 at 22:56
  • $\begingroup$ @J.M. Why? Is it seriuos difference? I've just put it to avoid ToString solution. $\endgroup$
    – garej
    Commented Nov 27, 2015 at 6:20
1
$\begingroup$

Using FractionBox:

For display only:

list = {1/36, 1/36, 1/18, 1/12, 1/18};

With [{z = LCM @@ Denominator@list}, 
 FractionBox @@@ 
   Transpose[{(list z), ConstantArray[z, Length@list]}] // DisplayForm
 ]

enter image description here


Inactive[Divide] @@@ 
 Transpose[{(list z), ConstantArray[z, Length@list]}]

enter image description here

Activate[%]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.