src/HOL/Decision_Procs/approximation_generator.ML
changeset 59629 0d77c51b5040
parent 59621 291934bac95e
child 59850 f339ff48a6ee
equal deleted inserted replaced
59628:2b15625b85fc 59629:0d77c51b5040
   115     "int_of_integer (- 1) = - 1"
   115     "int_of_integer (- 1) = - 1"
   116     by auto
   116     by auto
   117   }
   117   }
   118 
   118 
   119 fun rewrite_with ctxt thms = Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps thms)
   119 fun rewrite_with ctxt thms = Simplifier.rewrite (put_simpset HOL_basic_ss ctxt addsimps thms)
   120 fun conv_term thy conv r = Thm.global_cterm_of thy r |> conv |> Thm.prop_of |> Logic.dest_equals |> snd
   120 fun conv_term ctxt conv r = Thm.cterm_of ctxt r |> conv |> Thm.prop_of |> Logic.dest_equals |> snd
   121 
   121 
   122 fun approx_random ctxt prec eps frees e xs genuine_only size seed =
   122 fun approx_random ctxt prec eps frees e xs genuine_only size seed =
   123   let
   123   let
   124     val (rs, seed') = random_float_list size xs seed
   124     val (rs, seed') = random_float_list size xs seed
   125     fun mk_approx_form e ts =
   125     fun mk_approx_form e ts =
   136         val ts = map (fn x => snd x ()) rs
   136         val ts = map (fn x => snd x ()) rs
   137         val ts' = map
   137         val ts' = map
   138           (AList.lookup op = (map dest_Free xs ~~ ts)
   138           (AList.lookup op = (map dest_Free xs ~~ ts)
   139             #> the_default Term.dummy
   139             #> the_default Term.dummy
   140             #> curry op $ @{term "real::float\<Rightarrow>_"}
   140             #> curry op $ @{term "real::float\<Rightarrow>_"}
   141             #> conv_term (Proof_Context.theory_of ctxt) (rewrite_with ctxt postproc_form_eqs))
   141             #> conv_term ctxt (rewrite_with ctxt postproc_form_eqs))
   142           frees
   142           frees
   143       in
   143       in
   144         if approximate ctxt (mk_approx_form e ts) |> is_True
   144         if approximate ctxt (mk_approx_form e ts) |> is_True
   145         then SOME (true, ts')
   145         then SOME (true, ts')
   146         else (if genuine_only then NONE else SOME (false, ts'))
   146         else (if genuine_only then NONE else SOME (false, ts'))
   157     "\<not> (a < b) \<longleftrightarrow> b \<le> a"
   157     "\<not> (a < b) \<longleftrightarrow> b \<le> a"
   158     "\<not> (a \<le> b) \<longleftrightarrow> b < a"
   158     "\<not> (a \<le> b) \<longleftrightarrow> b < a"
   159     "\<not> (p \<and> q) \<longleftrightarrow> \<not> p \<or> \<not> q"
   159     "\<not> (p \<and> q) \<longleftrightarrow> \<not> p \<or> \<not> q"
   160     "\<not> (p \<or> q) \<longleftrightarrow> \<not> p \<and> \<not> q"
   160     "\<not> (p \<or> q) \<longleftrightarrow> \<not> p \<and> \<not> q"
   161     "\<not> \<not> q \<longleftrightarrow> q"
   161     "\<not> \<not> q \<longleftrightarrow> q"
   162     by auto
   162     by auto}
   163   }
       
   164 
   163 
   165 fun reify_goal ctxt t =
   164 fun reify_goal ctxt t =
   166   HOLogic.mk_not t
   165   HOLogic.mk_not t
   167     |> conv_term (Proof_Context.theory_of ctxt) (rewrite_with ctxt preproc_form_eqs)
   166     |> conv_term ctxt (rewrite_with ctxt preproc_form_eqs)
   168     |> conv_term (Proof_Context.theory_of ctxt) (Reification.conv ctxt form_equations)
   167     |> conv_term ctxt (Reification.conv ctxt form_equations)
   169     |> dest_interpret_form
   168     |> dest_interpret_form
   170     ||> HOLogic.dest_list
   169     ||> HOLogic.dest_list
   171 
   170 
   172 fun approximation_generator_raw ctxt t =
   171 fun approximation_generator_raw ctxt t =
   173   let
   172   let