src/Tools/isac/ProgLang/Calculate.thy
author wneuper <walther.neuper@jku.at>
Mon, 19 Jul 2021 18:39:02 +0200
changeset 60338 a2719d9fe512
parent 60331 40eb8aa2b0d6
child 60401 54d17d6d4245
permissions -rw-r--r--
eliminate type float; was an early attempt overrun by Isabelle
     1 (* Title:  ProgLang/Calculate.thy
     2    Author: Walther Neuper 000301
     3    (c) copyright due to lincense terms.
     4 *)
     5 
     6 theory Calculate
     7   imports "$ISABELLE_ISAC/BaseDefinitions/BaseDefinitions"
     8 begin
     9 
    10 text \<open>Abstract:
    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 + - * / ^.
    16 
    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.
    19 \<close>
    20 
    21 ML_file evaluate.sml
    22 
    23 ML \<open>
    24 \<close> ML \<open>
    25 (*** evaluate binary associative operations ***)
    26 
    27 fun eval_binop _ _
    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
    30       let
    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
    35     else NONE
    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
    40       let
    41         val res = Eval.calcul op0 (t1, t2);
    42         val prop = HOLogic.Trueprop $ (HOLogic.mk_eq (t, opp $ res $ v));
    43       in
    44         SOME ("#: " ^ UnparseC.term prop, prop)
    45       end
    46     else NONE
    47   | eval_binop _ _ (t as (Const (op0, _) $ t1 $ t2)) _ =                       (* binary . n1.n2 *)
    48     if TermC.is_num t1 andalso TermC.is_num t2 then
    49       let
    50         val res = Eval.calcul op0 (t1, t2);
    51         val prop = HOLogic.Trueprop $ (HOLogic.mk_eq (t, res));
    52       in
    53         SOME ("#: " ^ UnparseC.term prop, prop)
    54       end
    55     else NONE
    56   | eval_binop _ _ _ _ = NONE; 
    57 \<close> ML \<open>
    58 \<close> ML \<open>
    59 \<close>
    60 
    61 end