test/Tools/isac/ProgLang/prog_expr.sml
changeset 60336 dcb37736d573
parent 60331 40eb8aa2b0d6
child 60339 0d22a6bf1fc6
equal deleted inserted replaced
60335:7701598a2182 60336:dcb37736d573
    89 "-------- fun eval_const -----------------------------------------------------------------------";
    89 "-------- fun eval_const -----------------------------------------------------------------------";
    90 "-------- fun eval_const -----------------------------------------------------------------------";
    90 "-------- fun eval_const -----------------------------------------------------------------------";
    91 "-------- fun eval_const -----------------------------------------------------------------------";
    91 "-------- fun eval_const -----------------------------------------------------------------------";
    92 val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_const";
    92 val t = (Thm.term_of o the o (TermC.parse @{theory Test})) "2 is_const";
    93 case rewrite_set_ @{theory Test} false tval_rls t of
    93 case rewrite_set_ @{theory Test} false tval_rls t of
    94   SOME (Const ("HOL.True", _), []) => ()
    94   SOME (Const (\<^const_name>\<open>True\<close>, _), []) => ()
    95 | _ => error "2 is_const CHANGED";
    95 | _ => error "2 is_const CHANGED";
    96 
    96 
    97 val t = TermC.str2term "2 * x is_const";
    97 val t = TermC.str2term "2 * x is_const";
    98 val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
    98 val SOME (str, t') = eval_const "" "" t (@{theory "Isac_Knowledge"});
    99 if UnparseC.term t' = "(2 * x is_const) = False" then ()
    99 if UnparseC.term t' = "(2 * x is_const) = False" then ()
   164 eval_equ: string -> string -> term -> 'a -> (string * term) option;
   164 eval_equ: string -> string -> term -> 'a -> (string * term) option;
   165 
   165 
   166 case eval_equ "#less_" "Orderings.ord_class.less" @{term "1 < (2::real)"} "" of
   166 case eval_equ "#less_" "Orderings.ord_class.less" @{term "1 < (2::real)"} "" of
   167 SOME
   167 SOME
   168     ("#less_1_2",
   168     ("#less_1_2",
   169      Const ("HOL.Trueprop", _) $
   169      Const (\<^const_name>\<open>Trueprop\<close>, _) $
   170        (Const ("HOL.eq", _) $
   170        (Const (\<^const_name>\<open>HOL.eq\<close>, _) $
   171          (Const ("Orderings.ord_class.less", _) $ Const ("Groups.one_class.one", _) $
   171          (Const (\<^const_name>\<open>ord_class.less\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _) $
   172            (Const ("Num.numeral_class.numeral", _) $ (Const ("Num.num.Bit0", _) $ Const ("Num.num.One", _)))) $
   172            (Const (\<^const_name>\<open>numeral\<close>, _) $ (Const (\<^const_name>\<open>num.Bit0\<close>, _) $ Const (\<^const_name>\<open>num.One\<close>, _)))) $
   173          Const ("HOL.True", _))) => ()
   173          Const (\<^const_name>\<open>True\<close>, _))) => ()
   174 | _ => error "eval_equ   1 < 2   CHANGED";
   174 | _ => error "eval_equ   1 < 2   CHANGED";
   175 
   175 
   176 case eval_equ "#less_" "Orderings.ord_class.less" @{term "1 < (1::real)"} "" of
   176 case eval_equ "#less_" "Orderings.ord_class.less" @{term "1 < (1::real)"} "" of
   177 SOME
   177 SOME
   178     ("#less_1_1",
   178     ("#less_1_1",
   179      Const ("HOL.Trueprop", _) $
   179      Const (\<^const_name>\<open>Trueprop\<close>, _) $
   180        (Const ("HOL.eq", _) $ (Const ("Orderings.ord_class.less", _) $ Const ("Groups.one_class.one", _) $ Const ("Groups.one_class.one", _)) $
   180        (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (Const (\<^const_name>\<open>ord_class.less\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _) $ Const (\<^const_name>\<open>one_class.one\<close>, _)) $
   181          Const ("HOL.False", _))) => ()
   181          Const (\<^const_name>\<open>False\<close>, _))) => ()
   182 | _ => error "eval_equ   1 < 1   CHANGED";
   182 | _ => error "eval_equ   1 < 1   CHANGED";
   183 
   183 
   184 
   184 
   185 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
   185 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
   186 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
   186 "-------- fun eval_equal for x \<noteq> 0: \<rightarrow> indetermined, NOT \<rightarrow> 'True' -----------------------------";
   329 "---------fun eval_sameFunId -------------------------------------------------------------------";
   329 "---------fun eval_sameFunId -------------------------------------------------------------------";
   330 "---------fun eval_sameFunId -------------------------------------------------------------------";
   330 "---------fun eval_sameFunId -------------------------------------------------------------------";
   331 "---------fun eval_sameFunId -------------------------------------------------------------------";
   331 "---------fun eval_sameFunId -------------------------------------------------------------------";
   332 val t = @{term "M_b L"}; TermC.atomty t;
   332 val t = @{term "M_b L"}; TermC.atomty t;
   333 val t as f1 $ _ = @{term "M_b L"};
   333 val t as f1 $ _ = @{term "M_b L"};
   334 val t as Const ("HOL.eq", _) $ (f2 $ _) $ _ = @{term "M_b x = c + L*x"};
   334 val t as Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (f2 $ _) $ _ = @{term "M_b x = c + L*x"};
   335 f1 = f2 (*true*);
   335 f1 = f2 (*true*);
   336 val (p as Const ("Prog_Expr.sameFunId",_) $ 
   336 val (p as Const (\<^const_name>\<open>sameFunId\<close>, _) $ 
   337 			(f1 $ _) $ 
   337 			(f1 $ _) $ 
   338 			(Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (f2 $ _) $ _)) = 
   338 			(Const (\<^const_name>\<open>HOL.eq\<close>, _) $ (f2 $ _) $ _)) = 
   339     @{term "sameFunId (M_b L) (M_b x = c + L*x)"};
   339     @{term "sameFunId (M_b L) (M_b x = c + L*x)"};
   340 f1 = f2 (*true*);
   340 f1 = f2 (*true*);
   341 eval_sameFunId "" "Prog_Expr.sameFunId" 
   341 eval_sameFunId "" "Prog_Expr.sameFunId" 
   353 "---------fun eval_filter_sameFunId ------------------------------------------------------------";
   353 "---------fun eval_filter_sameFunId ------------------------------------------------------------";
   354 "---------fun eval_filter_sameFunId ------------------------------------------------------------";
   354 "---------fun eval_filter_sameFunId ------------------------------------------------------------";
   355 "---------fun eval_filter_sameFunId ------------------------------------------------------------";
   355 "---------fun eval_filter_sameFunId ------------------------------------------------------------";
   356 val flhs as (fid $ _) = @{term "y' L"};
   356 val flhs as (fid $ _) = @{term "y' L"};
   357 val fs = @{term "[M_b x = c + L*x, y' x = c + L*x, y x = c + L*x]"};
   357 val fs = @{term "[M_b x = c + L*x, y' x = c + L*x, y x = c + L*x]"};
   358 val (p as Const ("Prog_Expr.filter_sameFunId",_) $ (fid $ _) $ fs) = 
   358 val (p as Const (\<^const_name>\<open>filter_sameFunId\<close>,_) $ (fid $ _) $ fs) = 
   359     @{term "filter_sameFunId (y' L) [M_b x = c + L*x, y' x = c + L*x, y x = c + L*x]"};
   359     @{term "filter_sameFunId (y' L) [M_b x = c + L*x, y' x = c + L*x, y x = c + L*x]"};
   360 val SOME (str, es) = eval_filter_sameFunId "" "Prog_Expr.filter_sameFunId" p "";
   360 val SOME (str, es) = eval_filter_sameFunId "" "Prog_Expr.filter_sameFunId" p "";
   361 if UnparseC.term es = "(filter_sameFunId y' L [M_b x = c + L * x, y' x = c + L * x,\n                        y x = c + L * x]) =\n[y' x = c + L * x]" then ()
   361 if UnparseC.term es = "(filter_sameFunId y' L [M_b x = c + L * x, y' x = c + L * x,\n                        y x = c + L * x]) =\n[y' x = c + L * x]" then ()
   362 else error "atools.slm diff.behav. in filter_sameFunId";
   362 else error "atools.slm diff.behav. in filter_sameFunId";
   363 
   363 
   364 
   364 
   365 "---------fun eval_boollist2sum ----------------------------------------------------------------";
   365 "---------fun eval_boollist2sum ----------------------------------------------------------------";
   366 "---------fun eval_boollist2sum ----------------------------------------------------------------";
   366 "---------fun eval_boollist2sum ----------------------------------------------------------------";
   367 "---------fun eval_boollist2sum ----------------------------------------------------------------";
   367 "---------fun eval_boollist2sum ----------------------------------------------------------------";
   368 fun lhs (Const ("HOL.eq",_) $ l $ _) = l
   368 fun lhs (Const (\<^const_name>\<open>HOL.eq\<close>,_) $ l $ _) = l
   369   | lhs t = error("lhs called with (" ^ UnparseC.term t ^ ")");
   369   | lhs t = error("lhs called with (" ^ UnparseC.term t ^ ")");
   370 "----------- \<up> redefined due to overwritten identifier -----------";
   370 "----------- \<up> redefined due to overwritten identifier -----------";
   371 val u_ = @{term "[]"};
   371 val u_ = @{term "[]"};
   372 val u_ = @{term "[b1 = k - 2*q]"};
   372 val u_ = @{term "[b1 = k - 2*q]"};
   373 val u_ = @{term "[b1 = k - 2*q, b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
   373 val u_ = @{term "[b1 = k - 2*q, b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
   376 val t = list2sum sum_;
   376 val t = list2sum sum_;
   377 UnparseC.term t;
   377 UnparseC.term t;
   378 
   378 
   379 val t = @{term "boollist2sum [b1 = k - 2*(q::real), b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
   379 val t = @{term "boollist2sum [b1 = k - 2*(q::real), b2 = k - 2*q, b3 = k - 2*q, b4 = k - 2*q]"};
   380 case t of
   380 case t of
   381 Const ("Prog_Expr.boollist2sum", _) $
   381 Const (\<^const_name>\<open>boollist2sum\<close>, _) $
   382      (Const ("List.list.Cons", _) $
   382      (Const (\<^const_name>\<open>Cons\<close>, _) $
   383        (Const ("HOL.eq", _) $ Free ("b1", _) $ _ ) $
   383        (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b1", _) $ _ ) $
   384        (Const ("List.list.Cons", _) $
   384        (Const (\<^const_name>\<open>Cons\<close>, _) $
   385          (Const ("HOL.eq", _) $ Free ("b2", _) $ _ ) $
   385          (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b2", _) $ _ ) $
   386          (Const ("List.list.Cons", _) $
   386          (Const (\<^const_name>\<open>Cons\<close>, _) $
   387            (Const ("HOL.eq", _) $ Free ("b3", _) $ _ ) $
   387            (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b3", _) $ _ ) $
   388            (Const ("List.list.Cons", _) $
   388            (Const (\<^const_name>\<open>Cons\<close>, _) $
   389              (Const ("HOL.eq", _) $ Free ("b4", _) $ _ ) $
   389              (Const (\<^const_name>\<open>HOL.eq\<close>, _) $ Free ("b4", _) $ _ ) $
   390              Const ("List.list.Nil", _))))) => ()
   390              Const (\<^const_name>\<open>Nil\<close>, _))))) => ()
   391 | _ => error "boollist2sum CHANGED";
   391 | _ => error "boollist2sum CHANGED";
   392 val SOME (str, pred) = eval_boollist2sum "" "Prog_Expr.boollist2sum" t "";
   392 val SOME (str, pred) = eval_boollist2sum "" "Prog_Expr.boollist2sum" t "";
   393 if UnparseC.term pred = "boollist2sum\n [b1 = k - 2 * q, b2 = k - 2 * q, b3 = k - 2 * q, b4 = k - 2 * q] =\nb1 + b2 + b3 + b4" then () 
   393 if UnparseC.term pred = "boollist2sum\n [b1 = k - 2 * q, b2 = k - 2 * q, b3 = k - 2 * q, b4 = k - 2 * q] =\nb1 + b2 + b3 + b4" then () 
   394 else error "atools.sml diff.behav. in eval_boollist2sum";
   394 else error "atools.sml diff.behav. in eval_boollist2sum";
   395 
   395 
   443 
   443 
   444 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
   444 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
   445 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
   445 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
   446 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
   446 "-------- fun or2list: HOL.disj HOL.eq HOL.True HOL.False etc ----------------------------------";
   447 "see: --------- search for Or_to_List ---";
   447 "see: --------- search for Or_to_List ---";
   448 case or2list @{term True} of Const ("ListC.UniversalList", _) => ()
   448 case or2list @{term True} of Const (\<^const_name>\<open>UniversalList\<close>, _) => ()
   449   | _ => error "TermC.UniversalList changed 1";
   449   | _ => error "TermC.UniversalList changed 1";
   450 case or2list @{term False} of Const (\<^const_name>\<open>Nil\<close>, _) => ()
   450 case or2list @{term False} of Const (\<^const_name>\<open>Nil\<close>, _) => ()
   451   | _ => error "TermC.UniversalList changed 2";
   451   | _ => error "TermC.UniversalList changed 2";
   452 val t =  (TermC.str2term "x=3");
   452 val t =  (TermC.str2term "x=3");
   453 if UnparseC.term (or2list t) = "[x = 3]" then ()
   453 if UnparseC.term (or2list t) = "[x = 3]" then ()