Karim Belabas on Sun, 23 Oct 2022 16:44:57 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: expression normalization


* Ruud H.G. van Tol [2022-10-22 16:59]:
> 
> ? (a-b)/(c-d)
> %1 = 1/(c - d)*a - 1/(c - d)*b
> ? ((a-b)/(c-d))
> %2 = 1/(c - d)*a - 1/(c - d)*b
> 
> ? (b-a)/(d-c)
> %3 = -1/(-c + d)*a + 1/(-c + d)*b
> ? ((b-a)/(d-c))
> %4 = -1/(-c + d)*a + 1/(-c + d)*b
> 
> I wondered why these don't all "normalize"
> to the same internal (?) format.
> 
> And if there is no special reason for that:
> if it is worth the effort to make it so.

No special reason. I just changed the t_RFRAC normalization code to ensure the
"leading coefficient" of the denominator is positive if real.

? (a-b)/(c-d)
%1 = 1/(c - d)*a - 1/(c - d)*b
? (b-a)/(d-c)
%2 = 1/(c - d)*a - 1/(c - d)*b
? b/a-c/d
%3 = (-c*a + d*b)/(d*a)
? b/a-d/c
%4 = (-d*a + c*b)/(c*a)

I didn't try to extend the normalization further, e.g. it "fails" over complex
numbers (and finite rings, and number rings etc.)
? 1/(1-I*x)
%5 = 1/(-I*x + 1)
? 1/(I*x-1)
%6 = 1/(I*x - 1)

Cheers,

    K.B.

P.S. This part of your examples is due to variable priorities
? type(a/b-c/d)
%16 = "t_POL"
? type(b/a-d/c)
%17 = "t_RFRAC"

See section 2.5.3 is the User's Guide to PARI/GP. Variables are sorted in
"priority" order, not alphabetic.

--
Karim Belabas, IMB (UMR 5251), Université de Bordeaux
Vice-président en charge du Numérique
T: (+33) 05 40 00 29 77; http://www.math.u-bordeaux.fr/~kbelabas/
`