On Thu, May 29, 2008 at 11:54 AM, Richard Fateman
<fateman at cs.berkeley.edu> wrote:
> Sometimes people want a very particular form. x-y, -y+x, -1*y^1+1*x^1, ...
> e^(-x), exp(-x), 1/exp(x), 1/e^x ....
Besides using simp:false, which has its own problems, box seems to
work for cases like this:
box(-1)*y^box(1)+box(1)*x^box(1)
The main problem with this is that there is no way to keep the boxes
but turn off their display (including the space for the box) --
perhaps boxchar:"" should do that (currently it is not useful).
That said, box'ing doesn't control ordering and does allow
cancellation if you're not careful -- you have to write e.g.
box(x,1)/box(x,2) to avoid the simplification box(x)/box(x) => 1.
I don't see any downside to using box this way, except that we don't
have useful operators around it, though they'd be pretty
straightforward to write either as explicit code or as
pattern-matching rules
bx_count: 0$
-- make a non-cancelling box
bx(expr):=box(expr,bx_count:bx_count+1)$
-- one-level unboxing, unlike rembox
unbox(expr):= if atom(expr) then expr elseif op(expr)='box then
first(expr) else expr$
distribute_1level( box(2)*(box(3)+box(4)) ) => box(6)+box(8)