default category packages that overlap

4 views
Skip to first unread message

Ralf Hemmecke

unread,
Jun 22, 2025, 12:32:08 PMJun 22
to fricas-devel
Hi Waldek,

I just found another instance of an overlapping default implementations.

In AbelianGroup
https://github.com/fricas/fricas/blob/master/src/algebra/catdef.spad#L34
opposite?(x,y) == x = -y

In AbelianMonoid
https://github.com/fricas/fricas/blob/master/src/algebra/catdef.spad#L75
opposite?(x,y) == zero?(x + y)

While this looks computationally equally expansive, the problem
certainly is for functions that can be implemented more efficiently, in
richer structures.

A few lines above
https://github.com/fricas/fricas/blob/master/src/algebra/catdef.spad#L29
I find

if not (% has Ring) then ...

which does not really look attractive to me since it makes AbelianMonoid
depending on Ring and thus creating an actually needless circular
dependency.

Anyhow, the common understanding is still that it is **undefined** which
of the overlapping default implementations is actually used when a
domain does not explicitly implements that function, right?

Ralf

Waldek Hebisch

unread,
Jun 22, 2025, 1:24:11 PMJun 22
to 'Ralf Hemmecke' via FriCAS - computer algebra system
On Sun, Jun 22, 2025 at 06:32:04PM +0200, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> Hi Waldek,
>
> I just found another instance of an overlapping default implementations.
>
> In AbelianGroup
> https://github.com/fricas/fricas/blob/master/src/algebra/catdef.spad#L34
> opposite?(x,y) == x = -y
>
> In AbelianMonoid
> https://github.com/fricas/fricas/blob/master/src/algebra/catdef.spad#L75
> opposite?(x,y) == zero?(x + y)

Yes, the definition in AbelianGroup would not work in AbelianMonoid,
so we need different definition.

> While this looks computationally equally expansive, the problem certainly is
> for functions that can be implemented more efficiently, in richer
> structures.
>
> A few lines above
> https://github.com/fricas/fricas/blob/master/src/algebra/catdef.spad#L29
> I find
>
> if not (% has Ring) then ...
>
> which does not really look attractive to me since it makes AbelianMonoid
> depending on Ring and thus creating an actually needless circular
> dependency.

That is really not circular: default package of AbelianMonoid depends
on Ring, but default package is different than AbelianMonoid and
compilation of Ring does not depend on default package of AbelianMonoid.

> Anyhow, the common understanding is still that it is **undefined** which of
> the overlapping default implementations is actually used when a domain does
> not explicitly implements that function, right?

Well, there is search order which is defined, but probably it is
unwise to depend in search order. You can depend on fact that
strictly more specific definition will be choosen in preference
to less specific one (but things get complicated when there are
definitions uncomparable in generality). What is really undefined
is overload resolution, that is decision which category declares
given operation. When you look at operations in HyperDoc
"Origin" is supposed to tell you this, but several origins may
give matching signature and there is possibility for different
types.

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