src/Tools/isac/IsacKnowledge/Poly.ML
branchisac-update-Isa09-2
changeset 37926 e6fc98fbcb85
parent 37922 30eff896074c
child 37930 f2b8d1b3fcc2
equal deleted inserted replaced
37925:d957275620d4 37926:e6fc98fbcb85
    63 	finddivide t v
    63 	finddivide t v
    64     end;
    64     end;
    65     
    65     
    66 fun eval_is_polyrat_in _ _ (p as (Const ("Poly.is'_polyrat'_in",_) $ t $ v)) _  =
    66 fun eval_is_polyrat_in _ _ (p as (Const ("Poly.is'_polyrat'_in",_) $ t $ v)) _  =
    67     if is_polyrat_in t v then 
    67     if is_polyrat_in t v then 
    68 	Some ((term2str p) ^ " = True",
    68 	SOME ((term2str p) ^ " = True",
    69 	      Trueprop $ (mk_equality (p, HOLogic.true_const)))
    69 	      Trueprop $ (mk_equality (p, HOLogic.true_const)))
    70     else Some ((term2str p) ^ " = True",
    70     else SOME ((term2str p) ^ " = True",
    71 	       Trueprop $ (mk_equality (p, HOLogic.false_const)))
    71 	       Trueprop $ (mk_equality (p, HOLogic.false_const)))
    72   | eval_is_polyrat_in _ _ _ _ = ((*writeln"### nichts matcht";*) None);
    72   | eval_is_polyrat_in _ _ _ _ = ((*writeln"### nichts matcht";*) NONE);
    73 
    73 
    74 
    74 
    75 local
    75 local
    76     (*.a 'c is coefficient of v' if v does NOT occur in c.*)
    76     (*.a 'c is coefficient of v' if v does NOT occur in c.*)
    77     fun coeff_in c v = not (v mem (vars c));
    77     fun coeff_in c v = not (v mem (vars c));
    92       if (1) then degree 0
    92       if (1) then degree 0
    93       if (2) then v is a factor on the very right, ev. with exponent.*)
    93       if (2) then v is a factor on the very right, ev. with exponent.*)
    94     fun factor_right_deg (*case 2*)
    94     fun factor_right_deg (*case 2*)
    95     	    (t as Const ("op *",_) $ t1 $ 
    95     	    (t as Const ("op *",_) $ t1 $ 
    96     	       (Const ("Atools.pow",_) $ vv $ Free (d,_))) v =
    96     	       (Const ("Atools.pow",_) $ vv $ Free (d,_))) v =
    97     	if ((vv = v) andalso (coeff_in t1 v)) then Some (int_of_str' d) else None
    97     	if ((vv = v) andalso (coeff_in t1 v)) then SOME (int_of_str' d) else NONE
    98       | factor_right_deg 
    98       | factor_right_deg 
    99     	    (t as Const ("Atools.pow",_) $ vv $ Free (d,_)) v =
    99     	    (t as Const ("Atools.pow",_) $ vv $ Free (d,_)) v =
   100     	if (vv = v) then Some (int_of_str' d) else None
   100     	if (vv = v) then SOME (int_of_str' d) else NONE
   101       | factor_right_deg (t as Const ("op *",_) $ t1 $ vv) v = 
   101       | factor_right_deg (t as Const ("op *",_) $ t1 $ vv) v = 
   102     	if ((vv = v) andalso (coeff_in t1 v))then Some 1 else None
   102     	if ((vv = v) andalso (coeff_in t1 v))then SOME 1 else NONE
   103       | factor_right_deg vv v =
   103       | factor_right_deg vv v =
   104     	if (vv = v) then Some 1 else None;    
   104     	if (vv = v) then SOME 1 else NONE;    
   105     fun mono_deg_in m v =
   105     fun mono_deg_in m v =
   106     	if coeff_in m v then (*case 1*) Some 0
   106     	if coeff_in m v then (*case 1*) SOME 0
   107     	else factor_right_deg m v;
   107     	else factor_right_deg m v;
   108     (*
   108     (*
   109      val v = (term_of o the o (parse thy)) "x";
   109      val v = (term_of o the o (parse thy)) "x";
   110      val t = (term_of o the o (parse thy)) "(a*b+c)*x^^^7";
   110      val t = (term_of o the o (parse thy)) "(a*b+c)*x^^^7";
   111      mono_deg_in t v;
   111      mono_deg_in t v;
   112      (*val it = Some 7*)
   112      (*val it = SOME 7*)
   113      val t = (term_of o the o (parse thy)) "x^^^7";
   113      val t = (term_of o the o (parse thy)) "x^^^7";
   114      mono_deg_in t v;
   114      mono_deg_in t v;
   115      (*val it = Some 7*)
   115      (*val it = SOME 7*)
   116      val t = (term_of o the o (parse thy)) "(a*b+c)*x";
   116      val t = (term_of o the o (parse thy)) "(a*b+c)*x";
   117      mono_deg_in t v;
   117      mono_deg_in t v;
   118      (*val it = Some 1*)
   118      (*val it = SOME 1*)
   119      val t = (term_of o the o (parse thy)) "(a*b+x)*x";
   119      val t = (term_of o the o (parse thy)) "(a*b+x)*x";
   120      mono_deg_in t v;
   120      mono_deg_in t v;
   121      (*val it = None*)
   121      (*val it = NONE*)
   122      val t = (term_of o the o (parse thy)) "x";
   122      val t = (term_of o the o (parse thy)) "x";
   123      mono_deg_in t v;
   123      mono_deg_in t v;
   124      (*val it = Some 1*)
   124      (*val it = SOME 1*)
   125      val t = (term_of o the o (parse thy)) "(a*b+c)";
   125      val t = (term_of o the o (parse thy)) "(a*b+c)";
   126      mono_deg_in t v;
   126      mono_deg_in t v;
   127      (*val it = Some 0*)
   127      (*val it = SOME 0*)
   128      val t = (term_of o the o (parse thy)) "ab - (a*b)*x";
   128      val t = (term_of o the o (parse thy)) "ab - (a*b)*x";
   129      mono_deg_in t v;
   129      mono_deg_in t v;
   130      (*val it = None*)
   130      (*val it = NONE*)
   131     *)
   131     *)
   132     fun expand_deg_in t v =
   132     fun expand_deg_in t v =
   133     	let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
   133     	let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
   134     		(case mono_deg_in t2 v of (* $ is left associative*)
   134     		(case mono_deg_in t2 v of (* $ is left associative*)
   135     		     Some d' => edi d' d' t1
   135     		     SOME d' => edi d' d' t1
   136 		   | None => None)
   136 		   | NONE => NONE)
   137     	      | edi ~1 ~1 (Const ("op -",_) $ t1 $ t2) =
   137     	      | edi ~1 ~1 (Const ("op -",_) $ t1 $ t2) =
   138     		(case mono_deg_in t2 v of
   138     		(case mono_deg_in t2 v of
   139     		     Some d' => edi d' d' t1
   139     		     SOME d' => edi d' d' t1
   140 		   | None => None)
   140 		   | NONE => NONE)
   141     	      | edi d dmax (Const ("op -",_) $ t1 $ t2) =
   141     	      | edi d dmax (Const ("op -",_) $ t1 $ t2) =
   142     		(case mono_deg_in t2 v of
   142     		(case mono_deg_in t2 v of
   143 		     (*RL  orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4  +x*)
   143 		     (*RL  orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4  +x*)
   144     		     Some d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then edi d' dmax t1 else None
   144     		     SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then edi d' dmax t1 else NONE
   145 		   | None => None)
   145 		   | NONE => NONE)
   146     	      | edi d dmax (Const ("op +",_) $ t1 $ t2) =
   146     	      | edi d dmax (Const ("op +",_) $ t1 $ t2) =
   147     		(case mono_deg_in t2 v of
   147     		(case mono_deg_in t2 v of
   148 		     (*RL  orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4  +x*)
   148 		     (*RL  orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4  +x*)
   149     		     Some d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then edi d' dmax t1 else None
   149     		     SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then edi d' dmax t1 else NONE
   150 		   | None => None)
   150 		   | NONE => NONE)
   151     	      | edi ~1 ~1 t =
   151     	      | edi ~1 ~1 t =
   152     		(case mono_deg_in t v of
   152     		(case mono_deg_in t v of
   153     		     d as Some _ => d
   153     		     d as SOME _ => d
   154 		   | None => None)
   154 		   | NONE => NONE)
   155     	      | edi d dmax t = (*basecase last*)
   155     	      | edi d dmax t = (*basecase last*)
   156     		(case mono_deg_in t v of
   156     		(case mono_deg_in t v of
   157     		     Some d' => if ((d > d') orelse ((d=0) andalso (d'=0)))  then Some dmax else None
   157     		     SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0)))  then SOME dmax else NONE
   158 		   | None => None)
   158 		   | NONE => NONE)
   159     	in edi ~1 ~1 t end;
   159     	in edi ~1 ~1 t end;
   160     (*
   160     (*
   161      val v = (term_of o the o (parse thy)) "x";
   161      val v = (term_of o the o (parse thy)) "x";
   162      val t = (term_of o the o (parse thy)) "a+b";
   162      val t = (term_of o the o (parse thy)) "a+b";
   163      expand_deg_in t v;
   163      expand_deg_in t v;
   164      (*val it = Some 0*)   
   164      (*val it = SOME 0*)   
   165      val t = (term_of o the o (parse thy)) "(a+b)*x";
   165      val t = (term_of o the o (parse thy)) "(a+b)*x";
   166      expand_deg_in t v;
   166      expand_deg_in t v;
   167      (*Some 1*)   
   167      (*SOME 1*)   
   168      val t = (term_of o the o (parse thy)) "a*b - (a+b)*x";
   168      val t = (term_of o the o (parse thy)) "a*b - (a+b)*x";
   169      expand_deg_in t v;
   169      expand_deg_in t v;
   170      (*Some 1*)   
   170      (*SOME 1*)   
   171      val t = (term_of o the o (parse thy)) "a*b + (a-b)*x";
   171      val t = (term_of o the o (parse thy)) "a*b + (a-b)*x";
   172      expand_deg_in t v;
   172      expand_deg_in t v;
   173      (*Some 1*)   
   173      (*SOME 1*)   
   174      val t = (term_of o the o (parse thy)) "a*b + (a+b)*x + x^^^2";
   174      val t = (term_of o the o (parse thy)) "a*b + (a+b)*x + x^^^2";
   175      expand_deg_in t v;
   175      expand_deg_in t v;
   176     *)   
   176     *)   
   177     fun poly_deg_in t v =
   177     fun poly_deg_in t v =
   178     	let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
   178     	let fun edi ~1 ~1 (Const ("op +",_) $ t1 $ t2) =
   179     		(case mono_deg_in t2 v of (* $ is left associative*)
   179     		(case mono_deg_in t2 v of (* $ is left associative*)
   180     		     Some d' => edi d' d' t1
   180     		     SOME d' => edi d' d' t1
   181 		   | None => None)
   181 		   | NONE => NONE)
   182     	      | edi d dmax (Const ("op +",_) $ t1 $ t2) =
   182     	      | edi d dmax (Const ("op +",_) $ t1 $ t2) =
   183     		(case mono_deg_in t2 v of
   183     		(case mono_deg_in t2 v of
   184  		     (*RL  orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4  +x*)
   184  		     (*RL  orelse ((d=0) andalso (d'=0)) need to handle 3+4-...4  +x*)
   185    		     Some d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then edi d' dmax t1 else None
   185    		     SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then edi d' dmax t1 else NONE
   186 		   | None => None)
   186 		   | NONE => NONE)
   187     	      | edi ~1 ~1 t =
   187     	      | edi ~1 ~1 t =
   188     		(case mono_deg_in t v of
   188     		(case mono_deg_in t v of
   189     		     d as Some _ => d
   189     		     d as SOME _ => d
   190 		   | None => None)
   190 		   | NONE => NONE)
   191     	      | edi d dmax t = (*basecase last*)
   191     	      | edi d dmax t = (*basecase last*)
   192     		(case mono_deg_in t v of
   192     		(case mono_deg_in t v of
   193     		     Some d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then Some dmax else None
   193     		     SOME d' => if ((d > d') orelse ((d=0) andalso (d'=0))) then SOME dmax else NONE
   194 		   | None => None)
   194 		   | NONE => NONE)
   195     	in edi ~1 ~1 t end;
   195     	in edi ~1 ~1 t end;
   196 in
   196 in
   197 
   197 
   198 fun is_expanded_in t v =
   198 fun is_expanded_in t v =
   199     case expand_deg_in t v of Some _ => true | None => false;
   199     case expand_deg_in t v of SOME _ => true | NONE => false;
   200 fun is_poly_in t v =
   200 fun is_poly_in t v =
   201     case poly_deg_in t v of Some _ => true | None => false;
   201     case poly_deg_in t v of SOME _ => true | NONE => false;
   202 fun has_degree_in t v =
   202 fun has_degree_in t v =
   203     case expand_deg_in t v of Some d => d | None => ~1;
   203     case expand_deg_in t v of SOME d => d | NONE => ~1;
   204 end;
   204 end;
   205 (*
   205 (*
   206  val v = (term_of o the o (parse thy)) "x";
   206  val v = (term_of o the o (parse thy)) "x";
   207  val t = (term_of o the o (parse thy)) "a*b - (a+b)*x + x^^^2";
   207  val t = (term_of o the o (parse thy)) "a*b - (a+b)*x + x^^^2";
   208  has_degree_in t v;
   208  has_degree_in t v;
   217 
   217 
   218 (*("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in ""))*)
   218 (*("is_expanded_in", ("Poly.is'_expanded'_in", eval_is_expanded_in ""))*)
   219 fun eval_is_expanded_in _ _ 
   219 fun eval_is_expanded_in _ _ 
   220 	     (p as (Const ("Poly.is'_expanded'_in",_) $ t $ v)) _ =
   220 	     (p as (Const ("Poly.is'_expanded'_in",_) $ t $ v)) _ =
   221     if is_expanded_in t v
   221     if is_expanded_in t v
   222     then Some ((term2str p) ^ " = True",
   222     then SOME ((term2str p) ^ " = True",
   223 	  Trueprop $ (mk_equality (p, HOLogic.true_const)))
   223 	  Trueprop $ (mk_equality (p, HOLogic.true_const)))
   224     else Some ((term2str p) ^ " = True",
   224     else SOME ((term2str p) ^ " = True",
   225 	  Trueprop $ (mk_equality (p, HOLogic.false_const)))
   225 	  Trueprop $ (mk_equality (p, HOLogic.false_const)))
   226   | eval_is_expanded_in _ _ _ _ = None;
   226   | eval_is_expanded_in _ _ _ _ = NONE;
   227 (*
   227 (*
   228  val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) is_expanded_in x";
   228  val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) is_expanded_in x";
   229  val Some (id, t') = eval_is_expanded_in 0 0 t 0;
   229  val SOME (id, t') = eval_is_expanded_in 0 0 t 0;
   230  (*val id = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
   230  (*val id = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
   231  term2str t';
   231  term2str t';
   232  (*val it = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
   232  (*val it = "Poly.is'_expanded'_in (-8 - 2 * x + x ^^^ 2) x = True"*)
   233 *)
   233 *)
   234 (*("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in ""))*)
   234 (*("is_poly_in", ("Poly.is'_poly'_in", eval_is_poly_in ""))*)
   235 fun eval_is_poly_in _ _ 
   235 fun eval_is_poly_in _ _ 
   236 	     (p as (Const ("Poly.is'_poly'_in",_) $ t $ v)) _ =
   236 	     (p as (Const ("Poly.is'_poly'_in",_) $ t $ v)) _ =
   237     if is_poly_in t v
   237     if is_poly_in t v
   238     then Some ((term2str p) ^ " = True",
   238     then SOME ((term2str p) ^ " = True",
   239 	  Trueprop $ (mk_equality (p, HOLogic.true_const)))
   239 	  Trueprop $ (mk_equality (p, HOLogic.true_const)))
   240     else Some ((term2str p) ^ " = True",
   240     else SOME ((term2str p) ^ " = True",
   241 	  Trueprop $ (mk_equality (p, HOLogic.false_const)))
   241 	  Trueprop $ (mk_equality (p, HOLogic.false_const)))
   242   | eval_is_poly_in _ _ _ _ = None;
   242   | eval_is_poly_in _ _ _ _ = NONE;
   243 (*
   243 (*
   244  val t = (term_of o the o (parse thy)) "(8 + 2*x + x^^^2) is_poly_in x";
   244  val t = (term_of o the o (parse thy)) "(8 + 2*x + x^^^2) is_poly_in x";
   245  val Some (id, t') = eval_is_poly_in 0 0 t 0;
   245  val SOME (id, t') = eval_is_poly_in 0 0 t 0;
   246  (*val id = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
   246  (*val id = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
   247  term2str t';
   247  term2str t';
   248  (*val it = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
   248  (*val it = "Poly.is'_poly'_in (8 + 2 * x + x ^^^ 2) x = True"*)
   249 *)
   249 *)
   250 
   250 
   251 (*("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in ""))*)
   251 (*("has_degree_in", ("Poly.has'_degree'_in", eval_has_degree_in ""))*)
   252 fun eval_has_degree_in _ _ 
   252 fun eval_has_degree_in _ _ 
   253 	     (p as (Const ("Poly.has'_degree'_in",_) $ t $ v)) _ =
   253 	     (p as (Const ("Poly.has'_degree'_in",_) $ t $ v)) _ =
   254     let val d = has_degree_in t v
   254     let val d = has_degree_in t v
   255 	val d' = term_of_num HOLogic.realT d
   255 	val d' = term_of_num HOLogic.realT d
   256     in Some ((term2str p) ^ " = " ^ (string_of_int d),
   256     in SOME ((term2str p) ^ " = " ^ (string_of_int d),
   257 	  Trueprop $ (mk_equality (p, d')))
   257 	  Trueprop $ (mk_equality (p, d')))
   258     end
   258     end
   259   | eval_has_degree_in _ _ _ _ = None;
   259   | eval_has_degree_in _ _ _ _ = NONE;
   260 (*
   260 (*
   261 > val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) has_degree_in x";
   261 > val t = (term_of o the o (parse thy)) "(-8 - 2*x + x^^^2) has_degree_in x";
   262 > val Some (id, t') = eval_has_degree_in 0 0 t 0;
   262 > val SOME (id, t') = eval_has_degree_in 0 0 t 0;
   263 val id = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
   263 val id = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
   264 > term2str t';
   264 > term2str t';
   265 val it = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
   265 val it = "Poly.has'_degree'_in (-8 - 2 * x + x ^^^ 2) x = 2" : string
   266 *)
   266 *)
   267 
   267 
   309   | dest_hd' (Bound i) = ((("", i), dummyT), 3)
   309   | dest_hd' (Bound i) = ((("", i), dummyT), 3)
   310   | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
   310   | dest_hd' (Abs (_, T, _)) = ((("", 0), T), 4);
   311 
   311 
   312 fun get_order_pow (t $ (Free(order,_))) = (* RL FIXXXME:geht zufaellig?WN*)
   312 fun get_order_pow (t $ (Free(order,_))) = (* RL FIXXXME:geht zufaellig?WN*)
   313     	(case int_of_str (order) of
   313     	(case int_of_str (order) of
   314 	             Some d => d
   314 	             SOME d => d
   315 		   | None   => 0)
   315 		   | NONE   => 0)
   316   | get_order_pow _ = 0;
   316   | get_order_pow _ = 0;
   317 
   317 
   318 fun size_of_term' (Const(str,_) $ t) =
   318 fun size_of_term' (Const(str,_) $ t) =
   319   if "Atools.pow"= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
   319   if "Atools.pow"= str then 1000 + size_of_term' t else 1+size_of_term' t(*WN*)
   320   | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
   320   | size_of_term' (Abs (_,_,body)) = 1 + size_of_term' body
   450 
   450 
   451 (*("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp ""))*)
   451 (*("is_polyexp", ("Poly.is'_polyexp", eval_is_polyexp ""))*)
   452 fun eval_is_polyexp (thmid:string) _ 
   452 fun eval_is_polyexp (thmid:string) _ 
   453 		       (t as (Const("Poly.is'_polyexp", _) $ arg)) thy = 
   453 		       (t as (Const("Poly.is'_polyexp", _) $ arg)) thy = 
   454     if is_polyexp arg
   454     if is_polyexp arg
   455     then Some (mk_thmid thmid "" 
   455     then SOME (mk_thmid thmid "" 
   456 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
   456 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
   457 	       Trueprop $ (mk_equality (t, HOLogic.true_const)))
   457 	       Trueprop $ (mk_equality (t, HOLogic.true_const)))
   458     else Some (mk_thmid thmid "" 
   458     else SOME (mk_thmid thmid "" 
   459 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
   459 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
   460 	       Trueprop $ (mk_equality (t, HOLogic.false_const)))
   460 	       Trueprop $ (mk_equality (t, HOLogic.false_const)))
   461   | eval_is_polyexp _ _ _ _ = None; 
   461   | eval_is_polyexp _ _ _ _ = NONE; 
   462 
   462 
   463 val expand_poly_rat_ = 
   463 val expand_poly_rat_ = 
   464   Rls{id = "expand_poly_rat_", preconds = [], 
   464   Rls{id = "expand_poly_rat_", preconds = [], 
   465       rew_ord = ("dummy_ord", dummy_ord),
   465       rew_ord = ("dummy_ord", dummy_ord),
   466       erls =  append_rls "e_rls-is_polyexp" e_rls
   466       erls =  append_rls "e_rls-is_polyexp" e_rls
  1096 	    ((monom_degree xs, xs), (monom_degree ys, ys));
  1096 	    ((monom_degree xs, xs), (monom_degree ys, ys));
  1097 
  1097 
  1098 fun hd_str str = substring (str, 0, 1);
  1098 fun hd_str str = substring (str, 0, 1);
  1099 fun tl_str str = substring (str, 1, (size str) - 1);
  1099 fun tl_str str = substring (str, 1, (size str) - 1);
  1100 
  1100 
  1101 (* liefert nummerischen Koeffizienten eines Monoms oder None *)
  1101 (* liefert nummerischen Koeffizienten eines Monoms oder NONE *)
  1102 fun get_koeff_of_mon [] =  raise error("get_koeff_of_mon: called with l = []")
  1102 fun get_koeff_of_mon [] =  raise error("get_koeff_of_mon: called with l = []")
  1103   | get_koeff_of_mon (l as x::xs) = if is_nums x then Some x
  1103   | get_koeff_of_mon (l as x::xs) = if is_nums x then SOME x
  1104 				    else None;
  1104 				    else NONE;
  1105 
  1105 
  1106 (* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
  1106 (* wandelt Koeffizient in (zum sortieren geeigneten) String um *)
  1107 fun koeff2ordStr (Some x) = (case x of 
  1107 fun koeff2ordStr (SOME x) = (case x of 
  1108 				 (Free (str, T)) => 
  1108 				 (Free (str, T)) => 
  1109 				     if (hd_str str) = "-" then (tl_str str)^"0" (* 3 < -3 *)
  1109 				     if (hd_str str) = "-" then (tl_str str)^"0" (* 3 < -3 *)
  1110 				     else str
  1110 				     else str
  1111 			       | _ => "aaa") (* "num.Ausdruck" --> gross *)
  1111 			       | _ => "aaa") (* "num.Ausdruck" --> gross *)
  1112   | koeff2ordStr None = "---"; (* "kein Koeff" --> kleinste *)
  1112   | koeff2ordStr NONE = "---"; (* "kein Koeff" --> kleinste *)
  1113 
  1113 
  1114 (* Order zum Vergleich von Koeffizienten (strings): 
  1114 (* Order zum Vergleich von Koeffizienten (strings): 
  1115    "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
  1115    "kein Koeff" < "0" < "1" < "-1" < "2" < "-2" < ... < "num.Ausdruck" *)
  1116 fun compare_koeff_ord (xs, ys) = 
  1116 fun compare_koeff_ord (xs, ys) = 
  1117     string_ord ((koeff2ordStr o get_koeff_of_mon) xs,
  1117     string_ord ((koeff2ordStr o get_koeff_of_mon) xs,
  1183 fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
  1183 fun is_multUnordered t = ((is_polyexp t) andalso not (t = sort_variables t));
  1184 
  1184 
  1185 fun eval_is_multUnordered (thmid:string) _ 
  1185 fun eval_is_multUnordered (thmid:string) _ 
  1186 		       (t as (Const("Poly.is'_multUnordered", _) $ arg)) thy = 
  1186 		       (t as (Const("Poly.is'_multUnordered", _) $ arg)) thy = 
  1187     if is_multUnordered arg
  1187     if is_multUnordered arg
  1188     then Some (mk_thmid thmid "" 
  1188     then SOME (mk_thmid thmid "" 
  1189 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1189 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1190 	       Trueprop $ (mk_equality (t, HOLogic.true_const)))
  1190 	       Trueprop $ (mk_equality (t, HOLogic.true_const)))
  1191     else Some (mk_thmid thmid "" 
  1191     else SOME (mk_thmid thmid "" 
  1192 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1192 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1193 	       Trueprop $ (mk_equality (t, HOLogic.false_const)))
  1193 	       Trueprop $ (mk_equality (t, HOLogic.false_const)))
  1194   | eval_is_multUnordered _ _ _ _ = None; 
  1194   | eval_is_multUnordered _ _ _ _ = NONE; 
  1195 
  1195 
  1196 
  1196 
  1197 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
  1197 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
  1198     []:(rule * (term * term list)) list;
  1198     []:(rule * (term * term list)) list;
  1199 fun init_state (_:term) = e_rrlsstate;
  1199 fun init_state (_:term) = e_rrlsstate;
  1200 fun locate_rule (_:rule list list) (_:term) (_:rule) =
  1200 fun locate_rule (_:rule list list) (_:term) (_:rule) =
  1201     ([]:(rule * (term * term list)) list);
  1201     ([]:(rule * (term * term list)) list);
  1202 fun next_rule (_:rule list list) (_:term) = (None:rule option);
  1202 fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
  1203 fun normal_form t = Some (sort_variables t,[]:term list);
  1203 fun normal_form t = SOME (sort_variables t,[]:term list);
  1204 
  1204 
  1205 val order_mult_ =
  1205 val order_mult_ =
  1206     Rrls {id = "order_mult_", 
  1206     Rrls {id = "order_mult_", 
  1207 	  prepat = 
  1207 	  prepat = 
  1208 	  [([(term_of o the o (parse thy)) "p is_multUnordered"], 
  1208 	  [([(term_of o the o (parse thy)) "p is_multUnordered"], 
  1236 (*WN.18.6.03 *)
  1236 (*WN.18.6.03 *)
  1237 (*("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))*)
  1237 (*("is_addUnordered", ("Poly.is'_addUnordered", eval_is_addUnordered ""))*)
  1238 fun eval_is_addUnordered (thmid:string) _ 
  1238 fun eval_is_addUnordered (thmid:string) _ 
  1239 		       (t as (Const("Poly.is'_addUnordered", _) $ arg)) thy = 
  1239 		       (t as (Const("Poly.is'_addUnordered", _) $ arg)) thy = 
  1240     if is_addUnordered arg
  1240     if is_addUnordered arg
  1241     then Some (mk_thmid thmid "" 
  1241     then SOME (mk_thmid thmid "" 
  1242 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1242 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1243 	       Trueprop $ (mk_equality (t, HOLogic.true_const)))
  1243 	       Trueprop $ (mk_equality (t, HOLogic.true_const)))
  1244     else Some (mk_thmid thmid "" 
  1244     else SOME (mk_thmid thmid "" 
  1245 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1245 			((string_of_cterm o cterm_of (sign_of thy)) arg) "", 
  1246 	       Trueprop $ (mk_equality (t, HOLogic.false_const)))
  1246 	       Trueprop $ (mk_equality (t, HOLogic.false_const)))
  1247   | eval_is_addUnordered _ _ _ _ = None; 
  1247   | eval_is_addUnordered _ _ _ _ = NONE; 
  1248 
  1248 
  1249 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
  1249 fun attach_form (_:rule list list) (_:term) (_:term) = (*still missing*)
  1250     []:(rule * (term * term list)) list;
  1250     []:(rule * (term * term list)) list;
  1251 fun init_state (_:term) = e_rrlsstate;
  1251 fun init_state (_:term) = e_rrlsstate;
  1252 fun locate_rule (_:rule list list) (_:term) (_:rule) =
  1252 fun locate_rule (_:rule list list) (_:term) (_:rule) =
  1253     ([]:(rule * (term * term list)) list);
  1253     ([]:(rule * (term * term list)) list);
  1254 fun next_rule (_:rule list list) (_:term) = (None:rule option);
  1254 fun next_rule (_:rule list list) (_:term) = (NONE:rule option);
  1255 fun normal_form t = Some (sort_monoms t,[]:term list);
  1255 fun normal_form t = SOME (sort_monoms t,[]:term list);
  1256 
  1256 
  1257 val order_add_ =
  1257 val order_add_ =
  1258     Rrls {id = "order_add_", 
  1258     Rrls {id = "order_add_", 
  1259 	  prepat = (*WN.18.6.03 Preconditions und Pattern,
  1259 	  prepat = (*WN.18.6.03 Preconditions und Pattern,
  1260 		    die beide passen muessen, damit das Rrls angewandt wird*)
  1260 		    die beide passen muessen, damit das Rrls angewandt wird*)
  1467    ("#Where" ,["t_ is_polyexp"]),
  1467    ("#Where" ,["t_ is_polyexp"]),
  1468    ("#Find"  ,["normalform n_"])
  1468    ("#Find"  ,["normalform n_"])
  1469   ],
  1469   ],
  1470   append_rls "e_rls" e_rls [(*for preds in where_*)
  1470   append_rls "e_rls" e_rls [(*for preds in where_*)
  1471 			    Calc ("Poly.is'_polyexp", eval_is_polyexp "")], 
  1471 			    Calc ("Poly.is'_polyexp", eval_is_polyexp "")], 
  1472   Some "Simplify t_", 
  1472   SOME "Simplify t_", 
  1473   [["simplification","for_polynomials"]]));
  1473   [["simplification","for_polynomials"]]));
  1474 
  1474 
  1475 
  1475 
  1476 (** methods **)
  1476 (** methods **)
  1477 
  1477