[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

*To*: JAR@MC.LCS.MIT.EDU*Subject*: small changes*From*: Alan Bawden <ALAN@MC.LCS.MIT.EDU>*Date*: Sun, 23 Mar 86 21:05:39 EST*cc*: RRRS-AUTHORS@MC.LCS.MIT.EDU*In-reply-to*: Msg of Sun 23 Mar 86 18:10:53 EST from Jonathan A Rees <JAR at MC.LCS.MIT.EDU>

Date: Sun, 23 Mar 86 18:10:53 EST From: Jonathan A Rees <JAR at MC> - Define GCD and LCM to work on Gaussian integers. (Complex numbers are inessential anyhow, so you won't be obliged to implement this - but I'll tell you how if you care.) - Define new procedures NUMERATOR and DENOMINATOR on nonzero Gaussian rationals which return canonical numerator and denominator (denominator will always be a positive integer). Super. I wanted these two in Common Lisp, but they were overlooked in the rush apparently. But you have to be careful about how you state the contract. What you have here is incorrect. GCD on integers always returns a non-negative result. On Gausian rationals you have to define some region of the complex plane that should contain the answer. You want it to include the non-negative integers for compatibility with the non-Gausian case. I would recommend { a+bi | a>0 & b>=0 or a=0 & b=0 }, which consists of the "first quadrant" and the non-negative real axis. LCM is constrained similarly for similar reasons. DENOMINATOR should also be defined to return a Gausian integer in the same region. It would be -incorrect- to always return a positive integer! For example, given (3/2)-(3/2)i, DENOMINATOR should return 1+i, since in lowest terms (3/2)-(3/2)i is 3/(1+i).

- Prev by Date:
**Scheme BNF** - Next by Date:
**Expunge LETREC, BEGIN and SEQUENCE.** - Prev by thread:
**small changes** - Next by thread:
**small changes** - Index(es):