1 is NonNegativeInteger

4 views
Skip to first unread message

Ralf Hemmecke

unread,
Mar 8, 2021, 11:21:04 AM3/8/21
to fricas-devel
Just for the record.

In my code I had something like this where
LZ ==> List Integer

qetaGrades(x: %): LZ ==
zero? x => [-1 for k in 1..ncusps]
[qetaGrade(x, k pretend PositiveInteger) for k in 1..ncusps]

That compiles fine. Now I ran into a case where "zero? x" was true.
Instead of getting a list of -1 entries, I got:

Function: -? : % -> % is missing from domain: NonNegativeInteger
Internal Error
The function - with signature $$ is missing from domain
NonNegativeInteger

It is easy to resolve via "-1$Integer", but it is sad that the compiler
accepts something and then produces code that throws an error, is not good.

I wonder by what mechanism the SPAD compiler finds a function "-" with
signature NonNegativeInteger -> Integer.

Ralf

Waldek Hebisch

unread,
Mar 8, 2021, 12:58:38 PM3/8/21
to fricas...@googlegroups.com
You posted incomplete code. When I added declarations needed to
compile it Spad compiler treated -1 as an Integer constant (as
it should) and there were no call to '-'.

If you want details you need to provide actual compilable testcase.
If you want abstract divagations, note that '-' is defined in
categories on condition that NonNegativeInteger has AbelianGroup.
Compiler should be smart enough to note that this condition
is false, but sometimes passes inconclusive cases to be
caught at runtime (if condition is actually satisfied, then
code works fine).
--
Waldek Hebisch

Ralf Hemmecke

unread,
Mar 9, 2021, 4:16:40 AM3/9/21
to fricas...@googlegroups.com
> You posted incomplete code.

I know. It took, however some time to construct a sufficiently small
example, see attachment.

Compile via ")co foo.spad".

(1) -> qetaGrades(0$Foo)
Function: -? : % -> % is missing from domain: NonNegativeInteger
Internal Error
The function - with signature $$ is missing from domain
NonNegativeInteger

You might wonder why there is

import from PositiveInteger

but originally I had there a statement

ncusps: P := fun(cusps)

where cusps was a parameter of type List Fraction Integer in the
arguments of Foo.

Maybe you want to change AbelianGroup to AbelianMonoid. Then the output
is correctly [-1, -1]. Strange.

As I said, I don't need a fix, but you wanted a short example.

Ralf
foo.spad
Reply all
Reply to author
Forward
0 new messages