On Fri, Jun 12, 2026 at 07:42:14AM +0800, Qian Yun wrote:
> On 6/11/26 11:48 PM, Waldek Hebisch wrote:
> >
> > I see, mutiplication in EXPR is probably good enough to pass
> > our existing tests, but this does not look right. Note that
> > we may have nested roots and mutiplying two roots may introduce
> > new denominators.
> >
> > In general, representation of Expression is only normal: when
> > result of an operation is 0 it will give 0 at representation
> > level, but equal expressions may have different representations.
> >
> > AFAICS the following should be OK:
> >
> > algreduc((numer(x)*$Rep denom(y) -$Rep numer(y)*$Rep denom(x))::%,
> > commonk(x, y)) =$Rep 0
> >
>
> Thanks, this works (need to tweak signature a bit), but the memory
> usage grows from 8.5GB to 9.7GB compare to previous (flawed) version.
>
> Profile shows lots of time and memory is spent in =$EXPR, reduc$EXPR.
>
> As I see it, the purpose of 'reduc' is to simplify algebraic expression,
> and the purpose of 'algreduc' is to rationalize the denominator
> depending on getSimplifyDenomsFlag.
Yes. Actually, above in test for equality we should be able to
replace 'algreduc' by 'reduc'.
> I can leave 'algreduc' alone. But for 'reduc', I think its
> implementation is very inefficient. I think, in theory,
> we can walk the variables of Rep to check for algebraic kernels
> and do transformation if necessary.
Hmm, that is what 'reduc' is essentially doing. But there is a
catch: reducing with respect to one kernel may expose other ones.
So we order kernels and start reduction from the most complex
one and then repeat this with simpler kernels. Also, we allow
arbitrary algebraic kernels and do not require minimal polynomials
to be monic, so reduction is more complex than in case of roots.
--
Waldek Hebisch