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

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

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/fricas-devel/aA-Q_QYByBAUFyPS%40fricas.org.

Reply via email to