Anything that is purely an optimization (like memo'izing ratdisreps)
must be 100% reliable. Anything else makes the semantics of the system
too messy and impossible to document. What do you tell the user when
( x:[a,b], rat(x), x[1]:haha, rat(x) ) => [a,b] instead of [haha,b] ?
This is very different from telling the user that things don't get
re-simplified unless you force them to. In fact, automatic
resimplification may be more confusing. I have not used Mathematica, so
I don't know how that works there.
Actually, there is a confusing case in Maxima:
x: 2/3$
numer:true$
x => .667 Hmm, I guess this is OK
x: [2/3]$
numer:true$
x => [2/3] But this doesn't seem consistent....
(Yes, I know why it is this way, but it is still hard to explain.)
> One question is how this can be handled recursively. Do we want only
> top-level command expressions to be rat/memoized? In which case if
> u:rat(x+y)^2 is memoized, what happens to 3*u ?
I don't see why only top-level command expressions would be memoized.
In your example, rat(x+y) is memoized, as is rat(x+y)^2 if it is
displayed.
-s
PS There are some cases you have to be careful about. For example,
rat(ratdisrep(x)) may not equal x, not only if various flags are set,
but also if x is a Taylor series (Trunc flag).