diff -ur ../axiom-old/src/algebra/fraction.spad.pamphlet src/algebra/fraction.spad.pamphlet
--- ../axiom-old/src/algebra/fraction.spad.pamphlet	2005-01-05 00:47:38.000000000 +0100
+++ src/algebra/fraction.spad.pamphlet	2005-03-23 14:32:49.000000000 +0100
@@ -405,222 +405,284 @@
            then canonical
             ++ \spad{canonical} means that equal elements are in fact identical.
   == LocalAlgebra(S, S, S) add
-    Rep:= Record(num:S, den:S)
-    coerce(d:S):% == [d,1]
-    zero?(x:%) == zero? x.num
+    if S is Integer then
+	x,y: %
+        0 == 0$Lisp
+        1 == 1$Lisp
+        numer(x) ==  NUMERATOR(x)$Lisp
+        denom(x) == DENOMINATOR(x)$Lisp
+        numerator(x) == NUMERATOR(x)$Lisp
+        denominator(x) == DENOMINATOR(x)$Lisp
+        coerce(d:S):% == d pretend %
+        zero?(x) == ZEROP(x)$Lisp
+        one?(x) == x = 1
+	_^(x:%, n:Integer):% == x ** n
+     	x ** n: Integer == EXPT(x,n)$Lisp
+	_^(x:%, n:PositiveInteger):% == x ** n
+      	x ** n: PositiveInteger == EXPT(x,n)$Lisp
+	_^(x:%, n:NonNegativeInteger):% == x ** n
+     	x ** n: NonNegativeInteger == EXPT(x,n)$Lisp
+        x = y == EQL(x,y)$Lisp
+	x < y == (x<y)$Lisp
+        - x == (-x)$Lisp
+        retract(x):S ==
+        	DENOMINATOR(x)$Lisp = 1 => x pretend S
+	        error "Denominator not equal to 1"
+
+        retractIfCan(x):Union(S, "failed") ==
+--		CONSP(x)$Lisp and NOT(EQL(CDR(x)$Lisp,1)$Lisp)$Lisp => "failed"
+        	DENOMINATOR(x)$Lisp = 1 => x pretend S
+	        "failed"
+        coerce(x):OutputForm ==
+	        (xd := DENOMINATOR(x)$Lisp) = 1 => (NUMERATOR(x)$Lisp)::OutputForm
+        	(NUMERATOR(x)$Lisp)::OutputForm / (xd::OutputForm)
+
+        latex(x):String ==
+        	(EQL(x,1)$Lisp) => latex(NUMERATOR(x)$Lisp pretend S)
+	        nl : String := concat("{", concat(latex(NUMERATOR(x)$Lisp pretend S), "}")$String)$String
+        	dl : String := concat("{", concat(latex(DENOMINATOR(x)$Lisp pretend S), "}")$String)$String
+	        concat("{ ", concat(nl, concat(" \over ", concat(dl, " }")$String)$String)$String)$String
+
+        wholePart x == TRUNCATE(x)$Lisp
+        floor(x) == FLOOR(x)$Lisp
+        ceiling(x) == CEILING(x)$Lisp
+
+        x + y == (x+y)$Lisp
+        x - y == (x-y)$Lisp
+        x * y == (x*y)$Lisp
+        n:Integer * y == (n*y)$Lisp
+        n:S * y == (n*y)$Lisp
+        x / y ==
+	        ZEROP(y)$Lisp => error "division by zero"
+        	(x/y)$Lisp
+        nn:S / dd:S ==
+	        ZEROP(dd)$Lisp => error "division by zero"
+        	(nn/dd)$Lisp
+
+        recip x ==
+        	ZEROP(x)$Lisp => "failed"
+	        1/x
+    else
+        Rep:= Record(num:S, den:S)
+	coerce(d:S):% == [d,1]
+    	zero?(x:%) == zero? x.num
+
+    	if S has GcdDomain and S has canonicalUnitNormal then
+	      retract(x:%):S ==
+--      	  one?(x.den) => x.num
+	        ((x.den) = 1) => x.num
+        	error "Denominator not equal to 1"
+
+	      retractIfCan(x:%):Union(S, "failed") ==
+--      	  one?(x.den) => x.num
+	        ((x.den) = 1) => x.num
+        	"failed"
+	else
+	      retract(x:%):S ==
+        	(a:= x.num exquo x.den) case "failed" =>
+	           error "Denominator not equal to 1"
+        	a
+	      retractIfCan(x:%):Union(S,"failed") == x.num exquo x.den
+
+	if S has EuclideanDomain then
+	      wholePart x ==
+	--        one?(x.den) => x.num
+	        ((x.den) = 1) => x.num
+	        x.num quo x.den
+
+    	if S has IntegerNumberSystem then
+
+	      floor x ==
+	--        one?(x.den) => x.num
+	        ((x.den) = 1) => x.num
+	        x < 0 => -ceiling(-x)
+	        wholePart x
+
+	      ceiling x ==
+	--        one?(x.den) => x.num
+	        ((x.den) = 1) => x.num
+	        x < 0 => -floor(-x)
+	        1 + wholePart x
+
+	if S has GcdDomain then
+	      cancelGcd: % -> S
+	      normalize: % -> %
+
+	      normalize x ==
+        	zero?(x.num) => 0
+	--        one?(x.den) => x
+        	((x.den) = 1) => x
+	        uca := unitNormal(x.den)
+        	zero?(x.den := uca.canonical) => error "division by zero"
+	        x.num := x.num * uca.associate
+	        x
+
+	      recip x ==
+        	zero?(x.num) => "failed"
+	        normalize [x.den, x.num]
+
+	      cancelGcd x ==
+	--        one?(x.den) => x.den
+	        ((x.den) = 1) => x.den
+	        d := gcd(x.num, x.den)
+	        xn := x.num exquo d
+	        xn case "failed" =>
+	          error "gcd not gcd in QF cancelGcd (numerator)"
+	        xd := x.den exquo d
+	        xd case "failed" =>
+	          error "gcd not gcd in QF cancelGcd (denominator)"
+	        x.num := xn :: S
+	        x.den := xd :: S
+	        d
+	
+	      nn:S / dd:S ==
+	        zero? dd => error "division by zero"
+        	cancelGcd(z := [nn, dd])
+	        normalize z
+
+	      x:% / y:% ==
+		zero?(y.num) => error "division by zero"
+		x * normalize [y.den, y.num]
+
+	      x + y  ==
+	        zero? y => x
+        	zero? x => y
+	        z := [x.den,y.den]
+        	d := cancelGcd z
+	        g := [z.den * x.num + z.num * y.num, d]
+        	cancelGcd g
+	        g.den := g.den * z.num * z.den
+	        normalize g
+
+	      -- We can not rely on the defaulting mechanism
+	      -- to supply a definition for -, even though this
+	      -- definition would do, for thefollowing reasons:
+	      --  1) The user could have defined a subtraction
+	      --     in Localize, which would not work for
+	      --     QuotientField;
+	      --  2) even if he doesn't, the system currently
+	      --     places a default definition in Localize,
+	      --     which uses Localize's +, which does not
+	      --     cancel gcds
+	      x - y  ==
+	        zero? y => x
+	        z := [x.den, y.den]
+	        d := cancelGcd z
+	        g := [z.den * x.num - z.num * y.num, d]
+	        cancelGcd g
+	        g.den := g.den * z.num * z.den
+	        normalize g
+
+	      x:% * y:%  ==
+        	zero? x or zero? y => 0
+	--        one? x => y
+	        (x = 1) => y
+	--        one? y => x
+	        (y = 1) => x
+	        (x, y) := ([x.num, y.den], [y.num, x.den])
+	        cancelGcd x; cancelGcd y;
+	        normalize [x.num * y.num, x.den * y.den]
+
+	      n:Integer * x:% ==
+	        y := [n::S, x.den]
+	        cancelGcd y
+	        normalize [x.num * y.num, y.den]
+	
+	      nn:S * x:% ==
+	        y := [nn, x.den]
+	        cancelGcd y
+	        normalize [x.num * y.num, y.den]
+
+	      differentiate(x:%, deriv:S -> S) ==
+	        y := [deriv(x.den), x.den]
+	        d := cancelGcd(y)
+	        y.num := deriv(x.num) * y.den - x.num * y.num
+	        (d, y.den) := (y.den, d)
+	        cancelGcd y
+	        y.den := y.den * d * d
+	        normalize y
+
+	      if S has canonicalUnitNormal then
+        	x = y == (x.num = y.num) and (x.den = y.den)
+	    --x / dd == (cancelGcd (z:=[x.num,dd*x.den]); normalize z)
+	
+	--        one? x == one? (x.num) and one? (x.den)
+	        one? x == ((x.num) = 1) and ((x.den) = 1)
+	                  -- again assuming canonical nature of representation
+
+	    else
+	      nn:S/dd:S == if zero? dd then error "division by zero" else [nn,dd]
+
+	      recip x ==
+        	zero?(x.num) => "failed"
+	        [x.den, x.num]
 
+    if (S has RetractableTo Fraction Integer) then
+      retract(x:%):Fraction(Integer) == retract(retract(x)@S)
 
-    if S has GcdDomain and S has canonicalUnitNormal then
-      retract(x:%):S ==
---        one?(x.den) => x.num
-        ((x.den) = 1) => x.num
-        error "Denominator not equal to 1"
-
-      retractIfCan(x:%):Union(S, "failed") ==
---        one?(x.den) => x.num
-        ((x.den) = 1) => x.num
-        "failed"
-    else
-      retract(x:%):S ==
-        (a:= x.num exquo x.den) case "failed" =>
-           error "Denominator not equal to 1"
-        a
-      retractIfCan(x:%):Union(S,"failed") == x.num exquo x.den
-
-    if S has EuclideanDomain then
-      wholePart x ==
---        one?(x.den) => x.num
-        ((x.den) = 1) => x.num
-        x.num quo x.den
-
-    if S has IntegerNumberSystem then
-
-      floor x ==
---        one?(x.den) => x.num
-        ((x.den) = 1) => x.num
-        x < 0 => -ceiling(-x)
-        wholePart x
-
-      ceiling x ==
---        one?(x.den) => x.num
-        ((x.den) = 1) => x.num
-        x < 0 => -floor(-x)
-        1 + wholePart x
-
-      if S has OpenMath then
-        -- TODO: somwhere this file does something which redefines the division
-        -- operator. Doh!
+      retractIfCan(x:%):Union(Fraction Integer, "failed") ==
+        (u := retractIfCan(x)@Union(S, "failed")) case "failed" => "failed"
+        retractIfCan(u::S)
 
-        writeOMFrac(dev: OpenMathDevice, x: %): Void ==
+    else if (S has RetractableTo Integer) then
+      retract(x:%):Fraction(Integer) ==
+        retract(numer x) / retract(denom x)
+
+      retractIfCan(x:%):Union(Fraction Integer, "failed") ==
+        (n := retractIfCan numer x) case "failed" => "failed"
+        (d := retractIfCan denom x) case "failed" => "failed"
+        (n::Integer) / (d::Integer)
+
+
+    if S has IntegerNumberSytem and S has OpenMath then
+    -- TODO: somwhere this file does something which redefines the division
+    -- operator. Doh!
+
+      	writeOMFrac(dev: OpenMathDevice, x: %): Void ==
           OMputApp(dev)
           OMputSymbol(dev, "nums1", "rational")
-          OMwrite(dev, x.num, false)
-          OMwrite(dev, x.den, false)
-          OMputEndApp(dev)
+       	  OMwrite(dev, numer x, false)
+          OMwrite(dev, denom x, false)
+       	  OMputEndApp(dev)
 
         OMwrite(x: %): String ==
-          s: String := ""
+       	  s: String := ""
           sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
-          dev: OpenMathDevice := _
-		  	OMopenString(sp pretend String, OMencodingXML)
-          OMputObject(dev)
+       	  dev: OpenMathDevice := _
+                        OMopenString(sp pretend String, OMencodingXML)
+       	  OMputObject(dev)
           writeOMFrac(dev, x)
-          OMputEndObject(dev)
+       	  OMputEndObject(dev)
           OMclose(dev)
-          s := OM_-STRINGPTRTOSTRING(sp)$Lisp pretend String
+       	  s := OM_-STRINGPTRTOSTRING(sp)$Lisp pretend String
           s
 
-        OMwrite(x: %, wholeObj: Boolean): String ==
+       	OMwrite(x: %, wholeObj: Boolean): String ==
           s: String := ""
-          sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
+       	  sp := OM_-STRINGTOSTRINGPTR(s)$Lisp
           dev: OpenMathDevice := _
-		  	OMopenString(sp pretend String, OMencodingXML)
+       	                OMopenString(sp pretend String, OMencodingXML)
           if wholeObj then
             OMputObject(dev)
-          writeOMFrac(dev, x)
+       	  writeOMFrac(dev, x)
           if wholeObj then
-            OMputEndObject(dev)
+       	    OMputEndObject(dev)
           OMclose(dev)
-          s := OM_-STRINGPTRTOSTRING(sp)$Lisp pretend String
+       	  s := OM_-STRINGPTRTOSTRING(sp)$Lisp pretend String
           s
 
-        OMwrite(dev: OpenMathDevice, x: %): Void ==
+       	OMwrite(dev: OpenMathDevice, x: %): Void ==
           OMputObject(dev)
-          writeOMFrac(dev, x)
+       	  writeOMFrac(dev, x)
           OMputEndObject(dev)
 
-        OMwrite(dev: OpenMathDevice, x: %, wholeObj: Boolean): Void ==
+       	OMwrite(dev: OpenMathDevice, x: %, wholeObj: Boolean): Void ==
           if wholeObj then
-            OMputObject(dev)
+       	    OMputObject(dev)
           writeOMFrac(dev, x)
-          if wholeObj then
+       	  if wholeObj then
             OMputEndObject(dev)
 
-    if S has GcdDomain then
-      cancelGcd: % -> S
-      normalize: % -> %
-
-      normalize x ==
-        zero?(x.num) => 0
---        one?(x.den) => x
-        ((x.den) = 1) => x
-        uca := unitNormal(x.den)
-        zero?(x.den := uca.canonical) => error "division by zero"
-        x.num := x.num * uca.associate
-        x
-
-      recip x ==
-        zero?(x.num) => "failed"
-        normalize [x.den, x.num]
-
-      cancelGcd x ==
---        one?(x.den) => x.den
-        ((x.den) = 1) => x.den
-        d := gcd(x.num, x.den)
-        xn := x.num exquo d
-        xn case "failed" =>
-          error "gcd not gcd in QF cancelGcd (numerator)"
-        xd := x.den exquo d
-        xd case "failed" =>
-          error "gcd not gcd in QF cancelGcd (denominator)"
-        x.num := xn :: S
-        x.den := xd :: S
-        d
-
-      nn:S / dd:S ==
-        zero? dd => error "division by zero"
-        cancelGcd(z := [nn, dd])
-        normalize z
-
-      x + y  ==
-        zero? y => x
-        zero? x => y
-        z := [x.den,y.den]
-        d := cancelGcd z
-        g := [z.den * x.num + z.num * y.num, d]
-        cancelGcd g
-        g.den := g.den * z.num * z.den
-        normalize g
-
-      -- We can not rely on the defaulting mechanism
-      -- to supply a definition for -, even though this
-      -- definition would do, for thefollowing reasons:
-      --  1) The user could have defined a subtraction
-      --     in Localize, which would not work for
-      --     QuotientField;
-      --  2) even if he doesn't, the system currently
-      --     places a default definition in Localize,
-      --     which uses Localize's +, which does not
-      --     cancel gcds
-      x - y  ==
-        zero? y => x
-        z := [x.den, y.den]
-        d := cancelGcd z
-        g := [z.den * x.num - z.num * y.num, d]
-        cancelGcd g
-        g.den := g.den * z.num * z.den
-        normalize g
-
-      x:% * y:%  ==
-        zero? x or zero? y => 0
---        one? x => y
-        (x = 1) => y
---        one? y => x
-        (y = 1) => x
-        (x, y) := ([x.num, y.den], [y.num, x.den])
-        cancelGcd x; cancelGcd y;
-        normalize [x.num * y.num, x.den * y.den]
-
-      n:Integer * x:% ==
-        y := [n::S, x.den]
-        cancelGcd y
-        normalize [x.num * y.num, y.den]
-
-      nn:S * x:% ==
-        y := [nn, x.den]
-        cancelGcd y
-        normalize [x.num * y.num, y.den]
-
-      differentiate(x:%, deriv:S -> S) ==
-        y := [deriv(x.den), x.den]
-        d := cancelGcd(y)
-        y.num := deriv(x.num) * y.den - x.num * y.num
-        (d, y.den) := (y.den, d)
-        cancelGcd y
-        y.den := y.den * d * d
-        normalize y
-
-      if S has canonicalUnitNormal then
-        x = y == (x.num = y.num) and (x.den = y.den)
-    --x / dd == (cancelGcd (z:=[x.num,dd*x.den]); normalize z)
-
---        one? x == one? (x.num) and one? (x.den)
-        one? x == ((x.num) = 1) and ((x.den) = 1)
-                  -- again assuming canonical nature of representation
-
-    else
-      nn:S/dd:S == if zero? dd then error "division by zero" else [nn,dd]
-
-      recip x ==
-        zero?(x.num) => "failed"
-        [x.den, x.num]
-
-    if (S has RetractableTo Fraction Integer) then
-      retract(x:%):Fraction(Integer) == retract(retract(x)@S)
-
-      retractIfCan(x:%):Union(Fraction Integer, "failed") ==
-        (u := retractIfCan(x)@Union(S, "failed")) case "failed" => "failed"
-        retractIfCan(u::S)
-
-    else if (S has RetractableTo Integer) then
-      retract(x:%):Fraction(Integer) ==
-        retract(numer x) / retract(denom x)
-
-      retractIfCan(x:%):Union(Fraction Integer, "failed") ==
-        (n := retractIfCan numer x) case "failed" => "failed"
-        (d := retractIfCan denom x) case "failed" => "failed"
-        (n::Integer) / (d::Integer)
-
     QFP ==> SparseUnivariatePolynomial %
     DP ==> SparseUnivariatePolynomial S
     import UnivariatePolynomialCategoryFunctions2(%,QFP,S,DP)
@@ -650,23 +712,23 @@
        if S has CharacteristicNonZero then
           if S has canonicalUnitNormal and S has GcdDomain then
              charthRoot x ==
-               n:= charthRoot x.num
+               n:= charthRoot numer x
                n case "failed" => "failed"
-               d:=charthRoot x.den
+               d:=charthRoot denom x
                d case "failed" => "failed"
                n/d
           else
              charthRoot x ==
                -- to find x = p-th root of n/d
                -- observe that xd is p-th root of n*d**(p-1)
-               ans:=charthRoot(x.num *
-                      (x.den)**(characteristic()$%-1)::NonNegativeInteger)
+               ans:=charthRoot(numer x *
+                      (denom x)**(characteristic()$%-1)::NonNegativeInteger)
                ans case "failed" => "failed"
-               ans / x.den
+               ans / denom x
           clear: List % -> List S
           clear l ==
-             d:="lcm"/[x.den for x in l]
-             [ x.num * (d exquo x.den)::S for x in l]
+             d:="lcm"/[denom x for x in l]
+             [ numer x * (d exquo denom x)::S for x in l]
           mat: Matrix %
           conditionP mat ==
             matD: Matrix S
