Ruud H.G. van Tol on Sat, 22 Oct 2022 17:25:24 +0200


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

Re: expression normalization




On 2022-10-22 16:59, Ruud H.G. van Tol wrote:

? (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.

-- Ruud

? a/b-c/d
%5 = 1/b*a - 1/d*c
? b/a-c/d
%6 = (c*a - d*b)/(-d*a)
? b/a-d/c
%7 = (-d*a + c*b)/(c*a)

? a/b-d/c
%8 = 1/b*a - d/c
? w/x-z/y
%9 = (-z*x + w*y)/(y*x)

Least multiplication/division steps, could be a goal?
And then alphabetical order preservation?

I'm really only guessing here, didn't benchmark anything,
and also didn't think through any commutativity and distributivity implications.

? type(a/b-c/d)
%16 = "t_POL"
? type(b/a-d/c)
%17 = "t_RFRAC"

-- Ruud