Question regarding the rat-function (and "CRE" in general)
Subject: Question regarding the rat-function (and "CRE" in general)
From: Oliver Kullmann
Date: Wed, 30 Nov 2011 19:31:16 +0000
Hello,
reading the recent discussion about CRE and so on, I thought
this could be the chance finally understanding what this is
about --- until now, for me and our group, CRE was just a
source of annoyance --- it shows up suddenly, causing
unexpected errors, and one has to get rid off it.
So I looked up "? rat", but it creates problems. First w.r.t.
to the example it shows:
(%i28) t:((x - 2*y)^4/(x^2 - 4*y^2)^2 + 1)*(y + a)*(2*y + x) /(4*y^2 + x^2);
Evaluation took 0.0010 seconds (0.0010 elapsed)
(%o28) (y+a)*(2*y+x)*((x-2*y)^4/(x^2-4*y^2)^2+1)/(4*y^2+x^2)
(%i29) rat(t);
Evaluation took 0.0000 seconds (0.0010 elapsed)
(%o29) (2*y+2*a)/(2*y+x)
(%i30) display2d;
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%o30) false
(%i31) display2d:true;
Evaluation took 0.0000 seconds (0.0010 elapsed)
(%o31) true
(%i32) rat(t);
Evaluation took 0.0010 seconds (0.0010 elapsed)
2*y + 2*a
(%o32)/R/ ---------
2*y + x
Now neither the documentation of rat nor that of display2d
mentions the (perhaps "obvious") suppression of "/R/", and
since I find CRE such a confusing thing, perhaps a mentioning
should be added somewhere.
(By the way: I always found "2-d-display" a rather annoying thing,
and I live much happier since I switched it off. Especially in
a programming-context, 2-d-display is a permanent source of problems.)
Second then comes the assertion in "? rat":
For example,
`rat(x)- x' yields `rat(0)' which has a different internal
representation than 0.
However:
(%i35) is(rat(x)-x=0);
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%o35) true
Regarding the three flags mentioned in "? rat" I have
(%i36) ratfac;
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%o36) false
(%i37) ratprint;
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%o37) false
(%i38) keepfloat;
Evaluation took 0.0000 seconds (0.0000 elapsed)
(%o38) false
Only ratprint does not have the default-value, and it should not
have any effect here? So is the documentation of rat outdated?
We have (now with display2d=true):
(%i45) rat(x)-x;
Evaluation took 0.0000 seconds (0.0010 elapsed)
(%o45)/R/ 0
So apparently /R/0 and 0 are "syntactically equal" ?
Finally, perhaps I can finally understand what "CRE" is?!?:
Until now, I actually thought "CRE" would represent a general mathematical concept,
but trying google with "canonical rational expression" the Maxima
manual shows up first, and the only references one finds are
http://books.google.co.uk/books?id=TXfY891RiiEC&pg=PA89&lpg=PA89&dq=canonical+rational+expression&source=bl&ots=5KwLuJOPHS&sig=F4r7Lh3PFLMnkTKdW-4eek625Tc&hl=en#v=onepage&q=canonical rational expression&f=false
where one has Definition 3.6 of
[Algorithms for computer algebra
By Keith O. Geddes, Stephen R. Czapor, George Labahn]
which needed quite some time to digest, but suggest that it is not a general
mathematical concept, but a specific algorithmic concept.
One also finds
http://groups.csail.mit.edu/mac/users/gjs/6.945/readings/simplification/martin-fateman-macsyma.pdf
but this seems only to refer to CRE, and doesn't explain it.
Okay, following google we find also
http://flex.phys.tohoku.ac.jp/texi/maxima/maxima_12.html
which is a bit outdated (in 5.25.1 it is Subsection 14.1), however the text
seems to be still the same.
And this text doesn't tell me much. It seems to be purely an internal thing
of Maxima, since immediately we find a regression from mathematical symbolism
to some internal Maxima-syntax:
Thus the principal part of the CRE form of 3*X^2-1 is (X 2 3 0 -1) and that of 2*X*Y+X-3 is (Y 1 (X 1 2) 0 (X 1 1 0 -3)) assuming Y is the main variable, and is (X 1 (Y 1 2 0 1) 0 -3) assuming X is the main variable.
This suggests that it is not mathematically meaningful, but it would be only
some Lisp-expression which happens to be used for some reason.
This seems to be the only place where "CRE" is "explained". How is a user supposed
to make sense of it??
The documentation of rat also gives no clue why one should use "rat":
-- Function: rat (<expr>, <x_1>, ..., <x_n>)
Converts <expr> to canonical rational expression (CRE) form by
expanding and combining all terms over a common denominator and
cancelling out the greatest common divisor of the numerator and
denominator, as well as converting floating point numbers to
rational numbers within a tolerance of `ratepsilon'. The
variables are ordered according to the <x_1>, ..., <x_n>, if
specified, as in `ratvars'.
As if "CRE" would be something one learns at school. And actually, until
now I thought it would be a bit like that, since it shows up in Maxima
all over the place, and is never explained, so everybody else seems
to know what it is. Perhaps somewhere there is an entry-exam into the
use of computer-algebra systems, and I missed that exam ... so I better
kept quite. But now encouraged by the mentioning of the naive user, and
that actually some thoughts are spend on him, I thought I could dare
to leave my hideout, and expose my ignorance.
So, to summarise, I would find it really necessary that some effort is
spent on "CRE" in the documentation:
1) Either it is supposed to be a fundamental concept, and than there must be
a full *mathematical* explanation of it somewhere in the Maxima-documentation.
2) Or it is only an internal representation, and then for most usages the user
should not be exposed to "CRE".
This is perhaps especially written as somebody how (with my group) uses Maxima
mostly as a programming-language, and then "CRE" is just a mysterious thing
one has to detect in expressions, and then has to eliminate it (like a disease,
which has infested the expression, and where one has to cure the poor expression).
Hope you have some understanding for my concerns.
Oliver