representation depending on a parameter

4 views
Skip to first unread message

Ralf Hemmecke

unread,
Aug 31, 2025, 6:48:27 PM (8 days ago) Aug 31
to fricas-devel
I thought the following would be possible in SPAD.

-----------------------------
)abbrev package FOO Foo
Foo(n: Integer): Exports == Implementation where
Exports ==> Ring
Implementation ==>
n > 2 => Fraction Integer
Integer
-----------------------------

However, it gives

%%% (148) -> )co ../foo
Compiling FriCAS source code from file
/home/hemmecke/backup/git/qeta/tmp/../foo.spad using system
compiler.
FOO abbreviates package Foo
****** comp fails at level 1 with expression: ******
((DEF (|Foo| |n|) ((|Ring|) (|Integer|))
(IF (> |n| 2)
(|Fraction| (|Integer|))
(|Integer|))))
****** level 1 ******
x:= (DEF (Foo n) ((Ring) (Integer)) (IF (> n 2) (Fraction (Integer))
(Integer)))
m:= $EmptyMode
f:=
((((|$DomainsInScope| # #))))

>> Apparent user error:
bad == form
(DEF (Foo n) ((Ring) ) (IF (> n 2) (Fraction (Integer)) (Integer)))

Cannot I implement a domain that uses a certain representation depending
on an argument.

Actually, Expression is doing that, but it does it with only one "add"
keyword.

Of course, in the above example, I actually want

Implementation ==>
n > 2 => Fraction Integer add ...
Integer add ...

i.e. with a few more function. But since it does not work even without
the "add" ...

Is this a weakness of the SPAD-compiler?

Ralf

Waldek Hebisch

unread,
Aug 31, 2025, 7:26:50 PM (8 days ago) Aug 31
to 'Ralf Hemmecke' via FriCAS - computer algebra system
<snip>
> Is this a weakness of the SPAD-compiler?

Try the following:

)abbrev package FOO Foo
Foo(n: Integer): Exports == Implementation where
Exports ==> Ring
Implementation ==> (n > 2 => Fraction(Integer); Integer) add
foo () : Integer == 1

I do not know if it works, but at least for me it compiles.
Note that there is one and only one 'add' here.

Yes, it is a weakness in SPAD compiler. Theoretically without 'add'
your definition should work, but you get what you get.

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