login  home  contents  what's new  discussion  bug reports     help  links  subscribe  changes  refresh  edit

Edit detail for FormalFraction revision 1 of 4

1 2 3 4
Editor: 127.0.0.1
Time: 2007/11/11 11:25:57 GMT-8
Note: transferred from axiom-developer

changed:
-
Author -- M.G. Richardson

Date Created -- 1996 Jan. 23

Related Constructors -- Fraction

Source repository URL -- http://axiom.axiom-developer.org/src/algebra/ffrac.as.pamphlet

N.B. --  ndftip.as inlines this, must be recompiled if this is.

Description:

 This type represents formal fractions - that is, pairs displayed as
 fractions with no simplification.

 If the elements of the pair have a type X which is an integral
 domain, a FFRAC X can be coerced to a FRAC X, provided that this
 is a valid type.  A FRAC X can always be coerced to a FFRAC X.
 If the type of the elements is a Field, a FFRAC X can be coerced
 to X.

 Formal fractions are used to return results from numerical methods
 which determine numerator and denominator separately, to enable
 users to inspect these components and recognise, for example,
 ratios of very small numbers as potentially indeterminate.

\begin{aldor}
#include "axiom.as"

FFRAC ==> FormalFraction ;
 
OF    ==> OutputForm ;
SC    ==> SetCategory ;
FRAC  ==> Fraction ;
ID    ==> IntegralDomain ;

FormalFraction(X : SC) : SC with {

-- Could generalise further to allow numerator and denominator to be of
-- different types, X and Y, both SCs.  "Left as an exercise."

  / : (X,X) -> % ;
++ / forms the formal quotient of two items.

  numer : % -> X ;
++ numer returns the numerator of a FormalFraction.

  denom : % -> X ;
++ denom returns the denominator of a FormalFraction.

  if X has ID then {
  
    coerce : % -> FRAC(X pretend ID) ;
++ coerce x converts a FormalFraction over an IntegralDomain to a
++ Fraction over that IntegralDomain.

    coerce : FRAC(X pretend ID) -> % ;
++ coerce converts a Fraction to a FormalFraction.

  }

  if X has Field then coerce : % -> (X pretend Field) ;

} == add {

  import from Record(num : X, den : X) ;
  
  Rep == Record(num : X, den : X) ; -- representation

  ((x : %) = (y : %)) : Boolean ==
    ((rep(x).num = rep(y).num) and (rep(x).den = rep(y).den)) ;

  ((n : X)/(d : X)) : % == per(record(n,d)) ;

  coerce(r : %) : OF == (rep(r).num :: OF) / (rep(r).den :: OF) ;

  numer(r : %) : X == rep(r).num ;

  denom(r : %) : X == rep(r).den ;

  if X has ID then {
 
    coerce(r : %) : FRAC(X pretend ID)
      == ((rep(r).num)/(rep(r).den)) @ (FRAC(X pretend ID)) ;

    coerce(x : FRAC(X pretend ID)) : % == x pretend % ; 

  }

  if X has Field then coerce(r : %) : (X pretend Field)
    == ((rep(r).num)/(rep(r).den)) $ (X pretend Field) ;

}
\end{aldor}

\begin{axiom}
f1 : FormalFraction Integer
f1 := 6/3

--       6
--       -
--       3

f2 := (3.6/2.4)$FormalFraction Float

--       3.6
--       ---
--       2.4

numer f1

--       6

denom f2

--       2.4

f1 :: FRAC INT

--       2

% :: FormalFraction Integer      

--       2
--       -
--       1

f2 :: Float

--       1.5

\end{axiom}

Author
M.G. Richardson
Date Created
1996 Jan. 23
Related Constructors
Fraction
Source repository URL
http://axiom.axiom-developer.org/src/algebra/ffrac.as.pamphlet
N.B.
ndftip.as inlines this, must be recompiled if this is.

Description:

This type represents formal fractions - that is, pairs displayed as fractions with no simplification.

If the elements of the pair have a type X which is an integral domain, a FFRAC X can be coerced to a FRAC X, provided that this is a valid type. A FRAC X can always be coerced to a FFRAC X. If the type of the elements is a Field, a FFRAC X can be coerced to X.

Formal fractions are used to return results from numerical methods which determine numerator and denominator separately, to enable users to inspect these components and recognise, for example, ratios of very small numbers as potentially indeterminate.

aldor
#include "axiom.as"
FFRAC ==> FormalFraction ;
OF ==> OutputForm ; SC ==> SetCategory ; FRAC ==> Fraction ; ID ==> IntegralDomain ;
FormalFraction(X : SC) : SC with {
-- Could generalise further to allow numerator and denominator to be of -- different types, X and Y, both SCs. "Left as an exercise."
/ : (X,X) -> % ; ++ / forms the formal quotient of two items.
numer : % -> X ; ++ numer returns the numerator of a FormalFraction.
denom : % -> X ; ++ denom returns the denominator of a FormalFraction.
if X has ID then {
coerce : % -> FRAC(X pretend ID) ; ++ coerce x converts a FormalFraction over an IntegralDomain to a ++ Fraction over that IntegralDomain.
coerce : FRAC(X pretend ID) -> % ; ++ coerce converts a Fraction to a FormalFraction.
}
if X has Field then coerce : % -> (X pretend Field) ;
} == add {
import from Record(num : X, den : X) ;
Rep == Record(num : X, den : X) ; -- representation
((x : %) = (y : %)) : Boolean == ((rep(x).num = rep(y).num) and (rep(x).den = rep(y).den)) ;
((n : X)/(d : X)) : % == per(record(n,d)) ;
coerce(r : %) : OF == (rep(r).num :: OF) / (rep(r).den :: OF) ;
numer(r : %) : X == rep(r).num ;
denom(r : %) : X == rep(r).den ;
if X has ID then {
coerce(r : %) : FRAC(X pretend ID) == ((rep(r).num)/(rep(r).den)) @ (FRAC(X pretend ID)) ;
coerce(x : FRAC(X pretend ID)) : % == x pretend % ;
}
if X has Field then coerce(r : %) : (X pretend Field) == ((rep(r).num)/(rep(r).den)) $ (X pretend Field) ;
}
aldor
   Compiling FriCAS source code from file 
      /var/zope2/var/LatexWiki/846558072561508006-25px001.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./846558072561508006-25px001.lsp
   Issuing )library command for 846558072561508006-25px001
   Reading /var/zope2/var/LatexWiki/846558072561508006-25px001.asy
   FormalFraction is now explicitly exposed in frame initial 
   FormalFraction will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/846558072561508006-25px001

axiom
f1 : FormalFraction Integer
Type: Void
axiom
f1 := 6/3
LatexWiki Image(1)
Type: FormalFraction? Integer
axiom
--       6
--       -
--       3
f2 := (3.6/2.4)$FormalFraction Float
LatexWiki Image(2)
Type: FormalFraction? Float
axiom
--       3.6
--       ---
--       2.4
numer f1
LatexWiki Image(3)
Type: PositiveInteger?
axiom
--       6
denom f2
LatexWiki Image(4)
Type: Float
axiom
--       2.4
f1 :: FRAC INT
LatexWiki Image(5)
Type: Fraction Integer
axiom
--       2
% :: FormalFraction Integer
LatexWiki Image(6)
Type: FormalFraction? Integer
axiom
--       2
--       -
--       1
f2 :: Float
LatexWiki Image(7)
Type: Float