On Sat, Jun 21, 2025 at 01:40:15PM +0200, 'Ralf Hemmecke' via FriCAS - computer algebra system wrote:
> Ooops. In OrderedRing I find
>
> positive? x == x>0
> negative? x == x<0
> sign x ==
> positive? x => 1
> negative? x => -1
> zero? x => 0
> error "x satisfies neither positive?, negative? or zero?"
> abs x ==
> positive? x => x
> negative? x => -x
> zero? x => 0
> error "x satisfies neither positive?, negative? or zero?"
>
> If a ring is equipped with a total order, how can this error case ever
> occur? It would mean there are elements that are neither 0 nor smaller nor
> bigger than 0. What kind of total order is this?
>
> Or is it taking care of the Float domain? But Float is only a fake ring for
> convenience. In the long run I would like to take away the Ring property
> from Float.
AFAICS Float has honest linear order. That could be for DoubleFloat
where due to IEEE thing hardware will return stupid results. But I
suspect that this is just "defensive" coding.
BTW: DoubleFloat should use hardware or system abs and sign, so our
definitions above should not matter for it.
> Anyway, if I now provide a patch in moving the above functions to
> OrderedAbelianGroup, I would like to remove this error case. But I fear that
> this might change something in other places of FriCAS.
I would probably write:
abs(x) ==
x < 0 => -x
x
and similar for sign. But error case does not bother me too much.
If there are bugs in say comparison routine, than getting error
is slightly better than propagating further wrong result.
Your current patch is reasonable. But it is also reasonable to
eliminate error cases.
BTW: You can find a few 'error "impossible"' instructions that
I wrote. Assuming that there are no errors in coding and
reasoning they will be never executed. But practice is
imperfect, and some of those actually produced error message.
--
Waldek Hebisch