# Questions about srfi-77 Generic Arithmetic

I'm trying to understand the R5RS-style Generic Arithmetic and I have some questions. Please forgive me if some of these have been answered previously.


1. In the first paragraph it says "The generic operations all implement inexact operations." What does that mean?


2. In the first paragraph it says "A number is inexact if it is infinite, if it was written as an inexact constant, if it was derived using inexact ingredients, or if it was derived using inexact operations."
    (a) I prefer some other word to "ingredients".

(b) What is an inexact operation? The in* functions? Or, do you mean every operation in this section?
    (c) If 0 denotes exact 0 and 1 denotes exact 1, I prefer
(log 1) = (sin 0)=(asin 0)=(atan 0)=(tan 0)=...=0
and
(cos 0) = (exp 0)=1,

in the same way that I prefer (sqrt 4) = 2 (where 4 denotes exact 4 and 2 denotes exact 2). Is this allowed in your proposal?


3. Paragraph 6 says "With the exception of inexact->exact, the operations described in this section must return inexact results when given any inexact arguments." (a) I prefer (* 0 x) => 0 for any x; is this allowed in your proposal? (The principle here is that if you get the same answer for any possible exact x, then you should get the same answer for any inexact x, too, even if +inf.0, -inf.0, or +nan.0.) I don't see that there is not a conflict here with "The procedures described here behave consistently with the inexact arithmetic if passed inexact arguments, and consistently with the exact arithmetic if passed exact arguments;" we have to decide what to do when mixing exact and inexact arguments.


4. "nan?" takes any complex as an argument. If the real or imaginary part of z is a NaN, and the other is rational, does that make z a NaN?
Maybe you should restrict the argument of nan? to be real.


5. Re: "If any of these procedures are applied to mixed non-rational real and non-real complex arguments, they either report a violation of an implementation restriction or return an unspecified number." What does this mean? That
      (+ +nan.0 +4.0i)

is not specified? Are you allowing here an implementation to use the computable reals as the inexact representation? I really don't understand this.


6. Perhaps you should remove strictly double argument "-" and "/" from the manual, since this case is subsumed into the case with two or more arguments.


7. Why do "-" and "/" not have the commentary "If any of these procedures are applied to mixed non-rational real and non-real complex arguments, they either report a violation of an implementation restriction or return an unspecified number."?

8.  Integer Divison.

(a) I think it is a really bad design to have the basic operation of div+mod change when the second argument changes sign.
    (b) I think it is a really bad design to have
(div x1 0) => 0

It conflicts with the requirement in quotient+remainder, quotient, remainder, and modulo that "n2 should be nonzero". (Unless I read "should" here in the language lawyer sense, i.e., that it is totally nonprescriptive.) The only way I can think of making division by exact 0 make sense is by divorcing the meaning of "div" from any notion of mathematical division. (c) This is one place where the Rationale says to refer to Egner et al. to see an argument why these procedures "are better suited than quotient and remainder to implement modular reduction." As a point of procedure, I would really prefer to have the arguments included in this document; I don't want to have to discuss my opinions of Egner et al. just to discuss my opinions of this specific proposal.


9. I don't agree that +inf.0, -inf.0, and +nan.0 should be in the domain of floor, round, ceiling, and truncate; returning these values as results implies, to me, that they are integers, and I believe they aren't integers, since they aren't rational.


10. I don't agree that rationalize should take +inf.0, -inf.0, or +nan.0 as arguments. "Rationalize" should, by its nature and name, return a rational value, and I don't believe that +inf.0, -inf.0, or +nan.0 are rational.


11. Re: log, etc. You have the statement "If the function has a real- valued limit as its argument tends toward positive infinity, then that is the value returned by the function applied to +inf.0. If the function has a real-valued limit as its argument tends toward negative infinity, then that is the value returned by the function applied to -inf.0." Why are complex-valued limits not specified, too?


Also, you have "In the event that these formulae do not yield a real result for the given arguments, the result may be +nan.0, or may be some meaningless inexact number." I don't understand the reason for this statement.

12. (a) You give the examples:
(log +inf.0) => +inf.0
(log -1.0+0.0i) => 0.0+pii
(log -1.0-0.0i) => 0.0-pii
yet
(log -inf.0) => unspecified
Given the previous examples, shouldn't
(log -inf.0) => +inf.0+pii


(b) You don't say what (log 0) evaluates to; I would prefer it to be an error.


13. For sqrt: Is your intention to no longer have sqrt return exact results when possible given exact arguments? Or will
     (sqrt 4) => 2
(sqrt z) => (exp (/ (log z) 2.0))

seems to preclude it by putting in that inexact 2. Do you mean the right hand side of this formula literally, with exp and log being Scheme procedures, or do you mean to represent the mathematical formula $e^{\log(z)/2}$ (in TeX notation).

13 bis: Again for sqrt, why is
(sqrt -inf.0) => unspecified
and not
(sqrt -inf.0) => +inf.0i
You didn't have any problem with
(log 0.0) => -inf.0


14. About expt: In contrast to my comments about sqrt, I note that your definition of expt uses mathematical notation to define it, so
     (expt 5 3)  => 125, not 125.0
is not only allowed, but required?  Is
(expt 125 1/3) => 5
allowed?

15.  I agree with Knuth, and would very much prefer
(expt 0 0) => 1
so that the binomial expansion formula
x^n = (x+0)^n = x^n\times 0^0 + nx^{n-1}\times 0^2+...
holds.  In fact, for any other z1, I would also have
(expt z1 0) => (exp (* 0 (log z1))) => (exp 0) => 1


16. About magnitude: Following Kahan, I think it should be required that
     (magnitude z) => +inf.0

if either the real or imaginary part of z is infinite (even if the other part is a NaN). Here Kahan is following the argument that, if the real or imaginary part is infinite, you would get the same answer no matter the (finite) value of the other part, so you should give that answer even if the other part is infinite or NaN.