src/HOL/Library/normarith.ML
changeset 31118 541d43bee678
parent 30868 1040425c86a2
child 31293 198eae6f5a35
equal deleted inserted replaced
31117:527ba4a37843 31118:541d43bee678
     1 (* A functor for finite mappings based on Tables *)
     1 (* Title:      Library/normarith.ML
     2 signature FUNC = 
     2    Author:     Amine Chaieb, University of Cambridge
     3 sig
     3    Description: A simple decision procedure for linear problems in euclidean space
     4  type 'a T
     4 *)
     5  type key
       
     6  val apply : 'a T -> key -> 'a
       
     7  val applyd :'a T -> (key -> 'a) -> key -> 'a
       
     8  val combine : ('a -> 'a -> 'a) -> ('a -> bool) -> 'a T -> 'a T -> 'a T
       
     9  val defined : 'a T -> key -> bool
       
    10  val dom : 'a T -> key list
       
    11  val fold : (key * 'a -> 'b -> 'b) -> 'a T -> 'b -> 'b
       
    12  val graph : 'a T -> (key * 'a) list
       
    13  val is_undefined : 'a T -> bool
       
    14  val mapf : ('a -> 'b) -> 'a T -> 'b T
       
    15  val tryapplyd : 'a T -> key -> 'a -> 'a
       
    16  val undefine :  key -> 'a T -> 'a T
       
    17  val undefined : 'a T
       
    18  val update : key * 'a -> 'a T -> 'a T
       
    19  val updatep : (key * 'a -> bool) -> key * 'a -> 'a T -> 'a T
       
    20  val choose : 'a T -> key * 'a
       
    21  val onefunc : key * 'a -> 'a T
       
    22  val get_first: (key*'a -> 'a option) -> 'a T -> 'a option
       
    23  val fns: 
       
    24    {key_ord: key*key -> order,
       
    25     apply : 'a T -> key -> 'a,
       
    26     applyd :'a T -> (key -> 'a) -> key -> 'a,
       
    27     combine : ('a -> 'a -> 'a) -> ('a -> bool) -> 'a T -> 'a T -> 'a T,
       
    28     defined : 'a T -> key -> bool,
       
    29     dom : 'a T -> key list,
       
    30     fold : (key * 'a -> 'b -> 'b) -> 'a T -> 'b -> 'b,
       
    31     graph : 'a T -> (key * 'a) list,
       
    32     is_undefined : 'a T -> bool,
       
    33     mapf : ('a -> 'b) -> 'a T -> 'b T,
       
    34     tryapplyd : 'a T -> key -> 'a -> 'a,
       
    35     undefine :  key -> 'a T -> 'a T,
       
    36     undefined : 'a T,
       
    37     update : key * 'a -> 'a T -> 'a T,
       
    38     updatep : (key * 'a -> bool) -> key * 'a -> 'a T -> 'a T,
       
    39     choose : 'a T -> key * 'a,
       
    40     onefunc : key * 'a -> 'a T,
       
    41     get_first: (key*'a -> 'a option) -> 'a T -> 'a option}
       
    42 end;
       
    43 
       
    44 functor FuncFun(Key: KEY) : FUNC=
       
    45 struct
       
    46 
       
    47 type key = Key.key;
       
    48 structure Tab = TableFun(Key);
       
    49 type 'a T = 'a Tab.table;
       
    50 
       
    51 val undefined = Tab.empty;
       
    52 val is_undefined = Tab.is_empty;
       
    53 val mapf = Tab.map;
       
    54 val fold = Tab.fold;
       
    55 val graph = Tab.dest;
       
    56 val dom = Tab.keys;
       
    57 fun applyd f d x = case Tab.lookup f x of 
       
    58    SOME y => y
       
    59  | NONE => d x;
       
    60 
       
    61 fun apply f x = applyd f (fn _ => raise Tab.UNDEF x) x;
       
    62 fun tryapplyd f a d = applyd f (K d) a;
       
    63 val defined = Tab.defined;
       
    64 fun undefine x t = (Tab.delete x t handle UNDEF => t);
       
    65 val update = Tab.update;
       
    66 fun updatep p (k,v) t = if p (k, v) then t else update (k,v) t
       
    67 fun combine f z a b = 
       
    68  let
       
    69   fun h (k,v) t = case Tab.lookup t k of
       
    70      NONE => Tab.update (k,v) t
       
    71    | SOME v' => let val w = f v v'
       
    72      in if z w then Tab.delete k t else Tab.update (k,w) t end;
       
    73   in Tab.fold h a b end;
       
    74 
       
    75 fun choose f = case Tab.max_key f of 
       
    76    SOME k => (k,valOf (Tab.lookup f k))
       
    77  | NONE => error "FuncFun.choose : Completely undefined function"
       
    78 
       
    79 fun onefunc kv = update kv undefined
       
    80 
       
    81 local
       
    82 fun  find f (k,v) NONE = f (k,v)
       
    83    | find f (k,v) r = r
       
    84 in
       
    85 fun get_first f t = fold (find f) t NONE
       
    86 end
       
    87 
       
    88 val fns = 
       
    89    {key_ord = Key.ord,
       
    90     apply = apply,
       
    91     applyd = applyd,
       
    92     combine = combine,
       
    93     defined = defined,
       
    94     dom = dom,
       
    95     fold = fold,
       
    96     graph = graph,
       
    97     is_undefined = is_undefined,
       
    98     mapf = mapf,
       
    99     tryapplyd = tryapplyd,
       
   100     undefine = undefine,
       
   101     undefined = undefined,
       
   102     update = update,
       
   103     updatep = updatep,
       
   104     choose = choose,
       
   105     onefunc = onefunc,
       
   106     get_first = get_first}
       
   107 
       
   108 end;
       
   109 
       
   110 structure Intfunc = FuncFun(type key = int val ord = int_ord);
       
   111 structure Symfunc = FuncFun(type key = string val ord = fast_string_ord);
       
   112 structure Termfunc = FuncFun(type key = term val ord = TermOrd.fast_term_ord);
       
   113 structure Ctermfunc = FuncFun(type key = cterm val ord = (fn (s,t) => TermOrd.fast_term_ord(term_of s, term_of t)));
       
   114 structure Ratfunc = FuncFun(type key = Rat.rat val ord = Rat.ord);
       
   115 
       
   116     (* Some conversions-related stuff which has been forbidden entrance into Pure/conv.ML*)
       
   117 structure Conv2 = 
       
   118 struct
       
   119  open Conv
       
   120 fun instantiate_cterm' ty tms = Drule.cterm_rule (Drule.instantiate' ty tms)
       
   121 fun is_comb t = case (term_of t) of _$_ => true | _ => false;
       
   122 fun is_abs t = case (term_of t) of Abs _ => true | _ => false;
       
   123 
       
   124 fun end_itlist f l =
       
   125  case l of 
       
   126    []     => error "end_itlist"
       
   127  | [x]    => x
       
   128  | (h::t) => f h (end_itlist f t);
       
   129 
       
   130  fun absc cv ct = case term_of ct of 
       
   131  Abs (v,_, _) => 
       
   132   let val (x,t) = Thm.dest_abs (SOME v) ct
       
   133   in Thm.abstract_rule ((fst o dest_Free o term_of) x) x (cv t)
       
   134   end
       
   135  | _ => all_conv ct;
       
   136 
       
   137 fun cache_conv conv =
       
   138  let 
       
   139   val tab = ref Termtab.empty
       
   140   fun cconv t =  
       
   141     case Termtab.lookup (!tab) (term_of t) of
       
   142      SOME th => th
       
   143    | NONE => let val th = conv t
       
   144              in ((tab := Termtab.insert Thm.eq_thm (term_of t, th) (!tab)); th) end
       
   145  in cconv end;
       
   146 fun is_binop ct ct' = ct aconvc (Thm.dest_fun (Thm.dest_fun ct'))
       
   147   handle CTERM _ => false;
       
   148 
       
   149 local
       
   150  fun thenqc conv1 conv2 tm =
       
   151    case try conv1 tm of
       
   152     SOME th1 => (case try conv2 (Thm.rhs_of th1) of SOME th2 => Thm.transitive th1 th2 | NONE => th1)
       
   153   | NONE => conv2 tm
       
   154 
       
   155  fun thencqc conv1 conv2 tm =
       
   156     let val th1 = conv1 tm 
       
   157     in (case try conv2 (Thm.rhs_of th1) of SOME th2 => Thm.transitive th1 th2 | NONE => th1)
       
   158     end
       
   159  fun comb_qconv conv tm =
       
   160    let val (l,r) = Thm.dest_comb tm 
       
   161    in (case try conv l of 
       
   162         SOME th1 => (case try conv r of SOME th2 => Thm.combination th1 th2 
       
   163                                       | NONE => Drule.fun_cong_rule th1 r)
       
   164       | NONE => Drule.arg_cong_rule l (conv r))
       
   165    end
       
   166  fun repeatqc conv tm = thencqc conv (repeatqc conv) tm 
       
   167  fun sub_qconv conv tm =  if is_abs tm then absc conv tm else comb_qconv conv tm 
       
   168  fun once_depth_qconv conv tm =
       
   169       (conv else_conv (sub_qconv (once_depth_qconv conv))) tm
       
   170  fun depth_qconv conv tm =
       
   171     thenqc (sub_qconv (depth_qconv conv))
       
   172            (repeatqc conv) tm
       
   173  fun redepth_qconv conv tm =
       
   174     thenqc (sub_qconv (redepth_qconv conv))
       
   175            (thencqc conv (redepth_qconv conv)) tm
       
   176  fun top_depth_qconv conv tm =
       
   177     thenqc (repeatqc conv)
       
   178            (thencqc (sub_qconv (top_depth_qconv conv))
       
   179                     (thencqc conv (top_depth_qconv conv))) tm
       
   180  fun top_sweep_qconv conv tm =
       
   181     thenqc (repeatqc conv)
       
   182            (sub_qconv (top_sweep_qconv conv)) tm
       
   183 in 
       
   184 val (once_depth_conv, depth_conv, rdepth_conv, top_depth_conv, top_sweep_conv) = 
       
   185   (fn c => try_conv (once_depth_qconv c),
       
   186    fn c => try_conv (depth_qconv c),
       
   187    fn c => try_conv (redepth_qconv c),
       
   188    fn c => try_conv (top_depth_qconv c),
       
   189    fn c => try_conv (top_sweep_qconv c));
       
   190 end;
       
   191 end;
       
   192 
       
   193 
       
   194     (* Some useful derived rules *)
       
   195 fun deduct_antisym_rule tha thb = 
       
   196     equal_intr (implies_intr (cprop_of thb) tha) 
       
   197      (implies_intr (cprop_of tha) thb);
       
   198 
       
   199 fun prove_hyp tha thb = 
       
   200   if exists (curry op aconv (concl_of tha)) (#hyps (rep_thm thb)) 
       
   201   then equal_elim (symmetric (deduct_antisym_rule tha thb)) tha else thb;
       
   202 
       
   203 
       
   204 
       
   205 signature REAL_ARITH = 
       
   206 sig
       
   207   datatype positivstellensatz =
       
   208    Axiom_eq of int
       
   209  | Axiom_le of int
       
   210  | Axiom_lt of int
       
   211  | Rational_eq of Rat.rat
       
   212  | Rational_le of Rat.rat
       
   213  | Rational_lt of Rat.rat
       
   214  | Square of cterm
       
   215  | Eqmul of cterm * positivstellensatz
       
   216  | Sum of positivstellensatz * positivstellensatz
       
   217  | Product of positivstellensatz * positivstellensatz;
       
   218 
       
   219 val gen_gen_real_arith :
       
   220   Proof.context -> (Rat.rat -> Thm.cterm) * conv * conv * conv * 
       
   221    conv * conv * conv * conv * conv * conv * 
       
   222     ( (thm list * thm list * thm list -> positivstellensatz -> thm) ->
       
   223         thm list * thm list * thm list -> thm) -> conv
       
   224 val real_linear_prover : 
       
   225   (thm list * thm list * thm list -> positivstellensatz -> thm) ->
       
   226    thm list * thm list * thm list -> thm
       
   227 
       
   228 val gen_real_arith : Proof.context ->
       
   229    (Rat.rat -> cterm) * conv * conv * conv * conv * conv * conv * conv *
       
   230    ( (thm list * thm list * thm list -> positivstellensatz -> thm) ->
       
   231        thm list * thm list * thm list -> thm) -> conv
       
   232 val gen_prover_real_arith : Proof.context ->
       
   233    ((thm list * thm list * thm list -> positivstellensatz -> thm) ->
       
   234      thm list * thm list * thm list -> thm) -> conv
       
   235 val real_arith : Proof.context -> conv
       
   236 end
       
   237 
       
   238 structure RealArith (* : REAL_ARITH *)=
       
   239 struct
       
   240 
       
   241  open Conv Thm Conv2;;
       
   242 (* ------------------------------------------------------------------------- *)
       
   243 (* Data structure for Positivstellensatz refutations.                        *)
       
   244 (* ------------------------------------------------------------------------- *)
       
   245 
       
   246 datatype positivstellensatz =
       
   247    Axiom_eq of int
       
   248  | Axiom_le of int
       
   249  | Axiom_lt of int
       
   250  | Rational_eq of Rat.rat
       
   251  | Rational_le of Rat.rat
       
   252  | Rational_lt of Rat.rat
       
   253  | Square of cterm
       
   254  | Eqmul of cterm * positivstellensatz
       
   255  | Sum of positivstellensatz * positivstellensatz
       
   256  | Product of positivstellensatz * positivstellensatz;
       
   257          (* Theorems used in the procedure *)
       
   258 
       
   259 fun conjunctions th = case try Conjunction.elim th of
       
   260    SOME (th1,th2) => (conjunctions th1) @ conjunctions th2
       
   261  | NONE => [th];
       
   262 
       
   263 val pth = @{lemma "(((x::real) < y) == (y - x > 0)) &&& ((x <= y) == (y - x >= 0)) 
       
   264      &&& ((x = y) == (x - y = 0)) &&& ((~(x < y)) == (x - y >= 0)) &&& ((~(x <= y)) == (x - y > 0))
       
   265      &&& ((~(x = y)) == (x - y > 0 | -(x - y) > 0))"
       
   266   by (atomize (full), auto simp add: less_diff_eq le_diff_eq not_less)} |> 
       
   267 conjunctions;
       
   268 
       
   269 val pth_final = @{lemma "(~p ==> False) ==> p" by blast}
       
   270 val pth_add = 
       
   271  @{lemma "(x = (0::real) ==> y = 0 ==> x + y = 0 ) &&& ( x = 0 ==> y >= 0 ==> x + y >= 0) 
       
   272     &&& (x = 0 ==> y > 0 ==> x + y > 0) &&& (x >= 0 ==> y = 0 ==> x + y >= 0) 
       
   273     &&& (x >= 0 ==> y >= 0 ==> x + y >= 0) &&& (x >= 0 ==> y > 0 ==> x + y > 0) 
       
   274     &&& (x > 0 ==> y = 0 ==> x + y > 0) &&& (x > 0 ==> y >= 0 ==> x + y > 0) 
       
   275     &&& (x > 0 ==> y > 0 ==> x + y > 0)"  by simp_all} |> conjunctions ;
       
   276 
       
   277 val pth_mul = 
       
   278   @{lemma "(x = (0::real) ==> y = 0 ==> x * y = 0) &&& (x = 0 ==> y >= 0 ==> x * y = 0) &&& 
       
   279            (x = 0 ==> y > 0 ==> x * y = 0) &&& (x >= 0 ==> y = 0 ==> x * y = 0) &&& 
       
   280            (x >= 0 ==> y >= 0 ==> x * y >= 0 ) &&& ( x >= 0 ==> y > 0 ==> x * y >= 0 ) &&&
       
   281            (x > 0 ==>  y = 0 ==> x * y = 0 ) &&& ( x > 0 ==> y >= 0 ==> x * y >= 0 ) &&&
       
   282            (x > 0 ==>  y > 0 ==> x * y > 0)"
       
   283   by (auto intro: mult_mono[where a="0::real" and b="x" and d="y" and c="0", simplified]
       
   284     mult_strict_mono[where b="x" and d="y" and a="0" and c="0", simplified])} |> conjunctions;
       
   285 
       
   286 val pth_emul = @{lemma "y = (0::real) ==> x * y = 0"  by simp};
       
   287 val pth_square = @{lemma "x * x >= (0::real)"  by simp};
       
   288 
       
   289 val weak_dnf_simps = List.take (simp_thms, 34) 
       
   290     @ conjunctions @{lemma "((P & (Q | R)) = ((P&Q) | (P&R))) &&& ((Q | R) & P) = ((Q&P) | (R&P)) &&& (P & Q) = (Q & P) &&& ((P | Q) = (Q | P))" by blast+};
       
   291 
       
   292 val nnfD_simps = conjunctions @{lemma "((~(P & Q)) = (~P | ~Q)) &&& ((~(P | Q)) = (~P & ~Q) ) &&& ((P --> Q) = (~P | Q) ) &&& ((P = Q) = ((P & Q) | (~P & ~ Q))) &&& ((~(P = Q)) = ((P & ~ Q) | (~P & Q)) ) &&& ((~ ~(P)) = P)" by blast+}
       
   293 
       
   294 val choice_iff = @{lemma "(ALL x. EX y. P x y) = (EX f. ALL x. P x (f x))" by metis};
       
   295 val prenex_simps = map (fn th => th RS sym) ([@{thm "all_conj_distrib"}, @{thm "ex_disj_distrib"}] @ @{thms "all_simps"(1-4)} @ @{thms "ex_simps"(1-4)});
       
   296 
       
   297 val real_abs_thms1 = conjunctions @{lemma
       
   298   "((-1 * abs(x::real) >= r) = (-1 * x >= r & 1 * x >= r)) &&&
       
   299   ((-1 * abs(x) + a >= r) = (a + -1 * x >= r & a + 1 * x >= r)) &&&
       
   300   ((a + -1 * abs(x) >= r) = (a + -1 * x >= r & a + 1 * x >= r)) &&&
       
   301   ((a + -1 * abs(x) + b >= r) = (a + -1 * x + b >= r & a + 1 * x + b >= r)) &&&
       
   302   ((a + b + -1 * abs(x) >= r) = (a + b + -1 * x >= r & a + b + 1 * x >= r)) &&&
       
   303   ((a + b + -1 * abs(x) + c >= r) = (a + b + -1 * x + c >= r & a + b + 1 * x + c >= r)) &&&
       
   304   ((-1 * max x y >= r) = (-1 * x >= r & -1 * y >= r)) &&&
       
   305   ((-1 * max x y + a >= r) = (a + -1 * x >= r & a + -1 * y >= r)) &&&
       
   306   ((a + -1 * max x y >= r) = (a + -1 * x >= r & a + -1 * y >= r)) &&&
       
   307   ((a + -1 * max x y + b >= r) = (a + -1 * x + b >= r & a + -1 * y  + b >= r)) &&&
       
   308   ((a + b + -1 * max x y >= r) = (a + b + -1 * x >= r & a + b + -1 * y >= r)) &&&
       
   309   ((a + b + -1 * max x y + c >= r) = (a + b + -1 * x + c >= r & a + b + -1 * y  + c >= r)) &&&
       
   310   ((1 * min x y >= r) = (1 * x >= r & 1 * y >= r)) &&&
       
   311   ((1 * min x y + a >= r) = (a + 1 * x >= r & a + 1 * y >= r)) &&&
       
   312   ((a + 1 * min x y >= r) = (a + 1 * x >= r & a + 1 * y >= r)) &&&
       
   313   ((a + 1 * min x y + b >= r) = (a + 1 * x + b >= r & a + 1 * y  + b >= r) )&&&
       
   314   ((a + b + 1 * min x y >= r) = (a + b + 1 * x >= r & a + b + 1 * y >= r)) &&&
       
   315   ((a + b + 1 * min x y + c >= r) = (a + b + 1 * x + c >= r & a + b + 1 * y  + c >= r)) &&&
       
   316   ((min x y >= r) = (x >= r &  y >= r)) &&&
       
   317   ((min x y + a >= r) = (a + x >= r & a + y >= r)) &&&
       
   318   ((a + min x y >= r) = (a + x >= r & a + y >= r)) &&&
       
   319   ((a + min x y + b >= r) = (a + x + b >= r & a + y  + b >= r)) &&&
       
   320   ((a + b + min x y >= r) = (a + b + x >= r & a + b + y >= r) )&&&
       
   321   ((a + b + min x y + c >= r) = (a + b + x + c >= r & a + b + y + c >= r)) &&&
       
   322   ((-1 * abs(x) > r) = (-1 * x > r & 1 * x > r)) &&&
       
   323   ((-1 * abs(x) + a > r) = (a + -1 * x > r & a + 1 * x > r)) &&&
       
   324   ((a + -1 * abs(x) > r) = (a + -1 * x > r & a + 1 * x > r)) &&&
       
   325   ((a + -1 * abs(x) + b > r) = (a + -1 * x + b > r & a + 1 * x + b > r)) &&&
       
   326   ((a + b + -1 * abs(x) > r) = (a + b + -1 * x > r & a + b + 1 * x > r)) &&&
       
   327   ((a + b + -1 * abs(x) + c > r) = (a + b + -1 * x + c > r & a + b + 1 * x + c > r)) &&&
       
   328   ((-1 * max x y > r) = ((-1 * x > r) & -1 * y > r)) &&&
       
   329   ((-1 * max x y + a > r) = (a + -1 * x > r & a + -1 * y > r)) &&&
       
   330   ((a + -1 * max x y > r) = (a + -1 * x > r & a + -1 * y > r)) &&&
       
   331   ((a + -1 * max x y + b > r) = (a + -1 * x + b > r & a + -1 * y  + b > r)) &&&
       
   332   ((a + b + -1 * max x y > r) = (a + b + -1 * x > r & a + b + -1 * y > r)) &&&
       
   333   ((a + b + -1 * max x y + c > r) = (a + b + -1 * x + c > r & a + b + -1 * y  + c > r)) &&&
       
   334   ((min x y > r) = (x > r &  y > r)) &&&
       
   335   ((min x y + a > r) = (a + x > r & a + y > r)) &&&
       
   336   ((a + min x y > r) = (a + x > r & a + y > r)) &&&
       
   337   ((a + min x y + b > r) = (a + x + b > r & a + y  + b > r)) &&&
       
   338   ((a + b + min x y > r) = (a + b + x > r & a + b + y > r)) &&&
       
   339   ((a + b + min x y + c > r) = (a + b + x + c > r & a + b + y + c > r))"
       
   340   by auto};
       
   341 
       
   342 val abs_split' = @{lemma "P (abs (x::'a::ordered_idom)) == (x >= 0 & P x | x < 0 & P (-x))"
       
   343   by (atomize (full)) (auto split add: abs_split)};
       
   344 
       
   345 val max_split = @{lemma "P (max x y) == ((x::'a::linorder) <= y & P y | x > y & P x)"
       
   346   by (atomize (full)) (cases "x <= y", auto simp add: max_def)};
       
   347 
       
   348 val min_split = @{lemma "P (min x y) == ((x::'a::linorder) <= y & P x | x > y & P y)"
       
   349   by (atomize (full)) (cases "x <= y", auto simp add: min_def)};
       
   350 
       
   351 
       
   352          (* Miscalineous *)
       
   353 fun literals_conv bops uops cv = 
       
   354  let fun h t =
       
   355   case (term_of t) of 
       
   356    b$_$_ => if member (op aconv) bops b then binop_conv h t else cv t
       
   357  | u$_ => if member (op aconv) uops u then arg_conv h t else cv t
       
   358  | _ => cv t
       
   359  in h end;
       
   360 
       
   361 fun cterm_of_rat x = 
       
   362 let val (a, b) = Rat.quotient_of_rat x
       
   363 in 
       
   364  if b = 1 then Numeral.mk_cnumber @{ctyp "real"} a
       
   365   else Thm.capply (Thm.capply @{cterm "op / :: real => _"} 
       
   366                    (Numeral.mk_cnumber @{ctyp "real"} a))
       
   367         (Numeral.mk_cnumber @{ctyp "real"} b)
       
   368 end;
       
   369 
       
   370   fun dest_ratconst t = case term_of t of
       
   371    Const(@{const_name divide}, _)$a$b => Rat.rat_of_quotient(HOLogic.dest_number a |> snd, HOLogic.dest_number b |> snd)
       
   372  | Const(@{const_name inverse}, _)$a => Rat.rat_of_quotient(1, HOLogic.dest_number a |> snd)
       
   373  | _ => Rat.rat_of_int (HOLogic.dest_number (term_of t) |> snd)
       
   374  fun is_ratconst t = can dest_ratconst t
       
   375 
       
   376 fun find_term p t = if p t then t else 
       
   377  case t of
       
   378   a$b => (find_term p a handle TERM _ => find_term p b)
       
   379  | Abs (_,_,t') => find_term p t'
       
   380  | _ => raise TERM ("find_term",[t]);
       
   381 
       
   382 fun find_cterm p t = if p t then t else 
       
   383  case term_of t of
       
   384   a$b => (find_cterm p (Thm.dest_fun t) handle CTERM _ => find_cterm p (Thm.dest_arg t))
       
   385  | Abs (_,_,t') => find_cterm p (Thm.dest_abs NONE t |> snd)
       
   386  | _ => raise CTERM ("find_cterm",[t]);
       
   387 
       
   388 
       
   389     (* A general real arithmetic prover *)
       
   390 
       
   391 fun gen_gen_real_arith ctxt (mk_numeric,
       
   392        numeric_eq_conv,numeric_ge_conv,numeric_gt_conv,
       
   393        poly_conv,poly_neg_conv,poly_add_conv,poly_mul_conv,
       
   394        absconv1,absconv2,prover) = 
       
   395 let
       
   396  open Conv Thm; 
       
   397  val pre_ss = HOL_basic_ss addsimps simp_thms@ ex_simps@ all_simps@[@{thm not_all},@{thm not_ex},ex_disj_distrib, all_conj_distrib, @{thm if_bool_eq_disj}]
       
   398  val prenex_ss = HOL_basic_ss addsimps prenex_simps
       
   399  val skolemize_ss = HOL_basic_ss addsimps [choice_iff]
       
   400  val presimp_conv = Simplifier.rewrite (Simplifier.context ctxt pre_ss)
       
   401  val prenex_conv = Simplifier.rewrite (Simplifier.context ctxt prenex_ss)
       
   402  val skolemize_conv = Simplifier.rewrite (Simplifier.context ctxt skolemize_ss)
       
   403  val weak_dnf_ss = HOL_basic_ss addsimps weak_dnf_simps
       
   404  val weak_dnf_conv = Simplifier.rewrite (Simplifier.context ctxt weak_dnf_ss)
       
   405  fun eqT_elim th = equal_elim (symmetric th) @{thm TrueI}
       
   406  fun oprconv cv ct = 
       
   407   let val g = Thm.dest_fun2 ct
       
   408   in if g aconvc @{cterm "op <= :: real => _"} 
       
   409        orelse g aconvc @{cterm "op < :: real => _"} 
       
   410      then arg_conv cv ct else arg1_conv cv ct
       
   411   end
       
   412 
       
   413  fun real_ineq_conv th ct =
       
   414   let
       
   415    val th' = (instantiate (match (lhs_of th, ct)) th 
       
   416       handle MATCH => raise CTERM ("real_ineq_conv", [ct]))
       
   417   in transitive th' (oprconv poly_conv (Thm.rhs_of th'))
       
   418   end 
       
   419   val [real_lt_conv, real_le_conv, real_eq_conv,
       
   420        real_not_lt_conv, real_not_le_conv, _] =
       
   421        map real_ineq_conv pth
       
   422   fun match_mp_rule ths ths' = 
       
   423    let
       
   424      fun f ths ths' = case ths of [] => raise THM("match_mp_rule",0,ths)
       
   425       | th::ths => (ths' MRS th handle THM _ => f ths ths')
       
   426    in f ths ths' end
       
   427   fun mul_rule th th' = fconv_rule (arg_conv (oprconv poly_mul_conv))
       
   428          (match_mp_rule pth_mul [th, th'])
       
   429   fun add_rule th th' = fconv_rule (arg_conv (oprconv poly_add_conv))
       
   430          (match_mp_rule pth_add [th, th'])
       
   431   fun emul_rule ct th = fconv_rule (arg_conv (oprconv poly_mul_conv)) 
       
   432        (instantiate' [] [SOME ct] (th RS pth_emul)) 
       
   433   fun square_rule t = fconv_rule (arg_conv (oprconv poly_mul_conv))
       
   434        (instantiate' [] [SOME t] pth_square)
       
   435 
       
   436   fun hol_of_positivstellensatz(eqs,les,lts) =
       
   437    let 
       
   438     fun translate prf = case prf of
       
   439         Axiom_eq n => nth eqs n
       
   440       | Axiom_le n => nth les n
       
   441       | Axiom_lt n => nth lts n
       
   442       | Rational_eq x => eqT_elim(numeric_eq_conv(capply @{cterm Trueprop} 
       
   443                           (capply (capply @{cterm "op =::real => _"} (mk_numeric x)) 
       
   444                                @{cterm "0::real"})))
       
   445       | Rational_le x => eqT_elim(numeric_ge_conv(capply @{cterm Trueprop} 
       
   446                           (capply (capply @{cterm "op <=::real => _"} 
       
   447                                      @{cterm "0::real"}) (mk_numeric x))))
       
   448       | Rational_lt x => eqT_elim(numeric_gt_conv(capply @{cterm Trueprop} 
       
   449                       (capply (capply @{cterm "op <::real => _"} @{cterm "0::real"})
       
   450                         (mk_numeric x))))
       
   451       | Square t => square_rule t
       
   452       | Eqmul(t,p) => emul_rule t (translate p)
       
   453       | Sum(p1,p2) => add_rule (translate p1) (translate p2)
       
   454       | Product(p1,p2) => mul_rule (translate p1) (translate p2)
       
   455    in fn prf => 
       
   456       fconv_rule (first_conv [numeric_ge_conv, numeric_gt_conv, numeric_eq_conv, all_conv]) 
       
   457           (translate prf)
       
   458    end
       
   459   
       
   460   val init_conv = presimp_conv then_conv
       
   461       nnf_conv then_conv skolemize_conv then_conv prenex_conv then_conv
       
   462       weak_dnf_conv
       
   463 
       
   464   val concl = dest_arg o cprop_of
       
   465   fun is_binop opr ct = (dest_fun2 ct aconvc opr handle CTERM _ => false)
       
   466   val is_req = is_binop @{cterm "op =:: real => _"}
       
   467   val is_ge = is_binop @{cterm "op <=:: real => _"}
       
   468   val is_gt = is_binop @{cterm "op <:: real => _"}
       
   469   val is_conj = is_binop @{cterm "op &"}
       
   470   val is_disj = is_binop @{cterm "op |"}
       
   471   fun conj_pair th = (th RS @{thm conjunct1}, th RS @{thm conjunct2})
       
   472   fun disj_cases th th1 th2 = 
       
   473    let val (p,q) = dest_binop (concl th)
       
   474        val c = concl th1
       
   475        val _ = if c aconvc (concl th2) then () else error "disj_cases : conclusions not alpha convertible"
       
   476    in implies_elim (implies_elim (implies_elim (instantiate' [] (map SOME [p,q,c]) @{thm disjE}) th) (implies_intr (capply @{cterm Trueprop} p) th1)) (implies_intr (capply @{cterm Trueprop} q) th2)
       
   477    end
       
   478  fun overall dun ths = case ths of
       
   479   [] =>
       
   480    let 
       
   481     val (eq,ne) = List.partition (is_req o concl) dun
       
   482      val (le,nl) = List.partition (is_ge o concl) ne
       
   483      val lt = filter (is_gt o concl) nl 
       
   484     in prover hol_of_positivstellensatz (eq,le,lt) end
       
   485  | th::oths =>
       
   486    let 
       
   487     val ct = concl th 
       
   488    in 
       
   489     if is_conj ct  then
       
   490      let 
       
   491       val (th1,th2) = conj_pair th in
       
   492       overall dun (th1::th2::oths) end
       
   493     else if is_disj ct then
       
   494       let 
       
   495        val th1 = overall dun (assume (capply @{cterm Trueprop} (dest_arg1 ct))::oths)
       
   496        val th2 = overall dun (assume (capply @{cterm Trueprop} (dest_arg ct))::oths)
       
   497       in disj_cases th th1 th2 end
       
   498    else overall (th::dun) oths
       
   499   end
       
   500   fun dest_binary b ct = if is_binop b ct then dest_binop ct 
       
   501                          else raise CTERM ("dest_binary",[b,ct])
       
   502   val dest_eq = dest_binary @{cterm "op = :: real => _"}
       
   503   val neq_th = nth pth 5
       
   504   fun real_not_eq_conv ct = 
       
   505    let 
       
   506     val (l,r) = dest_eq (dest_arg ct)
       
   507     val th = instantiate ([],[(@{cpat "?x::real"},l),(@{cpat "?y::real"},r)]) neq_th
       
   508     val th_p = poly_conv(dest_arg(dest_arg1(Thm.rhs_of th)))
       
   509     val th_x = Drule.arg_cong_rule @{cterm "uminus :: real => _"} th_p
       
   510     val th_n = fconv_rule (arg_conv poly_neg_conv) th_x
       
   511     val th' = Drule.binop_cong_rule @{cterm "op |"} 
       
   512      (Drule.arg_cong_rule (capply @{cterm "op <::real=>_"} @{cterm "0::real"}) th_p)
       
   513      (Drule.arg_cong_rule (capply @{cterm "op <::real=>_"} @{cterm "0::real"}) th_n)
       
   514     in transitive th th' 
       
   515   end
       
   516  fun equal_implies_1_rule PQ = 
       
   517   let 
       
   518    val P = lhs_of PQ
       
   519   in implies_intr P (equal_elim PQ (assume P))
       
   520   end
       
   521  (* FIXME!!! Copied from groebner.ml *)
       
   522  val strip_exists =
       
   523   let fun h (acc, t) =
       
   524    case (term_of t) of
       
   525     Const("Ex",_)$Abs(x,T,p) => h (dest_abs NONE (dest_arg t) |>> (fn v => v::acc))
       
   526   | _ => (acc,t)
       
   527   in fn t => h ([],t)
       
   528   end
       
   529   fun name_of x = case term_of x of
       
   530    Free(s,_) => s
       
   531  | Var ((s,_),_) => s
       
   532  | _ => "x"
       
   533 
       
   534   fun mk_forall x th = Drule.arg_cong_rule (instantiate_cterm' [SOME (ctyp_of_term x)] [] @{cpat "All :: (?'a => bool) => _" }) (abstract_rule (name_of x) x th)
       
   535 
       
   536   val specl = fold_rev (fn x => fn th => instantiate' [] [SOME x] (th RS spec));
       
   537 
       
   538  fun ext T = Drule.cterm_rule (instantiate' [SOME T] []) @{cpat Ex}
       
   539  fun mk_ex v t = Thm.capply (ext (ctyp_of_term v)) (Thm.cabs v t)
       
   540 
       
   541  fun choose v th th' = case concl_of th of 
       
   542    @{term Trueprop} $ (Const("Ex",_)$_) => 
       
   543     let
       
   544      val p = (funpow 2 Thm.dest_arg o cprop_of) th
       
   545      val T = (hd o Thm.dest_ctyp o ctyp_of_term) p
       
   546      val th0 = fconv_rule (Thm.beta_conversion true)
       
   547          (instantiate' [SOME T] [SOME p, (SOME o Thm.dest_arg o cprop_of) th'] exE)
       
   548      val pv = (Thm.rhs_of o Thm.beta_conversion true) 
       
   549            (Thm.capply @{cterm Trueprop} (Thm.capply p v))
       
   550      val th1 = forall_intr v (implies_intr pv th')
       
   551     in implies_elim (implies_elim th0 th) th1  end
       
   552  | _ => raise THM ("choose",0,[th, th'])
       
   553 
       
   554   fun simple_choose v th = 
       
   555      choose v (assume ((Thm.capply @{cterm Trueprop} o mk_ex v) ((Thm.dest_arg o hd o #hyps o Thm.crep_thm) th))) th
       
   556 
       
   557  val strip_forall =
       
   558   let fun h (acc, t) =
       
   559    case (term_of t) of
       
   560     Const("All",_)$Abs(x,T,p) => h (dest_abs NONE (dest_arg t) |>> (fn v => v::acc))
       
   561   | _ => (acc,t)
       
   562   in fn t => h ([],t)
       
   563   end
       
   564 
       
   565  fun f ct =
       
   566   let 
       
   567    val nnf_norm_conv' = 
       
   568      nnf_conv then_conv 
       
   569      literals_conv [@{term "op &"}, @{term "op |"}] [] 
       
   570      (cache_conv 
       
   571        (first_conv [real_lt_conv, real_le_conv, 
       
   572                     real_eq_conv, real_not_lt_conv, 
       
   573                     real_not_le_conv, real_not_eq_conv, all_conv]))
       
   574   fun absremover ct = (literals_conv [@{term "op &"}, @{term "op |"}] [] 
       
   575                   (try_conv (absconv1 then_conv binop_conv (arg_conv poly_conv))) then_conv 
       
   576         try_conv (absconv2 then_conv nnf_norm_conv' then_conv binop_conv absremover)) ct
       
   577   val nct = capply @{cterm Trueprop} (capply @{cterm "Not"} ct)
       
   578   val th0 = (init_conv then_conv arg_conv nnf_norm_conv') nct
       
   579   val tm0 = dest_arg (Thm.rhs_of th0)
       
   580   val th = if tm0 aconvc @{cterm False} then equal_implies_1_rule th0 else
       
   581    let 
       
   582     val (evs,bod) = strip_exists tm0
       
   583     val (avs,ibod) = strip_forall bod
       
   584     val th1 = Drule.arg_cong_rule @{cterm Trueprop} (fold mk_forall avs (absremover ibod))
       
   585     val th2 = overall [] [specl avs (assume (Thm.rhs_of th1))]
       
   586     val th3 = fold simple_choose evs (prove_hyp (equal_elim th1 (assume (capply @{cterm Trueprop} bod))) th2)
       
   587    in  Drule.implies_intr_hyps (prove_hyp (equal_elim th0 (assume nct)) th3)
       
   588    end
       
   589   in implies_elim (instantiate' [] [SOME ct] pth_final) th
       
   590  end
       
   591 in f
       
   592 end;
       
   593 
       
   594 (* A linear arithmetic prover *)
       
   595 local
       
   596   val linear_add = Ctermfunc.combine (curry op +/) (fn z => z =/ Rat.zero)
       
   597   fun linear_cmul c = Ctermfunc.mapf (fn x => c */ x)
       
   598   val one_tm = @{cterm "1::real"}
       
   599   fun contradictory p (e,_) = ((Ctermfunc.is_undefined e) andalso not(p Rat.zero)) orelse
       
   600      ((gen_eq_set (op aconvc) (Ctermfunc.dom e, [one_tm])) andalso not(p(Ctermfunc.apply e one_tm)))
       
   601 
       
   602   fun linear_ineqs vars (les,lts) = 
       
   603    case find_first (contradictory (fn x => x >/ Rat.zero)) lts of
       
   604     SOME r => r
       
   605   | NONE => 
       
   606    (case find_first (contradictory (fn x => x >/ Rat.zero)) les of
       
   607      SOME r => r
       
   608    | NONE => 
       
   609      if null vars then error "linear_ineqs: no contradiction" else
       
   610      let 
       
   611       val ineqs = les @ lts
       
   612       fun blowup v =
       
   613        length(filter (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero =/ Rat.zero) ineqs) +
       
   614        length(filter (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero >/ Rat.zero) ineqs) *
       
   615        length(filter (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero </ Rat.zero) ineqs)
       
   616       val  v = fst(hd(sort (fn ((_,i),(_,j)) => int_ord (i,j))
       
   617                  (map (fn v => (v,blowup v)) vars)))
       
   618       fun addup (e1,p1) (e2,p2) acc =
       
   619        let 
       
   620         val c1 = Ctermfunc.tryapplyd e1 v Rat.zero 
       
   621         val c2 = Ctermfunc.tryapplyd e2 v Rat.zero
       
   622        in if c1 */ c2 >=/ Rat.zero then acc else
       
   623         let 
       
   624          val e1' = linear_cmul (Rat.abs c2) e1
       
   625          val e2' = linear_cmul (Rat.abs c1) e2
       
   626          val p1' = Product(Rational_lt(Rat.abs c2),p1)
       
   627          val p2' = Product(Rational_lt(Rat.abs c1),p2)
       
   628         in (linear_add e1' e2',Sum(p1',p2'))::acc
       
   629         end
       
   630        end
       
   631       val (les0,les1) = 
       
   632          List.partition (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero =/ Rat.zero) les
       
   633       val (lts0,lts1) = 
       
   634          List.partition (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero =/ Rat.zero) lts
       
   635       val (lesp,lesn) = 
       
   636          List.partition (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero >/ Rat.zero) les1
       
   637       val (ltsp,ltsn) = 
       
   638          List.partition (fn (e,_) => Ctermfunc.tryapplyd e v Rat.zero >/ Rat.zero) lts1
       
   639       val les' = fold_rev (fn ep1 => fold_rev (addup ep1) lesp) lesn les0
       
   640       val lts' = fold_rev (fn ep1 => fold_rev (addup ep1) (lesp@ltsp)) ltsn
       
   641                       (fold_rev (fn ep1 => fold_rev (addup ep1) (lesn@ltsn)) ltsp lts0)
       
   642      in linear_ineqs (remove (op aconvc) v vars) (les',lts')
       
   643      end)
       
   644 
       
   645   fun linear_eqs(eqs,les,lts) = 
       
   646    case find_first (contradictory (fn x => x =/ Rat.zero)) eqs of
       
   647     SOME r => r
       
   648   | NONE => (case eqs of 
       
   649     [] => 
       
   650      let val vars = remove (op aconvc) one_tm 
       
   651            (fold_rev (curry (gen_union (op aconvc)) o Ctermfunc.dom o fst) (les@lts) []) 
       
   652      in linear_ineqs vars (les,lts) end
       
   653    | (e,p)::es => 
       
   654      if Ctermfunc.is_undefined e then linear_eqs (es,les,lts) else
       
   655      let 
       
   656       val (x,c) = Ctermfunc.choose (Ctermfunc.undefine one_tm e)
       
   657       fun xform (inp as (t,q)) =
       
   658        let val d = Ctermfunc.tryapplyd t x Rat.zero in
       
   659         if d =/ Rat.zero then inp else
       
   660         let 
       
   661          val k = (Rat.neg d) */ Rat.abs c // c
       
   662          val e' = linear_cmul k e
       
   663          val t' = linear_cmul (Rat.abs c) t
       
   664          val p' = Eqmul(cterm_of_rat k,p)
       
   665          val q' = Product(Rational_lt(Rat.abs c),q) 
       
   666         in (linear_add e' t',Sum(p',q')) 
       
   667         end 
       
   668       end
       
   669      in linear_eqs(map xform es,map xform les,map xform lts)
       
   670      end)
       
   671 
       
   672   fun linear_prover (eq,le,lt) = 
       
   673    let 
       
   674     val eqs = map2 (fn p => fn n => (p,Axiom_eq n)) eq (0 upto (length eq - 1))
       
   675     val les = map2 (fn p => fn n => (p,Axiom_le n)) le (0 upto (length le - 1))
       
   676     val lts = map2 (fn p => fn n => (p,Axiom_lt n)) lt (0 upto (length lt - 1))
       
   677    in linear_eqs(eqs,les,lts)
       
   678    end 
       
   679   
       
   680   fun lin_of_hol ct = 
       
   681    if ct aconvc @{cterm "0::real"} then Ctermfunc.undefined
       
   682    else if not (is_comb ct) then Ctermfunc.onefunc (ct, Rat.one)
       
   683    else if is_ratconst ct then Ctermfunc.onefunc (one_tm, dest_ratconst ct)
       
   684    else
       
   685     let val (lop,r) = Thm.dest_comb ct 
       
   686     in if not (is_comb lop) then Ctermfunc.onefunc (ct, Rat.one)
       
   687        else
       
   688         let val (opr,l) = Thm.dest_comb lop 
       
   689         in if opr aconvc @{cterm "op + :: real =>_"} 
       
   690            then linear_add (lin_of_hol l) (lin_of_hol r)
       
   691            else if opr aconvc @{cterm "op * :: real =>_"} 
       
   692                    andalso is_ratconst l then Ctermfunc.onefunc (r, dest_ratconst l)
       
   693            else Ctermfunc.onefunc (ct, Rat.one)
       
   694         end
       
   695     end
       
   696 
       
   697   fun is_alien ct = case term_of ct of 
       
   698    Const(@{const_name "real"}, _)$ n => 
       
   699      if can HOLogic.dest_number n then false else true
       
   700   | _ => false
       
   701  open Thm
       
   702 in 
       
   703 fun real_linear_prover translator (eq,le,lt) = 
       
   704  let 
       
   705   val lhs = lin_of_hol o dest_arg1 o dest_arg o cprop_of
       
   706   val rhs = lin_of_hol o dest_arg o dest_arg o cprop_of
       
   707   val eq_pols = map lhs eq
       
   708   val le_pols = map rhs le
       
   709   val lt_pols = map rhs lt 
       
   710   val aliens =  filter is_alien
       
   711       (fold_rev (curry (gen_union (op aconvc)) o Ctermfunc.dom) 
       
   712           (eq_pols @ le_pols @ lt_pols) [])
       
   713   val le_pols' = le_pols @ map (fn v => Ctermfunc.onefunc (v,Rat.one)) aliens
       
   714   val (_,proof) = linear_prover (eq_pols,le_pols',lt_pols)
       
   715   val le' = le @ map (fn a => instantiate' [] [SOME (dest_arg a)] @{thm real_of_nat_ge_zero}) aliens 
       
   716  in (translator (eq,le',lt) proof) : thm
       
   717  end
       
   718 end;
       
   719 
       
   720 (* A less general generic arithmetic prover dealing with abs,max and min*)
       
   721 
       
   722 local
       
   723  val absmaxmin_elim_ss1 = HOL_basic_ss addsimps real_abs_thms1
       
   724  fun absmaxmin_elim_conv1 ctxt = 
       
   725     Simplifier.rewrite (Simplifier.context ctxt absmaxmin_elim_ss1)
       
   726 
       
   727  val absmaxmin_elim_conv2 =
       
   728   let 
       
   729    val pth_abs = instantiate' [SOME @{ctyp real}] [] abs_split'
       
   730    val pth_max = instantiate' [SOME @{ctyp real}] [] max_split
       
   731    val pth_min = instantiate' [SOME @{ctyp real}] [] min_split
       
   732    val abs_tm = @{cterm "abs :: real => _"}
       
   733    val p_tm = @{cpat "?P :: real => bool"}
       
   734    val x_tm = @{cpat "?x :: real"}
       
   735    val y_tm = @{cpat "?y::real"}
       
   736    val is_max = is_binop @{cterm "max :: real => _"}
       
   737    val is_min = is_binop @{cterm "min :: real => _"} 
       
   738    fun is_abs t = is_comb t andalso dest_fun t aconvc abs_tm
       
   739    fun eliminate_construct p c tm =
       
   740     let 
       
   741      val t = find_cterm p tm
       
   742      val th0 = (symmetric o beta_conversion false) (capply (cabs t tm) t)
       
   743      val (p,ax) = (dest_comb o Thm.rhs_of) th0
       
   744     in fconv_rule(arg_conv(binop_conv (arg_conv (beta_conversion false))))
       
   745                (transitive th0 (c p ax))
       
   746    end
       
   747 
       
   748    val elim_abs = eliminate_construct is_abs
       
   749     (fn p => fn ax => 
       
   750        instantiate ([], [(p_tm,p), (x_tm, dest_arg ax)]) pth_abs)
       
   751    val elim_max = eliminate_construct is_max
       
   752     (fn p => fn ax => 
       
   753       let val (ax,y) = dest_comb ax 
       
   754       in  instantiate ([], [(p_tm,p), (x_tm, dest_arg ax), (y_tm,y)]) 
       
   755       pth_max end)
       
   756    val elim_min = eliminate_construct is_min
       
   757     (fn p => fn ax => 
       
   758       let val (ax,y) = dest_comb ax 
       
   759       in  instantiate ([], [(p_tm,p), (x_tm, dest_arg ax), (y_tm,y)]) 
       
   760       pth_min end)
       
   761    in first_conv [elim_abs, elim_max, elim_min, all_conv]
       
   762   end;
       
   763 in fun gen_real_arith ctxt (mkconst,eq,ge,gt,norm,neg,add,mul,prover) =
       
   764         gen_gen_real_arith ctxt (mkconst,eq,ge,gt,norm,neg,add,mul,
       
   765                        absmaxmin_elim_conv1 ctxt,absmaxmin_elim_conv2,prover)
       
   766 end;
       
   767 
       
   768 (* An instance for reals*) 
       
   769 
       
   770 fun gen_prover_real_arith ctxt prover = 
       
   771  let
       
   772   fun simple_cterm_ord t u = TermOrd.term_ord (term_of t, term_of u) = LESS
       
   773   val {add,mul,neg,pow,sub,main} = 
       
   774      Normalizer.semiring_normalizers_ord_wrapper ctxt
       
   775       (valOf (NormalizerData.match ctxt @{cterm "(0::real) + 1"})) 
       
   776      simple_cterm_ord
       
   777 in gen_real_arith ctxt
       
   778    (cterm_of_rat, field_comp_conv, field_comp_conv,field_comp_conv,
       
   779     main,neg,add,mul, prover)
       
   780 end;
       
   781 
       
   782 fun real_arith ctxt = gen_prover_real_arith ctxt real_linear_prover;
       
   783 end
       
   784 
     5 
   785   (* Now the norm procedure for euclidean spaces *)
     6   (* Now the norm procedure for euclidean spaces *)
   786 
     7 
   787 
     8 
   788 signature NORM_ARITH = 
     9 signature NORM_ARITH =