(* File:Real_Asymp_Approx.thy Author:ManuelEberl,TUMünchen Integratestheapproximationmethodintothereal_asympframeworkasasignoracle toautomaticallyprovepositivity/negativityofrealconstants
*) theory Real_Asymp_Approx imports Real_Asymp "HOL-Decision_Procs.Approximation" begin
text‹
For large enough constants (such as term‹exp (exp 10000 :: real)›), the
@{method approximation} method can require a huge amount of time and memory, effectively not
terminating and causing the entire prover environment to crash.
To avoid causing such situations, we first check the plausibility of the fact to prove using
floating-point arithmetic and only run the approximation method if the floating point evaluation
supports the claim. In particular, exorbitantly large numbers like the one above will lead to
floating point overflow, which makes the check fail. ›
ML ‹
REAL_ASYMP_APPROX =
val real_asymp_approx : bool Config.T
val sign_oracle_tac : Proof.context -> int -> tactic
val eval : term -> real
nan = Real.fromInt 0 / Real.fromInt 0
clamp n = if n < 0 then 0 else n
eval_nat (term‹(+) :: nat => _› $ a $ b) = bin (op +) (a, b)
| eval_nat (term‹(-) :: nat => _› $ a $ b) = bin (clamp o op -) (a, b)
| eval_nat (\<^term>\<open>(*) :: nat => _› $ a $ b) = bin (op *) (a, b)
| eval_nat (term‹(div) :: nat => _› $ a $ b) = bin Int.div (a, b) |eval_nat(\<^term>\<open>(^)::nat=>_\<close>$a$b)=bin(fn(a,b)=>Integer.powab)(a,b) |eval_nat(tas(\<^term>\<open>numeral::_=>nat\<close>$_))=snd(HOLogic.dest_numbert) |eval_nat(\<^term>\<open>0::nat\<close>)=0 |eval_nat(\<^term>\<open>1::nat\<close>)=1 |eval_nat(\<^term>\<open>Nat.Suc\<close>$a)=un(fnn=>n+1)a |eval_nat_=~1 andunfa= let vala=eval_nata in ifa>=0thenfaelse~1 end andbinf(a,b)= let val(a,b)=apply2eval_nat(a,b) in ifa>=0andalsob>=0thenf(a,b)else~1 end
funeval(\<^term>\<open>(+)::real=>_\<close>$a$b)=evala+evalb |eval(\<^term>\<open>(-)::real=>_\<close>$a$b)=evala-evalb
| eval (\<^term>\<open>(*) :: real => _› $ a $ b) = eval a * eval b
| eval (term‹(/) :: real => _› $ a $ b) = letvala=evala;valb=evalbin ifReal.==(b,Real.fromInt0)thennanelsea/b end |eval(\<^term>\<open>inverse::real=>_\<close>$a)=Real.fromInt1/evala |eval(\<^term>\<open>uminus::real=>_\<close>$a)=Real.~(evala) |eval(\<^term>\<open>exp::real=>_\<close>$a)=Math.exp(evala) |eval(\<^term>\<open>ln::real=>_\<close>$a)= letvala=evalainifa>Real.fromInt0thenMath.lnaelsenanend |eval(\<^term>\<open>(powr)::real=>_\<close>$a$b)= let vala=evala;valb=evalb in ifa<Real.fromInt0orelsenot(Real.isFinitea)orelsenot(Real.isFiniteb)then nan elseifReal.==(a,Real.fromInt0)then Real.fromInt0 else Math.pow(a,b) end |eval(\<^term>\<open>(^)::real=>_\<close>$a$b)= let funpowrxy= ifnot(Real.isFinitex)orelsey<0then nan elseifx<Real.fromInt0andalsoymod2=1then Real.~(Math.pow(Real.~x,Real.fromInty)) else Math.pow(Real.absx,Real.fromInty) in powr(evala)(eval_natb) end |eval(\<^term>\<open>root::nat=>real=>_\<close>$n$a)= letvala=evala;valn=eval_natnin ifn=0thenReal.fromInt0 elsesgna*Math.pow(Real.absa,Real.fromInt1/Real.fromIntn)end |eval(\<^term>\<open>sqrt::real=>_\<close>$a)= letvala=evalainsgna*Math.sqrt(absa)end |eval(\<^term>\<open>log::real=>_\<close>$a$b)= let val(a,b)=apply2eval(a,b) in ifb>Real.fromInt0andalsoa>Real.fromInt0andalsoReal.!=(a,Real.fromInt1)then Math.lnb/Math.lna else nan end |eval(tas(\<^term>\<open>numeral::_=>real\<close>$_))= Real.fromInt(snd(HOLogic.dest_numbert)) |eval(\<^term>\<open>0::real\<close>)=Real.fromInt0 |eval(\<^term>\<open>1::real\<close>)=Real.fromInt1 |eval_=nan
funsign_oracle_tacctxti= let funtac{context=ctxt,concl,...}= let valb= caseHOLogic.dest_Trueprop(Thm.term_ofconcl)of \<^term>\<open>(<)::real\<Rightarrow>_\<close>$lhs$rhs=> let val(x,y)=apply2eval(lhs,rhs) in Real.isFinitexandalsoReal.isFiniteyandalsox<y end |\<^term>\<open>HOL.Not\<close>$(\<^term>\<open>(=)::real\<Rightarrow>_\<close>$lhs$rhs)=> let val(x,y)=apply2eval(lhs,rhs) in Real.isFinitexandalsoReal.isFiniteyandalsoReal.!=(x,y) end |_=>false in ifbthenHEADGOAL(Approximation.approximation_tac10[]NONEctxt)elseno_tac end in ifConfig.getctxtreal_asymp_approxthen Subgoal.FOCUStacctxti else no_tac end
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.