src/Tools/isac/Knowledge/RootEq.thy
author Walther Neuper <wneuper@ist.tugraz.at>
Sun, 23 Jun 2019 14:23:09 +0200
changeset 59552 ab7955d2ead3
parent 59551 6ea6d9c377a0
child 59603 30cd47104ad7
permissions -rw-r--r--
funpack: remove remainings of Script, finished.
neuper@37906
     1
(*.(c) by Richard Lang, 2003 .*)
neuper@37906
     2
(* collecting all knowledge for Root Equations
neuper@37906
     3
   created by: rlang 
neuper@37906
     4
         date: 02.08
neuper@37906
     5
   changed by: rlang
neuper@37906
     6
   last change by: rlang
neuper@37906
     7
             date: 02.11.14
neuper@37906
     8
*)
neuper@37906
     9
s1210629013@55339
    10
theory RootEq imports Root Equation begin
neuper@37906
    11
wneuper@59472
    12
text \<open>univariate equations containing real square roots:
neuper@42398
    13
  This type of equations has been used to bootstrap Lucas-Interpretation.
neuper@42398
    14
  In 2003 this type has been extended and integrated into ISAC's equation solver
neuper@42398
    15
  by Richard Lang in 2003.
neuper@42398
    16
  The assumptions (all containing "<") didn't pass the xml-parsers at the 
neuper@42398
    17
  interface between math-engine and front-end.
neuper@42398
    18
  The migration Isabelle2002 --> 2011 dropped this type of equation, see
neuper@42398
    19
  test/../rooteq.sml, rootrateq.sml.
wneuper@59472
    20
\<close>
neuper@42398
    21
wneuper@59526
    22
subsection \<open>consts definition for predicates\<close>
neuper@37906
    23
consts
neuper@37985
    24
  is'_rootTerm'_in     :: "[real, real] => bool" ("_ is'_rootTerm'_in _")
neuper@37950
    25
  is'_sqrtTerm'_in     :: "[real, real] => bool" ("_ is'_sqrtTerm'_in _") 
neuper@37950
    26
  is'_normSqrtTerm'_in :: "[real, real] => bool" ("_ is'_normSqrtTerm'_in _") 
neuper@37906
    27
 
wneuper@59526
    28
subsection \<open>theorems not yet adopted from Isabelle\<close>
neuper@52148
    29
axiomatization where
wneuper@59370
    30
(* normalise *)
neuper@52148
    31
  makex1_x:            "a^^^1  = a"   and
neuper@52148
    32
  real_assoc_1:        "a+(b+c) = a+b+c" and
neuper@52148
    33
  real_assoc_2:        "a*(b*c) = a*b*c" and
neuper@37906
    34
neuper@37906
    35
  (* simplification of root*)
neuper@52148
    36
  sqrt_square_1:       "[|0 <= a|] ==>  (sqrt a)^^^2 = a" and
neuper@52148
    37
  sqrt_square_2:       "sqrt (a ^^^ 2) = a" and
neuper@52148
    38
  sqrt_times_root_1:   "sqrt a * sqrt b = sqrt(a*b)" and
neuper@52148
    39
  sqrt_times_root_2:   "a * sqrt b * sqrt c = a * sqrt(b*c)" and
neuper@37906
    40
neuper@37906
    41
  (* isolate one root on the LEFT or RIGHT hand side of the equation *)
neuper@37983
    42
  sqrt_isolate_l_add1: "[|bdv occurs_in c|] ==> 
neuper@52148
    43
   (a + b*sqrt(c) = d) = (b * sqrt(c) = d+ (-1) * a)" and
neuper@37983
    44
  sqrt_isolate_l_add2: "[|bdv occurs_in c|] ==>
neuper@52148
    45
   (a + sqrt(c) = d) = ((sqrt(c) = d+ (-1) * a))" and
neuper@37983
    46
  sqrt_isolate_l_add3: "[|bdv occurs_in c|] ==>
neuper@52148
    47
   (a + b*(e/sqrt(c)) = d) = (b * (e/sqrt(c)) = d + (-1) * a)" and
neuper@37983
    48
  sqrt_isolate_l_add4: "[|bdv occurs_in c|] ==>
neuper@52148
    49
   (a + b/(f*sqrt(c)) = d) = (b / (f*sqrt(c)) = d + (-1) * a)" and
neuper@37983
    50
  sqrt_isolate_l_add5: "[|bdv occurs_in c|] ==>
neuper@52148
    51
   (a + b*(e/(f*sqrt(c))) = d) = (b * (e/(f*sqrt(c))) = d+ (-1) * a)" and
neuper@37983
    52
  sqrt_isolate_l_add6: "[|bdv occurs_in c|] ==>
neuper@52148
    53
   (a + b/sqrt(c) = d) = (b / sqrt(c) = d+ (-1) * a)" and
neuper@37983
    54
  sqrt_isolate_r_add1: "[|bdv occurs_in f|] ==>
neuper@52148
    55
   (a = d + e*sqrt(f)) = (a + (-1) * d = e*sqrt(f))" and
neuper@37983
    56
  sqrt_isolate_r_add2: "[|bdv occurs_in f|] ==>
neuper@52148
    57
   (a = d + sqrt(f)) = (a + (-1) * d = sqrt(f))" and
wneuper@59370
    58
 (* small hack: thm 3,5,6 are not needed if rootnormalise is well done*)
neuper@37983
    59
  sqrt_isolate_r_add3: "[|bdv occurs_in f|] ==>
neuper@52148
    60
   (a = d + e*(g/sqrt(f))) = (a + (-1) * d = e*(g/sqrt(f)))" and
neuper@37983
    61
  sqrt_isolate_r_add4: "[|bdv occurs_in f|] ==>
neuper@52148
    62
   (a = d + g/sqrt(f)) = (a + (-1) * d = g/sqrt(f))" and
neuper@37983
    63
  sqrt_isolate_r_add5: "[|bdv occurs_in f|] ==>
neuper@52148
    64
   (a = d + e*(g/(h*sqrt(f)))) = (a + (-1) * d = e*(g/(h*sqrt(f))))" and
neuper@37983
    65
  sqrt_isolate_r_add6: "[|bdv occurs_in f|] ==>
neuper@52148
    66
   (a = d + g/(h*sqrt(f))) = (a + (-1) * d = g/(h*sqrt(f)))" and
neuper@37906
    67
 
neuper@37906
    68
  (* eliminate isolates sqrt *)
neuper@37983
    69
  sqrt_square_equation_both_1: "[|bdv occurs_in b; bdv occurs_in d|] ==> 
neuper@37950
    70
   ( (sqrt a + sqrt b         = sqrt c + sqrt d) = 
neuper@52148
    71
     (a+2*sqrt(a)*sqrt(b)+b  = c+2*sqrt(c)*sqrt(d)+d))" and
neuper@37983
    72
  sqrt_square_equation_both_2: "[|bdv occurs_in b; bdv occurs_in d|] ==> 
neuper@37950
    73
   ( (sqrt a - sqrt b           = sqrt c + sqrt d) = 
neuper@52148
    74
     (a - 2*sqrt(a)*sqrt(b)+b  = c+2*sqrt(c)*sqrt(d)+d))" and
neuper@37983
    75
  sqrt_square_equation_both_3: "[|bdv occurs_in b; bdv occurs_in d|] ==> 
neuper@37950
    76
   ( (sqrt a + sqrt b           = sqrt c - sqrt d) = 
neuper@52148
    77
     (a + 2*sqrt(a)*sqrt(b)+b  = c - 2*sqrt(c)*sqrt(d)+d))" and
neuper@37983
    78
  sqrt_square_equation_both_4: "[|bdv occurs_in b; bdv occurs_in d|] ==> 
neuper@37950
    79
   ( (sqrt a - sqrt b           = sqrt c - sqrt d) = 
neuper@52148
    80
     (a - 2*sqrt(a)*sqrt(b)+b  = c - 2*sqrt(c)*sqrt(d)+d))" and
neuper@37983
    81
  sqrt_square_equation_left_1: "[|bdv occurs_in a; 0 <= a; 0 <= b|] ==>
neuper@52148
    82
   ( (sqrt (a) = b) = (a = (b^^^2)))" and
neuper@37983
    83
  sqrt_square_equation_left_2: "[|bdv occurs_in a; 0 <= a; 0 <= b*c|] ==> 
neuper@52148
    84
   ( (c*sqrt(a) = b) = (c^^^2*a = b^^^2))" and
neuper@37983
    85
  sqrt_square_equation_left_3: "[|bdv occurs_in a; 0 <= a; 0 <= b*c|] ==> 
neuper@52148
    86
   ( c/sqrt(a) = b) = (c^^^2 / a = b^^^2)" and
wneuper@59370
    87
  (* small hack: thm 4-6 are not needed if rootnormalise is well done*)
neuper@37983
    88
  sqrt_square_equation_left_4: "[|bdv occurs_in a; 0 <= a; 0 <= b*c*d|] ==> 
neuper@52148
    89
   ( (c*(d/sqrt (a)) = b) = (c^^^2*(d^^^2/a) = b^^^2))" and
neuper@37983
    90
  sqrt_square_equation_left_5: "[|bdv occurs_in a; 0 <= a; 0 <= b*c*d|] ==> 
neuper@52148
    91
   ( c/(d*sqrt(a)) = b) = (c^^^2 / (d^^^2*a) = b^^^2)" and
neuper@37983
    92
  sqrt_square_equation_left_6: "[|bdv occurs_in a; 0 <= a; 0 <= b*c*d*e|] ==> 
neuper@52148
    93
   ( (c*(d/(e*sqrt (a))) = b) = (c^^^2*(d^^^2/(e^^^2*a)) = b^^^2))" and
neuper@37983
    94
  sqrt_square_equation_right_1:  "[|bdv occurs_in b; 0 <= a; 0 <= b|] ==> 
neuper@52148
    95
   ( (a = sqrt (b)) = (a^^^2 = b))" and
neuper@37983
    96
  sqrt_square_equation_right_2: "[|bdv occurs_in b; 0 <= a*c; 0 <= b|] ==> 
neuper@52148
    97
   ( (a = c*sqrt (b)) = ((a^^^2) = c^^^2*b))" and
neuper@37983
    98
  sqrt_square_equation_right_3: "[|bdv occurs_in b; 0 <= a*c; 0 <= b|] ==> 
neuper@52148
    99
   ( (a = c/sqrt (b)) = (a^^^2 = c^^^2/b))" and
wneuper@59370
   100
 (* small hack: thm 4-6 are not needed if rootnormalise is well done*)
neuper@37983
   101
  sqrt_square_equation_right_4: "[|bdv occurs_in b; 0 <= a*c*d; 0 <= b|] ==> 
neuper@52148
   102
   ( (a = c*(d/sqrt (b))) = ((a^^^2) = c^^^2*(d^^^2/b)))" and
neuper@37983
   103
  sqrt_square_equation_right_5: "[|bdv occurs_in b; 0 <= a*c*d; 0 <= b|] ==> 
neuper@52148
   104
   ( (a = c/(d*sqrt (b))) = (a^^^2 = c^^^2/(d^^^2*b)))" and
neuper@37983
   105
  sqrt_square_equation_right_6: "[|bdv occurs_in b; 0 <= a*c*d*e; 0 <= b|] ==> 
neuper@37950
   106
   ( (a = c*(d/(e*sqrt (b)))) = ((a^^^2) = c^^^2*(d^^^2/(e^^^2*b))))"
neuper@37950
   107
wneuper@59526
   108
subsection \<open>predicates\<close>
wneuper@59472
   109
ML \<open>
neuper@37972
   110
val thy = @{theory};
neuper@37972
   111
neuper@37950
   112
(* true if bdv is under sqrt of a Equation*)
neuper@37950
   113
fun is_rootTerm_in t v = 
wneuper@59525
   114
  let 
wneuper@59526
   115
   	fun findroot (t as (_ $ _ $ _ $ _)) _ = raise TERM ( "is_rootTerm_in", [t])
neuper@37950
   116
	  (* at the moment there is no term like this, but ....*)
wneuper@59527
   117
	  | findroot (Const ("Root.nroot",_) $ _ $ t3) v = occurs_in v t3
wneuper@59526
   118
	  | findroot (_ $ t2 $ t3) v = findroot t2 v orelse findroot t3 v
wneuper@59527
   119
	  | findroot (Const ("NthRoot.sqrt", _) $ t2) v = occurs_in v t2
wneuper@59526
   120
	  | findroot (_ $ t2) v = findroot t2 v
neuper@37950
   121
	  | findroot _ _ = false;
wneuper@59526
   122
  in
wneuper@59526
   123
	  findroot t v
wneuper@59526
   124
  end;
neuper@37950
   125
wneuper@59526
   126
fun is_sqrtTerm_in t v = 
wneuper@59526
   127
  let 
wneuper@59526
   128
    fun findsqrt (t as (_ $ _ $ _ $ _)) _ = raise TERM ("is_sqrteqation_in", [t])
wneuper@59526
   129
    (* at the moment there is no term like this, but ....*)
wneuper@59526
   130
    | findsqrt (_ $ t1 $ t2) v = (findsqrt t1 v) orelse (findsqrt t2 v)
wneuper@59527
   131
    | findsqrt (Const ("NthRoot.sqrt", _) $ a) v = occurs_in v a
wneuper@59526
   132
    | findsqrt (_ $ t1) v = findsqrt t1 v
wneuper@59526
   133
    | findsqrt _ _ = false;
wneuper@59526
   134
  in
wneuper@59526
   135
   findsqrt t v
wneuper@59526
   136
  end;
neuper@37950
   137
neuper@37950
   138
(* RL: 030518: Is in the rightest subterm of a term a sqrt with bdv,
wneuper@59370
   139
and the subterm ist connected with + or * --> is normalised*)
wneuper@59526
   140
fun is_normSqrtTerm_in t v =
wneuper@59526
   141
  let
wneuper@59526
   142
     fun isnorm (t as (_ $ _ $ _ $ _)) _ = raise TERM ("is_normSqrtTerm_in", [t])
wneuper@59526
   143
         (* at the moment there is no term like this, but ....*)
wneuper@59526
   144
       | isnorm (Const ("Groups.plus_class.plus",_) $ _ $ t2) v = is_sqrtTerm_in t2 v
wneuper@59526
   145
       | isnorm (Const ("Groups.times_class.times",_) $ _ $ t2) v = is_sqrtTerm_in t2 v
wneuper@59526
   146
       | isnorm (Const ("Groups.minus_class.minus",_) $ _ $ _) _ = false
wneuper@59526
   147
       | isnorm (Const ("Rings.divide_class.divide",_) $ t1 $ t2) v =
wneuper@59526
   148
         is_sqrtTerm_in t1 v orelse is_sqrtTerm_in t2 v
wneuper@59527
   149
       | isnorm (Const ("NthRoot.sqrt", _) $ t1) v = occurs_in v t1
wneuper@59526
   150
	     | isnorm (_ $ t1) v = is_sqrtTerm_in t1 v
wneuper@59526
   151
       | isnorm _ _ = false;
wneuper@59526
   152
   in
wneuper@59526
   153
     isnorm t v
wneuper@59526
   154
   end;
neuper@37950
   155
wneuper@59526
   156
fun eval_is_rootTerm_in _ _ (p as (Const ("RootEq.is'_rootTerm'_in",_) $ t $ v)) _ =
wneuper@59526
   157
    if is_rootTerm_in t v
wneuper@59526
   158
    then SOME ((Rule.term2str p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
wneuper@59526
   159
    else SOME ((Rule.term2str p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
neuper@38015
   160
  | eval_is_rootTerm_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
neuper@37950
   161
wneuper@59526
   162
fun eval_is_sqrtTerm_in _ _ (p as (Const ("RootEq.is'_sqrtTerm'_in",_) $ t $ v)) _ =
wneuper@59526
   163
    if is_sqrtTerm_in t v
wneuper@59526
   164
    then SOME ((Rule.term2str p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
wneuper@59526
   165
    else SOME ((Rule.term2str p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
neuper@38015
   166
  | eval_is_sqrtTerm_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
neuper@37950
   167
wneuper@59526
   168
fun eval_is_normSqrtTerm_in _ _ (p as (Const ("RootEq.is'_normSqrtTerm'_in",_) $ t $ v)) _ =
wneuper@59526
   169
    if is_normSqrtTerm_in t v
wneuper@59526
   170
    then SOME ((Rule.term2str p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term True})))
wneuper@59526
   171
    else SOME ((Rule.term2str p) ^ " = True", HOLogic.Trueprop $ (TermC.mk_equality (p, @{term False})))
neuper@38015
   172
  | eval_is_normSqrtTerm_in _ _ _ _ = ((*tracing"### nichts matcht";*) NONE);
wneuper@59526
   173
\<close>
wneuper@59526
   174
setup \<open>KEStore_Elems.add_calcs
wneuper@59526
   175
  [("is_rootTerm_in", ("RootEq.is'_rootTerm'_in", eval_is_rootTerm_in"")),
wneuper@59526
   176
    ("is_sqrtTerm_in", ("RootEq.is'_sqrtTerm'_in", eval_is_sqrtTerm_in"")),
wneuper@59526
   177
    ("is_normSqrtTerm_in", ("RootEq.is_normSqrtTerm_in", eval_is_normSqrtTerm_in""))]\<close>
neuper@37950
   178
wneuper@59526
   179
subsection \<open>rule-sets\<close>
wneuper@59526
   180
ML \<open>
neuper@37950
   181
val RootEq_prls =(*15.10.02:just the following order due to subterm evaluation*)
wneuper@59416
   182
  Rule.append_rls "RootEq_prls" Rule.e_rls 
wneuper@59416
   183
	     [Rule.Calc ("Atools.ident",eval_ident "#ident_"),
wneuper@59491
   184
	      Rule.Calc ("Tools.matches", Tools.eval_matches ""),
wneuper@59491
   185
	      Rule.Calc ("Tools.lhs"    , Tools.eval_lhs ""),
wneuper@59491
   186
	      Rule.Calc ("Tools.rhs"    , Tools.eval_rhs ""),
wneuper@59416
   187
	      Rule.Calc ("RootEq.is'_sqrtTerm'_in",eval_is_sqrtTerm_in ""),
wneuper@59416
   188
	      Rule.Calc ("RootEq.is'_rootTerm'_in",eval_is_rootTerm_in ""),
wneuper@59416
   189
	      Rule.Calc ("RootEq.is'_normSqrtTerm'_in",eval_is_normSqrtTerm_in ""),
wneuper@59416
   190
	      Rule.Calc ("HOL.eq",eval_equal "#equal_"),
wneuper@59416
   191
	      Rule.Thm ("not_true",TermC.num_str @{thm not_true}),
wneuper@59416
   192
	      Rule.Thm ("not_false",TermC.num_str @{thm not_false}),
wneuper@59416
   193
	      Rule.Thm ("and_true",TermC.num_str @{thm and_true}),
wneuper@59416
   194
	      Rule.Thm ("and_false",TermC.num_str @{thm and_false}),
wneuper@59416
   195
	      Rule.Thm ("or_true",TermC.num_str @{thm or_true}),
wneuper@59416
   196
	      Rule.Thm ("or_false",TermC.num_str @{thm or_false})
neuper@37950
   197
	      ];
neuper@37950
   198
neuper@37950
   199
val RootEq_erls =
wneuper@59526
   200
  Rule.append_rls "RootEq_erls" Root_erls
wneuper@59526
   201
    [Rule.Thm ("divide_divide_eq_left", TermC.num_str @{thm divide_divide_eq_left})];
neuper@37950
   202
neuper@37950
   203
val RootEq_crls = 
wneuper@59526
   204
  Rule.append_rls "RootEq_crls" Root_crls
wneuper@59526
   205
    [Rule.Thm ("divide_divide_eq_left", TermC.num_str @{thm divide_divide_eq_left})];
neuper@37950
   206
neuper@37950
   207
val rooteq_srls = 
wneuper@59526
   208
  Rule.append_rls "rooteq_srls" Rule.e_rls
wneuper@59526
   209
    [Rule.Calc ("RootEq.is'_sqrtTerm'_in", eval_is_sqrtTerm_in ""),
wneuper@59526
   210
     Rule.Calc ("RootEq.is'_normSqrtTerm'_in", eval_is_normSqrtTerm_in""),
wneuper@59526
   211
     Rule.Calc ("RootEq.is'_rootTerm'_in", eval_is_rootTerm_in "")];
wneuper@59472
   212
\<close>
wneuper@59472
   213
ML \<open>
neuper@37950
   214
neuper@37950
   215
(*isolate the bound variable in an sqrt equation; 'bdv' is a meta-constant*)
s1210629013@55444
   216
 val sqrt_isolate = prep_rls'(
wneuper@59416
   217
  Rule.Rls {id = "sqrt_isolate", preconds = [], rew_ord = ("termlessI",termlessI), 
wneuper@59416
   218
       erls = RootEq_erls, srls = Rule.Erls, calc = [], errpatts = [],
neuper@37950
   219
       rules = [
wneuper@59416
   220
       Rule.Thm("sqrt_square_1",TermC.num_str @{thm sqrt_square_1}),
neuper@37950
   221
                     (* (sqrt a)^^^2 -> a *)
wneuper@59416
   222
       Rule.Thm("sqrt_square_2",TermC.num_str @{thm sqrt_square_2}),
neuper@37950
   223
                     (* sqrt (a^^^2) -> a *)
wneuper@59416
   224
       Rule.Thm("sqrt_times_root_1",TermC.num_str @{thm sqrt_times_root_1}),
neuper@37950
   225
            (* sqrt a sqrt b -> sqrt(ab) *)
wneuper@59416
   226
       Rule.Thm("sqrt_times_root_2",TermC.num_str @{thm sqrt_times_root_2}),
neuper@37950
   227
            (* a sqrt b sqrt c -> a sqrt(bc) *)
wneuper@59416
   228
       Rule.Thm("sqrt_square_equation_both_1",
wneuper@59389
   229
           TermC.num_str @{thm sqrt_square_equation_both_1}),
neuper@37950
   230
       (* (sqrt a + sqrt b  = sqrt c + sqrt d) -> 
neuper@37950
   231
            (a+2*sqrt(a)*sqrt(b)+b) = c+2*sqrt(c)*sqrt(d)+d) *)
wneuper@59416
   232
       Rule.Thm("sqrt_square_equation_both_2",
wneuper@59389
   233
            TermC.num_str @{thm sqrt_square_equation_both_2}),
neuper@37950
   234
       (* (sqrt a - sqrt b  = sqrt c + sqrt d) -> 
neuper@37950
   235
            (a-2*sqrt(a)*sqrt(b)+b) = c+2*sqrt(c)*sqrt(d)+d) *)
wneuper@59416
   236
       Rule.Thm("sqrt_square_equation_both_3",
wneuper@59389
   237
            TermC.num_str @{thm sqrt_square_equation_both_3}),
neuper@37950
   238
       (* (sqrt a + sqrt b  = sqrt c - sqrt d) -> 
neuper@37950
   239
            (a+2*sqrt(a)*sqrt(b)+b) = c-2*sqrt(c)*sqrt(d)+d) *)
wneuper@59416
   240
       Rule.Thm("sqrt_square_equation_both_4",
wneuper@59389
   241
            TermC.num_str @{thm sqrt_square_equation_both_4}),
neuper@37950
   242
       (* (sqrt a - sqrt b  = sqrt c - sqrt d) -> 
neuper@37950
   243
            (a-2*sqrt(a)*sqrt(b)+b) = c-2*sqrt(c)*sqrt(d)+d) *)
wneuper@59416
   244
       Rule.Thm("sqrt_isolate_l_add1",
wneuper@59389
   245
            TermC.num_str @{thm sqrt_isolate_l_add1}), 
neuper@37950
   246
       (* a+b*sqrt(x)=d -> b*sqrt(x) = d-a *)
wneuper@59416
   247
       Rule.Thm("sqrt_isolate_l_add2",
wneuper@59389
   248
            TermC.num_str @{thm sqrt_isolate_l_add2}), 
neuper@37950
   249
       (* a+  sqrt(x)=d ->   sqrt(x) = d-a *)
wneuper@59416
   250
       Rule.Thm("sqrt_isolate_l_add3",
wneuper@59389
   251
            TermC.num_str @{thm sqrt_isolate_l_add3}), 
neuper@37950
   252
       (* a+b*c/sqrt(x)=d->b*c/sqrt(x)=d-a *)
wneuper@59416
   253
       Rule.Thm("sqrt_isolate_l_add4",
wneuper@59389
   254
            TermC.num_str @{thm sqrt_isolate_l_add4}), 
neuper@37950
   255
       (* a+c/sqrt(x)=d -> c/sqrt(x) = d-a *)
wneuper@59416
   256
       Rule.Thm("sqrt_isolate_l_add5",
wneuper@59389
   257
            TermC.num_str @{thm sqrt_isolate_l_add5}), 
neuper@37950
   258
       (* a+b*c/f*sqrt(x)=d->b*c/f*sqrt(x)=d-a *)
wneuper@59416
   259
       Rule.Thm("sqrt_isolate_l_add6",
wneuper@59389
   260
            TermC.num_str @{thm sqrt_isolate_l_add6}), 
neuper@37950
   261
       (* a+c/f*sqrt(x)=d -> c/f*sqrt(x) = d-a *)
wneuper@59416
   262
       (*Rule.Thm("sqrt_isolate_l_div",TermC.num_str @{thm sqrt_isolate_l_div}),*)
neuper@37950
   263
         (* b*sqrt(x) = d sqrt(x) d/b *)
wneuper@59416
   264
       Rule.Thm("sqrt_isolate_r_add1",
wneuper@59389
   265
            TermC.num_str @{thm sqrt_isolate_r_add1}),
neuper@37950
   266
       (* a= d+e*sqrt(x) -> a-d=e*sqrt(x) *)
wneuper@59416
   267
       Rule.Thm("sqrt_isolate_r_add2",
wneuper@59389
   268
            TermC.num_str @{thm sqrt_isolate_r_add2}),
neuper@37950
   269
       (* a= d+  sqrt(x) -> a-d=  sqrt(x) *)
wneuper@59416
   270
       Rule.Thm("sqrt_isolate_r_add3",
wneuper@59389
   271
            TermC.num_str @{thm sqrt_isolate_r_add3}),
neuper@37950
   272
       (* a=d+e*g/sqrt(x)->a-d=e*g/sqrt(x)*)
wneuper@59416
   273
       Rule.Thm("sqrt_isolate_r_add4",
wneuper@59389
   274
            TermC.num_str @{thm sqrt_isolate_r_add4}),
neuper@37950
   275
       (* a= d+g/sqrt(x) -> a-d=g/sqrt(x) *)
wneuper@59416
   276
       Rule.Thm("sqrt_isolate_r_add5",
wneuper@59389
   277
            TermC.num_str @{thm sqrt_isolate_r_add5}),
neuper@37950
   278
       (* a=d+e*g/h*sqrt(x)->a-d=e*g/h*sqrt(x)*)
wneuper@59416
   279
       Rule.Thm("sqrt_isolate_r_add6",
wneuper@59389
   280
            TermC.num_str @{thm sqrt_isolate_r_add6}),
neuper@37950
   281
       (* a= d+g/h*sqrt(x) -> a-d=g/h*sqrt(x) *)
wneuper@59416
   282
       (*Rule.Thm("sqrt_isolate_r_div",TermC.num_str @{thm sqrt_isolate_r_div}),*)
neuper@37950
   283
         (* a=e*sqrt(x) -> a/e = sqrt(x) *)
wneuper@59416
   284
       Rule.Thm("sqrt_square_equation_left_1",
wneuper@59389
   285
            TermC.num_str @{thm sqrt_square_equation_left_1}),   
neuper@37950
   286
       (* sqrt(x)=b -> x=b^2 *)
wneuper@59416
   287
       Rule.Thm("sqrt_square_equation_left_2",
wneuper@59389
   288
            TermC.num_str @{thm sqrt_square_equation_left_2}),   
neuper@37950
   289
       (* c*sqrt(x)=b -> c^2*x=b^2 *)
wneuper@59416
   290
       Rule.Thm("sqrt_square_equation_left_3",TermC.num_str @{thm sqrt_square_equation_left_3}),  
neuper@37950
   291
	      (* c/sqrt(x)=b -> c^2/x=b^2 *)
wneuper@59416
   292
       Rule.Thm("sqrt_square_equation_left_4",TermC.num_str @{thm sqrt_square_equation_left_4}),
neuper@37950
   293
	      (* c*d/sqrt(x)=b -> c^2*d^2/x=b^2 *)
wneuper@59416
   294
       Rule.Thm("sqrt_square_equation_left_5",TermC.num_str @{thm sqrt_square_equation_left_5}),
neuper@37950
   295
	      (* c/d*sqrt(x)=b -> c^2/d^2x=b^2 *)
wneuper@59416
   296
       Rule.Thm("sqrt_square_equation_left_6",TermC.num_str @{thm sqrt_square_equation_left_6}),
neuper@37950
   297
	      (* c*d/g*sqrt(x)=b -> c^2*d^2/g^2x=b^2 *)
wneuper@59416
   298
       Rule.Thm("sqrt_square_equation_right_1",TermC.num_str @{thm sqrt_square_equation_right_1}),
neuper@37950
   299
	      (* a=sqrt(x) ->a^2=x *)
wneuper@59416
   300
       Rule.Thm("sqrt_square_equation_right_2",TermC.num_str @{thm sqrt_square_equation_right_2}),
neuper@37950
   301
	      (* a=c*sqrt(x) ->a^2=c^2*x *)
wneuper@59416
   302
       Rule.Thm("sqrt_square_equation_right_3",TermC.num_str @{thm sqrt_square_equation_right_3}),
neuper@37950
   303
	      (* a=c/sqrt(x) ->a^2=c^2/x *)
wneuper@59416
   304
       Rule.Thm("sqrt_square_equation_right_4",TermC.num_str @{thm sqrt_square_equation_right_4}),
neuper@37950
   305
	      (* a=c*d/sqrt(x) ->a^2=c^2*d^2/x *)
wneuper@59416
   306
       Rule.Thm("sqrt_square_equation_right_5",TermC.num_str @{thm sqrt_square_equation_right_5}),
neuper@37950
   307
	      (* a=c/e*sqrt(x) ->a^2=c^2/e^2x *)
wneuper@59416
   308
       Rule.Thm("sqrt_square_equation_right_6",TermC.num_str @{thm sqrt_square_equation_right_6})
neuper@37950
   309
	      (* a=c*d/g*sqrt(x) ->a^2=c^2*d^2/g^2*x *)
wneuper@59552
   310
       ],scr = Rule.EmptyScr
wneuper@59406
   311
      });
neuper@52125
   312
wneuper@59526
   313
\<close> ML \<open>
neuper@37950
   314
(*isolate the bound variable in an sqrt left equation; 'bdv' is a meta-constant*)
s1210629013@55444
   315
 val l_sqrt_isolate = prep_rls'(
wneuper@59416
   316
     Rule.Rls {id = "l_sqrt_isolate", preconds = [], 
neuper@37950
   317
	  rew_ord = ("termlessI",termlessI), 
wneuper@59416
   318
          erls = RootEq_erls, srls = Rule.Erls, calc = [], errpatts = [],
neuper@37950
   319
     rules = [
wneuper@59416
   320
     Rule.Thm("sqrt_square_1",TermC.num_str @{thm sqrt_square_1}),
neuper@37950
   321
                            (* (sqrt a)^^^2 -> a *)
wneuper@59416
   322
     Rule.Thm("sqrt_square_2",TermC.num_str @{thm sqrt_square_2}),
neuper@37950
   323
                            (* sqrt (a^^^2) -> a *)
wneuper@59416
   324
     Rule.Thm("sqrt_times_root_1",TermC.num_str @{thm sqrt_times_root_1}),
neuper@37950
   325
            (* sqrt a sqrt b -> sqrt(ab) *)
wneuper@59416
   326
     Rule.Thm("sqrt_times_root_2",TermC.num_str @{thm sqrt_times_root_2}),
neuper@37950
   327
        (* a sqrt b sqrt c -> a sqrt(bc) *)
wneuper@59416
   328
     Rule.Thm("sqrt_isolate_l_add1",TermC.num_str @{thm sqrt_isolate_l_add1}),
neuper@37950
   329
        (* a+b*sqrt(x)=d -> b*sqrt(x) = d-a *)
wneuper@59416
   330
     Rule.Thm("sqrt_isolate_l_add2",TermC.num_str @{thm sqrt_isolate_l_add2}),
neuper@37950
   331
        (* a+  sqrt(x)=d ->   sqrt(x) = d-a *)
wneuper@59416
   332
     Rule.Thm("sqrt_isolate_l_add3",TermC.num_str @{thm sqrt_isolate_l_add3}),
neuper@37950
   333
        (* a+b*c/sqrt(x)=d->b*c/sqrt(x)=d-a *)
wneuper@59416
   334
     Rule.Thm("sqrt_isolate_l_add4",TermC.num_str @{thm sqrt_isolate_l_add4}),
neuper@37950
   335
        (* a+c/sqrt(x)=d -> c/sqrt(x) = d-a *)
wneuper@59416
   336
     Rule.Thm("sqrt_isolate_l_add5",TermC.num_str @{thm sqrt_isolate_l_add5}),
neuper@37950
   337
        (* a+b*c/f*sqrt(x)=d->b*c/f*sqrt(x)=d-a *)
wneuper@59416
   338
     Rule.Thm("sqrt_isolate_l_add6",TermC.num_str @{thm sqrt_isolate_l_add6}),
neuper@37950
   339
        (* a+c/f*sqrt(x)=d -> c/f*sqrt(x) = d-a *)
wneuper@59416
   340
   (*Rule.Thm("sqrt_isolate_l_div",TermC.num_str @{thm sqrt_isolate_l_div}),*)
neuper@37950
   341
        (* b*sqrt(x) = d sqrt(x) d/b *)
wneuper@59416
   342
     Rule.Thm("sqrt_square_equation_left_1",TermC.num_str @{thm sqrt_square_equation_left_1}),
neuper@37950
   343
	      (* sqrt(x)=b -> x=b^2 *)
wneuper@59416
   344
     Rule.Thm("sqrt_square_equation_left_2",TermC.num_str @{thm sqrt_square_equation_left_2}),
neuper@37950
   345
	      (* a*sqrt(x)=b -> a^2*x=b^2*)
wneuper@59416
   346
     Rule.Thm("sqrt_square_equation_left_3",TermC.num_str @{thm sqrt_square_equation_left_3}),   
neuper@37950
   347
	      (* c/sqrt(x)=b -> c^2/x=b^2 *)
wneuper@59416
   348
     Rule.Thm("sqrt_square_equation_left_4",TermC.num_str @{thm sqrt_square_equation_left_4}),   
neuper@37950
   349
	      (* c*d/sqrt(x)=b -> c^2*d^2/x=b^2 *)
wneuper@59416
   350
     Rule.Thm("sqrt_square_equation_left_5",TermC.num_str @{thm sqrt_square_equation_left_5}),   
neuper@37950
   351
	      (* c/d*sqrt(x)=b -> c^2/d^2x=b^2 *)
wneuper@59416
   352
     Rule.Thm("sqrt_square_equation_left_6",TermC.num_str @{thm sqrt_square_equation_left_6})  
neuper@37950
   353
	      (* c*d/g*sqrt(x)=b -> c^2*d^2/g^2x=b^2 *)
neuper@37950
   354
    ],
wneuper@59552
   355
    scr = Rule.EmptyScr
wneuper@59406
   356
   });
neuper@37950
   357
wneuper@59526
   358
\<close> ML \<open>
neuper@37950
   359
(* -- right 28.8.02--*)
neuper@37950
   360
(*isolate the bound variable in an sqrt right equation; 'bdv' is a meta-constant*)
s1210629013@55444
   361
 val r_sqrt_isolate = prep_rls'(
wneuper@59416
   362
     Rule.Rls {id = "r_sqrt_isolate", preconds = [], 
neuper@37950
   363
	  rew_ord = ("termlessI",termlessI), 
wneuper@59416
   364
          erls = RootEq_erls, srls = Rule.Erls, calc = [], errpatts = [],
neuper@37950
   365
     rules = [
wneuper@59416
   366
     Rule.Thm("sqrt_square_1",TermC.num_str @{thm sqrt_square_1}),
neuper@37950
   367
                           (* (sqrt a)^^^2 -> a *)
wneuper@59416
   368
     Rule.Thm("sqrt_square_2",TermC.num_str @{thm sqrt_square_2}), 
neuper@37950
   369
                           (* sqrt (a^^^2) -> a *)
wneuper@59416
   370
     Rule.Thm("sqrt_times_root_1",TermC.num_str @{thm sqrt_times_root_1}),
neuper@37950
   371
           (* sqrt a sqrt b -> sqrt(ab) *)
wneuper@59416
   372
     Rule.Thm("sqrt_times_root_2",TermC.num_str @{thm sqrt_times_root_2}),
neuper@37950
   373
       (* a sqrt b sqrt c -> a sqrt(bc) *)
wneuper@59416
   374
     Rule.Thm("sqrt_isolate_r_add1",TermC.num_str @{thm sqrt_isolate_r_add1}),
neuper@37950
   375
       (* a= d+e*sqrt(x) -> a-d=e*sqrt(x) *)
wneuper@59416
   376
     Rule.Thm("sqrt_isolate_r_add2",TermC.num_str @{thm sqrt_isolate_r_add2}),
neuper@37950
   377
       (* a= d+  sqrt(x) -> a-d=  sqrt(x) *)
wneuper@59416
   378
     Rule.Thm("sqrt_isolate_r_add3",TermC.num_str @{thm sqrt_isolate_r_add3}),
neuper@37950
   379
       (* a=d+e*g/sqrt(x)->a-d=e*g/sqrt(x)*)
wneuper@59416
   380
     Rule.Thm("sqrt_isolate_r_add4",TermC.num_str @{thm sqrt_isolate_r_add4}),
neuper@37950
   381
       (* a= d+g/sqrt(x) -> a-d=g/sqrt(x) *)
wneuper@59416
   382
     Rule.Thm("sqrt_isolate_r_add5",TermC.num_str @{thm sqrt_isolate_r_add5}),
neuper@37950
   383
       (* a=d+e*g/h*sqrt(x)->a-d=e*g/h*sqrt(x)*)
wneuper@59416
   384
     Rule.Thm("sqrt_isolate_r_add6",TermC.num_str @{thm sqrt_isolate_r_add6}),
neuper@37950
   385
       (* a= d+g/h*sqrt(x) -> a-d=g/h*sqrt(x) *)
wneuper@59416
   386
   (*Rule.Thm("sqrt_isolate_r_div",TermC.num_str @{thm sqrt_isolate_r_div}),*)
neuper@37950
   387
       (* a=e*sqrt(x) -> a/e = sqrt(x) *)
wneuper@59416
   388
     Rule.Thm("sqrt_square_equation_right_1",TermC.num_str @{thm sqrt_square_equation_right_1}),
neuper@37950
   389
	      (* a=sqrt(x) ->a^2=x *)
wneuper@59416
   390
     Rule.Thm("sqrt_square_equation_right_2",TermC.num_str @{thm sqrt_square_equation_right_2}),
neuper@37950
   391
	      (* a=c*sqrt(x) ->a^2=c^2*x *)
wneuper@59416
   392
     Rule.Thm("sqrt_square_equation_right_3",TermC.num_str @{thm sqrt_square_equation_right_3}),
neuper@37950
   393
	      (* a=c/sqrt(x) ->a^2=c^2/x *)
wneuper@59416
   394
     Rule.Thm("sqrt_square_equation_right_4",TermC.num_str @{thm sqrt_square_equation_right_4}), 
neuper@37950
   395
	      (* a=c*d/sqrt(x) ->a^2=c^2*d^2/x *)
wneuper@59416
   396
     Rule.Thm("sqrt_square_equation_right_5",TermC.num_str @{thm sqrt_square_equation_right_5}),
neuper@37950
   397
	      (* a=c/e*sqrt(x) ->a^2=c^2/e^2x *)
wneuper@59416
   398
     Rule.Thm("sqrt_square_equation_right_6",TermC.num_str @{thm sqrt_square_equation_right_6})
neuper@37950
   399
	      (* a=c*d/g*sqrt(x) ->a^2=c^2*d^2/g^2*x *)
neuper@37950
   400
    ],
wneuper@59552
   401
    scr = Rule.EmptyScr
wneuper@59406
   402
   });
neuper@37950
   403
wneuper@59526
   404
\<close> ML \<open>
s1210629013@55444
   405
val rooteq_simplify = prep_rls'(
wneuper@59416
   406
  Rule.Rls {id = "rooteq_simplify", 
neuper@37950
   407
       preconds = [], rew_ord = ("termlessI",termlessI), 
wneuper@59416
   408
       erls = RootEq_erls, srls = Rule.Erls, calc = [], errpatts = [],
neuper@37950
   409
       (*asm_thm = [("sqrt_square_1","")],*)
wneuper@59416
   410
       rules = [Rule.Thm  ("real_assoc_1",TermC.num_str @{thm real_assoc_1}),
neuper@37950
   411
                             (* a+(b+c) = a+b+c *)
wneuper@59416
   412
                Rule.Thm  ("real_assoc_2",TermC.num_str @{thm real_assoc_2}),
neuper@37950
   413
                             (* a*(b*c) = a*b*c *)
wneuper@59416
   414
                Rule.Calc ("Groups.plus_class.plus",eval_binop "#add_"),
wneuper@59416
   415
                Rule.Calc ("Groups.minus_class.minus",eval_binop "#sub_"),
wneuper@59416
   416
                Rule.Calc ("Groups.times_class.times",eval_binop "#mult_"),
wneuper@59416
   417
                Rule.Calc ("Rings.divide_class.divide", eval_cancel "#divide_e"),
wneuper@59416
   418
                Rule.Calc ("NthRoot.sqrt",eval_sqrt "#sqrt_"),
wneuper@59416
   419
                Rule.Calc ("Atools.pow" ,eval_binop "#power_"),
wneuper@59416
   420
                Rule.Thm("real_plus_binom_pow2",TermC.num_str @{thm real_plus_binom_pow2}),
wneuper@59416
   421
                Rule.Thm("real_minus_binom_pow2",TermC.num_str @{thm real_minus_binom_pow2}),
wneuper@59416
   422
                Rule.Thm("realpow_mul",TermC.num_str @{thm realpow_mul}),    
neuper@37950
   423
                     (* (a * b)^n = a^n * b^n*)
wneuper@59416
   424
                Rule.Thm("sqrt_times_root_1",TermC.num_str @{thm sqrt_times_root_1}), 
neuper@37950
   425
                     (* sqrt b * sqrt c = sqrt(b*c) *)
wneuper@59416
   426
                Rule.Thm("sqrt_times_root_2",TermC.num_str @{thm sqrt_times_root_2}),
neuper@37950
   427
                     (* a * sqrt a * sqrt b = a * sqrt(a*b) *)
wneuper@59416
   428
                Rule.Thm("sqrt_square_2",TermC.num_str @{thm sqrt_square_2}),
neuper@37950
   429
                            (* sqrt (a^^^2) = a *)
wneuper@59416
   430
                Rule.Thm("sqrt_square_1",TermC.num_str @{thm sqrt_square_1}) 
neuper@37950
   431
                            (* sqrt a ^^^ 2 = a *)
neuper@37950
   432
                ],
wneuper@59552
   433
       scr = Rule.EmptyScr
wneuper@59406
   434
    });
wneuper@59472
   435
\<close>
wneuper@59526
   436
setup \<open>KEStore_Elems.add_rlss 
wneuper@59526
   437
  [("RootEq_erls", (Context.theory_name @{theory}, RootEq_erls)), 
wneuper@59526
   438
  ("rooteq_srls", (Context.theory_name @{theory}, rooteq_srls)),
wneuper@59526
   439
  ("sqrt_isolate", (Context.theory_name @{theory}, sqrt_isolate)),
wneuper@59526
   440
  ("l_sqrt_isolate", (Context.theory_name @{theory}, l_sqrt_isolate)),
wneuper@59526
   441
  ("r_sqrt_isolate", (Context.theory_name @{theory}, r_sqrt_isolate)),
wneuper@59526
   442
  ("rooteq_simplify", (Context.theory_name @{theory}, rooteq_simplify))]\<close>
wneuper@59526
   443
wneuper@59526
   444
subsection \<open>problems\<close>
wneuper@59472
   445
setup \<open>KEStore_Elems.add_pbts
s1210629013@55363
   446
  (* ---------root----------- *)
wneuper@59406
   447
  [(Specify.prep_pbt thy "pbl_equ_univ_root" [] Celem.e_pblID
wneuper@59489
   448
      (["rootX","univariate","equation"],
s1210629013@55339
   449
        [("#Given" ,["equality e_e","solveFor v_v"]),
s1210629013@55339
   450
          ("#Where" ,["(lhs e_e) is_rootTerm_in  (v_v::real) | " ^
s1210629013@55339
   451
	          "(rhs e_e) is_rootTerm_in  (v_v::real)"]),
s1210629013@55339
   452
          ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339
   453
        RootEq_prls, SOME "solve (e_e::bool, v_v)", [])),
s1210629013@55339
   454
    (* ---------sqrt----------- *)
wneuper@59406
   455
    (Specify.prep_pbt thy "pbl_equ_univ_root_sq" [] Celem.e_pblID
wneuper@59489
   456
      (["sq","rootX","univariate","equation"],
s1210629013@55339
   457
        [("#Given" ,["equality e_e","solveFor v_v"]),
s1210629013@55339
   458
          ("#Where" ,["( ((lhs e_e) is_sqrtTerm_in (v_v::real)) &" ^
s1210629013@55339
   459
            "  ((lhs e_e) is_normSqrtTerm_in (v_v::real))   )  |" ^
s1210629013@55339
   460
	          "( ((rhs e_e) is_sqrtTerm_in (v_v::real)) &" ^
s1210629013@55339
   461
            "  ((rhs e_e) is_normSqrtTerm_in (v_v::real))   )"]),
s1210629013@55339
   462
          ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55339
   463
          RootEq_prls,  SOME "solve (e_e::bool, v_v)", [["RootEq","solve_sq_root_equation"]])),
wneuper@59370
   464
    (* ---------normalise----------- *)
wneuper@59406
   465
    (Specify.prep_pbt thy "pbl_equ_univ_root_norm" [] Celem.e_pblID
wneuper@59489
   466
      (["normalise","rootX","univariate","equation"],
s1210629013@55339
   467
        [("#Given" ,["equality e_e","solveFor v_v"]),
s1210629013@55339
   468
          ("#Where" ,["( ((lhs e_e) is_sqrtTerm_in (v_v::real)) &" ^
s1210629013@55339
   469
            "  Not((lhs e_e) is_normSqrtTerm_in (v_v::real)))  | " ^
s1210629013@55339
   470
	          "( ((rhs e_e) is_sqrtTerm_in (v_v::real)) &" ^
s1210629013@55339
   471
            "  Not((rhs e_e) is_normSqrtTerm_in (v_v::real)))"]),
s1210629013@55339
   472
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59472
   473
        RootEq_prls, SOME "solve (e_e::bool, v_v)", [["RootEq","norm_sq_root_equation"]]))]\<close>
neuper@37950
   474
wneuper@59526
   475
subsection \<open>methods\<close>
wneuper@59472
   476
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   477
    [Specify.prep_met thy "met_rooteq" [] Celem.e_metID
s1210629013@55373
   478
      (["RootEq"], [],
wneuper@59416
   479
        {rew_ord'="tless_true",rls'=Atools_erls,calc = [], srls = Rule.e_rls, prls=Rule.e_rls,
wneuper@59545
   480
          crls=RootEq_crls, errpats = [], nrls = norm_Poly}, @{thm refl})]
wneuper@59473
   481
\<close>
wneuper@59370
   482
    (*-- normalise 20.10.02 --*)
wneuper@59504
   483
partial_function (tailrec) norm_sqrt_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   484
  where
wneuper@59504
   485
"norm_sqrt_equ e_e v_v =
wneuper@59504
   486
  (let e_e = ((Repeat(Try (Rewrite     ''makex1_x''            False))) @@
wneuper@59504
   487
              (Try (Repeat (Rewrite_Set ''expand_rootbinoms''  False))) @@
wneuper@59504
   488
              (Try (Rewrite_Set ''rooteq_simplify''              True)) @@
wneuper@59504
   489
              (Try (Repeat (Rewrite_Set ''make_rooteq''        False))) @@
wneuper@59504
   490
              (Try (Rewrite_Set ''rooteq_simplify''              True))) e_e
wneuper@59504
   491
   in SubProblem (''RootEq'', [''univariate'', ''equation''], [''no_met''])
wneuper@59504
   492
        [BOOL e_e, REAL v_v])"
wneuper@59473
   493
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   494
    [Specify.prep_met thy "met_rooteq_norm" [] Celem.e_metID
s1210629013@55373
   495
      (["RootEq","norm_sq_root_equation"],
s1210629013@55373
   496
        [("#Given" ,["equality e_e","solveFor v_v"]),
s1210629013@55373
   497
          ("#Where" ,["( ((lhs e_e) is_sqrtTerm_in (v_v::real)) &" ^
s1210629013@55373
   498
              "  Not((lhs e_e) is_normSqrtTerm_in (v_v::real)))  | " ^
s1210629013@55373
   499
              "( ((rhs e_e) is_sqrtTerm_in (v_v::real)) &" ^
s1210629013@55373
   500
              "  Not((rhs e_e) is_normSqrtTerm_in (v_v::real)))"]),
s1210629013@55373
   501
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59416
   502
        {rew_ord'="termlessI", rls'=RootEq_erls, srls=Rule.e_rls, prls=RootEq_prls, calc=[],
s1210629013@55373
   503
          crls=RootEq_crls, errpats = [], nrls = norm_Poly},
wneuper@59551
   504
        @{thm norm_sqrt_equ.simps})]
wneuper@59473
   505
\<close>
wneuper@59545
   506
wneuper@59504
   507
partial_function (tailrec) solve_sqrt_equ :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   508
  where
wneuper@59504
   509
"solve_sqrt_equ e_e v_v =
wneuper@59504
   510
  (let
wneuper@59504
   511
    e_e =
wneuper@59504
   512
      ((Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''sqrt_isolate'' True)) @@ 
wneuper@59504
   513
       (Try (Rewrite_Set         ''rooteq_simplify'' True)) @@ 
wneuper@59504
   514
       (Try (Repeat (Rewrite_Set ''expand_rootbinoms'' False))) @@
wneuper@59504
   515
       (Try (Repeat (Rewrite_Set ''make_rooteq ''  False))) @@
wneuper@59504
   516
       (Try (Rewrite_Set ''rooteq_simplify''  True)) ) e_e;
wneuper@59504
   517
    L_L =
wneuper@59504
   518
     (if (((lhs e_e) is_sqrtTerm_in v_v) | ((rhs e_e) is_sqrtTerm_in v_v))               
wneuper@59504
   519
      then SubProblem (''RootEq'', [''normalise'', ''rootX'', ''univariate'', ''equation''],
wneuper@59504
   520
             [''no_met'']) [BOOL e_e, REAL v_v]
wneuper@59504
   521
      else SubProblem (''RootEq'',[''univariate'',''equation''],
wneuper@59504
   522
             [''no_met'']) [BOOL e_e, REAL v_v])
wneuper@59504
   523
  in Check_elementwise L_L {(v_v::real). Assumptions})"
wneuper@59473
   524
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   525
    [Specify.prep_met thy "met_rooteq_sq" [] Celem.e_metID
s1210629013@55373
   526
      (["RootEq","solve_sq_root_equation"],
s1210629013@55373
   527
        [("#Given" ,["equality e_e", "solveFor v_v"]),
s1210629013@55373
   528
          ("#Where" ,["(((lhs e_e) is_sqrtTerm_in (v_v::real))     & " ^
s1210629013@55373
   529
              " ((lhs e_e) is_normSqrtTerm_in (v_v::real))) |" ^
s1210629013@55373
   530
              "(((rhs e_e) is_sqrtTerm_in (v_v::real))     & " ^
s1210629013@55373
   531
              " ((rhs e_e) is_normSqrtTerm_in (v_v::real)))"]),
s1210629013@55373
   532
          ("#Find"  ,["solutions v_v'i'"])],
s1210629013@55373
   533
        {rew_ord'="termlessI", rls'=RootEq_erls, srls = rooteq_srls, prls = RootEq_prls, calc = [],
s1210629013@55373
   534
          crls=RootEq_crls, errpats = [], nrls = norm_Poly},
wneuper@59551
   535
        @{thm solve_sqrt_equ.simps})]
wneuper@59473
   536
\<close>
s1210629013@55373
   537
    (*-- right 28.08.02 --*)
wneuper@59504
   538
partial_function (tailrec) solve_sqrt_equ_right :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   539
  where "solve_sqrt_equ_right e_e v_v =
wneuper@59504
   540
(let e_e =
wneuper@59504
   541
  ((Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''r_sqrt_isolate'' False)) @@
wneuper@59504
   542
   (Try (Rewrite_Set ''rooteq_simplify'' False)) @@
wneuper@59504
   543
   (Try (Repeat (Rewrite_Set ''expand_rootbinoms'' False))) @@
wneuper@59504
   544
   (Try (Repeat (Rewrite_Set ''make_rooteq'' False))) @@
wneuper@59504
   545
   (Try (Rewrite_Set ''rooteq_simplify'' False))) e_e
wneuper@59504
   546
 in
wneuper@59504
   547
   if (rhs e_e) is_sqrtTerm_in v_v
wneuper@59504
   548
   then SubProblem (''RootEq'',[''normalise'',''rootX'',''univariate'',''equation''],
wneuper@59504
   549
          [''no_met'']) [BOOL e_e, REAL v_v]
wneuper@59504
   550
   else SubProblem (''RootEq'',[''univariate'', ''equation''],
wneuper@59504
   551
          [''no_met'']) [BOOL e_e, REAL v_v])"
wneuper@59473
   552
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   553
    [Specify.prep_met thy "met_rooteq_sq_right" [] Celem.e_metID
s1210629013@55373
   554
      (["RootEq","solve_right_sq_root_equation"],
s1210629013@55373
   555
        [("#Given" ,["equality e_e","solveFor v_v"]),
s1210629013@55373
   556
          ("#Where" ,["(rhs e_e) is_sqrtTerm_in v_v"]),
s1210629013@55373
   557
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59416
   558
        {rew_ord' = "termlessI", rls' = RootEq_erls, srls = Rule.e_rls, prls = RootEq_prls, calc = [],
s1210629013@55373
   559
          crls = RootEq_crls, errpats = [], nrls = norm_Poly},
wneuper@59551
   560
        @{thm solve_sqrt_equ_right.simps})]
wneuper@59473
   561
\<close>
s1210629013@55373
   562
    (*-- left 28.08.02 --*)
wneuper@59504
   563
partial_function (tailrec) solve_sqrt_equ_left :: "bool \<Rightarrow> real \<Rightarrow> bool list"
wneuper@59504
   564
  where
wneuper@59504
   565
"solve_sqrt_equ_left e_e v_v =
wneuper@59504
   566
(let e_e =
wneuper@59504
   567
  ((Try (Rewrite_Set_Inst [(''bdv'', v_v)] ''l_sqrt_isolate'' False)) @@ 
wneuper@59504
   568
   (Try (Rewrite_Set ''rooteq_simplify'' False)) @@
wneuper@59504
   569
   (Try (Repeat (Rewrite_Set ''expand_rootbinoms'' False))) @@
wneuper@59504
   570
   (Try (Repeat (Rewrite_Set ''make_rooteq'' False))) @@
wneuper@59504
   571
   (Try (Rewrite_Set ''rooteq_simplify'' False))) e_e
wneuper@59504
   572
 in
wneuper@59504
   573
   if (lhs e_e) is_sqrtTerm_in v_v
wneuper@59504
   574
   then SubProblem (''RootEq'', [''normalise'',''rootX'',''univariate'',''equation''],
wneuper@59504
   575
          [''no_met'']) [BOOL e_e, REAL v_v]
wneuper@59504
   576
   else SubProblem (''RootEq'',[''univariate'',''equation''],
wneuper@59504
   577
          [''no_met'']) [BOOL e_e, REAL v_v])"
wneuper@59473
   578
setup \<open>KEStore_Elems.add_mets
wneuper@59473
   579
    [Specify.prep_met thy "met_rooteq_sq_left" [] Celem.e_metID
s1210629013@55373
   580
      (["RootEq","solve_left_sq_root_equation"],
s1210629013@55373
   581
        [("#Given" ,["equality e_e","solveFor v_v"]),
s1210629013@55373
   582
          ("#Where" ,["(lhs e_e) is_sqrtTerm_in v_v"]),
s1210629013@55373
   583
          ("#Find"  ,["solutions v_v'i'"])],
wneuper@59416
   584
        {rew_ord'="termlessI", rls'=RootEq_erls, srls=Rule.e_rls, prls=RootEq_prls, calc=[],
s1210629013@55373
   585
          crls=RootEq_crls, errpats = [], nrls = norm_Poly},
wneuper@59551
   586
        @{thm solve_sqrt_equ_left.simps})]
wneuper@59473
   587
\<close>
wneuper@59526
   588
ML \<open>
wneuper@59526
   589
\<close> ML \<open>
wneuper@59526
   590
\<close> 
neuper@37906
   591
end