Arithm: Arithmetic Operations on Integers

      $func Add     s.Int1 s.Int2 = s.Int;
      $func Sub     s.Int1 s.Int2 = s.Int;
      $func Mult    s.Int1 s.Int2 = s.Int;
      $func DivRem  s.Int1 s.Int2 = s.Quo s.Rem;
      $func Div     s.Int1 s.Int2 = s.Quo;
      $func Rem     s.Int1 s.Int2 = s.Rem;
      $func GCD     s.Int1 s.Int2 = s.GCD;

These functions provide operations on signed integers of arbitrary size. Each of the arguments of the arithmetic functions must be a single numeric symbol.

If one of the arguments of an arithmetic function is not a numeric symbols, the function returns the error $error(Fname "Invalid argument"), where Fname is the function's name.

If both arguments of an arithmetic function are numeric symbols, the function produces the result, depending on the function.

Add returns the sum of its arguments, Sub the difference of its arguments, Mult the product of its arguments, Div and Rem respectively the quotient and the remainder of its arguments, DivRem both the quotient and the remainder of its arguments, GCD the greatest common divisor of its arguments.

If the result produced by one of the operations Add, Sub, or Mult exceeds the size limit imposed by the Refal Plus implementation, the value returned is the error $error(Fname "Size limit exceeded"), where Fname is the function's name.

For example:

      <Add 3 5>      =>   8
      <Add 3 -5>     =>   -2
      <Sub 3 -5>     =>   8
      <Mult -2 3>    =>   -6
      <Div 5 2>      =>   2
      <Rem 5 2>      =>   1
      <DivRem 5 2>   =>   2 1
      <Div 6 2>      =>   3
      <Rem 6 2>      =>   0
      <DivRem 6 2>   =>   3 0

The signs of the quotient and the remainder are determined according to the following rule. If the sign of the dividend is the same as that of the divisor, the quotient must be positive, otherwise the quotient must be negative. The sign of the remainder must be the same as that of the dividend. Thus, there must always hold the equation

      dividend = (quotient * divisor) + remainder

For example:

      <Div  5  3>    =>   1 
      <Rem  5  3>    =>   2 
      <Div  5 -3>    =>  -1 
      <Rem  5 -3>    =>   2 
      <Div -5  3>    =>  -1 
      <Rem -5  3>    =>  -2 
      <Div -5 -3>    =>   1 
      <Rem -5 -3>    =>  -2 

An attempt at dividing a number by zero results in returning the error $error(Fname "Divide by zero"), where Fname is the function's name. For example:

      <Div 5 0>      =>   $error(Div "Divide by zero")
      <Rem 5 0>      =>   $error(Rem "Divide by zero")
      <DivRem 5 0>   =>   $error(DivRem "Divide by zero")

The function GCD, unless both its arguments are equal to zero, returns a positive integer, the greatest common divisor of its arguments. Otherwise, if both arguments are equal to zero, the result is the error $error(GCD "Zero arguments"). For example:

      <GCD  6 15>    =>   3 
      <GCD -6 15>    =>   3 
      <GCD 15 1>     =>   1 
      <GCD 15 0>     =>  15 
      <GCD  0 0>     =>   $error(GCD "Zero arguments")