author  paulson 
Thu, 19 Aug 1999 15:12:51 +0200  
changeset 7284  29105299799c 
parent 7237  2919daadba91 
child 7304  94c6f8f07631 
permissions  rwrr 
7237
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

1 
(* Title: HOL/SVC_Oracle.ML 
7144  2 
ID: $Id$ 
3 
Author: Lawrence C Paulson 

4 
Copyright 1999 University of Cambridge 

5 

6 
Installing the oracle for SVC (Stanford Validity Checker) 

7 

8 
Based upon the work of Søren T. Heilmann 

9 
*) 

10 

7284
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

11 

29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

12 
(*Generalize an Isabelle formula, replacing by Vars 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

13 
all subterms not intelligible to SVC.*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

14 
fun svc_abstract t = 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

15 
let 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

16 
val params = Term.strip_all_vars t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

17 
and body = Term.strip_all_body t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

18 
val Us = map #2 params 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

19 
val nPar = length params 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

20 
val vname = ref "V_a" 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

21 
val pairs = ref ([] : (term*term) list) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

22 
fun insert t = 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

23 
let val T = fastype_of t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

24 
val v = Unify.combound (Var ((!vname,0), Us>T), 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

25 
0, nPar) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

26 
in vname := bump_string (!vname); 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

27 
pairs := (t, v) :: !pairs; 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

28 
v 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

29 
end; 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

30 
fun replace t = 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

31 
case t of 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

32 
Free _ => t (*but not existing Vars, lest the names clash*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

33 
 Bound _ => t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

34 
 _ => (case gen_assoc (op aconv) (!pairs, t) of 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

35 
Some v => v 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

36 
 None => insert t) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

37 
(*abstraction of a real/rational expression*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

38 
fun rat ((c as Const("op +", _)) $ x $ y) = c $ (rat x) $ (rat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

39 
 rat ((c as Const("op ", _)) $ x $ y) = c $ (rat x) $ (rat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

40 
 rat ((c as Const("op /", _)) $ x $ y) = c $ (rat x) $ (rat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

41 
 rat ((c as Const("op *", _)) $ x $ y) = c $ (rat x) $ (rat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

42 
 rat ((c as Const("uminus", _)) $ x) = c $ (rat x) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

43 
 rat ((c as Const("RealDef.0r", _))) = c 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

44 
 rat ((c as Const("RealDef.1r", _))) = c 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

45 
 rat (t as Const("Numeral.number_of", _) $ w) = t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

46 
 rat t = replace t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

47 
(*abstraction of an integer expression: no div, mod*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

48 
fun int ((c as Const("op +", _)) $ x $ y) = c $ (int x) $ (int y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

49 
 int ((c as Const("op ", _)) $ x $ y) = c $ (int x) $ (int y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

50 
 int ((c as Const("op *", _)) $ x $ y) = c $ (int x) $ (int y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

51 
 int ((c as Const("uminus", _)) $ x) = c $ (int x) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

52 
 int (t as Const("Numeral.number_of", _) $ w) = t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

53 
 int t = replace t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

54 
(*abstraction of a natural number expression: no minus*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

55 
fun nat ((c as Const("op +", _)) $ x $ y) = c $ (nat x) $ (nat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

56 
 nat ((c as Const("op *", _)) $ x $ y) = c $ (nat x) $ (nat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

57 
 nat ((c as Const("Suc", _)) $ x) = c $ (nat x) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

58 
 nat (t as Const("0", _)) = t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

59 
 nat (t as Const("Numeral.number_of", _) $ w) = t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

60 
 nat t = replace t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

61 
(*abstraction of a relation: =, <, <=*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

62 
fun rel (T, c $ x $ y) = 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

63 
if T = HOLogic.realT then c $ (rat x) $ (rat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

64 
else if T = HOLogic.intT then c $ (int x) $ (int y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

65 
else if T = HOLogic.natT then c $ (nat x) $ (nat y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

66 
else if T = HOLogic.boolT then c $ (fm x) $ (fm y) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

67 
else replace (c $ x $ y) (*nonnumeric comparison*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

68 
(*abstraction of a formula*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

69 
and fm ((c as Const("op &", _)) $ p $ q) = c $ (fm p) $ (fm q) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

70 
 fm ((c as Const("op ", _)) $ p $ q) = c $ (fm p) $ (fm q) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

71 
 fm ((c as Const("op >", _)) $ p $ q) = c $ (fm p) $ (fm q) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

72 
 fm ((c as Const("Not", _)) $ p) = c $ (fm p) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

73 
 fm ((c as Const("True", _))) = c 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

74 
 fm ((c as Const("False", _))) = c 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

75 
 fm (t as Const("op =", Type ("fun", [T,_])) $ x $ y) = rel (T, t) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

76 
 fm (t as Const("op <", Type ("fun", [T,_])) $ x $ y) = rel (T, t) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

77 
 fm (t as Const("op <=", Type ("fun", [T,_])) $ x $ y) = rel (T, t) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

78 
 fm t = replace t 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

79 
(*entry point, and abstraction of a metaformula*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

80 
fun mt ((c as Const("Trueprop", _)) $ p) = c $ (fm p) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

81 
 mt ((c as Const("==>", _)) $ p $ q) = c $ (mt p) $ (mt q) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

82 
 mt t = fm t (*it might be a formula*) 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

83 
in (list_all (params, mt body), !pairs) end; 
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

84 

29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

85 

7144  86 
(*Present the entire subgoal to the oracle, assumptions and all, but possibly 
87 
abstracted. Use via compose_tac, which performs no lifting but will 

88 
instantiate variables.*) 

7237
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

89 
local val svc_thy = the_context () in 
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

90 

7162  91 
fun svc_tac i st = 
7237
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

92 
let val prem = BasisLibrary.List.nth (prems_of st, i1) 
7284
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

93 
val (absPrem, _) = svc_abstract prem 
7237
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

94 
val th = invoke_oracle svc_thy "svc_oracle" 
7284
29105299799c
now with abstraction code previously in HOL/Tools/svc_funcs.ML
paulson
parents:
7237
diff
changeset

95 
(#sign (rep_thm st), Svc.OracleExn absPrem) 
7162  96 
in 
97 
compose_tac (false, th, 0) i st 

98 
end 

99 
handle Svc.OracleExn _ => Seq.empty 

100 
 Subscript => Seq.empty; 

7144  101 

7237
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

102 
end; 
2919daadba91
turned SVC_Oracle into a newstyle theory in order to get automatic
wenzelm
parents:
7187
diff
changeset

103 

7144  104 

7187  105 
(*True if SVC appears to exist*) 
106 
fun svc_enabled() = getenv "SVC_HOME" <> ""; 