| author | haftmann |
| Thu, 18 Nov 2010 17:01:16 +0100 | |
| changeset 40607 | 30d512bf47a7 |
| parent 40445 | 65bd37d7d501 |
| child 41114 | f9ae7c2abf7e |
| permissions | -rw-r--r-- |
| 33100 | 1 |
(* Title: HOL/Tools/Function/relation.ML |
2 |
Author: Alexander Krauss, TU Muenchen |
|
3 |
||
4 |
A package for general recursive function definitions. |
|
5 |
Method "relation" to commence a termination proof using a user-specified relation. |
|
6 |
*) |
|
7 |
||
8 |
signature FUNCTION_RELATION = |
|
9 |
sig |
|
|
40445
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
10 |
val relation_tac: Proof.context -> (typ -> term) -> int -> tactic |
| 33100 | 11 |
val setup: theory -> theory |
12 |
end |
|
13 |
||
14 |
structure Function_Relation : FUNCTION_RELATION = |
|
15 |
struct |
|
16 |
||
|
40445
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
17 |
(* tactic version *) |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
18 |
|
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
19 |
fun inst_state_tac inst st = |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
20 |
case Term.add_vars (prop_of st) [] of |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
21 |
[v as (_, T)] => |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
22 |
let val cert = Thm.cterm_of (Thm.theory_of_thm st); |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
23 |
in PRIMITIVE (Thm.instantiate ([], [(cert (Var v), cert (inst T))])) st end |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
24 |
| _ => Seq.empty; |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
25 |
|
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
26 |
fun relation_tac ctxt rel i = |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
27 |
TRY (Function_Common.apply_termination_rule ctxt i) |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
28 |
THEN inst_state_tac rel; |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
29 |
|
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
30 |
|
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
31 |
(* method version (with type inference) *) |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
32 |
|
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
33 |
fun inst_state_infer_tac ctxt rel st = |
|
40057
b237f757b215
relation method: re-check given term with type constraints to avoid unspecific failure if ill-typed -- keep old behaviour for tactic version
krauss
parents:
36636
diff
changeset
|
34 |
case Term.add_vars (prop_of st) [] of |
|
b237f757b215
relation method: re-check given term with type constraints to avoid unspecific failure if ill-typed -- keep old behaviour for tactic version
krauss
parents:
36636
diff
changeset
|
35 |
[v as (_, T)] => |
|
b237f757b215
relation method: re-check given term with type constraints to avoid unspecific failure if ill-typed -- keep old behaviour for tactic version
krauss
parents:
36636
diff
changeset
|
36 |
let |
|
40445
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
37 |
val cert = Thm.cterm_of (ProofContext.theory_of ctxt); |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
38 |
val rel' = singleton (Variable.polymorphic ctxt) rel |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
39 |
|> map_types Type_Infer.paramify_vars |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
40 |
|> Type.constraint T |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
41 |
|> Syntax.check_term ctxt |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
42 |
|> cert; |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
43 |
in |
|
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
44 |
PRIMITIVE (Thm.instantiate ([], [(cert (Var v), rel')])) st |
|
40057
b237f757b215
relation method: re-check given term with type constraints to avoid unspecific failure if ill-typed -- keep old behaviour for tactic version
krauss
parents:
36636
diff
changeset
|
45 |
end |
|
b237f757b215
relation method: re-check given term with type constraints to avoid unspecific failure if ill-typed -- keep old behaviour for tactic version
krauss
parents:
36636
diff
changeset
|
46 |
| _ => Seq.empty; |
| 33100 | 47 |
|
|
40445
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
48 |
fun relation_meth rel ctxt = SIMPLE_METHOD' (fn i => |
|
34232
36a2a3029fd3
new year's resolution: reindented code in function package
krauss
parents:
33100
diff
changeset
|
49 |
TRY (Function_Common.apply_termination_rule ctxt i) |
|
40445
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
50 |
THEN inst_state_infer_tac ctxt rel); |
| 33100 | 51 |
|
52 |
val setup = |
|
|
40057
b237f757b215
relation method: re-check given term with type constraints to avoid unspecific failure if ill-typed -- keep old behaviour for tactic version
krauss
parents:
36636
diff
changeset
|
53 |
Method.setup @{binding relation} (Args.term >> relation_meth)
|
|
40445
65bd37d7d501
removed type-inference-like behaviour from relation_tac completely; tuned
krauss
parents:
40057
diff
changeset
|
54 |
"proves termination using a user-specified wellfounded relation"; |
| 33100 | 55 |
|
56 |
end |