axiom-developer
[Top][All Lists]

[Axiom-developer] [Fraction]

 From: Ralf Hemmecke Subject: [Axiom-developer] [Fraction] Date: Mon, 06 Feb 2006 06:14:24 -0600

Changes http://wiki.axiom-developer.org/Fraction/diff
--

Maybe this text should go into another place (where?), but the above code shows
some danger.
It says (look at the representation):

Fraction(S: IntegralDomain): QuotientFieldCategory S with
...
== LocalAlgebra(S, S, S) add
Rep:= Record(num:S, den:S)
...
and in LocalAlgebra one can read
LocalAlgebra(A: Algebra R,
R: CommutativeRing,
S: SubsetCategory(Monoid, R)): Algebra R with
...
== Localize(A, R, S) add
...
where
Localize(M:Module R,
R:CommutativeRing,
S:SubsetCategory(Monoid, R)): Module R with
...
==
Rep:= Record(num:M,den:S)
...

If someone is going to change the Rep of Localize say
Rep := Record(somedata: SomeType, num: M, den: S)
then I suspect the code of Fraction will not work anymore.
The implementation of LocalAlgebra is fine, since it does not introduce a Rep,
but in Fraction there should also be no appearance of Rep.

The implementation of Fraction should completely do without Rep (information
hiding)
since it should not know about the concrete representation of elements in the
domain
LocalAlgebra.

In fact, the Category for Localize(M, R, S) is not rich enough. It already
exports two functions
numer: % -> M
++ numer x returns the numerator of x.
denom: % -> S
++ denom x returns the denominator of x.
but obviously its use in Fraction call for destructive functions
set!: (%, 'num', M) -> M
set!: (%, 'den', S) -> S