1 (* Title: ProgLang/Calculate.thy
2 Author: Walther Neuper 000301
3 (c) copyright due to lincense terms.
7 imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions"
11 The Isac project required floating point numbers and complex numbers in early 2000,
12 before these numbers were available in Isabelle.
13 Since that time numeral calculations are done by ML functions, all named eval_
14 and integrated into rewriting. eval_binop below is not bound to a specific constant
15 (like in Prog_Expr.thy), rather calculates results of Isabelle's binary operations + - * / ^.
17 A specialty are the ad-hoc theorems for numeral calculations created in order to provide
18 the rewrite engine with theorems as done in general.
25 (*** evaluate binary associative operations ***)
28 (t as ((opp as Const (op0, _)) $ (Const (op0', _) $ v $ t1) $ t2)) _ =(* binary . (v.n1).n2 *)
29 if op0 = op0' andalso TermC.is_num t1 andalso TermC.is_num t2 then
31 val op' = if op0 = "Groups.minus_class.minus" then "Groups.plus_class.plus" else op0
32 val res = Eval.calcul op' (t1, t2);
33 val prop = HOLogic.Trueprop $ (HOLogic.mk_eq (t, opp $ v $ res));
34 in SOME ("#: " ^ UnparseC.term prop, prop) end
36 | eval_binop _ (_ : string)
37 (t as ((opp as Const (op0, _)) $ t1 $ (Const (op0', _) $ t2 $ v))) _ =(* binary . n1.(n2.v) *)
38 if op0 = op0' andalso op0 <> "Groups.minus_class.minus"
39 andalso TermC.is_num t1 andalso TermC.is_num t2 then
41 val res = Eval.calcul op0 (t1, t2);
42 val prop = HOLogic.Trueprop $ (HOLogic.mk_eq (t, opp $ res $ v));
44 SOME ("#: " ^ UnparseC.term prop, prop)
47 | eval_binop _ _ (t as (Const (op0, _) $ t1 $ t2)) _ = (* binary . n1.n2 *)
48 if TermC.is_num t1 andalso TermC.is_num t2 then
50 val res = Eval.calcul op0 (t1, t2);
51 val prop = HOLogic.Trueprop $ (HOLogic.mk_eq (t, res));
53 SOME ("#: " ^ UnparseC.term prop, prop)
56 | eval_binop _ _ _ _ = NONE;