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
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[
RowBox[{AdjustmentBox[SuperscriptBox["", MakeBoxes[n]],
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)
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]},
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:
C(9999999,x)*Power(1*1/Power(2,24),x)
TraditionalForm
seems to evaluate the fractions. $\endgroup$