On Mon, Jun 15, 2026 at 09:04:03AM +0800, Qian Yun wrote:
> On 6/15/26 8:49 AM, Waldek Hebisch wrote:
> > On Sun, Jun 14, 2026 at 10:40:59PM +0800, Qian Yun wrote:
> >> I keep finding new things down this rabbit hole...
> >>
> >> After latest patch, profiler shows smaller?$EXPR
> >> takes a lot of time. So I took a look.
> >>
> >> triage$Kernel calls smaller?$EXPR.
> >> It is used to sort the kernels.
> >>
> >> smaller?$EXPR calls
> >> smaller?(numer(x)*denom(y), numer(y)*denom(x))
> >>
> >> Well, we know there is no well defined order in EXPR.
> >>
> >> The multiplication is expensive, we can change it to
> >> smaller?(x : %, y : %) ==
> >> denom(x) = denom(y) => smaller?(numer(x), numer(y))
> >> smaller?(denom(x), denom(y))
> >>
> >> This should also have the side effect that kernels with same
> >> denom will appear near together?
> >
> > That looks problematic to me. Namely, if we have two different
> > representations x1 and x2 of the same value, than modified variant
> > will give them some order, that is smaller?(x1, x2) or
> > smaller?(x2, x1) will be true. Original version gives false
> > in such case.
>
> We can leave smaller?$EXPR aside for now.
>
> In Kernel:
>
> triage(k1, k2) ==
> height(k1) ~= height(k2) => B2Z(height(k1) < height(k2))
> operator(k1) ~= operator(k2) => B2Z(operator(k1) < operator(k2))
> (n1 := #(argument k1)) ~= (n2 := #(argument k2)) => B2Z(n1 < n2)
> for x1 in argument(k1) for x2 in argument(k2) repeat
> x1 ~= x2 => return B2Z(smaller?(x1, x2))
> 0
>
>
> There is already a check that x1~=x2.
> So in this case, it's perfectly fine to use the method above
> to determine order?
Probably. OTOH it looks to me that 'x1 ~= x2' already did all
expensive things needed for 'smaller?'. So replacing both
by their definitions and reusing subexpressions should be
as fast as what you propose.
--
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/ai9cQ8n9QN4s7How%40fricas.org.