On Thu, Jun 18, 2026 at 07:12:21AM +0800, Qian Yun wrote:
> Thanks for the nice explanation.
>
> Yes, it requires extra care for zero divisors.
>
> In this case, the denominator of x1,x2 does not multiply
> to zero, so we can get sensible result if we interpret
> that the branch is chosen to avoid division by zero.
>
> For 'reduc', the attached patch changes the evaluation
> order: reduction over algebraic kernels first,
> do the division at the end.
>
> This will make (x1-x2) return 0, which make the system
> a little bit more consistent.
I think that you want to avoid evaluating num and den when
possible. Otherwise it looks OK.
OTOH it is not clear to me how much attention to give to
cases involving zero divisors. Without comprehensive
theory there is risk that better output for some cases
will cause worse output for other ones.
> diff --git a/src/algebra/expr.spad b/src/algebra/expr.spad
> index ed89a42f..cda9f4fa 100644
> --- a/src/algebra/expr.spad
> +++ b/src/algebra/expr.spad
> @@ -386,13 +386,20 @@ Expression(R : Comparable) : Exports == Implementation where
> operator(name op, n@NonNegativeInteger)
>
> reduc(x, l) ==
> + num := numer x
> + den := denom x
> + evaled := false
> for k in l repeat
> p := minPoly k
> - d := degree p
> - -- avoid division when possible
> - 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
> + num1 := evl(num, k, p)
> + den1 := evl(den, k, p)
> + num := numer(num1)*denom(den1)
> + den := numer(den1)*denom(num1)
> + evaled := true
> + if evaled then
> + num /$Rep den
> + else
> + x
>
> evl0(p, k) ==
> numer univariate(p::Fraction(MP),
--
Waldek Hebisch