(** Why3 driver for Colibri (with floating point support) *)

prelude ";; produced by local colibri2.drv ;;"
prelude "(set-logic ALL)"
prelude "(set-info :smt-lib-version 2.6)"

filename "%f-%t-%g.psmt2"
unknown "^\\(unknown\\|sat\\|Fail\\)$" "\\1"
unknown "^(:reason-unknown \\([^)]*\\))$" "\\1"
time "why3cpulimit time : %s s"
valid "^unsat$"
steplimitexceeded "steplimitreached"
steps "^(steps \\([0-9]+.?[0-9]*\\))" 1

printer "smtv2.6par"

transformation "monomorphise_goal"
transformation "eliminate_builtin"
transformation "compile_match"
(* transformation "inline_trivial" *)
transformation "simplify_formula"
transformation "eliminate_inductive"
transformation "eliminate_literal"
transformation "eliminate_epsilon"


theory BuiltIn
  syntax type int   "Int"
  syntax type real  "Real"
  syntax predicate (=)  "(= %1 %2)"

end

theory int.Int

  prelude ";;; SMT-LIB2: integer arithmetic"

  syntax function zero "0"
  syntax function one  "1"

  syntax function (+)  "(+ %1 %2)"
  syntax function (-)  "(- %1 %2)"
  syntax function (*)  "(* %1 %2)"
  syntax function (-_) "(- %1)"

  syntax predicate (<=) "(<= %1 %2)"
  syntax predicate (<)  "(< %1 %2)"
  syntax predicate (>=) "(>= %1 %2)"
  syntax predicate (>)  "(> %1 %2)"

  remove prop MulComm.Comm
  remove prop MulAssoc.Assoc
  remove prop Unit_def_l
  remove prop Unit_def_r
  remove prop Inv_def_l
  remove prop Inv_def_r
  remove prop Assoc
  remove prop Mul_distr_l
  remove prop Mul_distr_r
  remove prop Comm
  remove prop Unitary
  remove prop Refl
  remove prop Trans
  remove prop Antisymm
  remove prop Total
  remove prop NonTrivialRing
  remove prop CompatOrderAdd
  remove prop CompatOrderMult
  remove prop ZeroLessOne

end

theory real.Real

  prelude ";;; SMT-LIB2: real arithmetic"

  syntax function zero "0.0"
  syntax function one  "1.0"

  syntax function (+)  "(+ %1 %2)"
  syntax function (-)  "(- %1 %2)"
  syntax function (*)  "(* %1 %2)"
  syntax function (/)  "(/ %1 %2)"
  syntax function (-_) "(- %1)"
  syntax function inv  "(/ 1.0 %1)"

  syntax predicate (<=) "(<= %1 %2)"
  syntax predicate (<)  "(< %1 %2)"
  syntax predicate (>=) "(>= %1 %2)"
  syntax predicate (>)  "(> %1 %2)"

  remove prop MulComm.Comm
  remove prop MulAssoc.Assoc
  remove prop Unit_def_l
  remove prop Unit_def_r
  remove prop Inv_def_l
  remove prop Inv_def_r
  remove prop Assoc
  remove prop Mul_distr_l
  remove prop Mul_distr_r
  remove prop Comm
  remove prop Unitary
  remove prop Inverse
  remove prop Refl
  remove prop Trans
  remove prop Antisymm
  remove prop Total
  remove prop NonTrivialRing
  remove prop CompatOrderAdd
  remove prop CompatOrderMult
  remove prop ZeroLessOne

end

theory real.Square
  syntax function sqrt "(colibri_sqrt %1)"

end

theory real.FromInt
  syntax function from_int "(to_real %1)"

  (* remove allprops *)
end

theory real.Abs
  syntax function abs "(colibri_abs_real %1)"
end

theory int.Abs
  syntax function abs "(colibri_abs_int %1)"
end

theory int.EuclideanDivision
  syntax function div "(div %1 %2)"
  syntax function mod "(mod %1 %2)"
end

theory int.ComputerDivision
  syntax function div "(colibri_cdiv %1 %2)"
  syntax function mod "(colibri_crem %1 %2)"
end


(*
theory real.MinMax

  remove allprops
end
*)

theory real.Truncate
  syntax function floor "(to_int %1)"
  syntax function ceil "(- (to_int (- %1)))"

  (* remove allprops *)
end


theory Bool
  syntax type     bool  "Bool"
  syntax function True  "true"
  syntax function False "false"
end

theory bool.Bool
  syntax function andb  "(and %1 %2)"
  syntax function orb   "(or %1 %2)"
  syntax function xorb  "(xor %1 %2)"
  syntax function notb  "(not %1)"
  syntax function implb "(=> %1 %2)"
end

theory bool.Ite
  syntax function ite "(ite %1 %2 %3)"
end
