Definition:
An
<S,>-algebra
, A, is said to be an initial
<S,>-algebra
if for every <S,>-algebra
B
there
is exactly one <S,>-
homomorphism from A to B.
The unique homomorphism from an initial algebra A
to an algebra B is sometimes refered to as
the initial homomorphism from A
to B
end
Initial algebra have two particularly important properties that will concern us at this time.
Notes:
Definition: Given <S,>-terms t and t' we say that t is a subterm of t' if, where t' = "(t1,...,t|w|)" that either t =t' or t is a subterm of one of the ti. We say t is a proper subterm of t' if, t is a subterm of t' but tt'.The first rule is really redundant (i.e., implied by the second line). It is common practice to omit the parentheses on "constant terms", i.e., terms of form "( )" , we will not follow this practice. What we have written above as "(t1,...,t|w|)" is an informal presentation of the actual string which, in accordance with our formal, mathematical definition of string is a mapping and not a sequence of symbols on a page (and in particular, not a sequence of symbols with an ellipsis "..." in the middle of it). Given that for each i=1,...,|w|, ti has length |ti |, then the actual string is the mapping, s, from the set {1,..., 2+|t1|+...+|t|w||+ |w|} to the set consisting of the symbols in plus left parenthesis, "(", and right parenthesis, ")" and comma, ",".such that
s(1) = s(2) = ( [left parenthesis] s(2+j) = t1,j for j=1,...,|t1| s(2+|t1|+1) = , [comma] s(2+|t1|+1+j ) = t2,j for j = 1,...,|t2| s(2+|t1|+1+|t2|+...+|t|w|-1|+1) = , [comma] s(2+|t1|+1+|t2|+...+|t|w|-1 |+1+j) = t|w|,j for j=1,...,|t|w|| s(2+|t1|+|t2|+...+|t|w||+|w| = ) [right parenthesis]
Example: For the signature SigP:
operators:
zero: -->int
pred:int-->int
succ:int-->int
add:int.int-->int
mult:int.int-->int
"zero( )",The term "zero( )" is a subterm in all the examples. The term "succ(zero( ))" is a subterm of the last two examples.
"add(zero( ), succ(zero( )))"
"mult(add(succ(zero( )), succ(zero( ))), succ(succ(zero( ))))"
Definition:For every signature <S,> the <S,>-terms form a <S,>-algebra T, called the <S,>-term algebra, where
Theorem: The algebra T is an initial <S,>-algebra .
Proof: What we must show is that
for each <S,>-algebra,
A, there is one, and only one, homomorphism hA:
TA.
As a first step we define an S-ary function
h:U( T)U(A)
by
employing the above inductive definiton of the S-ary
set of <S,. >-terms.
Let t be an <S,>-term
The algebra Tis not the only initial <S,>-algebra, indeed there are infinitely many. However, as the following result show, they are all isomorphic and so may be said to be essentially the same except for notation.
Theorem: If A and B are initial <S,>-algebras then they are isomorphic, that is, there exist homomorphism h:AB and g:BA such that hg = 1B and gh = 1A where 1A :AA and 1B :BB are the indicated identity homomorphisms.
Proof: Since A
is initial there must exist a unique morphism
h:AB. Since
B
is initial there must exist a unique morphism
g:BA.
But then hg:BB
and
gh:
AA.
But 1B :BB
and so, by uniqueness of initial homomorphisms, we must have hg
= 1B Similarly we get gh
= 1A .
end
These examples suggest that the result is that the given initial homomorphism from T to the named algebra evaluates the term using the operations defined in the algebra.
Recall that, SigQ is the signature
where JSInt(str) is a predicate (a JavaScript program) which determines whether or not a given string, str, corresponds to a (JavaScript) integer. What it actually does is determine whether or not the built-in JavaScript method parseInt(str) converts str to an integer.name: sigQsorts: {int}
operators:
zero: -->int
JSInt: -->int
pred:int-->int
succ:int-->int
add:int.int-->int
mult:int.int-->intEnd of signature sigQ.
Example: The evaluation
of
SigQ-terms using the "obvious interpretation"
of the operators can be done using alg_AA
and the program aitch.For example, try performing aitch("alg_AA",
"add(3( ), mult(17( ), 5( )))")
Note that you can display the definition of the algebra named
"alg_AA", by performing algDisplay("alg_AA")
Example: The set of constant operators occuring in a term.
We claim that the desired SigQ-algebra
is the algebra alg_BB where
the carrier of alg_BB is the set of all finite subsets of the set of JavaScript integers.We capture this algebra on the UA-Calculators with the algebra named "alg_BB" which is given as follows:alg_BB(zero) = {0}
alg_BB(str) = {n} if str is a string representing the JavaScript integers n.
alg_BB(pred)(s) = s
alg_BB(succ)(s) = s
alg_BB(add)(s, s') = ss'
alg_BB(mult)(s, s') = ss'
The signature of alg_BB is: sigQ
Note that this algebra actually has a different carrier (consisting of strings) than the algebra first proposed (which had abstract sets of JavaScript integers in its carrier) -- this is because JavaScript does not have a data type whose elements are abstract sets so we have to make use of their syntactic counterpart.
The carriers of alg_BB are:
["not specified"]
// the carrier is the set of JavaScript strings representing sets (e.g., "{1, 55, 70, 2}" is an element of the carrier )The operations of the algebra alg_BB are:
["zero", "'{0}'"]
[JSInt, mSet]
["succ", "arg[1]"]
["pred", "arg[1]"]
["add", "setUnion(arg[1],arg[2])"]
["mult", "setUnion(arg[1],arg[2])"]End of algebra alg_BB
For example try the following on a UA-Calculator
aitch("alg_BB", "mult(add(13( ), succ(zero( ))), 3( ))")
the carrier of alg_CC is the set of JavaScript integers.We capture this algebra on the UA-Calculators with the algebra named "alg_CC" which is given as follows:alg_CC(zero) = 1
alg_CC(str) = 1 if str is a string representing a JavaScript integer
alg_CC(pred)(n) = n+1
alg_CC(succ)(s) = n+1
alg_CC(add)(n, p) = 1+max(n, p)
alg_CC(mult)(s, s') = 1+max(n, p)
The signature of alg_CC is: sigQ
The carriers of alg_CC are:where retOne is a function which always returns the integer 1.
[""]The operations of the algebra alg_CC are:
["zero", "1"]
[JSInt, retOne]
["succ", "1+arg[1]"]
["pred", "1+arg[1]"]
["add", "1+Math.max(arg[1],arg[2])"]
["mult", "1+Math.max(arg[1],arg[2])"]End of algebra alg_CC
Example: Alternative notations
for expressions.
To define our term algebras we used a particular definition of <S, >-term
that employed a slight modification of what is usually called "prefix notation".
There are many other notations which work just as well but have a different
appearance. For example, here are five different notations for what
is essentially the same term
The terms are "essentially the same" in that we could have defined term algebra starting from any of these notations and have gotten an initial algebra that was isomorphic to the one we chose to use. The initial homomorphisms from T to these these other initial algebras provide a translation from our system of notation for terms to these other systems of notation. For example, here is the algebra for reverse polish notation for Sig_Q-terms:
the carrier of alg_DD is the set of JavaScript stringsalg_DD(zero) = "0"
alg_DD(str) =str if str is a string representing a JavaScript integer
alg_DD(pred)(n) = "s pred"
alg_DD(succ)(s) = "s succ"
alg_DD(add)(n, p) = s s' add
alg_DD(mult)(s, s') = s s' mult
The corresponding algebra for the UA-calculators is:
The algebra alg_DDendThe signature of alg_DD is: sigQ
The carriers of alg_DD are:
[""]The operations of the algebra alg_DD are:
["zero", "1"]
[JSInt, id]
["succ", "arg[1]+' succ'"]
["pred", "arg[1]+' pred'"]
["add", "arg[1]+' '+arg[2]+' +'"]
["mult", "arg[1]+' '+arg[2]+' *'"]End of algebra alg_DD
More Examples: For further, and more significant, examples of the uses of initial algebras see: