Is there a way to make a formula display in a human readable form? I have something like

Binomial[(10000000 - 1), x]*(1/2^24)^x

and I'd like it to display using C notation or variants thereof.


  • $\begingroup$ Take a look at TraditionalForm (and HoldForm in combination if you don't want evaluation) $\endgroup$ – ciao Feb 22 '15 at 7:26
  • $\begingroup$ @rasher Thanks. Is there a way to leave the output as fractions as well? TraditionalForm seems to evaluate the fractions. $\endgroup$ – Kar Feb 22 '15 at 8:18
  • $\begingroup$ HoldForm[Binomial[(10000000 - 1), x]*(1/2^24)^x] // TraditionalForm does not do what you're after? $\endgroup$ – ciao Feb 22 '15 at 8:21
  • $\begingroup$ @rasher Well, not entirely. TraditionalForm evaluates (1/2^24)^x to 16777216^-x whereas HoldForm doesn't use a C notation but outputs Binomial[10000000-1, x]. I wonder if there's some kind of merge of the two? :) $\endgroup$ – Kar Feb 22 '15 at 9:12
  • $\begingroup$ Perhaps you need to clarify what you're after. Do you want the binomial to be 9999999,x? $\endgroup$ – ciao Feb 22 '15 at 9:19

I hope I understand the question. I have interpreted this is wishing to display an expression in a particular form.

f /: MakeBoxes[f[n_, x_, num_], StandardForm] := 
    RowBox[{AdjustmentBox[SuperscriptBox["", MakeBoxes[n]], 
       BoxMargins -> -0.15, BoxBaselineShift -> -1], 
      MakeBoxes[Style["C", Italic, 20], StandardForm]}], 
    RowBox[{"(", FractionBox[1, SuperscriptBox[2, MakeBoxes[num]]], 
      ")"}], MakeBoxes[x]]}]


Grid[{{f[a, b, c], Rasterize@TraditionalForm[f[a, b, c]]},
  {f[10000000 - 1, x, 24], 
   Rasterize@TraditionalForm[f[10000000 - 1, x, 24]]}}, Frame -> All]

enter image description here


If it is C-like syntax you are after, CForm is your friend:




To better preserve the original formula you gave, you can use:


which outputs

Binomial(10000000 - 1,x)*Power(1/Power(2,24),x)


As you seemed to look for only the Binomial's arguments to be evaluated, while the fractions should stay there, please try:

 Binomial[(10000000-1),x]*(1/2^24)^x],{Times[x_, y_] :> 
  Times[HoldForm[x], HoldForm[y]], Binomial->C},{3, \[Infinity]},
 Heads -> True] // ReleaseHold

giving the possibly desired result. Of course you can then call CForm again, in order to get the round brackets, but this time with only the Binomial's parameters having been simplified:


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.