author | Christian Urban <urbanc@in.tum.de> |
Thu, 10 Nov 2011 19:25:25 +0000 | |
changeset 494 | 743020b817af |
parent 488 | 780100cd4060 |
child 514 | 7e25716c3744 |
permissions | -rw-r--r-- |
23 | 1 |
theory Base |
459 | 2 |
imports Main |
3 |
"~~/src/HOL/Library/LaTeXsugar" |
|
23 | 4 |
uses |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
5 |
("output_tutorial.ML") |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
6 |
("antiquote_setup.ML") |
23 | 7 |
begin |
8 |
||
394 | 9 |
notation (latex output) |
10 |
Cons ("_ # _" [66,65] 65) |
|
11 |
||
317
d69214e47ef9
added an experimental antiquotation to replace eventually ML_response_fake
Christian Urban <urbanc@in.tum.de>
parents:
316
diff
changeset
|
12 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
13 |
(* re-definition of various ML antiquotations *) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
14 |
(* to have a special tag for text enclosed in ML; *) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
15 |
(* they also write the code into a separate file *) |
301
2728e8daebc0
replaced "writeln" with "tracing"
Christian Urban <urbanc@in.tum.de>
parents:
264
diff
changeset
|
16 |
|
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
17 |
ML {* |
462 | 18 |
val filename = Attrib.setup_config_string @{binding "filename"} (K "File_Code.ML") |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
19 |
*} |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
20 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
21 |
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
22 |
ML {* |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
23 |
fun write_file txt thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
24 |
let |
423 | 25 |
val stream = Config.get_global thy filename |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
26 |
|> TextIO.openAppend |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
27 |
in |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
28 |
TextIO.output (stream, txt); |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
29 |
TextIO.flushOut stream; (* needed ?*) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
30 |
TextIO.closeOut stream |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
31 |
end |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
32 |
*} |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
33 |
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
34 |
ML {* |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
35 |
fun write_file_ml_blk txt thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
36 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
37 |
val pre = implode ["\n", "ML ", "{", "*", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
38 |
val post = implode ["\n", "*", "}", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
39 |
val _ = write_file (enclose pre post txt) thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
40 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
41 |
thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
42 |
end |
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
43 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
44 |
fun write_file_setup_blk txt thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
45 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
46 |
val pre = implode ["\n", "setup ", "{", "*", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
47 |
val post = implode ["\n", "*", "}", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
48 |
val _ = write_file (enclose pre post txt) thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
49 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
50 |
thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
51 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
52 |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
53 |
fun write_file_lsetup_blk txt lthy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
54 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
55 |
val pre = implode ["\n", "local_setup ", "{", "*", "\n"] |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
56 |
val post = implode ["\n", "*", "}", "\n"] |
475
25371f74c768
updated to post-2011-1 Isabelle
Christian Urban <urbanc@in.tum.de>
parents:
471
diff
changeset
|
57 |
val _ = write_file (enclose pre post txt) (Proof_Context.theory_of lthy) |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
58 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
59 |
lthy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
60 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
61 |
|
310
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
62 |
*} |
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
63 |
|
007922777ff1
added some rudimentary inrastructure for producing the ML-code
Christian Urban <urbanc@in.tum.de>
parents:
302
diff
changeset
|
64 |
ML {* |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
65 |
fun open_file name thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
66 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
67 |
val _ = tracing ("Open File: " ^ name) |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
68 |
val _ = TextIO.openOut name |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
69 |
in |
423 | 70 |
Config.put_global filename name thy |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
71 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
72 |
*} |
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
73 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
74 |
ML {* |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
75 |
fun open_file_with_prelude name txts thy = |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
76 |
let |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
77 |
val thy' = open_file name thy |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
78 |
val _ = write_file (cat_lines txts) thy' |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
79 |
in |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
80 |
thy' |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
81 |
end |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
82 |
*} |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
83 |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
84 |
ML {* |
260
5accec94b6df
updated to lates Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
256
diff
changeset
|
85 |
fun propagate_env (context as Context.Proof lthy) = |
394 | 86 |
Context.Proof (Local_Theory.map_contexts (ML_Env.inherit context) lthy) |
264 | 87 |
| propagate_env context = context |
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
88 |
|
260
5accec94b6df
updated to lates Isabelle changes
Christian Urban <urbanc@in.tum.de>
parents:
256
diff
changeset
|
89 |
fun propagate_env_prf prf = Proof.map_contexts |
264 | 90 |
(Context.proof_map (ML_Env.inherit (Context.Proof (Proof.context_of prf)))) prf |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
91 |
*} |
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
92 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
93 |
ML {* |
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
94 |
val _ = |
426 | 95 |
Outer_Syntax.command "ML" "eval ML text within theory" |
96 |
(Keyword.tag "TutorialML" Keyword.thy_decl) |
|
97 |
(Parse.position Parse.text >> |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
98 |
(fn (txt, pos) => |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
99 |
Toplevel.generic_theory |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
100 |
(ML_Context.exec |
438 | 101 |
(fn () => ML_Context.eval_text true pos txt) |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
102 |
#> propagate_env #> Context.map_theory (write_file_ml_blk txt)))) |
438 | 103 |
*} |
488 | 104 |
|
438 | 105 |
ML {* |
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
106 |
val _ = |
426 | 107 |
Outer_Syntax.command "ML_prf" "ML text within proof" |
488 | 108 |
(Keyword.tag "TutorialMLprf" Keyword.prf_decl) |
426 | 109 |
(Parse.ML_source >> (fn (txt, pos) => |
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
110 |
Toplevel.proof (Proof.map_context (Context.proof_map |
438 | 111 |
(ML_Context.exec (fn () => ML_Context.eval_text true pos txt))) #> propagate_env_prf))) |
112 |
*} |
|
210
db8e302f44c8
more work on the simple inductive section
Christian Urban <urbanc@in.tum.de>
parents:
189
diff
changeset
|
113 |
|
438 | 114 |
ML {* |
224
647cab4a72c2
finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents:
210
diff
changeset
|
115 |
val _ = |
426 | 116 |
Outer_Syntax.command "ML_val" "diagnostic ML text" |
117 |
(Keyword.tag "TutorialML" Keyword.diag) |
|
438 | 118 |
(Parse.ML_source >> Isar_Cmd.ml_diag true) |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
119 |
*} |
224
647cab4a72c2
finished the heavy duty stuff for the inductive package
Christian Urban <urbanc@in.tum.de>
parents:
210
diff
changeset
|
120 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
121 |
ML {* |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
122 |
val _ = |
426 | 123 |
Outer_Syntax.command "setup" "ML theory setup" |
124 |
(Keyword.tag_ml Keyword.thy_decl) |
|
125 |
(Parse.ML_source >> (fn (txt, pos) => |
|
438 | 126 |
(Toplevel.theory (Isar_Cmd.global_setup (txt, pos) #> write_file_setup_blk txt)))) |
64
9a6e5e0c4906
deleted old files and added code to give a special tag to the command ML
Christian Urban <urbanc@in.tum.de>
parents:
57
diff
changeset
|
127 |
*} |
239
b63c72776f03
replaced "warning" with "writeln"
Christian Urban <urbanc@in.tum.de>
parents:
224
diff
changeset
|
128 |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
129 |
ML {* |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
130 |
val _ = |
426 | 131 |
Outer_Syntax.local_theory "local_setup" "ML local theory setup" |
132 |
(Keyword.tag_ml Keyword.thy_decl) |
|
133 |
(Parse.ML_source >> (fn (txt, pos) => |
|
438 | 134 |
Isar_Cmd.local_setup (txt, pos) #> write_file_lsetup_blk txt)); |
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
135 |
*} |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
136 |
|
396 | 137 |
ML {* |
138 |
fun P n = @{term "P::nat \<Rightarrow> bool"} $ (HOLogic.mk_number @{typ "nat"} n) |
|
139 |
||
140 |
fun rhs 1 = P 1 |
|
141 |
| rhs n = HOLogic.mk_conj (P n, rhs (n - 1)) |
|
142 |
||
143 |
fun lhs 1 n = HOLogic.mk_imp (HOLogic.mk_eq (P 1, P n), rhs n) |
|
144 |
| lhs m n = HOLogic.mk_conj (HOLogic.mk_imp |
|
145 |
(HOLogic.mk_eq (P (m - 1), P m), rhs n), lhs (m - 1) n) |
|
146 |
||
147 |
fun de_bruijn n = |
|
148 |
HOLogic.mk_Trueprop (HOLogic.mk_imp (lhs n n, rhs n)) |
|
149 |
*} |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
150 |
|
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
151 |
use "output_tutorial.ML" |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
152 |
use "antiquote_setup.ML" |
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
153 |
|
471 | 154 |
setup {* OutputTutorial.setup *} |
155 |
setup {* AntiquoteSetup.setup *} |
|
346
0fea8b7a14a1
tuned the ML-output mechanism; tuned slightly the text
Christian Urban <urbanc@in.tum.de>
parents:
328
diff
changeset
|
156 |
|
239
b63c72776f03
replaced "warning" with "writeln"
Christian Urban <urbanc@in.tum.de>
parents:
224
diff
changeset
|
157 |
end |