124 end; |
124 end; |
125 |
125 |
126 |
126 |
127 (* proofs *) |
127 (* proofs *) |
128 |
128 |
|
129 datatype zproof_name = |
|
130 ZAxiom of string |
|
131 | ZOracle of string |
|
132 | ZBox of serial; |
|
133 |
129 datatype zproof = |
134 datatype zproof = |
130 ZDummy (*dummy proof*) |
135 ZDummy (*dummy proof*) |
|
136 | ZConstP of zproof_name * zterm * ztyp ZTVars.table * zterm ZVars.table |
131 | ZBoundP of int |
137 | ZBoundP of int |
132 | ZHyp of zterm |
138 | ZHyp of zterm |
133 | ZAbst of string * ztyp * zproof |
139 | ZAbst of string * ztyp * zproof |
134 | ZAbsP of string * zterm * zproof |
140 | ZAbsP of string * zterm * zproof |
135 | ZAppt of zproof * zterm |
141 | ZAppt of zproof * zterm |
136 | ZAppP of zproof * zproof |
142 | ZAppP of zproof * zproof |
137 | ZClassP of ztyp * class (*OFCLASS proof from sorts algebra*) |
143 | ZClassP of ztyp * class; (*OFCLASS proof from sorts algebra*) |
138 | ZAxiom of {name: string, oracle: bool} * zterm * (ztyp ZTVars.table * zterm ZVars.table); |
|
139 |
144 |
140 |
145 |
141 |
146 |
142 (*** local ***) |
147 (*** local ***) |
143 |
148 |
157 val term_of: Consts.T -> zterm -> term |
162 val term_of: Consts.T -> zterm -> term |
158 val global_zterm_of: theory -> term -> zterm |
163 val global_zterm_of: theory -> term -> zterm |
159 val global_term_of: theory -> zterm -> term |
164 val global_term_of: theory -> zterm -> term |
160 val dummy_proof: 'a -> zproof |
165 val dummy_proof: 'a -> zproof |
161 val todo_proof: 'a -> zproof |
166 val todo_proof: 'a -> zproof |
162 val axiom_proof: theory -> {name: string, oracle: bool} -> term -> zproof |
167 val axiom_proof: theory -> string -> term -> zproof |
|
168 val oracle_proof: theory -> string -> term -> zproof |
163 val assume_proof: theory -> term -> zproof |
169 val assume_proof: theory -> term -> zproof |
164 val trivial_proof: theory -> term -> zproof |
170 val trivial_proof: theory -> term -> zproof |
165 val implies_intr_proof: theory -> term -> zproof -> zproof |
171 val implies_intr_proof: theory -> term -> zproof -> zproof |
166 val forall_intr_proof: theory -> typ -> string * term -> zproof -> zproof |
172 val forall_intr_proof: theory -> typ -> string * term -> zproof -> zproof |
167 val forall_elim_proof: theory -> term -> zproof -> zproof |
173 val forall_elim_proof: theory -> term -> zproof -> zproof |
194 |
200 |
195 (* instantiation *) |
201 (* instantiation *) |
196 |
202 |
197 fun init_instT t = ZTVars.build (ZTVars.add_tvars t) |> ZTVars.map (fn v => fn _ => ZTVar v); |
203 fun init_instT t = ZTVars.build (ZTVars.add_tvars t) |> ZTVars.map (fn v => fn _ => ZTVar v); |
198 fun init_inst t = ZVars.build (ZVars.add_vars t) |> ZVars.map (fn v => fn _ => ZVar v); |
204 fun init_inst t = ZVars.build (ZVars.add_vars t) |> ZVars.map (fn v => fn _ => ZVar v); |
199 fun init_insts t = (init_instT t, init_inst t); |
205 |
|
206 fun map_const_proof (f, g) prf = |
|
207 (case prf of |
|
208 ZConstP (a, A, instT, inst) => |
|
209 let |
|
210 val instT' = ZTVars.map (fn ((x, _), _) => fn y => the_default y (try f x)) instT; |
|
211 val inst' = ZVars.map (fn ((x, _), _) => fn y => the_default y (try g x)) inst; |
|
212 in ZConstP (a, A, instT', inst') end |
|
213 | _ => prf); |
200 |
214 |
201 |
215 |
202 (* convert ztyp / zterm vs. regular typ / term *) |
216 (* convert ztyp / zterm vs. regular typ / term *) |
203 |
217 |
204 fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S) |
218 fun ztyp_of (TFree (a, S)) = ZTVar ((a, ~1), S) |
262 val todo_proof = dummy_proof; |
276 val todo_proof = dummy_proof; |
263 |
277 |
264 |
278 |
265 (* basic logic *) |
279 (* basic logic *) |
266 |
280 |
267 fun axiom_proof thy a A = |
281 fun const_proof thy a A = |
268 let |
282 let |
269 val t = global_zterm_of thy A; |
283 val t = global_zterm_of thy A; |
270 val insts = init_insts t; |
284 val instT = init_instT t; |
271 in ZAxiom (a, t, insts) end; |
285 val inst = init_inst t; |
|
286 in ZConstP (a, t, instT, inst) end; |
|
287 |
|
288 fun axiom_proof thy name = const_proof thy (ZAxiom name); |
|
289 fun oracle_proof thy name = const_proof thy (ZOracle name); |
272 |
290 |
273 fun assume_proof thy A = |
291 fun assume_proof thy A = |
274 ZHyp (global_zterm_of thy A); |
292 ZHyp (global_zterm_of thy A); |
275 |
293 |
276 fun trivial_proof thy A = |
294 fun trivial_proof thy A = |
324 (Binding.name "imp", propT --> propT --> propT, NoSyn), |
342 (Binding.name "imp", propT --> propT --> propT, NoSyn), |
325 (Binding.name "eq", Term.aT [] --> Term.aT [] --> propT, NoSyn)]; |
343 (Binding.name "eq", Term.aT [] --> Term.aT [] --> propT, NoSyn)]; |
326 |
344 |
327 val [reflexive_axiom, symmetric_axiom, transitive_axiom, equal_intr_axiom, equal_elim_axiom, |
345 val [reflexive_axiom, symmetric_axiom, transitive_axiom, equal_intr_axiom, equal_elim_axiom, |
328 abstract_rule_axiom, combination_axiom] = |
346 abstract_rule_axiom, combination_axiom] = |
329 Theory.equality_axioms |> map (fn (b, t) => |
347 Theory.equality_axioms |> map (fn (b, t) => axiom_proof thy0 (Sign.full_name thy0 b) t); |
330 axiom_proof thy0 {name = Sign.full_name thy0 b, oracle = false} t); |
|
331 |
|
332 fun inst_axiom (f, g) (ZAxiom (a, A, (instT, inst))) = |
|
333 let |
|
334 val instT' = ZTVars.map (fn ((x, _), _) => fn y => the_default y (try f x)) instT; |
|
335 val inst' = ZVars.map (fn ((x, _), _) => fn y => the_default y (try g x)) inst; |
|
336 in ZAxiom (a, A, (instT', inst')) end; |
|
337 |
348 |
338 in |
349 in |
339 |
350 |
340 val is_reflexive_proof = |
351 val is_reflexive_proof = |
341 fn ZAxiom ({name = "Pure.reflexive", oracle = false}, _, _) => true | _ => false; |
352 fn ZConstP (ZAxiom "Pure.reflexive", _, _, _) => true | _ => false; |
342 |
353 |
343 fun reflexive_proof thy T t = |
354 fun reflexive_proof thy T t = |
344 let |
355 let |
345 val A = ztyp_of T; |
356 val A = ztyp_of T; |
346 val x = global_zterm_of thy t; |
357 val x = global_zterm_of thy t; |
347 in inst_axiom (fn "'a" => A, fn "x" => x) reflexive_axiom end; |
358 in map_const_proof (fn "'a" => A, fn "x" => x) reflexive_axiom end; |
348 |
359 |
349 fun symmetric_proof thy T t u prf = |
360 fun symmetric_proof thy T t u prf = |
350 if is_reflexive_proof prf then prf |
361 if is_reflexive_proof prf then prf |
351 else |
362 else |
352 let |
363 let |
353 val A = ztyp_of T; |
364 val A = ztyp_of T; |
354 val x = global_zterm_of thy t; |
365 val x = global_zterm_of thy t; |
355 val y = global_zterm_of thy u; |
366 val y = global_zterm_of thy u; |
356 val ax = inst_axiom (fn "'a" => A, fn "x" => x | "y" => y) symmetric_axiom; |
367 val ax = map_const_proof (fn "'a" => A, fn "x" => x | "y" => y) symmetric_axiom; |
357 in ZAppP (ax, prf) end; |
368 in ZAppP (ax, prf) end; |
358 |
369 |
359 fun transitive_proof thy T t u v prf1 prf2 = |
370 fun transitive_proof thy T t u v prf1 prf2 = |
360 if is_reflexive_proof prf1 then prf2 |
371 if is_reflexive_proof prf1 then prf2 |
361 else if is_reflexive_proof prf2 then prf1 |
372 else if is_reflexive_proof prf2 then prf1 |
363 let |
374 let |
364 val A = ztyp_of T; |
375 val A = ztyp_of T; |
365 val x = global_zterm_of thy t; |
376 val x = global_zterm_of thy t; |
366 val y = global_zterm_of thy u; |
377 val y = global_zterm_of thy u; |
367 val z = global_zterm_of thy v; |
378 val z = global_zterm_of thy v; |
368 val ax = inst_axiom (fn "'a" => A, fn "x" => x | "y" => y | "z" => z) transitive_axiom; |
379 val ax = map_const_proof (fn "'a" => A, fn "x" => x | "y" => y | "z" => z) transitive_axiom; |
369 in ZAppP (ZAppP (ax, prf1), prf2) end; |
380 in ZAppP (ZAppP (ax, prf1), prf2) end; |
370 |
381 |
371 fun equal_intr_proof thy t u prf1 prf2 = |
382 fun equal_intr_proof thy t u prf1 prf2 = |
372 let |
383 let |
373 val A = global_zterm_of thy t; |
384 val A = global_zterm_of thy t; |
374 val B = global_zterm_of thy u; |
385 val B = global_zterm_of thy u; |
375 val ax = inst_axiom (undefined, fn "A" => A | "B" => B) equal_intr_axiom; |
386 val ax = map_const_proof (undefined, fn "A" => A | "B" => B) equal_intr_axiom; |
376 in ZAppP (ZAppP (ax, prf1), prf2) end; |
387 in ZAppP (ZAppP (ax, prf1), prf2) end; |
377 |
388 |
378 fun equal_elim_proof thy t u prf1 prf2 = |
389 fun equal_elim_proof thy t u prf1 prf2 = |
379 let |
390 let |
380 val A = global_zterm_of thy t; |
391 val A = global_zterm_of thy t; |
381 val B = global_zterm_of thy u; |
392 val B = global_zterm_of thy u; |
382 val ax = inst_axiom (undefined, fn "A" => A | "B" => B) equal_elim_axiom; |
393 val ax = map_const_proof (undefined, fn "A" => A | "B" => B) equal_elim_axiom; |
383 in ZAppP (ZAppP (ax, prf1), prf2) end; |
394 in ZAppP (ZAppP (ax, prf1), prf2) end; |
384 |
395 |
385 fun abstract_rule_proof thy T U x t u prf = |
396 fun abstract_rule_proof thy T U x t u prf = |
386 let |
397 let |
387 val A = ztyp_of T; |
398 val A = ztyp_of T; |
388 val B = ztyp_of U; |
399 val B = ztyp_of U; |
389 val f = global_zterm_of thy t; |
400 val f = global_zterm_of thy t; |
390 val g = global_zterm_of thy u; |
401 val g = global_zterm_of thy u; |
391 val ax = inst_axiom (fn "'a" => A | "'b" => B, fn "f" => f | "g" => g) abstract_rule_axiom; |
402 val ax = |
|
403 map_const_proof (fn "'a" => A | "'b" => B, fn "f" => f | "g" => g) |
|
404 abstract_rule_axiom; |
392 in ZAppP (ax, forall_intr_proof thy T x prf) end; |
405 in ZAppP (ax, forall_intr_proof thy T x prf) end; |
393 |
406 |
394 fun combination_proof thy T U f g t u prf1 prf2 = |
407 fun combination_proof thy T U f g t u prf1 prf2 = |
395 let |
408 let |
396 val A = ztyp_of T; |
409 val A = ztyp_of T; |
398 val f' = global_zterm_of thy f; |
411 val f' = global_zterm_of thy f; |
399 val g' = global_zterm_of thy g; |
412 val g' = global_zterm_of thy g; |
400 val x = global_zterm_of thy t; |
413 val x = global_zterm_of thy t; |
401 val y = global_zterm_of thy u; |
414 val y = global_zterm_of thy u; |
402 val ax = |
415 val ax = |
403 inst_axiom (fn "'a" => A | "'b" => B, fn "f" => f' | "g" => g' | "x" => x | "y" => y) |
416 map_const_proof (fn "'a" => A | "'b" => B, fn "f" => f' | "g" => g' | "x" => x | "y" => y) |
404 combination_axiom; |
417 combination_axiom; |
405 in ZAppP (ZAppP (ax, prf1), prf2) end; |
418 in ZAppP (ZAppP (ax, prf1), prf2) end; |
406 |
419 |
407 end; |
420 end; |
408 |
421 |