listOfTerms vs terms

5 views
Skip to first unread message

Ralf Hemmecke

unread,
Dec 7, 2025, 8:00:33 PMDec 7
to fricas-devel
I wonder why we need a copy of the data structure for "terms" but not
for "listOfTerms". The specification unfortunately says nothing about
what the expected behaviour shoulld be. A copy is certainly safer, but
do we really need/want it?

Anyway, the docstring for "terms" claims "This is the internal
representation.". But it actually is a copy of it.

I also do not see why the implementation of "listOfTerms" appears under
the "if M has Comparable then ..." condition. Is it just because its
doctrics says something about "construct(listOfTerms x)=x" and
"construct" involves "smaller?" ?

Ralf

https://github.com/fricas/fricas/blob/master/src/algebra/mring.spad#L125


https://github.com/fricas/fricas/blob/master/src/algebra/mring.spad#L205

Waldek Hebisch

unread,
Dec 21, 2025, 10:07:07 AM (10 days ago) Dec 21
to 'Ralf Hemmecke' via FriCAS - computer algebra system
On Mon, Dec 08, 2025 at 02:00:29AM +0100, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> I wonder why we need a copy of the data structure for "terms" but not for
> "listOfTerms". The specification unfortunately says nothing about
> what the expected behaviour shoulld be. A copy is certainly safer, but do we
> really need/want it?

AFAICS copy is due to possibility of incorrect use. 'terms' is widely
used so I think copy was inserted either due to buggy uses or for
consistency with other places that do a copy.

In principle functions like 'terms' should be non-copying, and instead
all use places should be modified to avoid mutation. But we do not
have automation to enforce immutability where we need it, so copy
is a progamtic choice.

> Anyway, the docstring for "terms" claims "This is the internal
> representation.". But it actually is a copy of it.
>
> I also do not see why the implementation of "listOfTerms" appears under the
> "if M has Comparable then ..." condition. Is it just because its doctrics
> says something about "construct(listOfTerms x)=x" and "construct" involves
> "smaller?" ?

That is mostly historic. 'listOfTerms' was introduced partly as a
speedup, partly to allow sharing of low sevel code by several
domain. This is limited use interface, so there is much less
chance for bugs.

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