Below is a simplified scenario of a problem that I'm running into. There are 3 functions each wrapped with BaseForm[]
and a default base of 10 is passed to each through the optional f
parameter. Each function depends on the function before it.
Add[a_, b_, f_:10] := BaseForm[a + b, f]
MultSum[a_, b_, c_, f_:10] := BaseForm[Add[a, b]*c, f]
ExpMultSum[a_, b_, c_, d_, f_:10] := BaseForm[MultSum[a, b, c]^d, f]
Please be aware the functions above have nothing to do with what I'm trying to accomplish. They only exist to highlight the issue that I am encountering.
I intentionally avoid passing in the f
to the earlier functions because the output format isn't parseable by the caller. Add[]
works fine, as does MultSum[]
, but once we get to ExpMultSum[]
the Mathematica 9 parser appears to hit some internal limitation and stops evaluating the expression:
Add[2, 2]
4
MultSum[2,2,2]
8
ExpMultSum[2, 2, 2, 2]
8²
My best guess is that there is a nesting limitation? The only solution I can come up with is to move the BaseForm outside the function and wrap each call (ex. BaseForm[Add[2, 2],10]
). Is there a known workaround so I can keep the BaseForm internal to the function?
BaseForm[]
is only intended for output formatting. Why not do your arithmetic conventionally, and reserveBaseForm[]
when you're ready to display output? $\endgroup$$PrePrint
to have your output be always printed in base $k$ form, for some globally set value ofk
. $\endgroup$BaseForm[...]
. If you doFullForm[...]
of the outputs this will become more clear. $\endgroup$MatrixForm[]
. As in "Why doesn'tmat={{1,2},{3,4}}//MatrixForm;RowReduce[mat]
work?". Same issue. $\endgroup$BaseForm[expr,10]
formats without the "sub_10" part in contrast to other bases. But that's in the formatting handler. The fact isXXXForm
wrappers do not go away, so functions that see them in input need to be prepared for handling them. $\endgroup$