axiom-developer
[Top][All Lists]
Advanced

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

## [Axiom-developer] ffrac.spad

 From: daly Subject: [Axiom-developer] ffrac.spad Date: Mon, 2 Apr 2007 00:21:04 -0500

```Bill,

I don't see this email on the mailing list. I've attached the
ffrac.spad domain. It handles "formal fractions" which do not
evaluate the numerator or the denominator. Thus the formal
fraction is just a data structure except that there are
natural coercions to the algebra and back where they make sense.

This is related to the discussion of symbolic manipulation
versus algebraic manipulation.

In particular, there are two books by Joel Cohen called
"Computer Algebra and Symbolic Computation". I've had a
discussion with Joel about his work (which he has agreed
to allow Axiom to use at will). He defines MPL, a mathematical
programming language, that basically does expression-tree
manipulations.

I'd suggested that we could create a "Cohen Algebra" category and
domain set that would follow his MPL style quite closely. The main
thing would be to choose a common representatin (Record or List)
for all elements of the domain so they compose properly.

The big difference in an axiom implementation would be to have
coercions (or explicit import/export) from the Cohen domains
to algebraic domains and back where they make sense.

This would satisfy the apparent end-user need to manipulate
the expression trees.

Tim

===================================================================

--This fits in layer 10
)abbrev domain FFRAC FormalFraction

+++ Author: M.G. Richardson, Timothy Daly (spad rewrite)
+++ Date Created: 1996 Jan. 23
+++ Date Last Updated: 30 March 2007
+++ Basic Functions:
+++ Related Constructors: Fraction
+++ Also See:
+++ AMS Classifications:
+++ Keywords:
+++ References:
+++ 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.

FormalFraction(X : SetCategory) : SetCategory with

_/: (X,X) -> %
++ x / y is the formal fraction of the input arguments

numer : % -> X
++ numer(x) is the numerator of the formal fraction

denom : % -> X
++ denom(x) is the denominator of the formal fraction

if X has IntegralDomain then

coerce : % -> Fraction(X)
++ coerce(x) from here to Fraction(there)

coerce : Fraction(X) -> %
++ coerce(x) from Fraction(there) to here

if X has Field then

coerce : % -> X
++ coerce from here to Field(there)

== add

import Record(num : X, den : X)

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

-- (a::Symbol / b::Symbol)\$FFRAC(Symbol)
-- c:Symbol:=d
-- e:Symbol:=f
-- (c/e)\$FFRAC(Symbol)

(n:X / d:X):% == [n,d]

-- g:=(c/e)\$FFRAC(Symobl)
-- h:=(c/e)\$FFRAC(Symbol)
-- (g=h)::Boolean
-- i:=(a::Symbol / b::Symbol)\$FFRAC(Symbol)
-- j:=(a::Symbol / b::Symbol)\$FFRAC(Symbol)
-- (i=j)::Boolean

_=(x:%, y:%):Boolean == (x.num = y.num) and (x.den = y.den)

-- numer g
-- numer i

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

--denom g
--denom i

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

coerce(r:%):OutputForm == (r.num :: OutputForm) / (r.den :: OutputForm)

-- COMPLEX(INT) has FIELD
-- COMPLEX(INT) has IntegralDomain
-- p:COMPLEX(INT):=2
-- p::FRAC(COMPLEX(INT))::FFRAC(COMPLEX(INT))

if X has IntegralDomain then

coerce(r : %) : Fraction(X)
==  (r.num / r.den) @ Fraction(X)

coerce(x : Fraction(X)) : % == x pretend %

-- FRAC(POLY(INT)) has FIELD
-- m:=(x^2)@FRAC(POLY(INT))
-- m::FFRAC(POLY(INT))

if X has Field then

-- m:=(2/3)\$FFRAC(INT)
-- m::COMPLEX(FRAC(INT))

coerce(r : %) : X
== (r.num / r.den) @ X

```

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]