Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- The "Tm" type and the previously defined transition and closedness judgements.
- Do not modify these!
- The task starts at line 150.
- *)
- (* Require Import String. *)
- Require Import Coq.Strings.String.
- Require Import Coq.Lists.List.
- Require Import Coq.Lists.ListSet.
- Open Scope string_scope.
- (* Open Scope list_scope. *)
- Import ListNotations.
- (* -=- Var -=- *)
- Definition Var := string.
- Definition Var_dec := string_dec.
- Definition x := "x".
- Definition y := "y".
- Definition z := "z".
- (* -=- Tm -=- *)
- Inductive Tm : Set :=
- | variable (v : Var) : Tm
- | lambda (v : Var) (t : Tm) : Tm
- | application (t t' : Tm) : Tm
- .
- Notation "' v" := (variable v) (at level 3).
- Notation "\ v , t" := (lambda v t) (at level 5).
- Notation "t $ t'" := (application t t') (at level 4).
- (* -=- Rename -=- *)
- Reserved Notation "t { x |-> y }" (at level 1).
- Fixpoint rename (tm : Tm) (y z : Var) : Tm :=
- match tm with
- | ' x => if x =? y then 'z else 'x
- | \ x , t => if x =? y then \z,t{y|->z} else \x,t{y|->z}
- | t $ t' => t{y|->z} $ t'{y|->z}
- end
- where "t { y |-> z }" := (rename t y z).
- Compute (rename (\x,'x) x y).
- (* -=- Substitute -=- *)
- Reserved Notation "t [ x |-> t' ]" (at level 2).
- Fixpoint substitute (tm : Tm) (x : Var) (tm' : Tm) : Tm :=
- match tm with
- | ' y => if x =? y then tm' else ' y
- | \ y , t => if x =? y then \y,t else \y,t[x|->tm']
- | t $ t' => t[x|->tm'] $ t'[x|->tm']
- end
- where "t [ x |-> t' ]" := (substitute t x t').
- Compute (' x $ (\x, 'x $ ' x))[x |-> ' z].
- Compute (\y,'z)[z |-> 'y].
- (* -=- context -=- *)
- Definition context := list Var.
- Definition empty : context := nil.
- (* -=- Closed -=- *)
- Inductive Closed' : context -> Tm -> Prop :=
- | C_variable {c : context} {v : Var} : In v c -> Closed' c ('v)
- | C_lambda {c : context} {v : Var} {t : Tm} : Closed' (v :: c) t -> Closed' c (\v,t)
- | C_application {c : context} {t t' : Tm} : Closed' c t -> Closed' c t' -> Closed' c (t $ t')
- .
- Definition Closed := Closed' empty.
- Ltac proove_closed :=
- repeat (
- (
- eapply C_variable;
- simpl;
- repeat (
- (left; reflexivity) ||
- right
- )
- ) ||
- eapply C_lambda ||
- eapply C_application
- )
- .
- (* -=- One Step Transition Judgement -=- *)
- Reserved Notation "t |--> t'" (at level 100).
- Inductive OneStepTransitionJudgement : Tm -> Tm -> Prop :=
- | OSTJ_beta {x : Var} {t t1 : Tm} :
- Closed t1 ->
- ((\x,t) $ t1) |--> t[x |-> t1]
- | OSTJ_lambda {x : Var} {t t' : Tm} :
- (t |--> t') ->
- \x,t |--> \x,t'
- | OSTJ_application_left {t1 t1' t2 : Tm} :
- (t1 |--> t1') ->
- t1 $ t2 |--> t1' $ t2
- | OSTJ_application_right {t1 t2 t2' : Tm} :
- (t2 |--> t2') ->
- t1 $ t2 |--> t1 $ t2'
- where "t |--> t'" := (OneStepTransitionJudgement t t').
- (* -=- Any Step Transition Judgement -=- *)
- Reserved Notation "t |-->* t'" (at level 100).
- Ltac beta_reduce := eapply OSTJ_beta; (proove_closed || assumption).
- Inductive AnyStepTransitionJudgement : Tm -> Tm -> Prop :=
- | ASTJ_refl {t : Tm} :
- t |-->* t
- | ASTJ_trans {t t'' : Tm} (t' : Tm) :
- (t |--> t') -> (t' |-->* t'') ->
- t |-->* t''
- where "t |-->* t'" := (AnyStepTransitionJudgement t t').
- Ltac prove_closed :=
- repeat(
- ( eapply C_variable; simpl; repeat((left; reflexivity) || right))||
- eapply C_lambda ||
- eapply C_application )
- .
- Ltac beta := (eapply OSTJ_beta; prove_closed).
- (* -=- true, false -=- *)
- Definition true := \x,\y,'x.
- Definition false := \x,\y,'y.
- Definition not := \x,('x $ false $ true).
- Definition and := \x,\y,'x $ 'y $ false.
- Definition or := \x,\y,('x $ true $ 'y).
- Definition xor := \x,\y,('x $ ('y $ false $ true) $ 'y).
- (* -------------------------------------------------------------- *)
- Theorem not1 : not $ true |-->* false.
- Proof.
- eapply ASTJ_trans.
- beta.
- eapply ASTJ_trans.
- simpl.
- eapply OSTJ_application_left.
- beta.
- eapply ASTJ_trans.
- simpl.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- Theorem not2 : not $ false |-->* true.
- Proof.
- eapply ASTJ_trans.
- beta.
- eapply ASTJ_trans.
- simpl.
- eapply OSTJ_application_left.
- beta.
- eapply ASTJ_trans.
- simpl.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- (* -------------------------------------------------------------- *)
- Lemma and1 : and $ true $ true |-->* true.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl. unfold true.
- eapply ASTJ_refl.
- Qed.
- Lemma and2 : and $ true $ false |-->* false.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- unfold false.
- eapply ASTJ_refl.
- Qed.
- Lemma and3 : and $ false $ true |-->* false.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- unfold false.
- eapply ASTJ_refl.
- Qed.
- Lemma and4 : and $ false $ false |-->* false.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- unfold false.
- eapply ASTJ_refl.
- Qed.
- (* -------------------------------------------------------------- *)
- Theorem or1 : or $ true $ true |-->* true.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl. unfold true.
- eapply ASTJ_refl.
- Qed.
- Theorem or2 : or $ true $ false |-->* true.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- eapply ASTJ_trans.
- simpl.
- beta.
- eapply ASTJ_trans.
- simpl.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- Theorem or3 : or $ false $ true |-->* true.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- eapply ASTJ_trans.
- simpl.
- beta.
- eapply ASTJ_trans.
- simpl.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- Theorem or4 : or $ false $ false |-->* false.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- eapply ASTJ_trans.
- simpl.
- beta.
- eapply ASTJ_trans.
- simpl.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- (* -------------------------------------------------------------- *)
- Theorem xor1 : xor $ true $ true |-->* false.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- Theorem xor2 : xor $ true $ false |-->* true.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- Theorem xor3 : xor $ false $ true |-->* true.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
- Theorem xor4 : xor $ false $ false |-->* false.
- Proof.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_trans.
- eapply OSTJ_application_left.
- beta.
- simpl.
- eapply ASTJ_trans.
- beta.
- simpl.
- eapply ASTJ_refl.
- Qed.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement