src/CTT/ex/Equality.thy
author wenzelm
Sun Nov 02 18:21:45 2014 +0100 (2014-11-02)
changeset 58889 5b7a9633cfa8
parent 35762 af3ff2ba4c54
child 58963 26bf09b95dda
permissions -rw-r--r--
modernized header uniformly as section;
wenzelm@19761
     1
(*  Title:      CTT/ex/Equality.thy
wenzelm@19761
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
wenzelm@19761
     3
    Copyright   1991  University of Cambridge
wenzelm@19761
     4
*)
wenzelm@19761
     5
wenzelm@58889
     6
section "Equality reasoning by rewriting"
wenzelm@19761
     7
wenzelm@19761
     8
theory Equality
wenzelm@19761
     9
imports CTT
wenzelm@19761
    10
begin
wenzelm@19761
    11
wenzelm@19761
    12
lemma split_eq: "p : Sum(A,B) ==> split(p,pair) = p : Sum(A,B)"
wenzelm@19761
    13
apply (rule EqE)
wenzelm@19761
    14
apply (rule elim_rls, assumption)
wenzelm@19761
    15
apply (tactic "rew_tac []")
wenzelm@19761
    16
done
wenzelm@19761
    17
wenzelm@19761
    18
lemma when_eq: "[| A type;  B type;  p : A+B |] ==> when(p,inl,inr) = p : A + B"
wenzelm@19761
    19
apply (rule EqE)
wenzelm@19761
    20
apply (rule elim_rls, assumption)
wenzelm@19761
    21
apply (tactic "rew_tac []")
wenzelm@19761
    22
done
wenzelm@19761
    23
wenzelm@19761
    24
(*in the "rec" formulation of addition, 0+n=n *)
wenzelm@19761
    25
lemma "p:N ==> rec(p,0, %y z. succ(y)) = p : N"
wenzelm@19761
    26
apply (rule EqE)
wenzelm@19761
    27
apply (rule elim_rls, assumption)
wenzelm@19761
    28
apply (tactic "rew_tac []")
wenzelm@19761
    29
done
wenzelm@19761
    30
wenzelm@19761
    31
(*the harder version, n+0=n: recursive, uses induction hypothesis*)
wenzelm@19761
    32
lemma "p:N ==> rec(p,0, %y z. succ(z)) = p : N"
wenzelm@19761
    33
apply (rule EqE)
wenzelm@19761
    34
apply (rule elim_rls, assumption)
wenzelm@19761
    35
apply (tactic "hyp_rew_tac []")
wenzelm@19761
    36
done
wenzelm@19761
    37
wenzelm@19761
    38
(*Associativity of addition*)
wenzelm@19761
    39
lemma "[| a:N;  b:N;  c:N |]
wenzelm@19761
    40
      ==> rec(rec(a, b, %x y. succ(y)), c, %x y. succ(y)) =
wenzelm@19761
    41
          rec(a, rec(b, c, %x y. succ(y)), %x y. succ(y)) : N"
wenzelm@27208
    42
apply (tactic {* NE_tac @{context} "a" 1 *})
wenzelm@19761
    43
apply (tactic "hyp_rew_tac []")
wenzelm@19761
    44
done
wenzelm@19761
    45
wenzelm@19761
    46
(*Martin-Lof (1984) page 62: pairing is surjective*)
wenzelm@19761
    47
lemma "p : Sum(A,B) ==> <split(p,%x y. x), split(p,%x y. y)> = p : Sum(A,B)"
wenzelm@19761
    48
apply (rule EqE)
wenzelm@19761
    49
apply (rule elim_rls, assumption)
wenzelm@19761
    50
apply (tactic {* DEPTH_SOLVE_1 (rew_tac []) *}) (*!!!!!!!*)
wenzelm@19761
    51
done
wenzelm@19761
    52
wenzelm@19761
    53
lemma "[| a : A;  b : B |] ==>
wenzelm@19761
    54
     (lam u. split(u, %v w.<w,v>)) ` <a,b> = <b,a> : SUM x:B. A"
wenzelm@19761
    55
apply (tactic "rew_tac []")
wenzelm@19761
    56
done
wenzelm@19761
    57
wenzelm@19761
    58
(*a contrived, complicated simplication, requires sum-elimination also*)
wenzelm@19761
    59
lemma "(lam f. lam x. f`(f`x)) ` (lam u. split(u, %v w.<w,v>)) =
wenzelm@19761
    60
      lam x. x  :  PROD x:(SUM y:N. N). (SUM y:N. N)"
wenzelm@19761
    61
apply (rule reduction_rls)
wenzelm@19761
    62
apply (rule_tac [3] intrL_rls)
wenzelm@19761
    63
apply (rule_tac [4] EqE)
wenzelm@19761
    64
apply (rule_tac [4] SumE, tactic "assume_tac 4")
wenzelm@19761
    65
(*order of unifiers is essential here*)
wenzelm@19761
    66
apply (tactic "rew_tac []")
wenzelm@19761
    67
done
wenzelm@19761
    68
wenzelm@19761
    69
end