[PATCH] cleanup "*" in MRING

5 views
Skip to first unread message

oldk1331

unread,
Jul 23, 2019, 8:20:05 AM7/23/19
to fricas...@googlegroups.com
The local function "sortAndAdd" is almost the same as
"construct", but less efficient: it creates new "Term"
instead of using existing ones.

Also, the usage of "+" in "*" can also be omitted:
we can use the newly added "concat!" and pass the whole
list to "construct!".
cleanup_*_in_MRING_when_not_OrderedMonoid.patch

Waldek Hebisch

unread,
Jul 24, 2019, 9:56:02 AM7/24/19
to fricas...@googlegroups.com
It is not clear for me that we can do this. Existing code
is quite careful to eliminate terms with zero coefficient.
In your code it is not clear if/how this is done.

--
Waldek Hebisch

oldk1331

unread,
Jul 24, 2019, 10:55:25 AM7/24/19
to fricas...@googlegroups.com
Isn't "construct" carefully eliminate terms with zero coefficient?

--
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 on the web visit https://groups.google.com/d/msgid/fricas-devel/E1hqHkK-0000TH-Oe%40hera.math.uni.wroc.pl.

Waldek Hebisch

unread,
Jul 24, 2019, 11:32:10 AM7/24/19
to fricas...@googlegroups.com
oldk1331 wrote:
>
> Isn't "construct" carefully eliminate terms with zero coefficient?

'construct' for MonoidRing is should eliminate terms with zero
coefficients, but IIUC it is quite slow. You called 'construct!'
which seem to be defiend only for aggregates. For aggregates
eliminating zero coefficients would be incorrect...

--
Waldek Hebisch

oldk1331

unread,
Jul 24, 2019, 8:09:28 PM7/24/19
to fricas...@googlegroups.com
"construct" is not slow, it just sorts its argument
and scans it once. "construct!" just skips one
copy. They are faster than "sortAndAdd" or "+".

--
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.

oldk1331

unread,
Jul 25, 2019, 7:51:46 AM7/25/19
to fricas...@googlegroups.com
Actually, it's not necessary to treat differently for
OrderedMonoid/noZeroDivisors.  We can simply have

    a : % * b : % ==
        zero? a or zero? b => 0
        construct! concat! [[[ta.Mn*tb.Mn, ta.Cf*tb.Cf]$Term
            for tb in b] for ta in a]

we collect all the terms and let "construct" do the heavy lifting.
See my updated patch.

It's possible to do better though, for OrderedMonoid, we can do a
k-way merge, but we don't have such algorithm at hand.

My patch should already make this function much faster by
skipping allocation of temporary result of "+".
cleanup_*_in_MRING_v2.patch

oldk1331

unread,
Jul 26, 2019, 2:49:29 AM7/26/19
to fricas...@googlegroups.com
On 7/25/19 7:51 PM, oldk1331 wrote:
> Actually, it's not necessary to treat differently for
> OrderedMonoid/noZeroDivisors.  We can simply have
>
>     a : % * b : % ==
>         zero? a or zero? b => 0
>         construct! concat! [[[ta.Mn*tb.Mn, ta.Cf*tb.Cf]$Term
>             for tb in b] for ta in a]
>
> we collect all the terms and let "construct" do the heavy lifting.
> See my updated patch.

There is a serious problem in "construct" though, it may
modify the content of a "Term":

t1.c:= t1.c+t2.c

We should create new cells instead of reusing old ones.
Reply all
Reply to author
Forward
0 new messages