120 fun is_div_op (dv, (Const (op_, |
120 fun is_div_op (dv, (Const (op_, |
121 (Type ("fun", [Type (_, []), Type ("fun", [Type _, Type _])])))) ) = (dv = strip_thy op_) |
121 (Type ("fun", [Type (_, []), Type ("fun", [Type _, Type _])])))) ) = (dv = strip_thy op_) |
122 | is_div_op _ = false; |
122 | is_div_op _ = false; |
123 |
123 |
124 fun is_denom bdVar div_op t = |
124 fun is_denom bdVar div_op t = |
125 let fun is bool[v]dv (Const (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false) |
125 let |
126 | is bool[v]dv (Free (s,Type(_,[])))= bool andalso(if v=strip_thy s then true else false) |
126 fun is bool [v] _ (Const (s,Type(_,[])))= bool andalso(if v = strip_thy s then true else false) |
127 | is bool[v]dv (Var((s,_),Type(_,[])))= bool andalso(if v=strip_thy s then true else false) |
127 | is bool [v] _ (Free (s,Type(_,[])))= bool andalso(if v = strip_thy s then true else false) |
128 | is bool[v]dv((Const ("Bin.integ_of_bin",_)) $ _) = false |
128 | is bool [v] _ (Var((s,_),Type(_,[])))= bool andalso(if v = strip_thy s then true else false) |
129 | is bool[v]dv (h$n$d) = |
129 | is _ [_] _ ((Const ("Bin.integ_of_bin",_)) $ _) = false |
130 if is_div_op(dv,h) |
130 | is bool [v] dv (h$n$d) = |
131 then (is false[v]dv n)orelse(is true[v]dv d) |
131 if is_div_op (dv, h) |
132 else (is bool [v]dv n)orelse(is bool[v]dv d) |
132 then (is false [v] dv n) orelse(is true [v] dv d) |
133 in is false (varids bdVar) (strip_thy div_op) t end; |
133 else (is bool [v] dv n) orelse(is bool [v] dv d) |
|
134 | is _ _ _ _ = raise ERROR "is_denom: uncovered case in fun.def." |
|
135 in is false (varids bdVar) (strip_thy div_op) t end; |
134 |
136 |
135 |
137 |
136 fun rational t div_op bdVar = |
138 fun rational t div_op bdVar = |
137 is_denom bdVar div_op t andalso bin_ops_only t; |
139 is_denom bdVar div_op t andalso bin_ops_only t; |
138 |
140 |
236 "(x \<up> 2 = 0) = (x = 0)" and |
238 "(x \<up> 2 = 0) = (x = 0)" and |
237 |
239 |
238 (*isolate root on the LEFT hand side of the equation |
240 (*isolate root on the LEFT hand side of the equation |
239 otherwise shuffling from left to right would not terminate*) |
241 otherwise shuffling from left to right would not terminate*) |
240 |
242 |
241 rroot_to_lhs: |
243 (*Ambiguous input\<^here> produces 2 parse trees -----------------------------\\*) |
242 "is_root_free a ==> (a = sqrt b) = (a + (-1)*sqrt b = 0)" and |
244 rroot_to_lhs: "is_root_free a ==> (a = sqrt b) = (a + (-1)*sqrt b = 0)" and |
243 rroot_to_lhs_mult: |
245 rroot_to_lhs_mult: "is_root_free a ==> (a = c*sqrt b) = (a + (-1)*c*sqrt b = 0)" and |
244 "is_root_free a ==> (a = c*sqrt b) = (a + (-1)*c*sqrt b = 0)" and |
246 rroot_to_lhs_add_mult: "is_root_free a ==> (a = d+c*sqrt b) = (a + (-1)*c*sqrt b = d)" |
245 rroot_to_lhs_add_mult: |
247 (*Ambiguous input\<^here> produces 2 parse trees -----------------------------//*) |
246 "is_root_free a ==> (a = d+c*sqrt b) = (a + (-1)*c*sqrt b = d)" |
|
247 (*17.9.02 aus SqRoot.thy------------------------------ \<up> ---*) |
|
248 |
248 |
249 section \<open>eval functions\<close> |
249 section \<open>eval functions\<close> |
250 ML \<open> |
250 ML \<open> |
251 val thy = @{theory}; |
251 val thy = @{theory}; |
252 |
252 |
253 (** evaluation of numerals and predicates **) |
253 (** evaluation of numerals and predicates **) |
254 |
254 |
255 (*does a term contain a root ?*) |
255 (*does a term contain a root ?*) |
256 fun eval_contains_root (thmid:string) _ |
256 fun eval_contains_root (thmid:string) _ |
257 (t as (Const("Test.contains'_root",t0) $ arg)) thy = |
257 (t as (Const("Test.contains'_root", _) $ arg)) thy = |
258 if member op = (ids_of arg) "sqrt" |
258 if member op = (ids_of arg) "sqrt" |
259 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"", |
259 then SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"", |
260 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True}))) |
260 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term True}))) |
261 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"", |
261 else SOME (TermC.mk_thmid thmid (UnparseC.term_in_thy thy arg)"", |
262 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False}))) |
262 HOLogic.Trueprop $ (TermC.mk_equality (t, @{term False}))) |
292 fun pr_ord EQUAL = "EQUAL" |
292 fun pr_ord EQUAL = "EQUAL" |
293 | pr_ord LESS = "LESS" |
293 | pr_ord LESS = "LESS" |
294 | pr_ord GREATER = "GREATER"; |
294 | pr_ord GREATER = "GREATER"; |
295 |
295 |
296 fun dest_hd' (Const (a, T)) = (* ~ term.ML *) |
296 fun dest_hd' (Const (a, T)) = (* ~ term.ML *) |
297 (case a of |
297 (case a of |
298 "Prog_Expr.pow" => ((("|||||||||||||", 0), T), 0) (*WN greatest *) |
298 "Prog_Expr.pow" => ((("|||||||||||||", 0), T), 0) (*WN greatest *) |
299 | _ => (((a, 0), T), 0)) |
299 | _ => (((a, 0), T), 0)) |
300 | dest_hd' (Free (a, T)) = (((a, 0), T), 1) |
300 | dest_hd' (Free (a, T)) = (((a, 0), T), 1) |
301 | dest_hd' (Var v) = (v, 2) |
301 | dest_hd' (Var v) = (v, 2) |
302 | dest_hd' (Bound i) = ((("", i), dummyT), 3) |
302 | dest_hd' (Bound i) = ((("", i), dummyT), 3) |
303 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4); |
303 | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4) |
304 (* RL *) |
304 | dest_hd' _ = raise ERROR "dest_hd': uncovered case in fun.def."; |
305 fun get_order_pow (t $ (Free(order,_))) = |
305 |
|
306 \<^isac_test>\<open> |
|
307 fun get_order_pow (t $ (Free(order,_))) = |
306 (case TermC.int_opt_of_string order of |
308 (case TermC.int_opt_of_string order of |
307 SOME d => d |
309 SOME d => d |
308 | NONE => 0) |
310 | NONE => 0) |
309 | get_order_pow _ = 0; |
311 | get_order_pow _ = 0; |
|
312 \<close> |
310 |
313 |
311 fun size_of_term' (Const(str,_) $ t) = |
314 fun size_of_term' (Const(str,_) $ t) = |
312 if "Prog_Expr.pow"=str then 1000 + size_of_term' t else 1 + size_of_term' t(*WN*) |
315 if "Prog_Expr.pow"=str then 1000 + size_of_term' t else 1 + size_of_term' t(*WN*) |
313 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body |
316 | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body |
314 | size_of_term' (f$t) = size_of_term' f + size_of_term' t |
317 | size_of_term' (f$t) = size_of_term' f + size_of_term' t |
315 | size_of_term' _ = 1; |
318 | size_of_term' _ = 1; |
316 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *) |
319 fun term_ord' pr thy (Abs (_, T, t), Abs(_, U, u)) = (* ~ term.ML *) |
317 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) |
320 (case term_ord' pr thy (t, u) of EQUAL => Term_Ord.typ_ord (T, U) |
318 | ord => ord) |
321 | ord => ord) |
319 | term_ord' pr thy (t, u) = |
322 | term_ord' pr _ (t, u) = |
320 (if pr then |
323 (if pr then |
321 let val (f, ts) = strip_comb t and (g, us) = strip_comb u; |
324 let val (f, ts) = strip_comb t and (g, us) = strip_comb u; |
322 val _ = tracing ("t= f@ts= \"" ^ UnparseC.term f ^ "\" @ \"[" ^ |
325 val _ = tracing ("t= f@ts= \"" ^ UnparseC.term f ^ "\" @ \"[" ^ |
323 commas(map UnparseC.term ts) ^ "]\"") |
326 commas(map UnparseC.term ts) ^ "]\"") |
324 val _ = tracing ("u= g@us= \"" ^ UnparseC.term g ^"\" @ \"[" ^ |
327 val _ = tracing ("u= g@us= \"" ^ UnparseC.term g ^"\" @ \"[" ^ |