[PATCH] optimize "*" in SMP

3 views
Skip to first unread message

Qian Yun

unread,
Jun 28, 2026, 7:40:18 PM (8 hours ago) Jun 28
to fricas-devel
This patch saves allocation when one of the multiplicand
is the unit polynomial.

For mapleok.input, it saves 0.8% memory.

(This is actually on the hot path of =$EXPR, where likely
that one of the multiplicand is 1.
Also this is real-world saving of 0.8%. In hand-crafted
benchmarks, it can be much higher.)

- Qian

diff --git a/src/algebra/multpoly.spad b/src/algebra/multpoly.spad
index 62a232e1..4385232c 100644
--- a/src/algebra/multpoly.spad
+++ b/src/algebra/multpoly.spad
@@ -375,10 +375,13 @@
false

p1 * p2 ==
- p1 case R => p1::R * p2
+ p1 case R =>
+ one?(p1::R) => p2
+ p1::R * p2
p2 case R =>
+ one?(p2::R) => p1
mvar := p1.v
- up := p1.ts*p2
+ up := p1.ts * (p2::R)
if ground? up then leadingCoefficient(up) else [mvar, up]$VPoly
p1.v = p2.v =>
mvar := p1.v

Waldek Hebisch

unread,
Jun 28, 2026, 7:59:44 PM (8 hours ago) Jun 28
to fricas...@googlegroups.com
On Mon, Jun 29, 2026 at 07:40:13AM +0800, Qian Yun wrote:
> This patch saves allocation when one of the multiplicand
> is the unit polynomial.
>
> For mapleok.input, it saves 0.8% memory.
>
> (This is actually on the hot path of =$EXPR, where likely
> that one of the multiplicand is 1.
> Also this is real-world saving of 0.8%. In hand-crafted
> benchmarks, it can be much higher.)

OK, please commit.

> diff --git a/src/algebra/multpoly.spad b/src/algebra/multpoly.spad
> index 62a232e1..4385232c 100644
> --- a/src/algebra/multpoly.spad
> +++ b/src/algebra/multpoly.spad
> @@ -375,10 +375,13 @@
> false
>
> p1 * p2 ==
> - p1 case R => p1::R * p2
> + p1 case R =>
> + one?(p1::R) => p2
> + p1::R * p2
> p2 case R =>
> + one?(p2::R) => p1
> mvar := p1.v
> - up := p1.ts*p2
> + up := p1.ts * (p2::R)
> if ground? up then leadingCoefficient(up) else [mvar, up]$VPoly
> p1.v = p2.v =>
> mvar := p1.v
>
> --
> 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 fricas-devel...@googlegroups.com.
> To view this discussion visit https://groups.google.com/d/msgid/fricas-devel/ff102520-d143-490f-901c-1ca2334628a6%40gmail.com.

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