On Sat, Jun 13, 2026 at 11:55:55AM +0800, Qian Yun wrote:
> On 6/12/26 9:09 AM, Qian Yun wrote:
> > On 6/12/26 8:42 AM, Waldek Hebisch wrote:
> >>
> >>> 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.
> >>
> > 
> > Because 'reduc' is called by every + - * / =, any tiny
> > optimization could be helpful in the end.
> > 
> > My current plan is to do search and replace in parallel,
> > say for alg_ker1^n1*alg_ker2^n2, do transformation for them
> > in one loop.  Then loop on the result until no transformation
> > are needed.  This should save many memory allocations.
> > 
> > Also this opens doors for optimization like
> > sum([e1,e2,e3,...]), mul([e1,e2,e3,...]).
> > 
> > - Qian
> > 
> 
> I planed to do transformation at monomial level instead of smp level.
> Turns out this doesn't work.
> 
> But the following works, by avoiding unnecessary division (gcd).
> This saves memory usage of mapleok.input by around 30%.

Yes, good.

> The =$EXPR optimization saves another 30%.
> The kernel cache recycle patch saves around 30%.
> 
> So 3 patches together, for mapleok.input, memory usage drops
> from 13.5GB to 5.1GB, time drops from 15s to 8s.
> 
> - Qian
> 
> diff --git a/src/algebra/expr.spad b/src/algebra/expr.spad
> index 6b9a11b5..94a24e9e 100644
> --- a/src/algebra/expr.spad
> +++ b/src/algebra/expr.spad
> @@ -384,7 +384,9 @@
>              reduc(x, l) ==
>                  for k in l repeat
>                      p := minPoly k
> -                    x := evl(numer x, k, p) /$Rep evl(denom x, k, p)
> +                    d := degree p
> +                    if degree(numer x, k) >= d or degree(denom x, k) >=
> d then
> +                        x := evl(numer x, k, p) /$Rep evl(denom x, k, p)
>                  x
> 
>              evl0(p, k) ==
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To view this discussion visit 
> https://groups.google.com/d/msgid/fricas-devel/41614faa-0cc7-4957-877f-71eb453f4680%40gmail.com.

-- 
                              Waldek Hebisch

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/ai1IysNl-MLT86Q9%40fricas.org.

Reply via email to