0% found this document useful (0 votes)
28 views6 pages

COL226 12 Variables, Sigma Algebras, Homomorphic Extension Theorem

The document discusses the extension of expressions to formulas with variables in a tree algebra context, defining operations such as size, height, and evaluation of expressions. It introduces a syntactic function to extract variables and extends the semantics to include variable mapping through a function rho. Additionally, it presents the concept of unique homomorphic extensions and relevant variables in the evaluation of expressions within an algebraic framework.

Uploaded by

mayankgoel726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

COL226 12 Variables, Sigma Algebras, Homomorphic Extension Theorem

The document discusses the extension of expressions to formulas with variables in a tree algebra context, defining operations such as size, height, and evaluation of expressions. It introduces a syntactic function to extract variables and extends the semantics to include variable mapping through a function rho. Additionally, it presents the concept of unique homomorphic extensions and relevant variables in the evaluation of expressions within an algebraic framework.

Uploaded by

mayankgoel726
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

(*

Variables

We now move from expressions to formulas, i.e., expressions that contain


variables. As the name implies, a variable is a 0-ary symbol can be given different
values, in contrast with constants in a signature ∑, whose values are fixed, once
we fix a ∑-algebra . Assume a (denumerable) set of variables, disjoint from
symbols in ∑, i.e., ∩ Σ = ∅ *)
(*
Scaling back from the example toy language that we have already developed, let us
illustrate the ideas of Tree algebras, and ∑-homomorphisms:
Let us represent variables using the OCaml type string and extend the encoding
of the abstract syntax for expressions in the data type exp:
*)
type exp = Num of int
| V of string
| Plus of exp * exp
| Times of exp * exp;;

(* Note that we have a new family of base cases: variables, which are denoted using
the parameterised constructor V(_) which takes arguments of type string.
*)
(* The corresponding Concrete Syntax can also be extended
E —> T
E —> T + E
T —> F
T —> F * T
F —> n
F —> v // a family of variables
F —> ( E )
*)
(*
We now extend the syntactic functions on tree-structured expressions *)

(* size, as before, returns the number of nodes in the tree, with a variable counted
as a single node. This is an extension to deal with variables of a ∑-homomorphism
from exp, i.e.,TreeΣ to the integers ℤ, where all leaves are mapped to 1, and
constructors Plus and Times are both interpreted as the function
f (x1, x2) ∈ ℤ2 → ℤ = 1 + x1 + x2.
*)
let rec size t = match t with
Num _ -> 1
| V _ -> 1
| Plus(t1, t2) -> 1 + (size t1) + (size t2)
| Times(t1, t2) -> 1 + (size t1) + (size t2)
;;
𝒜𝒳𝒳
(* ht, also as before, returns one less than the number of levels in the tree, i.e.,
length of the longest path from root, with variables being treated as leaf nodes.
This is an extension of the previous definition of ht to deal with variables of a ∑-
homomorphism from exp, i.e.,TreeΣ to the integers ℤ, where all leaves are mapped
to 1, and constructors Plus and Times are both interpreted as the function
f (x1, x2) ∈ ℤ2 → ℤ = 1 + (max x1 x2).
*)

let rec ht t = match t with


Num _ -> 0
| V _ -> 0
| Plus(t1, t2) -> 1 + (max (ht t1) (ht t2))
| Times(t1, t2) -> 1 + (max (ht t1) (ht t2))
;;

(* As mentioned before, both size and ht are good measures for performing
induction on trees. *)

(* We now define a syntactic function on exp called vars which returns the list of
variables in the tree. (We will later see that we really want a function returning the
set of variables in a syntax tree. If we represent sets as lists, then the difference
goes away; of course, we must avoid duplicates and not care about the relative order
in which elements appear). *)
let rec vars t = match t with
Num _ -> [ ]
| V x -> [x]
| Plus(t1, t2) -> (vars t1) @ (vars t2)
| Times(t1, t2) -> (vars t1) @ (vars t2)
;;

(* We now extend the standard semantics — the definitional interpreter of a


language of expressions which include variables. The main question to answer is
“what is the value of an expression that contains variables?” The way to approach
this question is to pose a counter-question, asking what value each variable takes.
So eval now takes an extra argument, which we call rho, that maps each variable
to a value. For the most part, except the new base cases, argument rho is carried
along as extra baggage in each call. But it cannot be left out. (Why not?) Note that
rho is a function from string to int ! *)

let rec eval t rho = match t with


Num n -> n
| V x -> rho x
| Plus(t1, t2) -> (eval t1 rho) + (eval t2 rho)
| Times(t1, t2) -> (eval t1 rho) * (eval t2 rho)
;;
(* We now extend the compile function. First we introduce an opcode LOOKUP to
look up the value associated with a given variable.
*)
type opcode = LD of int
| LOOKUP of string //look up variable’s value
| PLUS
| TIMES
;;

(* The compiler as before, is a post-order traversal, i.e., a tree-recursive function,


with a straightforward new base case. *)
let rec compile t = match t with
Num n -> [LD (n)]
| V x -> [ LOOKUP(x) ]
| Plus(t1, t2) -> (compile t1) @ (compile t2) @ [PLUS]
| Times(t1, t2) -> (compile t1) @ (compile t2) @ [TIMES]
;;

(* The stack machine is again written as a tail recursive function driven


by the first op-code and the state of the stack, and a new component, a table env
(environment, “gamma”), which maps variables to their corresponding answers.
*)
let rec stkmc env s code = match s, code with
a::s, [ ] -> a
| s, (LD(n)) :: code' -> stkmc ((Num n) :: s) code'
| s, (LOOKUP(x))::code’ -> let a= (env x)
in stkmc env (a::s) code'
| (Num n1) :: (Num n2) :: s', PLUS :: code' ->
let n = n1 + n2
in stkmc env ((Num n) :: s') code'
| (Num n1) :: (Num n2) :: s', TIMES :: code' ->
let n = n1 * n2
in stkmc env ((Num n) :: s') code'
| _ -> raise (Stuck(env, s, code))
;;

(* Let us now abstract this treatment to arbitrary abstract syntax trees over
arbitrary signatures ∑. We do so by defining a set TreeΣ( ).

Definition: Suppose ∑ is a given signature.


Suppose is a (denumerable) set of variables.
The set TreeΣ( ) is inductively defined as follows:
Base cases:
- for each 0-ary symbol c in ∑, a labelled node •c is in TreeΣ( )
- for each variable x in , a labelled node •x is in TreeΣ( ).
Induction cases: for each k > 0,
for each k-ary symbol f in ∑,
𝒳
𝒳𝒳
𝒳
𝒳𝒳
for any trees t1, …, tk in TreeΣ( ),
the tree consisting of a labelled node •f at the root
with k trees t1, …, tk ordered as subtrees below the root node
is in TreeΣ( ).

The algebra of abstract syntax trees


TreeΣ( ) is the ∑-algebra with carrier set TreeΣ( ), where (as before)
- every 0-ary symbol c in ∑ is interpreted as the labelled node •c, in TreeΣ( ),
- every k-ary symbol (k >0) f in ∑ is interpreted as the tree-forming function
that takes k trees t1, …, tk from TreeΣ( ), and creates the tree
•f
/ \
t1…tk
by sticking t1, …, tk as the subtrees below a new root node labelled •f. *)
(* Observe is in 1-1 correspondence with a subset • of TreeΣ( ).
Note also that TreeΣ( ) contains • ∪ TreeΣ.

Definition (B-valuation). A function ρ : → B that maps variables to values in a


carrier set B is called a B-valuation.

Definition (Function extension) Let A1 ⊆ A2 and let f1 : A1 → B. Function


f2 : A2 → B extends f1 (to domain A2) if for all a ∈ A1, f2(a) = f1(a).

Definition (Function extension on valuations)


A function h: TreeΣ( ) → B extends function ρ : → B if
for all x ∈ , h(•x ) = ρ(x)

Unique Homomorphic Extension Theorem


For any signature ∑, and
any ∑-algebra, ℬ = ⟨B, …⟩,
and any B-valuation ρ : → B,
there is a unique ∑-homomorphic extension of ρ : → B, written
ρ ̂ : TreeΣ( ) → B
from the (syntactic) ∑-algebra TreeΣ( ) to the ∑-algebra ℬ.

Proof (First) Existence of a ∑-homomorphic extension of ρ : → B.


By construction: define ρ ̂ : TreeΣ( ) → B to be a ∑-homomorphism as follows:
- For each 0-ary symbol c in ∑: ρ (̂ •c ) = cℬ
- For each x ∈ , ρ (̂ •x ) = ρ(x)
- For each k-ary symbol (k >0) f in ∑, and t1, …, tk in TreeΣ( )
ρ (̂ •f ) = fℬ( ρ (̂ t1 ),…, ρ (̂ tk ) )
/ \
t1…tk

Uniqueness of ρ ̂
𝒳𝒳
𝒳
𝒳𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
Suppose j is an extension of ρ, and j : TreeΣ( ) → B is a ∑-homomorphism from
∑-algebra TreeΣ( ) to the ∑-algebra ℬ.

Proof by induction on (ht t) that for all t in TreeΣ( ), ρ (̂ t ) = j( t )


Base cases (ht t) = 0.
subcase t is of the form •c
for each 0-ary symbol c in ∑: ρ (̂ •c ) = cℬ // defn of ρ ̂
= j( •c ) // j is a ∑-homomorphism
// from TreeΣ( ) to ℬ
subcase t is of the form •x for some x ∈
ρ (̂ •x ) = ρ(x) // defn of ρ ̂
= j( •x ) // j extends ρ

Induction Hypothesis:
Assume that for all t’ in TreeΣ( ) such that (ht t) ≤ n,
ρ (̂ t’ ) = j( t’ )

Induction Step: Consider t in TreeΣ( ) s.t. (ht t) = n+1


t must be of the form
•f
/ \
t1…tk
with (ht ti) ≤ n (1 ≤ i≤ k)
Now, by definition,
for each k-ary symbol (k >0) f in ∑, and t1, …, tk in TreeΣ( ) s.t. (ht ti) ≤ n
ρ (̂ •f )
/ \
t1…tk

= fℬ( ρ (̂ t1 ),…, ρ (̂ tk ) ) // definition of ρ ̂


= fℬ( j( t1 ),…, j( tk ) ) // by IH on each of t1…tk
= j( •f ) // j : TreeΣ( ) → B is a ∑-homomorphism
/ \ // from ∑-algebra TreeΣ( ) to the ∑-algebra ℬ.
t1…tk
*)

(* Only those variables that appear in a tree (term, expression) matter in its
evaluation.
Lemma (Relevant Variables): Suppose ∑ is an arbitrary signature and is the
set of variables.
Let t in TreeΣ( ) be an arbitrary tree (term, expression).
Let V = vars( t ). // set of varaibles that appear in t
Consider any ∑-algebra ℬ = ⟨B, …⟩, and let ρ1, ρ2 ∈ → B be any two B-
valuations such that for all variables x ∈ V, ρ1(x) = ρ2(x).
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
𝒳
[Note: ρ1(y) and ρ2(y) may be very different for y ∉ V. ]
Then ρ1 ̂(t) = ρ2 ̂(t).

Proof by induction on ht( t ).


Base cases (ht( t ) = 0 ).

Therefore ρ1 ̂(∙c) = cℬ = ρ2 ̂(∙c)


subcases: t is of the form •c for some 0-ary symbol c in ∑.

subcases t is of the form •x for some x in . So x ∈ V.


Therefore ρ1 ̂(∙x) = ρ1(x) = ρ2(x) = ρ2 ̂(∙x)
Induction Hypothesis: Assume for all t’ in TreeΣ( ) such that ht( t’ ) ≤ n,
for all ρ′1, ρ′2 ∈ → B such that
for all variables x ∈ V′ = vars( t’ ), ρ′1(x) = ρ′2(x),
that ρ′1 ̂(t′) = ρ′2 ̂(t′).
Induction Step: Let t in TreeΣ( ) be such that ht( t ) = n+1.
By analysis t is of the form •f for some symbol f of arity k in ∑
/ \
t1…tk
and trees t1, …, tk from TreeΣ( ), where max ht( ti) = n. (1≤i≤k)
ρ1 ̂( •f ) = fℬ( ρ1 (̂ t1 ),…, ρ1 ̂( tk ) ) // defn of ρ1 ̂(t)
/ \
t1…tk

= fℬ( ρ2 ̂( t1 ),…, ρ2 (̂ tk ) ) // By IH on t1, …, tk with ρ′1 = ρ1 and ρ′2 = ρ2


// Note that Vi = vars( ti ) ⊆ vars( t) = V
// so if for all x ∈ V, ρ1(x) = ρ2(x),
// then for all x ∈ Vi, ρ1(x) = ρ2(x) (1≤i≤k)
= ρ2 (̂ •f )
/ \
t1…tk
*)

(*
Proposition: For any t in TreeΣ( ), V = vars( t ) is finite.
|V|
|B|
Corollary: t in TreeΣ( ) can evaluate to at most | B | values.
*)




𝒳
𝒳
𝒳
𝒳
𝒳
𝒳






𝒳

You might also like