3
$\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$
  • 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$ – Dr. belisarius Nov 26 '15 at 20:00
  • 2
    $\begingroup$ Try multiplying the list by the LCM of the denominators; that will give you the list of numerators. $\endgroup$ – Patrick Stevens Nov 26 '15 at 20:08
  • 2
    $\begingroup$ LCM@@Denominator[list]] might be what you want. $\endgroup$ – Daniel Lichtblau Nov 26 '15 at 20:38
  • 1
    $\begingroup$ Related: How to prevent simplification?, How to NOT simplify fraction. $\endgroup$ – jkuczm Nov 26 '15 at 22:59
2
$\begingroup$
l = {1/36, 1/36, 1/18, 1/12, 1/18};
lcm = LCM @@ (Denominator@l);
ToString[#]/lcm & /@ (l lcm);
|improve this answer|||||
$\endgroup$
4
$\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

|improve this answer|||||
$\endgroup$
2
$\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[]

|improve this answer|||||
$\endgroup$
  • $\begingroup$ I would prefer Defer[] (or Inactivate[] in newer versions) myself. $\endgroup$ – J. M.'s technical difficulties Nov 26 '15 at 22:56
  • $\begingroup$ @J.M. Why? Is it seriuos difference? I've just put it to avoid ToString solution. $\endgroup$ – garej Nov 27 '15 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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