## [Sbcl-bugs] a feature request/ extending rational arithmetic

 [Sbcl-bugs] a feature request/ extending rational arithmetic From: Richard Fateman - 2013-03-29 23:53:00 ```I have found it convenient to extend, in principle, the CL rational numbers by allowing division by zero. In particular 0/0, 1/0 are legitimate numbers representing "undefined" -- like the floating point NaN, and an unsigned projective infinity. This project infinity makes sense if you think of the rational numbers as positions on a circle where infinity and minus infinity are the same point, opposite 0. To do so generally requires LESS WORK, in the following senses. 1. first use a modified gcd such that gcd(x,0)=x except if x=0, then the gcd is 1. Right now, (gcd -4 0) is 4 rather than -4, and (gcd 0 0) =1 rather than 1. 2. computing a/b+c/d one computes the ratio(a*d+c*b, b*d). then reduces.. if a/b = 1/0, the result is ratio(d,0), divide numerator and denominator by gcd(d,0) which is d, giving ratio(1,0). 3. computing a/b * c/d one computes the ratio(a*c/b*d). if a/b = 0/0, the result is ratio(0,0). divide by gcd(0,0)=1. giving ratio(0,0) if a/b = 1/0, the result is ratio(c,0), divide by gcd to get ration(1,0). reference.. http://www.cs.berkeley.edu/~fateman/papers/extrat.pdf fringe stuff: conversion to float formats: use NaN and Inf. It is also possible to produce an AFFINE model with rationals, allowing -1/0 to represent negative infinity. And I think this would be more useful. This however requires a little more checking. See the reference above for details. Why do I care? I would like to do interval arithmetic really neatly in SBCL, as opposed to slightly-less neatly. Ideally one would be able to patch the rational arithmetic in a running SBCL by reading in some file. (Code for this using a user-defined class ERAT for extended rational is available, but it's building a whole layer on top of the rationals.) Richard Fateman ```

 [Sbcl-bugs] a feature request/ extending rational arithmetic From: Richard Fateman - 2013-03-29 23:53:00 ```I have found it convenient to extend, in principle, the CL rational numbers by allowing division by zero. In particular 0/0, 1/0 are legitimate numbers representing "undefined" -- like the floating point NaN, and an unsigned projective infinity. This project infinity makes sense if you think of the rational numbers as positions on a circle where infinity and minus infinity are the same point, opposite 0. To do so generally requires LESS WORK, in the following senses. 1. first use a modified gcd such that gcd(x,0)=x except if x=0, then the gcd is 1. Right now, (gcd -4 0) is 4 rather than -4, and (gcd 0 0) =1 rather than 1. 2. computing a/b+c/d one computes the ratio(a*d+c*b, b*d). then reduces.. if a/b = 1/0, the result is ratio(d,0), divide numerator and denominator by gcd(d,0) which is d, giving ratio(1,0). 3. computing a/b * c/d one computes the ratio(a*c/b*d). if a/b = 0/0, the result is ratio(0,0). divide by gcd(0,0)=1. giving ratio(0,0) if a/b = 1/0, the result is ratio(c,0), divide by gcd to get ration(1,0). reference.. http://www.cs.berkeley.edu/~fateman/papers/extrat.pdf fringe stuff: conversion to float formats: use NaN and Inf. It is also possible to produce an AFFINE model with rationals, allowing -1/0 to represent negative infinity. And I think this would be more useful. This however requires a little more checking. See the reference above for details. Why do I care? I would like to do interval arithmetic really neatly in SBCL, as opposed to slightly-less neatly. Ideally one would be able to patch the rational arithmetic in a running SBCL by reading in some file. (Code for this using a user-defined class ERAT for extended rational is available, but it's building a whole layer on top of the rationals.) Richard Fateman ```