{
O'Cult Unary Arithmetic Tests
Daniel Lyons - Abstraction Anonymous
<fusion AT storytotell dot org>
O'Cult is a cool language. Unfortunately, it has an annoying "balance" rule,
apparently a common thread of thinking in the Cult of the Bound Variable.
In O'Cult it means that if the current rule doesn't apply to the current
term, but applies equally many times to the left and right subterms, then
the rule *does not* apply and the next rule is considered.
This broken forces us to create extraneous rules for the sake of unbalancing
the term such that the next pass will find rules that apply different numbers
of times on the left and the right subterms. This wasn't particularly hard
for math, which has identity functions and properties which you can use to
handle symmetric expressions. In the XML file, on the other hand, I wasn't
able to discover how to deal with those cases in a general way.
-- Daniel Lyons, 2006-07-24 @ 1:34 PM.
}
{ addition
these rules work when the arguments are numerals
but not for all arbitrary expressions
}
Add Z y => y;
Add (S x) y => S (Add x y);
{
This rule is obsoleted by the associative property below.
-- done -- Add (Add x y) (Add z q) => Add x (Add y (Add z q));
}
{
I know this is a mathematical property, but I couldn't figure out how to
restate this to combine it with the similar multiplication rule below.
I fail middle school math. :(
}
Add (Mult Z y) (Mult z q) => Mult z q;
Add (Mult (S Z) y) (Mult z q) => Add y (Mult z q);
Add (Mult (S x) y) (Mult z q) => Add (Add y (Mult x y)) (Mult z q);
{
Multiplication. We use a recursive definition that works like this:
4 * 3 = 4 + (4 * 2) = 4 + 4 + (4 * 1) = 4 + 4 + 4
}
Mult Z y => Z;
Mult (S Z) y => y;
Mult (S x) y => Add y (Mult x y);
{
This is a helpful unbalancing rule. I'm sure it could be made abstract and
better.
}
Mult (Add (S x) y) z => Mult (S (Add x y)) z;
{
This property is obsoleted by the associative property rule below.
-- done -- Mult (Mult x y) (Mult z q) => Mult x (Mult y (Mult z q));
}
{
This is the associative property. We need it to unbalance the expression
and allow computation to continue in O'Cult.
}
a (a x y) (a z q) => a x (a y (a z q));
{ when all other computation is done }
Compute x => x;
. { end of rules }
STOP