Basic question to rep and call of elt

7 views
Skip to first unread message

Prof. Dr. Johannes Grabmeier

unread,
Oct 19, 2024, 9:54:46 AM10/19/24
to fricas...@googlegroups.com
I am revising Partition represented by List Integer:

    Rep := List Integer
    rep x ==> (x @ %) pretend Rep
    per x ==> (x @ Rep) pretend %

then I have a function

entries(p: %): List Integer == copy rep p

which is used for elt from Eltable(Integer, Integer):

    elt(p: %, i: Integer): Integer  ==
      i <= 0 => error "elt requires a positive second argument."
      i > #p => error "elt: second argument too large."
      entries(p).i

However, this constructs an infinite loop of calls to elt. Seamingly the
elt from List Integer ( as I thinks this could should point to) is not
called, but it uses the just defined elt from Partition.

The code is fixed by explicit function call:

elt(entries(p),i)$List(Integer)

Question: What is wrong here? Or if not  wrong, what is my misunderstanding?

--
Mit freundlichen Grüßen

Johannes Grabmeier

Prof. Dr. Johannes Grabmeier,
Köckstraße 1, D-94469 Deggendorf
Tel. +49-(0)-991-2979584, Tel. +49-(0)-151-681-70756
Fax: +49-(0)-991-2979592

Qian Yun

unread,
Oct 19, 2024, 10:12:57 AM10/19/24
to fricas...@googlegroups.com
Hi, showing a spad file that contains a minimal reproducible
example would be very helpful for people to debug.

If you want to debug it your self, you can utilize tools like
")trace", or ")set break break" and Ctrl-C and "backtrace"
to examine the call stack, or use the good old "printf" to debug.

From the posted snippet, I don't see a problem yet.

- Qian

On 10/19/24 9:54 PM, 'Prof. Dr. Johannes Grabmeier' via FriCAS -

Prof. Dr. Johannes Grabmeier

unread,
Oct 19, 2024, 10:18:53 AM10/19/24
to fricas...@googlegroups.com
I solved the problem and traced it, so this is not the point. The system
simply calls elt$Partition when I coded

entries(p).i

It should call elt$List(Integer) - after all enries(p) is a List Integer
and no longer represents a Partition!!

Somehow elt from Partition has higher priority and entries(p) seems to
be automatically converted to a Partition, which I think is wrong

I can send the code (when I finished revision) for put into the system
anyway.

Am 19.10.24 um 16:12 schrieb Qian Yun:

Ralf Hemmecke

unread,
Oct 19, 2024, 12:32:18 PM10/19/24
to fricas...@googlegroups.com
Indeed, a working example would always be helpful, but in this case
it seems that the compiler auto-coerces "entries(p)" into something of
type % and then the ".i" must be interpreted as elt from %.

Admittedly, it is sometimes nice that the compiler treats equally. But I
wouldn't mind to insert per's and rep's explicitly just to be clear
whether the object at hand is to be seen as something of type % or of
type Rep. Note that both types usually can come with quite different
exports.

I must say that after all these years I have not seen a documented rule
of how and when an element is auto-coerced (or rather "pretend"ed to Rep
or %. Similarly, I am missing the rul for X and Union(X,"failed").

Anyway, to me it looks like a compiler error.

Ralf

Grégory Vanuxem

unread,
Oct 19, 2024, 1:04:15 PM10/19/24
to fricas...@googlegroups.com
Hello,

Le sam. 19 oct. 2024 à 16:18, 'Prof. Dr. Johannes Grabmeier' via FriCAS - computer algebra system <fricas...@googlegroups.com> a écrit :
I solved the problem and traced it, so this is not the point. The system
simply calls elt$Partition when I coded

entries(p).i

It should call elt$List(Integer) - after all enries(p) is a List Integer
and no longer represents a Partition!!

Somehow elt from Partition has higher priority and entries(p) seems to
be automatically converted to a Partition, which I think is wrong

I don’t how you solved your problem but I encountered several times this. Usually I "helps" the compiler using a temporary variable and even declare its type for the affectation. Maybe but I am not sure the . (dot) is compiled differently than using elt or qelt. Maybe you have tried this solution (elt or qelt)?

- Greg

--
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/ab5bef64-ecaf-42da-9a63-dfe64ab29a2d%40grabmeier.net.

Prof. Dr. Johannes Grabmeier

unread,
Oct 19, 2024, 1:10:14 PM10/19/24
to fricas...@googlegroups.com

Mit freundlichen Grüßen
Johannes Grabmeier 

Am 19.10.2024 um 19:04 schrieb Grégory Vanuxem <g.va...@gmail.com>:



Prof. Dr. Johannes Grabmeier

unread,
Oct 19, 2024, 1:10:21 PM10/19/24
to fricas...@googlegroups.com

Mit freundlichen Grüßen
Johannes Grabmeier 
Am 19.10.2024 um 19:04 schrieb Grégory Vanuxem <g.va...@gmail.com>:



Grégory Vanuxem

unread,
Oct 19, 2024, 1:16:52 PM10/19/24
to fricas...@googlegroups.com
Le sam. 19 oct. 2024 à 18:32, 'Ralf Hemmecke' via FriCAS - computer algebra system <fricas...@googlegroups.com> a écrit :

Admittedly, it is sometimes nice that the compiler treats equally. But I
wouldn't mind to insert per's and rep's explicitly just to be clear
whether the object at hand is to be seen as something of type % or of
type Rep.

From my point of view Rep is completely private, encapsulated, and it is up to the developer of the domain to use or not operations from the internal representation, here, List(Integer). And otherwise throw an error if it is not defined in the domain being developed and not explicitly called using the Rep domain.

Note that both types usually can come with quite different
exports.

Completely.



I must say that after all these years I have not seen a documented rule
of how and when an element is auto-coerced (or rather "pretend"ed to Rep
or %. Similarly, I am missing the rul for X and Union(X,"failed").

Anyway, to me it looks like a compiler error.

I think so too.

- Greg

Grégory Vanuxem

unread,
Oct 19, 2024, 2:04:43 PM10/19/24
to fricas...@googlegroups.com
You forgot something apparently.

Grégory Vanuxem

unread,
Oct 19, 2024, 2:44:13 PM10/19/24
to fricas...@googlegroups.com
Non. Moi.
Reply all
Reply to author
Forward
0 new messages