Ralf Hemmecke wrote:
> 
> FriCAS Integer implements exquo via
> 
> INTEXQUO(x, y)$Lisp
> 
> https://github.com/fricas/fricas/blob/master/src/algebra/integer.spad#L143
> 
> I have several places where I know from context that the division will
> not fail (I divide out a gcd). Wouldn't it make sense to expose INTEXQUO
> in Integer as
> 
> exactQuotient(x: %, y: %): % == INTEXQUO(x, y)$Lisp pretend %
> 
> with the docstring saying
> 
> ++ exactQuotient(x, y) returns an integer z such that x = y * z
> ++ if such a z exists. The result is undefined if such a z does
> ++ not exist.
> 
> Clearly, that is a partial function. But I think it makes sense to also
> expose useful partial functions without putting the result in
> Union(Integer, "failed").
> Isn't it a waste to put an integer into a union, if the first thing a
> user does is to simply take out the integer from the union structure?

Currently all ways of computing quotient of integeres also compute
remainder.  What differs is the way to throw out remainder.  AFAICS
the most efficient should be 'quo' which just forgets about remainder.
INTEXQUO parforms extra checks and you propose to ignore result
of this checking.  In case of wrong use 'quo' will give wrong result,
INTEXQUO(x, y)$Lisp pretend % probably will give a crash, I am
not sure if one is preferable to another.

Concerning waste: typical use is via '(x exquo y)::Integer' which
will signal error in case of inexact division.  So this is really
cost of checking.  If one really cares about speed of 'exquo'
then probably one will use machine sized integers (SingleInteger)
if possible.

Of course logically 'exactQuotient' makes sense, but I am a bit
reluctant given that 'quo' has equivalent effect and for clarity
one can do

   exactQuotient(x, y) ==> x quo y

-- 
                              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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to