--  Ada.Numerics.Generic_Elementary_Functions (RM A.5.1), the functions Verada provides, with
--  the contracts the prover uses: their domains as preconditions, and bounds of their results.
--  The values come from the C library (correctly rounded to within an ulp or so), so the
--  contracts are trusted, like the rest of the predefined library.
generic
   type Float_Type is digits <>;
package Ada.Numerics.Generic_Elementary_Functions is
   function Sqrt (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X >= 0.0,
          Post => Sqrt'Result >= 0.0 and then Sqrt'Result <= (if X <= 1.0 then 1.0 else X);

   function Exp (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X <= 80.0,
          Post => Exp'Result >= 0.0;

   function Log (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X > 0.0,
          Post => Log'Result in -800.0 .. 800.0
                  and then (if X >= 2.0 then Log'Result >= 0.69)
                  and then (if X <= 0.5 then Log'Result <= -0.69);

   function Sin (X : Float_Type) return Float_Type
     with Global => null,
          Post => Sin'Result in -1.0 .. 1.0;

   function Cos (X : Float_Type) return Float_Type
     with Global => null,
          Post => Cos'Result in -1.0 .. 1.0;

   --  the logarithm of X to a base (as APL's `a ⍟ b`, the logarithm of b to the base a)
   function Log (X, Base : Float_Type) return Float_Type
     with Global => null,
          Pre => X > 0.0 and then (Base >= 2.0 or else (Base > 0.0 and then Base <= 0.5));

   function Tan (X : Float_Type) return Float_Type
     with Global => null,
          Post => Tan'Result in -1.0E17 .. 1.0E17;

   function Arcsin (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X in -1.0 .. 1.0,
          Post => Arcsin'Result in -1.6 .. 1.6;

   function Arccos (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X in -1.0 .. 1.0,
          Post => Arccos'Result in 0.0 .. 3.2;

   function Arctan (X : Float_Type) return Float_Type
     with Global => null,
          Post => Arctan'Result in -1.6 .. 1.6;

   function Sinh (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X in -80.0 .. 80.0,
          Post => Sinh'Result in -3.0E34 .. 3.0E34;

   function Cosh (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X in -80.0 .. 80.0,
          Post => Cosh'Result in 1.0 .. 3.0E34;

   function Tanh (X : Float_Type) return Float_Type
     with Global => null,
          Post => Tanh'Result in -1.0 .. 1.0;

   function Arcsinh (X : Float_Type) return Float_Type
     with Global => null,
          Post => Arcsinh'Result in -800.0 .. 800.0;

   function Arccosh (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X >= 1.0,
          Post => Arccosh'Result in 0.0 .. 800.0;

   function Arctanh (X : Float_Type) return Float_Type
     with Global => null,
          Pre => X > -1.0 and then X < 1.0,
          Post => Arctanh'Result in -800.0 .. 800.0;
end Ada.Numerics.Generic_Elementary_Functions;
