- Introduction to Unification Theory Lecture 1
- Sections 8.1 and 8.2 of The Handbook of Automated Reasoning
-
Define a type
Variableof metavariables.Template:
data Variable = … -
Write a type
FOOpenTermof first-order open terms (essentially rose trees where branches represent functions and leaf nodes represent metavariables and constants, and a constant is just a 0-ary function). This type should have one type parameter: a type of function symbols.Template:
data FOOpenTerm (fun ∷ ⋆) = … -
Write a new type
FOTermthat is likeFOOpenTerm, but parameterized over an arbitrary type of metavariables, so that you can represent closed terms by setting the parameter toVoid.Template:
data FOTerm (fun ∷ ⋆) (var ∷ ⋆) = … -
Write a new type
HOTerm, that is likeFOTerm, but it supports binder nodes, which can capture variables. Assume that each binder node can only capture one variable. The type of binders should be a parameter; for example, the lambda calculus would havedata Binder = Lamas the parameter, whereas first-order logic would havedata Binder = ForAll | Existsas the parameter.Template:
data HOTerm (fun ∷ ⋆) (var ∷ ⋆) (binder ∷ ⋆) = … -
Redefine
FOOpenTermandFOTermas type aliases in terms ofHOTerm. -
Write a function that computes the set of free variables in an
HOTerm.Template:
freeVars ∷ (Ord v) ⇒ HOTerm f v b → Set v -
Implement capture-avoiding substitution of a single variable on
HOTerms.Template:
subst ∷ (v, HOTerm f v b) → HOTerm f v b → HOTerm f v b -
Implement capture-avoiding simultaneous substitution on
HOTerms.Template:
simulSubst ∷ [(v, HOTerm f v b)] → HOTerm f v b → HOTerm f v b -
Write a type
HOSubstof substitutions in terms ofHOTerm(essentially a partial function from variables to terms).Template:
data HOSubst (fun ∷ ⋆) (var ∷ ⋆) (binder ∷ ⋆) = … -
Redefine
simulSubstin terms of your type of substitutions.Template:
simulSubst ∷ HOSubst f v b → HOTerm f v b → HOTerm f v b -
Define a type alias
FOSubstof substitutions on first-order terms in terms ofHOSubst. -
Implement syntactic unification (using the Robinson algorithm or the Martelli-Montanari algorithm) on
FOTerms.Template:
unify ∷ FOTerm f v → FOTerm f v → Maybe (FOSubst f v)
- Set Theory and Algebra in Computer Science by José Meseguer
- Term Rewriting And All That by Franz Baader and Tobias Nipkow
- Sections 9.1 through 9.6 of The Handbook of Automated Reasoning
-
A transition system is a pair
(S, →)of a set of statesSand a transition relation(→) ⊆ S². A labelled transition system is a triple(S, Λ, →)where(→) ⊆ (S × Λ × S).A term-rewriting system (TRS) is a transition system whose set of states is given by a set of terms, and whose transition relation is given by a set of rewrite rules, which, for our purposes, will be pairs
p ↦ ewherepis a pattern (FO open) term andeis an expression (FO open) term, and the set of free variables ineis a subset of the set of free variables inp.If
(a, b)is a pair of terms in a TRS, we say thataderivesb(denoteda →* b) when there exists a finite sequence of rewrites that starts ataand ends withb. In other words,→*is the reflexive-transitive closure of the→relation. Similarly, the transitive closure of→is denoted by→⁺.A pair of terms
(a, b)in a TRS is joinable (denoteda ↑ b) iff there exists a termcsuch thata →* candb →* c.A pair of terms
(a, b)in a TRS is meetable iff there exists a termcsuch thatc →* aandc →* b.A TRS is locally confluent if for every triple of terms
(a, b, c)such thata → banda → c, there exists a termdsuch thatb →* dandc →* d.A TRS is confluent (or satisfies the Church-Rosser property) if for every triple of terms
(a, b, c)such thata →* banda →* c, there exists a termdsuch thatb →* dandc →* d.Without referring to any outside resources (spoilers are easy to find), come up with a term-rewriting system that is locally confluent but not confluent.
Extra credit: come up with a term-rewriting system that has no cycles (when thought of as a digraph) that is locally confluent but not confluent.
-
Write a type
Rule f vfor first-order rewrite rules. -
We can apply a rewrite rule
p ↦ eto a termtby unifyingpwithtto get a substitutionθ, and then applyingθtoe.Write a function that does this.
Template:
applyRule ∷ Rule f v → FOTerm f v → Maybe (FOTerm f v) -
Write a type
TRS f vfor first-order term-rewriting systems in terms ofRule. A term-rewriting system cannot contain the same rule twice. -
Write a type
LTRS f v lfor labelled first-order term-rewriting systems. Thelparameter is for the type of labels. -
Rewrite
TRS f vas a type alias forLTRS f v (). -
Write a function that computes the set of terms that are the result of applying a rewrite rule to a given term.
Template:
oneStepTRS ∷ TRS f v → FOTerm f v → Set (FOTerm f v) -
Generalize the
oneStepTRSfunction to theLTRStype.Template:
oneStepLTRS ∷ (Ord f, Ord v) ⇒ LTRS f v l → FOTerm f v → Map (FOTerm f v) l -
We can compute the set of terms derivable from a given term in a TRS by doing a breadth-first search using
oneStepLTRS. The search may not terminate so the output should be given through a callback. The callback will take the current rule (the node in the search tree) and the list of rule labels used so far (the path from the root to the current node in the search tree).Template:
forDerivable ∷ (Monad m) ⇒ LTRS f v l → FOTerm f v → (FOTerm f v → [l] → m a) → m () -
A critical pair in a term-rewriting system is a pair of terms
(t₁, t₂)such that there exists a termtfor which two different applications of a rewrite rule (either the same rule applied differently, or two different rules) yield the termst₁andt₂.More precisely, to compute the set of critical pairs of a term-rewriting system, we do the following for every (not necessarily distinct) pair of rules
r₁ = (p₁ ↦ e₁)andr₂ = (p₂ ↦ e₂):-
Simultaneously (i.e.: with the same substitution) rename the variables in
p₂ande₂so that the set of free variables ofr₂is disjoint from that ofr₁. -
For each non-variable subterm
sinp₁, try unifyingswithp₂. If unification succeeds, assume it returns a substitutionθ(if it fails, continue on in the loop).Denote the application (i.e.: simultaneous substitution) of
θto a termtbyθ(t).Define
xto beθ(e₁). Defineyto be the result of replacing every instance ofθ(s)inθ(p₁)withθ(e₂).Yield the critical pair
(x, y)and continue the loops.
Implement this algorithm for the
TRStype.Template:
criticalPairs ∷ TRS f v → Set (FOTerm f v, FOTerm f v) -
-
A critical pair is convergent iff it is joinable. If all the critical pairs of a term-rewriting system are convergent, then it is locally confluent.
Write a program, using
criticalPairsandforDerivable, that automatically checks if a given term-rewriting system is locally confluent. Do not worry about the efficiency of the algorithm. It should terminate if the given term-rewriting system is strongly-normalizing, but it may not if that is not the case.Template:
isLocallyConfluent ∷ TRS f v → Bool -
Implement the Knuth-Bendix completion algorithm, which computes a confluent and terminating TRS with the same deductive closure as the input TRS. The algorithm may not terminate. Try it on some simple TRSes: a theory with only ground terms (no variables), the theory of monoids of size
n, the theory of groups of sizen.Template:
knuthBendix ∷ TRS f v → TRS f v
- SAT solvers
- write the type of formulae in first-order classical logic (parameterized on types for relation and function symbols)
- write a function to convert FO formulae to negation normal form
- write a function to convert FO formulae to conjunctive normal form using the Tseytin transformation
- write a simple resolution-based theorem prover for first-order classical logic
- write a SAT solver using DPLL
- write a type of binary decision diagrams (and associated functions and tests)
- SMT solvers
- implement Cooper's algorithm for quantifier elimination in the theory of the integers
- implement the Ferrante-Rackoff algorithm for quantifier elimination in the theory of the rationals
- implement the Nelson-Oppen method for combining decision procedures
- Type theory and proof theory
- implement an interpreter for the untyped lambda calculus
- implement a typechecker for simply-typed lambda calculus
- implement a typechecker for System F
- implement a typechecker for the calculus of constructions
- implement a typechecker for System F + row polymorphism (w/
Has+Lacks) - implement a typechecker for System F + refinement ("liquid") types
- implement a proof checker for proofs in ZF set theory
- Hoare logic
- define a simple imperative language IMP
- write an interpreter for IMP
- add
assertand preconditions and postconditions and loop invariant annotations to IMP - write a function that computes weakest precondition
- write a function that computes strongest postcondition
- write a function that computes a verification condition
- use SMT solver to automatically verify partial correctness of IMP code
- add ranking function annotations to IMP
- use SMT solver to automatically verify total correctness of IMP code
- Separation logic
- http://www.cs.cmu.edu/~jcr/seplogic.pdf
- add heap allocation and separation logic annotations to IMP
- write a proof checker for concurrent separation logic
- Modal logic
- write a tableaux prover for S4 modal logic
- express a situation in epistemic modal logic (S5)
- Temporal logic
- write the type of formulae in linear temporal logic (LTL)
- write a function to convert LTL formulae to negation normal form
- write a type of Büchi automata
- write a function to convert LTL formulae to the associated Büchi automaton
- write a function for the intersection of Büchi automata
- write a model checker for LTL (easy once you have done the above)
- write a type of Kripke structures
- write a type of formulae in computation tree logic (CTL)
- write a model checker for CTL
- Abstract interpretation
- write a function that does interval abstract interpretation on IMP (see section 12.2 of CoC)
- write a function that bounds the complexity class of IMP code using an abstract domain of countable ordinals