Question regarding the rat-function (and "CRE" in general)



On Wed, Nov 30, 2011 at 02:51:31PM -0500, Stavros Macrakis wrote:
> On Wed, Nov 30, 2011 at 14:31, Oliver Kullmann <O.Kullmann at swansea.ac.uk>
> wrote:
> 
>     For example,
>     ? ? `rat(x)- x' yields `rat(0)' which has a different internal
>     ? ? representation than 0.
> 
>     However:
> 
>     (%i35) is(rat(x)-x=0);
> 
> 
> "is" always converts CRE expressions (using ratdisrep) to the standard Maxima
> general representation before comparing. ?So:
> 
> rat(x+y,x,y) => y+x ?==ratdisrep=> y+x
> rat(x+y,y,x) => x+y??==ratdisrep=> y+x
> is(rat(x+y,x,y)=rat(x+y,y,x)) => true
>

Aha, I see.
 
>     Only ratprint does not have the default-value, and it should not
>     have any effect here? So is the documentation of rat outdated?
> 
> 
> I am surprised that ratprint isn't true (by default) in your system. ?It is in
> mine (Maxima 5.25.1 GCL Windows).
>

ratprint by default is true, but we set it to false, since it creates
a lot of output when running our tests.
 ?
>     (%i45) rat(x)-x;
>     (%o45)/R/ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?0
> 
>     So apparently /R/0 and 0 are "syntactically equal" ?
> 
> 
> Not sure why you conclude this.

I thought that two expressions a,b would be syntactically equal iff
is(a=b)
yields true; however, as you said above, "is" itself performs certain
simplifications itself (beyond "syntactical equality").

> 
> It is actually a pretty simple concept. ?A CRE is a rational function, a ratio
> of two multivariate polynomials. ?Polynomials are represented in the form sum(a
> [i]*x^i,i,0,...) where the coefficients a[i] are either numbers or polynomials
> of this form not including the variable x. ?The variables x (the 'kernels') can
> in theory be any expression in Maxima general representation, but in practice
> consist of things that cannot be represented as polynomials, e.g. special
> function calls like sin(x) and non-integer exponentials like x^(1/3) or %e^x.
> ?Generally CRE's try to use minimal fractional exponentials, e.g. x^(2/3)+x^(1/
> 3) is represented as q^2+q (q=x^(1/3)), but it is possible to generate things
> like?q+r (q=x^(2/3), r=x^(1/3)).
>

Thanks! Now I understand it somewhat better.

> 
> The simple explanation is polynomials with polynomial coefficients.
> ?
> 
>     The documentation of rat also gives no clue why one should use "rat":
> 
> 
> For efficiency in handling large expressions, mostly.
> 
> %i8) expand((x+y+1)^200)$
> Evaluation took 1.9600 seconds (1.9600 elapsed)
> (%i9) rat((x+y+1)^200)$
> Evaluation took 0.0200 seconds (0.0200 elapsed)
> 

Wouldn't ratexpand be more appropriate here?:

(%i64) expand((x+y+1)^200)$
Evaluation took 4.8220 seconds (4.8450 elapsed)
(%i65) rat((x+y+1)^200)$
Evaluation took 0.0280 seconds (0.0290 elapsed)
(%i66) ratexpand((x+y+1)^200)$
Evaluation took 0.4990 seconds (0.4980 elapsed)

Thanks again.

Oliver