author | paulson <lp15@cam.ac.uk> |
Fri, 08 Aug 2025 16:46:03 +0100 | |
changeset 82969 | dedd9d13c79c |
parent 76539 | 8c94ca4dd035 |
permissions | -rw-r--r-- |
19761 | 1 |
(* Title: CTT/ex/Typechecking.thy |
2 |
Author: Lawrence C Paulson, Cambridge University Computer Laboratory |
|
3 |
Copyright 1991 University of Cambridge |
|
4 |
*) |
|
5 |
||
76539
8c94ca4dd035
A new Isabelle/CTT example, and eliminated some old-style quotation marks
paulson <lp15@cam.ac.uk>
parents:
76377
diff
changeset
|
6 |
section \<open>Easy examples: type checking and type deduction\<close> |
19761 | 7 |
|
8 |
theory Typechecking |
|
58974 | 9 |
imports "../CTT" |
19761 | 10 |
begin |
11 |
||
60770 | 12 |
subsection \<open>Single-step proofs: verifying that a type is well-formed\<close> |
19761 | 13 |
|
61337 | 14 |
schematic_goal "?A type" |
76377 | 15 |
by (rule form_rls) |
19761 | 16 |
|
61337 | 17 |
schematic_goal "?A type" |
76377 | 18 |
apply (rule form_rls) |
19 |
back |
|
20 |
apply (rule form_rls) |
|
21 |
apply (rule form_rls) |
|
22 |
done |
|
19761 | 23 |
|
61391 | 24 |
schematic_goal "\<Prod>z:?A . N + ?B(z) type" |
76377 | 25 |
apply (rule form_rls) |
26 |
apply (rule form_rls) |
|
27 |
apply (rule form_rls) |
|
28 |
apply (rule form_rls) |
|
29 |
apply (rule form_rls) |
|
30 |
done |
|
19761 | 31 |
|
32 |
||
60770 | 33 |
subsection \<open>Multi-step proofs: Type inference\<close> |
19761 | 34 |
|
61391 | 35 |
lemma "\<Prod>w:N. N + N type" |
76377 | 36 |
by form |
19761 | 37 |
|
61337 | 38 |
schematic_goal "<0, succ(0)> : ?A" |
76377 | 39 |
apply intr done |
19761 | 40 |
|
61391 | 41 |
schematic_goal "\<Prod>w:N . Eq(?A,w,w) type" |
76377 | 42 |
apply typechk done |
19761 | 43 |
|
61391 | 44 |
schematic_goal "\<Prod>x:N . \<Prod>y:N . Eq(?A,x,y) type" |
76377 | 45 |
apply typechk done |
19761 | 46 |
|
76539
8c94ca4dd035
A new Isabelle/CTT example, and eliminated some old-style quotation marks
paulson <lp15@cam.ac.uk>
parents:
76377
diff
changeset
|
47 |
text \<open>typechecking an application of fst\<close> |
61391 | 48 |
schematic_goal "(\<^bold>\<lambda>u. split(u, \<lambda>v w. v)) ` <0, succ(0)> : ?A" |
76377 | 49 |
apply typechk done |
19761 | 50 |
|
76539
8c94ca4dd035
A new Isabelle/CTT example, and eliminated some old-style quotation marks
paulson <lp15@cam.ac.uk>
parents:
76377
diff
changeset
|
51 |
text \<open>typechecking the predecessor function\<close> |
61391 | 52 |
schematic_goal "\<^bold>\<lambda>n. rec(n, 0, \<lambda>x y. x) : ?A" |
76377 | 53 |
apply typechk done |
19761 | 54 |
|
76539
8c94ca4dd035
A new Isabelle/CTT example, and eliminated some old-style quotation marks
paulson <lp15@cam.ac.uk>
parents:
76377
diff
changeset
|
55 |
text \<open>typechecking the addition function\<close> |
61391 | 56 |
schematic_goal "\<^bold>\<lambda>n. \<^bold>\<lambda>m. rec(n, m, \<lambda>x y. succ(y)) : ?A" |
76377 | 57 |
apply typechk done |
19761 | 58 |
|
76377 | 59 |
text \<open>Proofs involving arbitrary types. |
60 |
For concreteness, every type variable left over is forced to be @{term N}\<close> |
|
59498
50b60f501b05
proper context for resolve_tac, eresolve_tac, dresolve_tac, forward_tac etc.;
wenzelm
parents:
58977
diff
changeset
|
61 |
method_setup N = |
60770 | 62 |
\<open>Scan.succeed (fn ctxt => SIMPLE_METHOD (TRYALL (resolve_tac ctxt @{thms NF})))\<close> |
19761 | 63 |
|
61391 | 64 |
schematic_goal "\<^bold>\<lambda>w. <w,w> : ?A" |
76377 | 65 |
apply typechk |
66 |
apply N |
|
67 |
done |
|
19761 | 68 |
|
61391 | 69 |
schematic_goal "\<^bold>\<lambda>x. \<^bold>\<lambda>y. x : ?A" |
76377 | 70 |
apply typechk |
71 |
apply N |
|
72 |
done |
|
19761 | 73 |
|
76539
8c94ca4dd035
A new Isabelle/CTT example, and eliminated some old-style quotation marks
paulson <lp15@cam.ac.uk>
parents:
76377
diff
changeset
|
74 |
text \<open>typechecking fst (as a function object)\<close> |
61391 | 75 |
schematic_goal "\<^bold>\<lambda>i. split(i, \<lambda>j k. j) : ?A" |
76377 | 76 |
apply typechk |
77 |
apply N |
|
78 |
done |
|
19761 | 79 |
|
80 |
end |