Tutorial
1. Type uniqueness
2. Reasoning about paths in lambda-terms
3. Subject reduction
4. Equality reasoning
5. Reasoning about a "smaller" relation on lambda-terms
This simple example illustrates the expressive power of Beluga. It is simpler than the example where we reason about paths in a lambda term. To simplify matters even further, this example uses untyped lambda-terms. They are defined as before, except that lambda-abstractions do not have type annotations.
If you'd like to run this example using Beluga, please download struct-smaller.bel, which contains all the data-type definitions and the implementation of the proof as a recursive function.
We begin by defining when a lambda-term is a subterm of another lambda-term. The type family
datatype eq : exp → exp →type = | e_ref: eq T T ;datatype lt : exp → exp →type = | lt_lam: ({x:exp}le N (M x)) → lt N (lam M) | lt_appl: le N M1 → lt N (app M1 M2) | lt_appr: le N M1 → lt N (app M1 M2) and le : exp → exp →type = | le_= : eq M N → le M N | le_< : lt M N → le M N ;
We want to prove the following theorem:
Theorem:
If, for all
This is a simple example to illustrate the expressive power of Beluga. Because the statements require nested quantification and implication, it is not possible to state this theorem directly in some systems such as the Twelf system.
We will state here a more general version which allows the context to be non-empty.
Lemma:
If, for all
The context Γ contains assumptions
schema ctx = exp ;
On paper proof:
To prove the above theorem, we proceed as follows: Assume that
"for all
The proof for the stated lemma can be implemented as a function which has the following type:
{g:ctx}({M:[g. exp]} [g. le (M ..) (N ..)] → [g. le (M ..) (K ..)])
→ [g. le (N ..) (K ..)]
The type corresponds directly to the specified lemma where
The proof can be implemented as a function in Beluga following closely the more informal
development given earlier. We treat computation-level expressions that correspond
to quantifier introduction and elimination the same as the expressions
corresponding to implication introduction and elimination. To introduce a universally
quantified meta-variable
rec lemma : {g:ctx}({M:[g. exp]} [g. le (M ..) (N ..)] → [g. le (M ..) (K ..)]) → [g. le (N ..) (K ..)] =mlam g ⇒fn f ⇒ f [g. _ ] [g. le_= e_ref] ;
In the code we write