File : balls.ads


with Ada.Text_IO, Reps;
use Ada.Text_IO, Reps;

pragma Elaborate (Reps);

package Balls is -- balls in a commutative Banach algebra with unit

  pragma Elaborate_Body;

  type Ball is private;

--- basic
  function IsNumeric(S: Ball) return Boolean;
  function IsSharp(S: Ball) return Boolean;
  function IsNumbers(S: Ball) return Boolean;
  procedure ModNumbers(S: in out Ball);
  procedure ToBalls(S: in out Ball);
  function Approx(S: Ball) return Rep;

  pragma Inline (IsNumbers,ModNumbers,Approx);

--- sets
  function Center0(S: Ball) return Boolean;
  function Contains0(S: Ball) return Boolean;
  function Contains(S1,S2: Ball) return Boolean;
  function BallAt0(R: Rep) return Ball;
  function BallAt0(S: Ball) return Ball;
  function DiskAt0(R: Rep) return Ball;
  function DiskAt0(S: Ball) return Ball;
  function Disk(R1,R2: Rep) return Ball;
  function Disk(S: Ball) return Ball;
  function Center(S: Ball) return Ball;
  function CenterDisk(S: Ball) return Ball;
  function ModCenter(S: Ball) return Ball;
  function Union(S1,S2: Ball) return Ball;
  function Intersection(S1,S2: Ball) return Ball;

  pragma Inline (Center0,Center,CenterDisk,ModCenter);

--- order
  function "<"(S1,S2: Ball) return Boolean;
  function "<="(S1,S2: Ball) return Boolean;
  function ">"(S1,S2: Ball) return Boolean;
  function ">="(S1,S2: Ball) return Boolean;
  function Min(S1,S2: Ball) return Ball;
  function Max(S1,S2: Ball) return Ball;
  function Inf(S: Ball) return Rep;
  function Sup(S: Ball) return Rep;

--- addition and multiplication etc.
  function IsZero(S: Ball) return Boolean;
  procedure SetZero(S: out Ball);
  procedure Neg(S: in out Ball);
  procedure Neg(S1: in Ball; S2: out Ball);
  function "-"(S: Ball) return Ball;
  procedure Add(S1: in Ball; S2: in out Ball);
  procedure Sum(S1,S2: in Ball; S3: out Ball);
  function "+"(S1,S2: Ball) return Ball;
  procedure Sub(S1: in Ball; S2: in out Ball);
  procedure Diff(S1,S2: in Ball; S3: out Ball);
  function "-"(S1,S2: Ball) return Ball;
  procedure Mult(I: in Integer; S: in out Ball);
  procedure Prod(I: in Integer; S1: in Ball; S2: out Ball);
  function "*"(I: Integer; S: Ball) return Ball;
  procedure MultAdd(I: Integer; S1: in Ball; S2: in out Ball);
  procedure Mult(R: in Rep; S: in out Ball);
  procedure Prod(R: in Rep; S1: in Ball; S2: out Ball);
  function "*"(R: Rep; S: Ball) return Ball;
  procedure MultAdd(R: in Rep; S1: in Ball; S2: in out Ball);
  procedure Mult(S1: in Ball; S2: in out Ball);
  procedure Prod(S1,S2: in Ball; S3: out Ball);
  function "*"(S1,S2: Ball) return Ball;
  procedure MultAdd(S1,S2: in Ball; S3: in out Ball);
  function "/"(S: Ball; R: Rep) return Ball;
  procedure Inv(S1: in Ball; S2: out Ball);
  function Inv(S: Ball) return Ball;
  function "/"(S1,S2: Ball) return Ball;
  function "**"(S: Ball; I: Integer) return Ball;

  pragma Inline (IsZero,SetZero,Neg);

--- functions
  function Sqr(S: Ball) return Ball;
  function Norm(S: Ball) return Ball;
  function MaxNorm(S: Ball) return Radius;
  function Exp(S: Ball) return Ball;
  function Log(S: Ball) return Ball;
  function Sqrt(S: Ball) return Ball;

--- conversion and i/o
  function Scal(K: Integer) return Ball;
  function Scal(R: Rep) return Ball;
  procedure ShowType(S: in Ball);
  procedure Show1(N: in String; S: in Ball);
  procedure Show2(N: in String; S1,S2: in Ball);
  procedure Get(F: in File_Type; S: out Ball; Decimal: in Boolean := False);
  procedure Put(F: in File_Type; S: in Ball; Decimal: in Boolean := False);

--- auxiliary
  procedure UpMultAdd(R1,R2: in Rep; R3: in out Rep);

  pragma Inline (Scal,UpMultAdd);

private

  type Ball is      -- ball around constant
    record
      C: Rep;       -- center
      R: Rep;       -- number radius
      B: Rep;       -- general radius
    end record;

  function ExpUp(R: Rep) return Rep;
  function ExpDown(R: Rep) return Rep;

  NegOne:    constant Rep  := -One;
  Ball_Zero: constant Ball := (Zero,Zero,Zero);
  Ball_One:  constant Ball := (One,Zero,Zero);
  PlusMinus: constant Ball := (Zero,One,Zero);

  pragma Inline (Inf,Sup);

end Balls;