src/CTT/ex/Typechecking.thy
author wenzelm
Mon, 14 Oct 2013 15:21:45 +0200
changeset 54332 a38160ad741c
parent 39159 0dec18004e75
child 58889 5b7a9633cfa8
permissions -rw-r--r--
tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     1
(*  Title:      CTT/ex/Typechecking.thy
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     2
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     3
    Copyright   1991  University of Cambridge
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     4
*)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     5
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     6
header "Easy examples: type checking and type deduction"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     7
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     8
theory Typechecking
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
     9
imports CTT
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    10
begin
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    11
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    12
subsection {* Single-step proofs: verifying that a type is well-formed *}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    13
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    14
schematic_lemma "?A type"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    15
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    16
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    17
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    18
schematic_lemma "?A type"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    19
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    20
back
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    21
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    22
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    23
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    24
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    25
schematic_lemma "PROD z:?A . N + ?B(z) type"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    26
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    27
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    28
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    29
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    30
apply (rule form_rls)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    31
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    32
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    33
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    34
subsection {* Multi-step proofs: Type inference *}
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    35
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    36
lemma "PROD w:N. N + N type"
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    37
apply (tactic form_tac)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    38
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    39
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    40
schematic_lemma "<0, succ(0)> : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    41
apply (tactic "intr_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    42
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    43
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    44
schematic_lemma "PROD w:N . Eq(?A,w,w) type"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    45
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    46
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    47
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    48
schematic_lemma "PROD x:N . PROD y:N . Eq(?A,x,y) type"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    49
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    50
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    51
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    52
text "typechecking an application of fst"
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    53
schematic_lemma "(lam u. split(u, %v w. v)) ` <0, succ(0)> : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    54
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    55
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    56
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    57
text "typechecking the predecessor function"
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    58
schematic_lemma "lam n. rec(n, 0, %x y. x) : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    59
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    60
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    61
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    62
text "typechecking the addition function"
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    63
schematic_lemma "lam n. lam m. rec(n, m, %x y. succ(y)) : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    64
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    65
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    66
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    67
(*Proofs involving arbitrary types.
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    68
  For concreteness, every type variable left over is forced to be N*)
39159
0dec18004e75 more antiquotations;
wenzelm
parents: 36319
diff changeset
    69
ML {* val N_tac = TRYALL (rtac @{thm NF}) *}
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    70
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    71
schematic_lemma "lam w. <w,w> : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    72
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    73
apply (tactic N_tac)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    74
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    75
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    76
schematic_lemma "lam x. lam y. x : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    77
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    78
apply (tactic N_tac)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    79
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    80
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    81
text "typechecking fst (as a function object)"
36319
8feb2c4bef1a mark schematic statements explicitly;
wenzelm
parents: 35762
diff changeset
    82
schematic_lemma "lam i. split(i, %j k. j) : ?A"
19761
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    83
apply (tactic "typechk_tac []")
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    84
apply (tactic N_tac)
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    85
done
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    86
5cd82054c2c6 removed obsolete ML files;
wenzelm
parents:
diff changeset
    87
end