[PATCH] change "smaller?" in EXPR

3 views
Skip to first unread message

Qian Yun

unread,
Jul 9, 2026, 11:09:49 PM (2 days ago) Jul 9
to fricas-devel
I decided to put the comparison logic in EXPR explicitly,
instead of depending on the implementation in FRAC implicitly.

I also checked differences in "cd src/input; make all" and
hyperpages, some expressions have changed display order among
monomials, some expressions are in equivalent form, some are
simpler, no outstanding surprises.

As we discuss before, this should be a positive change.

- Qian
expr-smaller.patch

Waldek Hebisch

unread,
Jul 10, 2026, 3:51:16 PM (11 hours ago) Jul 10
to fricas...@googlegroups.com
OK.

> diff --git a/src/algebra/expr.spad b/src/algebra/expr.spad
> index d7cb85c3..dd6db2f1 100644
> --- a/src/algebra/expr.spad
> +++ b/src/algebra/expr.spad
> @@ -155,7 +155,14 @@ Expression(R : Comparable) : Exports == Implementation where
> simplifyPower(numerator x, n::Integer) /
> simplifyPower(denominator x, n::Integer)
>
> - smaller?(x : %, y : %) == smaller?(x, y)$Rep
> + -- This is lexicographic order, not fully compatible with '=',
> + -- i.e. for some e1 = e2, smaller?(e1, e2) may also return true.
> + -- But it is good enough for ordering in Kernel, because it checks
> + -- for duplicates first.
> + smaller?(x : %, y : %) ==
> + denom(x) = denom(y) => smaller?(numer(x), numer(y))
> + smaller?(denom(x), denom(y))
> +
> numer x == numer(x)$Rep
> denom x == denom(x)$Rep
>
> diff --git a/src/input/rsimp.input b/src/input/rsimp.input
> index 5a4b2f44..50440eca 100644
> --- a/src/input/rsimp.input
> +++ b/src/input/rsimp.input
> @@ -39,10 +39,10 @@ testEquals("rs3a", "sqrt(3)::eI*(sqrt(6) + 3)/3")
>
> w4 := 28*11^(1/2)*15^(1/2)+497
> -- Need subst, otherwise square root would mangle the argument
> -a7715 := subst(a^(1/2), [a = 77/15])
> +a28 := subst(a^(1/2), [a = 28])
> rs4 := ratDenom(rsimp(sqrt(w4)))
> testEquals("w4 - rs4^2", "0")
> -testEquals("rs4", "(30*sqrt(11)::eI + 11*sqrt(15))*a7715/11")
> +testEquals("rs4", "(2*sqrt(15)::eI + sqrt(11))*a28/2")
>
> w5 := 16 - 2*sqrt(29) + 2*sqrt(55 - 10*sqrt(29));
> rs5 := rsimp(sqrt(w5))
> @@ -90,10 +90,9 @@ testEquals("w12 - rs12^5", "0")
> testEquals("rs12", "(3*sqrt(2) + 2*sqrt(3))*a544/2")
>
> w13 := 7*(2*sqrt(3) - sqrt(11))^6
> -a12096_1331 := subst(a^(1/6), [a = 12096/1331])
> rs13 := rsimp(w13^(1/6))
> testEquals("w13 - rs13^6", "0")
> -testEquals("rs13", "(6*sqrt(11) - 11*sqrt(3))*a12096_1331/6")
> +testEquals("rs13", "7^(1/6)*(sqrt(11)-2*sqrt(3))")
>
> w14 := 19*(5*sqrt(2) - sqrt(7))^7
> rs14 := rsimp(w14^(1/7))


--
Waldek Hebisch
Reply all
Reply to author
Forward
0 new messages