Theory PhiSem_Int_ArbiPrec

theory PhiSem_Int_ArbiPrec
  imports PhiSem_Generic_Boolean PhiSem_Common_Int
  abbrevs "<aint>" = "๐–บ๐—‚๐—‡๐—"
begin

chapter โ€นInteger of Arbitrary Precisionโ€บ

setup โ€นContext.theory_map (Generic_Variable_Access.Process_of_Argument.put
                                          (SOME Generic_Variable_Access.store_value_no_clean))โ€บ

section โ€นSemanticsโ€บ

debt_axiomatization ๐–บ๐—‚๐—‡๐— :: TY
                and sem_mk_aint   :: โ€นint โ‡’ VALโ€บ
                and sem_dest_aint :: โ€นVAL โ‡’ intโ€บ
where sem_mk_dest_aint[simp]: โ€นsem_dest_aint (sem_mk_aint i) = iโ€บ
  and WT_aint[simp]: โ€นWell_Type ๐–บ๐—‚๐—‡๐— = { sem_mk_aint i |i. True } โ€บ
  and ๐–บ๐—‚๐—‡๐—_neq_๐—‰๐—ˆ๐—‚๐—Œ๐—ˆ๐—‡[simp]: โ€น๐–บ๐—‚๐—‡๐— โ‰  ๐—‰๐—ˆ๐—‚๐—Œ๐—ˆ๐—‡โ€บ
  and can_eqcmp_aint[simp]: "Can_EqCompare res (sem_mk_aint i1) (sem_mk_aint i2)"
  and eqcmp_aint[simp]: "EqCompare (sem_mk_aint i1) (sem_mk_aint i2) โŸท i1 = i2"
  and  zero_aint[simp]: โ€นZero ๐–บ๐—‚๐—‡๐—   = Some (sem_mk_aint 0)โ€บ
  and ฯ†Sem_aint_to_logic_int[simp]: โ€นฯ†Sem_int_to_logic_int (sem_mk_aint i) = Some iโ€บ
  and ฯ†Sem_aint_to_logic_nat[simp]: โ€นฯ†Sem_int_to_logic_nat (sem_mk_aint i) = (if 0 โ‰ค i then Some (nat i) else None)โ€บ

lemma sem_mk_aint_inj[simp]:
  โ€นsem_mk_aint i = sem_mk_aint j โ‰ก i = jโ€บ
  by (smt (verit, best) sem_mk_dest_aint)
  

lemma [ฯ†reason %logical_spec_of_semantics]:
  โ€น ๐—‰๐—‹๐–พ๐—†๐—‚๐—Œ๐–พ 0 โ‰ค n
โŸน get_logical_nat_from_semantic_int (sem_mk_aint n โฆ‚ Itself) (nat n)โ€บ
  unfolding get_logical_nat_from_semantic_int_def Premise_def
  by simp

lemma [ฯ†reason %logical_spec_of_semantics]:
  โ€น get_logical_int_from_semantic_int (sem_mk_aint n โฆ‚ Itself) nโ€บ
  unfolding get_logical_int_from_semantic_int_def Premise_def
  by simp

lemma [ฯ†reason add]:
  โ€นIs_Type_Literal ๐–บ๐—‚๐—‡๐—โ€บ
  unfolding Is_Type_Literal_def ..

lemma has_Zero_๐–บ๐—‚๐—‡๐—[simp]:
  โ€น has_Zero ๐–บ๐—‚๐—‡๐— โ€บ
  unfolding has_Zero_def
  by simp



section โ€นฯ†-Typesโ€บ

subsection โ€นInteger in the normal senseโ€บ

ฯ†type_def ฯ†AInt :: "(VAL, int) ฯ†" ("โ„ค")
  where โ€นx โฆ‚ ฯ†AInt โ‰ก sem_mk_aint x โฆ‚ Itselfโ€บ
  deriving Basic
       and Abstract_DomainL
       and Semantic_Zero_Val
       and โ€น๐—๐—’๐—‰๐–พ๐—ˆ๐–ฟ โ„ค = ๐–บ๐—‚๐—‡๐—โ€บ
       and Functionality
       and Equiv_Class


lemma [ฯ†reason 1000]:
    "ฯ†Equal โ„ค (ฮปx y. True) (=)"
  unfolding ฯ†Equal_def by (simp add: eq_nat_nat_iff)

lemma [ฯ†reason %logical_spec_of_semantics]:
  โ€นget_logical_int_from_semantic_int (n โฆ‚ โ„ค) nโ€บ
  unfolding get_logical_int_from_semantic_int_def Ball_def
  by clarsimp

lemma [ฯ†reason %logical_spec_of_semantics]:
  โ€น ๐—‰๐—‹๐–พ๐—†๐—‚๐—Œ๐–พ 0 โ‰ค n
โŸน get_logical_nat_from_semantic_int (n โฆ‚ โ„ค) (nat n)โ€บ
  unfolding get_logical_nat_from_semantic_int_def Ball_def Premise_def
  by clarsimp


subsection โ€นNatural Nmberโ€บ

declare [[ฯ†trace_reasoning = 0]]

ฯ†type_def ฯ†ANat ("โ„•")
  where โ€นn โฆ‚ โ„• โ‰ก of_nat n โฆ‚ โ„คโ€บ
  deriving Basic
       and Abstract_DomainL
       and Semantic_Type
       and Semantic_Zero_Val
       and Inhabited
       and โ€น๐—๐—’๐—‰๐–พ๐—ˆ๐–ฟ โ„• = ๐–บ๐—‚๐—‡๐—โ€บ
       and Functionality
       and Equiv_Class


declare [[
    overloaded_operator_in_synthesis โ€นInt.intโ€บ,
    overloaded_operator_in_synthesis โ€นnatโ€บ
 ]]


lemma [ฯ†reason %ToA_num_conv_cut, ฯ†synthesis %ฯ†synthesis_transformation]:
  " Threshold_Cost 4
โŸน ๐—‰๐—‹๐–พ๐—†๐—‚๐—Œ๐–พ 0 โ‰ค x
โŸน x โฆ‚ โ„ค ๐—๐—‹๐–บ๐—‡๐—Œ๐–ฟ๐—ˆ๐—‹๐—†๐—Œ nat x โฆ‚ โ„•"
  โด
    โ€นnat x โฆ‚ MAKE 0 โ„•โ€บ
  โต.

lemma [ฯ†reason %ToA_num_conv_cut]:
  โ€น ๐—‰๐—‹๐–พ๐—†๐—‚๐—Œ๐–พ 0 โ‰ค x
โŸน x โฆ‚ โ„ค ๐—๐—‹๐–บ๐—‡๐—Œ๐–ฟ๐—ˆ๐—‹๐—†๐—Œ y โฆ‚ โ„• ๐—Œ๐—Ž๐–ป๐—ƒ y. y = nat x @tag to โ„•โ€บ โด โต.

declare ฯ†ANat.elim[condition โ€น๐—๐—๐—‹๐–พ๐—Œ๐—๐—ˆ๐—…๐–ฝ 2โ€บ,
                   ฯ†reason %ToA_num_conv_cut,
                   ฯ†synthesis %ฯ†synthesis_transformation]

lemma [ฯ†reason %ToA_num_conv_cut]:
  " x โฆ‚ โ„• ๐—๐—‹๐–บ๐—‡๐—Œ๐–ฟ๐—ˆ๐—‹๐—†๐—Œ y โฆ‚ โ„ค ๐—Œ๐—Ž๐–ป๐—ƒ y. y = Int.int x @tag to โ„ค " โด โต.

lemma [ฯ†reason 1000]: โ€นฯ†Equal โ„• (ฮป_ _. True) (=)โ€บ โด to โ„ค โต.

lemma [ฯ†reason %logical_spec_of_semantics]:
  โ€นget_logical_int_from_semantic_int (n โฆ‚ โ„•) (of_nat n)โ€บ
  unfolding get_logical_int_from_semantic_int_def Ball_def
  by clarsimp

lemma [ฯ†reason %logical_spec_of_semantics]:
  โ€นget_logical_nat_from_semantic_int (n โฆ‚ โ„•) nโ€บ
  unfolding get_logical_nat_from_semantic_int_def Ball_def
  by clarsimp


section โ€นInstructionsโ€บ

subsection โ€นArithmetic Operationsโ€บ

(* definition op_const_aint :: "int โ‡’ VAL proc"
  where "op_const_aint const = Return (ฯ†arg (sem_mk_aint const))" *)

definition op_aadd :: "(VAL ร— VAL, VAL) proc'"
  where "op_aadd =
      ฯ†M_caseV (ฮปvb va.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      Return (ฯ†arg (sem_mk_aint (val_a + val_b)))
  )))"

definition op_asub :: "(VAL ร— VAL, VAL) proc'"
  where "op_asub =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_aint (val_a - val_b)))
  )))"

definition op_aneg :: "(VAL, VAL) proc'"
  where "op_aneg rv =
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint rv (ฮปv.
      Return (ฯ†arg (sem_mk_aint (-v))))"

definition op_amul :: "(VAL ร— VAL, VAL) proc'"
  where "op_amul =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_aint (val_b * val_a)))
  )))"

definition op_adiv :: "(VAL ร— VAL, VAL) proc'"
  where "op_adiv =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_aint (val_a div val_b)))
  )))"

definition op_amod :: "(VAL ร— VAL, VAL) proc'"
  where "op_amod =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_aint (val_a mod val_b)))
  )))"

definition op_alshr :: "(VAL ร— VAL, VAL) proc'"
  where "op_alshr =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_aint (val_a div 2 ^ (Int.nat val_b))))
  )))"

definition op_alshl :: "(VAL ร— VAL, VAL) proc'"
  where "op_alshl =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_aint (val_a * 2 ^ (Int.nat val_b))))
  )))"

definition op_a_lt :: "(VAL ร— VAL, VAL) proc'"
  where "op_a_lt =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_bool (val_a < val_b)))
  )))"

definition op_a_le :: "(VAL ร— VAL, VAL) proc'"
  where "op_a_le =
      ฯ†M_caseV (ฮปva vb.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint va (ฮปval_a.
      ฯ†M_getV ๐–บ๐—‚๐—‡๐— sem_dest_aint vb (ฮปval_b.
      Return (ฯ†arg (sem_mk_bool (val_a โ‰ค val_b)))
  )))"


section โ€นAbstraction of Instructionsโ€บ

subsection โ€นArithmetic Operationsโ€บ

subsubsection โ€นConstant Integerโ€บ

lemma op_const_aint_ฯ†app[ฯ†reason %ฯ†synthesis_literal_number]:
  โ€น Is_Literal x
โŸน X ๐—๐—‹๐–บ๐—‡๐—Œ๐–ฟ๐—ˆ๐—‹๐—†๐—Œ x โฆ‚ ๐—๐–บ๐—…[semantic_literal (sem_mk_aint x)] โ„ค ๐—‹๐–พ๐—†๐–บ๐—‚๐—‡๐—Œ X @tag synthesisโ€บ
  for X :: assn
โด
  semantic_literal โ€นsem_mk_aint x โŠจ (x โฆ‚ โ„ค)โ€บ
โต .

lemma op_const_anat_ฯ†app[ฯ†reason %ฯ†synthesis_literal_number]:
  โ€น ๐—Œ๐—‚๐—†๐—‰๐—…๐—‚๐–ฟ๐—’[mode_literal] x' : of_nat x
โŸน X ๐—๐—‹๐–บ๐—‡๐—Œ๐–ฟ๐—ˆ๐—‹๐—†๐—Œ x โฆ‚ Val (semantic_literal (sem_mk_aint x')) โ„• ๐—‹๐–พ๐—†๐–บ๐—‚๐—‡๐—Œ X @tag synthesisโ€บ
  for X :: assn
โด
  semantic_literal โ€นsem_mk_aint x' โŠจ (x โฆ‚ โ„•)โ€บ
โต .

lemma [ฯ†reason %ฯ†synthesis_parse_number+10
    for โ€นSynthesis_Parse (numeral ?n::nat) (?X :: ?'ret โ‡’ assn)โ€บ
       โ€นSynthesis_Parse (1::nat) (?X :: ?'ret โ‡’ assn)โ€บ
       โ€นSynthesis_Parse (0::nat) (?X :: ?'ret โ‡’ assn)โ€บ
]:
  โ€น Synthesis_Parse (n โฆ‚ โ„•) X
โŸน Synthesis_Parse n Xโ€บ
  for X :: โ€น'ret โ‡’ assnโ€บ
  unfolding Synthesis_Parse_def ..

lemma [ฯ†reason %ฯ†synthesis_parse_number
    for โ€นSynthesis_Parse (numeral ?n::int) (?X :: ?'ret โ‡’ assn)โ€บ
       โ€นSynthesis_Parse (1::int) (?X :: ?'ret โ‡’ assn)โ€บ
       โ€นSynthesis_Parse (0::int) (?X :: ?'ret โ‡’ assn)โ€บ
]:
  โ€น Synthesis_Parse (n โฆ‚ โ„ค) X
โŸน Synthesis_Parse n Xโ€บ
  for X :: โ€น'ret โ‡’ assnโ€บ
  unfolding Synthesis_Parse_def ..


(* lemma op_const_size_t:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_const_size_t n โฆƒ Void โŸผ ๐—๐–บ๐—… n โฆ‚ Size โฆ„โ€บ
  unfolding op_const_size_t_def Premise_def
  by (ฯ†reason, simp add: ฯ†expns Big_def) *)


(* lemma [ฯ†reason 1200
    for โ€น๐—‰๐—‹๐—ˆ๐–ผ ?f โฆƒ ?X' โŸผ ?XโŸ SYNTHESIS ๐—๐–บ๐—… (numeral ?n) โฆ‚ Size โฆ„ ๐—๐—๐—‹๐—ˆ๐—๐—Œ ?E  @tag synthesis ?Gโ€บ
       โ€น๐—‰๐—‹๐—ˆ๐–ผ ?f โฆƒ ?X' โŸผ ?XโŸ SYNTHESIS ๐—๐–บ๐—… 0 โฆ‚ Size โฆ„ ๐—๐—๐—‹๐—ˆ๐—๐—Œ ?E  @tag synthesis ?Gโ€บ
       โ€น๐—‰๐—‹๐—ˆ๐–ผ ?f โฆƒ ?X' โŸผ ?XโŸ SYNTHESIS ๐—๐–บ๐—… 1 โฆ‚ Size โฆ„ ๐—๐—๐—‹๐—ˆ๐—๐—Œ ?E  @tag synthesis ?Gโ€บ
]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_const_size_t n โฆƒ R โŸผ RโŸ SYNTHESIS ๐—๐–บ๐—… n โฆ‚ Size โฆ„ @tag synthesis Gโ€บ
  unfolding Synthesis_def Action_Tag_def
  using op_const_size_t[THEN ฯ†frame, simplified] . *)

lemma int_literal_2_literal_int[simp]:
  โ€นint (literal x) = literal (int x)โ€บ
  unfolding literal_def
  by simp



subsubsection โ€นInteger Arithmeticโ€บ

paragraph โ€นAdditionโ€บ

lemma op_add_aint_ฯ†app
  [ฯ†overload +,
   ฯ†synthesis for _ (%synthesis_arith)
              and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x + y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_aadd (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„ค โŸผ ๐—๐–บ๐—… x + y โฆ‚ โ„ค โฆ„ โ€บ
  unfolding op_aadd_def Premise_def
  by (cases vx; cases vy; simp, rule, rule, simp add: Premise_def, rule,
      simp add: Premise_def, rule, simp)

lemma op_add_anat_ฯ†app
  [ฯ†overload +,
   ฯ†synthesis for _ (%synthesis_arith)
              and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x + y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_aadd (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„• โŸผ ๐—๐–บ๐—… x + y โฆ‚ โ„• โฆ„ โ€บ
  โด op_add_aint โต .


paragraph โ€นSubtractionโ€บ

lemma op_sub_aint_ฯ†app[ฯ†overload -,
                       ฯ†synthesis for _ (%synthesis_arith)
                                  and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x - y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_asub (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„ค โŸผ ๐—๐–บ๐—… x - y โฆ‚ โ„ค โฆ„โ€บ
  unfolding op_asub_def Premise_def
  by (cases vx; cases vy; simp, rule, rule, simp add: Premise_def,
      rule, simp add: Premise_def, rule, simp)

lemma op_sub_anat_ฯ†app[ฯ†overload -,
                       ฯ†synthesis for _ (%synthesis_arith)
                                  and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x - y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐–พ๐—†๐—‚๐—Œ๐–พ y โ‰ค x
โŸน ๐—‰๐—‹๐—ˆ๐–ผ op_asub (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„• โŸผ ๐—๐–บ๐—… x - y โฆ‚ โ„• โฆ„โ€บ
  โด op_sub_aint โต .


paragraph โ€นNegationโ€บ

lemma op_neg_aint_ฯ†app
  [ฯ†overload ~,
   ฯ†synthesis for _ (%synthesis_arith)
              and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. - x โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_aneg rv โฆƒ x โฆ‚ ๐—๐–บ๐—…[rv] โ„ค โŸผ ๐—๐–บ๐—… -x โฆ‚ โ„ค โฆ„ โ€บ
  unfolding op_aneg_def Premise_def
  by (cases rv; simp, rule, simp add: Premise_def, rule, simp)


paragraph โ€นTimesโ€บ

lemma op_mul_aint[ฯ†overload *,
                  ฯ†synthesis for _ (%synthesis_arith)
                             and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x * y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_amul (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„ค โŸผ ๐—๐–บ๐—… x * y โฆ‚ โ„ค โฆ„โ€บ
  unfolding op_amul_def
  by (cases vx; cases vy; simp, rule, rule, simp add: Premise_def,
      rule, simp add: Premise_def, rule, simp)

lemma op_mul_anat[ฯ†overload *,
                  ฯ†synthesis for _ (%synthesis_arith)
                             and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x * y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_amul (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„• โŸผ ๐—๐–บ๐—… x * y โฆ‚ โ„• โฆ„โ€บ
  โด op_mul_aint โต
      certified by (simp add: nat_mult_distrib) .


paragraph โ€นDivisionโ€บ

lemma op_udiv_aint_ฯ†app[ฯ†overload /,
                        ฯ†synthesis for _ (%synthesis_arith)
                                   and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x div y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_adiv (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„ค โŸผ ๐—๐–บ๐—… x div y โฆ‚ โ„ค โฆ„โ€บ
  unfolding op_adiv_def
  by (cases vx; cases vy; simp, rule, rule, simp add: Premise_def, rule, simp add: Premise_def,
      rule, simp)

lemma op_udiv_anat_ฯ†app[ฯ†overload /,
                        ฯ†synthesis for _ (%synthesis_arith)
                                   and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x div y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_adiv (ฯ†V_pair vx vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„• โŸผ ๐—๐–บ๐—… x div y โฆ‚ โ„• โฆ„โ€บ
  โด op_udiv_aint โต
      certified by (simp add: div_int_pos_iff nat_div_distrib) .


paragraph โ€นModuloโ€บ

lemma op_mod_aint_ฯ†app[ฯ†overload %,
                       ฯ†synthesis for _ (%synthesis_arith)
                                  and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x mod y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_amod (vx, vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„ค โŸผ ๐—๐–บ๐—… x mod y โฆ‚ โ„ค โฆ„โ€บ
  unfolding op_amod_def
  by (cases vx; cases vy; simp, rule, rule, simp add: Premise_def, rule, simp add: Premise_def,
      rule, simp)

lemma op_mod_anat_ฯ†app[ฯ†overload %,
                       ฯ†synthesis for _ (%synthesis_arith)
                                  and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x mod y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_amod (vx, vy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[vx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[vy] โ„• โŸผ ๐—๐–บ๐—… x mod y โฆ‚ โ„• โฆ„โ€บ
  โด op_mod_aint โต
      certified by (metis nat_int of_nat_0_le_iff zmod_int) .
    


paragraph โ€นRight Shiftโ€บ

lemma op_lshr_aint_pre_ฯ†app:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_alshr (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„ค โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„ค โŸผ ๐—๐–บ๐—… drop_bit (nat y) x โฆ‚ โ„ค โฆ„โ€บ
  unfolding op_alshr_def Premise_def
  by (cases raw1; cases raw2; simp; rule, rule, simp, rule, simp, simp,
      rule, simp, insert drop_bit_int_def, presburger)

lemma op_push_bit_right_aint_ฯ†app[ฯ†synthesis for _ (%synthesis_arith)
                                   and โ€นx โฆ‚ ๐—๐–บ๐—… โ„ค โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. drop_bit y x โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshr (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„ค โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… drop_bit y x โฆ‚ โ„ค โฆ„โ€บ
  โด op_lshr_aint_pre โต.

lemma op_lshr_aint_ฯ†app[ฯ†overload >>]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshr (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„ค โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… x div 2 ^ y โฆ‚ โ„ค โฆ„โ€บ
  โด op_lshr_aint_pre โต
      certified using drop_bit_int_def by blast .

lemma op_push_bit_right_anat_ฯ†app[ฯ†synthesis for _ (%synthesis_arith)
                                      and โ€นx โฆ‚ ๐—๐–บ๐—… โ„• โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปret. drop_bit y x โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshr (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„• โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… drop_bit y x โฆ‚ โ„• โฆ„โ€บ
  โด op_push_bit_right_aint โต
      certified by (simp add: drop_bit_of_nat)  .

lemma op_lshr_anat_ฯ†app[ฯ†overload >>]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshr (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„• โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… x div 2 ^ y โฆ‚ โ„• โฆ„โ€บ
  โด op_lshr_aint โต
      certified by (metis nat_int of_nat_0_le_iff of_nat_numeral of_nat_power zdiv_int) . 


paragraph โ€นLeft Shiftโ€บ

lemma op_lshl_aint_pre_ฯ†app:
  โ€น ๐—‰๐—‹๐—ˆ๐–ผ op_alshl (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„ค โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„ค โŸผ ๐—๐–บ๐—… push_bit (nat y) x โฆ‚ โ„ค โฆ„โ€บ
  unfolding op_alshl_def Premise_def
  by (cases raw1; cases raw2; simp; rule, rule, simp, rule, simp, rule, simp add: push_bit_int_def)

lemma op_push_bit_left_aint_ฯ†app[ฯ†synthesis for _ (%synthesis_arith)
                                   and โ€นx โฆ‚ ๐—๐–บ๐—… โ„ค โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. push_bit y x โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshl (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„ค โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… push_bit y x โฆ‚ โ„ค โฆ„โ€บ
  โด op_lshl_aint_pre โต.

lemma op_lshl_aint_ฯ†app[ฯ†overload <<]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshl (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„ค โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… x * 2 ^ y โฆ‚ โ„ค โฆ„โ€บ
  โด op_lshl_aint_pre โต certified by (simp add: push_bit_eq_mult) .

lemma op_push_bit_left_anat_ฯ†app[ฯ†synthesis for _ (%synthesis_arith)
                                   and โ€นx โฆ‚ ๐—๐–บ๐—… โ„• โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. push_bit y x โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshl (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„• โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… push_bit y x โฆ‚ โ„• โฆ„โ€บ
  โด op_push_bit_left_aint โต
      certified by (simp add: push_bit_of_nat) .

lemma op_lshl_anat_ฯ†app[ฯ†overload <<]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_alshl (raw1, raw2) โฆƒ x โฆ‚ ๐—๐–บ๐—…[raw1] โ„• โŸ y โฆ‚ ๐—๐–บ๐—…[raw2] โ„• โŸผ ๐—๐–บ๐—… x * 2 ^ y โฆ‚ โ„• โฆ„โ€บ
  โด op_lshl_aint โต
      certified by (simp add: nat_mult_distrib) .


paragraph โ€นLess Thanโ€บ

lemma op_lt_aint[ฯ†overload <,
                 ฯ†synthesis for _ (%synthesis_arith)
                            and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x < y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_a_lt (rawx, rawy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[rawx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[rawy] โ„ค โŸผ ๐—๐–บ๐—… x < y โฆ‚ ๐”น โฆ„โ€บ
  unfolding op_a_lt_def
  by (cases rawx; cases rawy; simp, rule, rule, simp, rule, simp, rule, simp)

lemma op_lt_anat[ฯ†overload <,
                 ฯ†synthesis for _ (%synthesis_arith)
                            and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x < y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_a_lt (rawx, rawy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[rawx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[rawy] โ„• โŸผ ๐—๐–บ๐—… x < y โฆ‚ ๐”น โฆ„โ€บ
  โด op_lt_aint โต.

setup โ€นContext.theory_map (Generic_Variable_Access.Process_of_Argument.put NONE)โ€บ

thm "<_ฯ†app"

proc (nodef) op_gt_aint[ฯ†overload >]:
  input  โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ
  output โ€น๐—๐–บ๐—… x > y โฆ‚ ๐”นโ€บ
โด
  $y < $x
โต.

proc (nodef) op_gt_anat[ฯ†overload >]:
  input  โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ
  output โ€น๐—๐–บ๐—… x > y โฆ‚ ๐”นโ€บ
โด
  $y < $x
โต.

setup โ€นContext.theory_map (Generic_Variable_Access.Process_of_Argument.put
                                          (SOME Generic_Variable_Access.store_value_no_clean))โ€บ

paragraph โ€นLess Equalโ€บ

lemma op_le_aint_ฯ†app[ฯ†overload โ‰ค,
                      ฯ†synthesis for _ (%synthesis_arith)
                                 and โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ โ‡’ โ€นฮปv. x โ‰ค y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_a_le (rawx, rawy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[rawx] โ„คโŸ y โฆ‚ ๐—๐–บ๐—…[rawy] โ„ค โŸผ ๐—๐–บ๐—… x โ‰ค y โฆ‚ ๐”น โฆ„โ€บ
  unfolding op_a_le_def
  by (cases rawx; cases rawy; simp, rule, rule, simp add: Premise_def,
      rule, simp add: Premise_def, rule, simp)

lemma op_le_anat_ฯ†app[ฯ†overload โ‰ค,
                      ฯ†synthesis for _ (%synthesis_arith)
                                 and โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ โ‡’ โ€นฮปv. x โ‰ค y โฆ‚ _โ€บ (%synthesis_arith_cut)]:
  โ€น๐—‰๐—‹๐—ˆ๐–ผ op_a_le (rawx, rawy) โฆƒ x โฆ‚ ๐—๐–บ๐—…[rawx] โ„•โŸ y โฆ‚ ๐—๐–บ๐—…[rawy] โ„• โŸผ ๐—๐–บ๐—… x โ‰ค y โฆ‚ ๐”น โฆ„โ€บ
  โด op_le_aint โต.


setup โ€นContext.theory_map (Generic_Variable_Access.Process_of_Argument.put NONE)โ€บ


proc (nodef) op_ge_aint[ฯ†overload โ‰ฅ]:
  input  โ€นx โฆ‚ ๐—๐–บ๐—… โ„คโŸ y โฆ‚ ๐—๐–บ๐—… โ„คโ€บ
  output โ€น๐—๐–บ๐—… x โ‰ฅ y โฆ‚ ๐”นโ€บ
โด
  $y โ‰ค $x
โต.

proc (nodef) op_ge_anat[ฯ†overload โ‰ฅ]:
  input  โ€นx โฆ‚ ๐—๐–บ๐—… โ„•โŸ y โฆ‚ ๐—๐–บ๐—… โ„•โ€บ
  output โ€น๐—๐–บ๐—… x โ‰ฅ y โฆ‚ ๐”นโ€บ
โด
  $y โ‰ค $x
โต.

end