problem with conditional exports

10 views
Skip to first unread message

Ralf Hemmecke

unread,
Apr 23, 2025, 5:33:28 AMApr 23
to fricas-devel
When I compile this ...

========================
)abbrev package FOO Foo
ZZ ==> Integer
LZZ ==> List ZZ
LLZZ ==> List LZZ
Foo: with
kleiner: (LLZZ, LLZZ) -> Boolean
== add
kleiner(x: LLZZ, y: LLZZ): Boolean == x <$LLZZ y
========================

I get

FOO abbreviates package Foo
------------------------------------------------------------------------
initializing NRLIB FOO for Foo
compiling into NRLIB FOO
compiling exported kleiner : (List List Integer,List List Integer)
-> Boolean
****** comp fails at level 1 with expression: ******
error in function kleiner

(((|Sel| (|List| (|List| (|Integer|))) <) |x| |y|))
****** level 1 ******
x:= ((Sel (List (List (Integer))) <) x y)
m:= (Boolean)
f:=
((((|y| # . #1=#) (|x| # . #2=#) (|y| . #1#) (|x| . #2#) ...)))

>> Apparent user error:
not known that (List (List (Integer))) has (AND (has (List (List
(Integer))) (finiteAggregate)) (has (List (Integer)) (OrderedSet)))

The compiler obviously has problems figuring out that List List Integer
must export <, because Integer and, therefore, also List(Integer) has
OrderedSet.

How can do I convince the compiler to produce the right code?

Ralf

Waldek Hebisch

unread,
Apr 28, 2025, 10:30:25 AMApr 28
to 'Ralf Hemmecke' via FriCAS - computer algebra system
One trick that sometimes work is writing package body like:

if LLZZ has _< : (LLZZ, LLZZ) -> Boolean then
kleiner(x: LLZZ, y: LLZZ): Boolean == x <$LLZZ y

That compiles, but apparently does not work. Which means that
Spad runtime has trouble finding '<'.

Deeper analysis shows that the message above has some merit: compiler
uses an utility function to check if conditions are statisfied.
For '<' there are two conditions: argument of the domain has
OrderedSet and domain (that is %) had finiteAggregate. Argument
of domain is List(Integer) and in this case check that % has
finiteAggregate fails. This failure is because condition
checking code does not properly track changing meaning of %
and at that point % is still your package (which does not have
finiteAggregate).

This is a bug in Spad compiler, I am noit sure how much effort
it will take to fix it.

And to literally answer your question, the following compiles
and AFAICS generates right code:

)abbrev package FOO Foo
ZZ ==> Integer
LZZ ==> List ZZ
LLZZ ==> List LZZ
Foo: finiteAggregate with
kleiner: (LLZZ, LLZZ) -> Boolean
== add
kleiner(x: LLZZ, y: LLZZ): Boolean == x <$LLZZ y

Of course, declaring that your package has finiteAggregate makes
no sense, but this is condition is checked due to bug...

--
Waldek Hebisch

Waldek Hebisch

unread,
May 16, 2025, 8:16:51 PMMay 16
to 'Ralf Hemmecke' via FriCAS - computer algebra system
On Wed, Apr 23, 2025 at 11:33:23AM +0200, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> When I compile this ...
>
> ========================
> )abbrev package FOO Foo
> ZZ ==> Integer
> LZZ ==> List ZZ
> LLZZ ==> List LZZ
> Foo: with
> kleiner: (LLZZ, LLZZ) -> Boolean
> == add
> kleiner(x: LLZZ, y: LLZZ): Boolean == x <$LLZZ y
> ========================
>
> I get
>
<snip>
> >> Apparent user error:
> not known that (List (List (Integer))) has (AND (has (List (List
> (Integer))) (finiteAggregate)) (has (List (Integer)) (OrderedSet)))

As I wrote this was a bug. I have now commited a change that
mostly fixes this, in particular I can compile your program.
AFACS this is not a complete fix, there still may be troubles
in some special cases, but should be much better than before.

--
Waldek Hebisch

Ralf Hemmecke

unread,
May 18, 2025, 9:23:04 AMMay 18
to fricas...@googlegroups.com
Dear Waldek,

thank you for taking care of this and the other issues that I submitted
recently.

Ralf
Reply all
Reply to author
Forward
0 new messages