# Format a formula in human readable form

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.

Thanks

• Take a look at TraditionalForm (and HoldForm in combination if you don't want evaluation) – ciao Feb 22 '15 at 7:26
• @rasher Thanks. Is there a way to leave the output as fractions as well? TraditionalForm seems to evaluate the fractions. – Kar Feb 22 '15 at 8:18
• HoldForm[Binomial[(10000000 - 1), x]*(1/2^24)^x] // TraditionalForm does not do what you're after? – ciao Feb 22 '15 at 8:21
• @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? :) – Kar Feb 22 '15 at 9:12
• Perhaps you need to clarify what you're after. Do you want the binomial to be 9999999,x? – 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[{SubscriptBox[
BoxMargins -> -0.15, BoxBaselineShift -> -1],
MakeBoxes[Style["C", Italic, 20], StandardForm]}],
MakeBoxes[x]],
SuperscriptBox[
RowBox[{"(", FractionBox[1, SuperscriptBox[2, MakeBoxes[num]]],
")"}], MakeBoxes[x]]}]


So,

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]


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

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


outputs

Binomial(9999999,x)/Power(16777216,x)

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

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


which outputs

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

# Update

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

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

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:
C(9999999,x)*Power(1*1/Power(2,24),x)