axiom-developer
[Top][All Lists]

## RE: [Axiom-developer] [MutualRecursion] (new)

 From: Page, Bill Subject: RE: [Axiom-developer] [MutualRecursion] (new) Date: Tue, 18 Jan 2005 13:43:11 -0500

Ralf,

On Tuesday, January 18, 2005 12:22 PM you wrote:
>
> Do you find the attached file relevant?
>

----------

#include "aldor"
#include "aldorio"

define Parity: Category == with {
parity: Integer -> Boolean;
}

parity(n:Integer): Boolean == {
(n>0) => parity(n-1)$Even; (n<0) => parity(n+1)$Even;
false;
}
}

parity(n: Integer): Boolean == {
n>0 => parity(n-1)$Odd; n<0 => parity(n+1)$Odd;
true;
}
}

main(): () == {
import from Integer;
stdout << "parity(   10)$Even=" << parity( 10)$Even << newline;
stdout << "parity(    8)$Odd =" << parity( 8)$Odd  << newline;
stdout << "parity(-1111)$Odd =" << parity(-111)$Odd  << newline;
}

main();

-----

Yes I do find it very relevant. Thank you!

I have tried for about 1/2 an hour without success to write
this same category in Axiom. Perhaps someone with more
experience with the Axiom compiler can help?

> It actually compiles with Aldor 1.0.2 and runs with the output
>
> aldor -grun -laldor EvenOdd.as
> parity(   10)$Even=T > parity( 8)$Odd =F
> parity(-1111)$Odd =T > > I wonder how the Aldor compiler handles such mutual recursive > structures. Perhaps Peter Broadbery knows. I would also like to know. > > Maybe this example is easy, because both domains are in the > same file> Do you know a good example where it makes sense > to put the domains much more away from each other? I can not give a simple example right now but I suspect that this happens very frequently in Axiom's algebra. > > BTW, who reads address@hidden address@hidden is the email address of the MathAction wiki. The content of new web pages created there be sent to the axiom-developer email list. So I suppose you could say that everyone on axiom-developer reads these emails from MathAction. > What if I write a mail to this address? If you send mail to this address you should delete the part of the subject before [MutualRecursion] then your email will be added to the MathAction page named [MutualRecursion]. Otherwise it will be added to the page named [Axiom-developer]. In both cases what you write will also be echoed back to the Axiom-developer email list. For greater control over the formatting of your reply you can also click on the forwarded from' link below. (Make sure that it is not split by your email reader). It will take you directly to the page on MathAction where you can make comments online (essentially the same as email) or you can click edit' and make any changes to the page that you wish including adding new Axiom commands and LaTeX mathematics. > > Bill Page wrote: > > Here is an example of defining functions by mutual > recursion in Axiom > > > > We start with a "bootstrap" definition of > 'parity(n)\$Even'. All that is
> > really needed here is a package that exports a function
> named 'parity'
> > with the right signature. This particular function will
> never be called
> > and will be re-defined later. It's only purpose is as a
> placeholder to
> > allow the later definition of **ODD**.
> >
> > \begin{axiom}
> > )abbrev package EVEN Even
> > Even(): E == I where
> >   E == with
> >     parity: Integer -> Boolean
> >     parity(n) == true
> > \end{axiom}
> >
> > Now we can define 'parity(n)\$Odd'. It depends on **EVEN**. > > > > \begin{axiom} > > )abbrev package ODD Odd > > Odd(): E == I where > > E == with > > parity: Integer -> Boolean > > I == add > > parity(n:Integer) == > > -- output("ODD",n::OutputForm)$OutputPackage
> >       (n>0) => parity(n-1)$Even > > (n<0) => parity(n+1)$Even
> >       false
> > \end{axiom}
> >
> > But the bootstrap definition of **EVEN** is incomplete. It really
> > depends (recusively) on **ODD**. So finally we need the
> full (re-)definition
> > of 'parity(n)\$Even' > > > > \begin{axiom} > > )abbrev package EVEN Even > > Even(): E == I where > > E == with > > parity: Integer -> Boolean > > I == add > > parity(n) == > > -- output("EVEN",n::OutputForm)$OutputPackage
> >       n>0 => parity(n-1)$Odd > > n<0 => parity(n+1)$Odd
> >       true
> > \end{axiom}
> >
> > Now we can test the new functions:
> >
> > \begin{axiom}
> > parity(10)$Even > > parity(8)$Odd
> > parity(-1111)\$Odd
> > \end{axiom}
> >
> > --
> > forwarded from
>
http://page.axiom-developer.org/zope/mathaction/MutualRecursion#msg200501172