floor/ceiling, ^, Syntax for categories with "with"

6 views
Skip to first unread message

Prof. Dr. Johannes Grabmeier privat

unread,
Jan 7, 2021, 4:01:06 AM1/7/21
to fricas...@googlegroups.com
Dear all,

writing code for apportionment methods (election, votes and seats) I
heavily need floor and ceiling: % -> Integer - the code should work for
Fraction Integer, DecimalExpansion and Floats

However, the two method in Float have signatures floor, ceiling: % -> %
(should be unified to have function name overloading).
One way out is to define a ExtendedFloat (EFLOAT) with these 2
signatures added, which I did

and having the following conditional code for a package parametrized by
a field K:

if K has with (floor: K -> Integer; ceiling: K -> Integer)

It then works, but in the interpreter I get an error for this:

(297) -> EFLOAT has with (floor: % -> Integer; ceiling: % -> Integer)
   Internal Error
   Unexpected error in call to system function pf2Sex1


Questions to syntax variations of this:

It also compiles if one drops the "with"

if K has with (floor: K -> Integer; ceiling: K -> Integer)

Can someone give a detailed description of the syntax and semantics of
"with"?


Things becomes more complicated using infix functions, which I also have
to use:

if K has with ("^": (K, Fraction Integer) -> K) then

The following behaviour is surprising: I extended Fraction Integer do
ExtendedFraction Integer to include such an approximating powering also
for the rational numbers. Then my package with parameter K = Extended
Fraction Integer recognizes the signatures defined under this condition.
However, the normal Float, which has such a signature implemented in the
system is not recognized. Mysterious.

Testing in the interpreter fails using "with"

(301) -> Float has with ("^": (%, Fraction Integer) -> %)

  Line   1: Float has with ("^": (%, Fraction Integer) -> %)
           ...............AB
  Error  A: Missing mate.
  Error  B: syntax error at top level
  Error  B: Possibly missing a )
   3 error(s) parsing

(301) -> Float has with (^: (%, Fraction Integer) -> %)

   Internal Error
   Unexpected error in call to system function pf2Sex1

(301) -> Float has with (_^: (%, Fraction Integer) -> %)

   Internal Error
   Unexpected error in call to system function pf2Sex1


However it works (partially) without the "with":


(302) -> Float has  (_^: (%, Fraction Integer) -> %)

   (302)  true
                                                                                      
Type: Boolean
                                                                                        
Time: 0 sec
(303) -> Float has  ("^": (%, Fraction Integer) -> %)

   (303)  false
                                                                                      
Type: Boolean
                                                                         
Time: 0.04 (OT) = 0.04 sec
(304) -> Float has  (^: (%, Fraction Integer) -> %)

   (304)  true


Can one unify Interpreter and Compiler and communicate clear (and unique
rules) for infix functions and escaping?



--
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
Tel. +49-(0)-991-3615-141 (d), Fax: +49-(0)-32224-192688

Waldek Hebisch

unread,
Jan 8, 2021, 2:01:02 PM1/8/21
to fricas...@googlegroups.com
1) 'with' is unsupported (unimplemented) in the interpreter. We
probably should add more sensible error message.

2)
> if K has with ("^": (K, Fraction Integer) -> K) then
>
> The following behaviour is surprising: I extended Fraction Integer do
> ExtendedFraction Integer to include such an approximating powering also
> for the rational numbers. Then my package with parameter K = Extended
> Fraction Integer recognizes the signatures defined under this condition.
> However, the normal Float, which has such a signature implemented in the
> system is not recognized. Mysterious.

Interpreter does not understand "^" above. Try:

K has _^ : ((%, Fraction Integer) -> %)


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