# Standard functions

### 5.16.2 Standard functions

- The max command finds the maximum of a sequence of real numbers.
  - max takes an arbitrary number of arguments:
    seq, a sequence (or list) of real numbers.
  - max(seq) returns the largest number in the sequence seq.

  #### Example.

  Input:

  max(0,1,2,-1,-2)

  Output:

  2

- The min command finds the minimum of a sequence of real numbers.
  - min takes an arbitrary number of arguments:
    seq, a sequence (or list) of real numbers.
  - min(seq) returns the smallest number in the sequence seq.

  #### Example.

  Input:

  min(0,1,2,-1,-2)

  Output:

  −2

- The abs command finds the absolute value of a real or complex number.
  - abs takes one argument:
    x, a real or complex number.
  - abs(x) returns the absolute value of x.

  #### Examples.

  - Input:
    abs(-5)
    Output:

    5

  - Input:
    abs(3+4*i)
    Output:

    5

- The sign command finds the sign of a real number (+1 if it is positive, 0 if it is zero, and -1 if it is negative).
  - sign takes one argument:
    x, a real number.
  - sign(x) returns the sign of x.

  #### Examples.

  - Input:
    sign(-4)
    Output:

    −1

  - Input:
    sign(0)
    Output:

    0

- The floor command finds the floor of a real number; namely, the largest integer less than or equal to the number.
  iPart) is a synonym for floor.
  - floor takes one argument:
    x, a real number.
  - floor(x) returns the floor of x.

  #### Examples.

  - Input:
    floor(4.1)
    Output:

    4

  - Input:
    floor(-4.1)
    Output:

    −5

- The round command rounds a number to the nearest integer, rounding up in the case of a half-integer.
  - round takes one argument:
    x, a real number.
  - round(x) returns the nearest integer to x.

  #### Examples.

  - Input:
    round(3.4)
    Output:

    3

  - Input:
    round(-3.4)
    Output:

    −3

  - Input:
    round(3.5)
    Output:

    4

- The ceil command finds the ceiling of a real number; namely, the smallest integer greater than or equal to the number.
  ceiling is a synonym for ceil.
  - ceil takes one argument:
    x, a real number.
  - ceil(x) returns the ceiling of x.

  #### Examples.

  - Input:
    ceiling(4.1)
    Output:

    5

  - Input:
    ceiling(-4.1)
    Output:

    −4

- The frac command finds the fractional part of a number; informally, the part of the number to the right of the decimal point with the appropriate plus or minus sign. For a positive real number x, the fractional part is x minus the floor of x; for a negative real number x, the fractional part is x minus the ceiling of x.
  fPart is a synonym for frac.
  - frac takes one argument:
    x, a real number.
  - frac(x) returns the fractional part of x.

  #### Examples.

  - Input:
    frac(3.24)
    Output:

    0.24

  - Input:
    frac(-3.24)
    Output:

    −0.24

- The trunc command truncates a real number; namely, it removes the fractional part. The truncated number added to the fractional part will equal the original number.
  - trunc takes one argument:
    x, a real number.
  - trunc(x) returns the truncated value of x.

  #### Examples.

  - Input:
    trunc(3.24)
    Output:

    3

  - Input:
    trunc(-3.24)
    Output:

    −3

- The id command is the identity function.
  - id takes one argument or a sequence of arguments:
    seq, whose elements can be any type.
  - id(seq) returns seq.

  #### Example.

- Input:
  id(a,1,"abc",[1,2,3])
  Output:

  a,1,"abc", | ⎡ ⎣ | 1,2,3 | ⎤ ⎦

- The sq command squares its argument.
  - sq takes one argument:
    x, any object that can be multiplied by itself.
  - sq(x) returns x2.

  #### Examples.

  - Input:
    sq(5)
    Output:

    25

  - Input:
    sq(x+y)
    Output:

    | ⎛ ⎝ | x+y | ⎞ ⎠ | 2

  - Input:
    sq([[1,2],[3,4]])
    (This is a matrix product; see Section 5.44).
    Output:

    ⎡
    ⎢
    ⎣

    7 | 10
    15 | 22

    ⎤
    ⎥
    ⎦

  - Input:
    sq([1,2,3])
    (This is the dot product of [1,2,3] with itself.)
    Output:

    14

- The sqrt command finds the square root of its argument.
  - sqrt takes one argument:
    x, any object for which the 1/2 power makes sense.
  - sqrt(x) returns x1/2.

  #### Examples.

  - Input:
    sqrt(9)
    Output:

    3

  - Input:
    sqrt((x+y)^2)
    Output:

    | ⎪ ⎪ | x+y | ⎪ ⎪

  - Input:
    simplify(sqrt([[2,3],[3,5]]))
    Output:

    ⎡
    ⎢
    ⎣

    1 | 1
    1 | 2

    ⎤
    ⎥
    ⎦

- The surd command finds roots of quantities.
  - surd takes two arguments:
    x and n, numbers.
  - surd(x,n) returns the nth root of x; i.e., x1/n.

  #### Example.

- Input:
  surd(15.625,3)
  Output:

  2.5

- The exp command computes the exponential function.
  - exp takes one argument:
    x, a number.
  - exp(x) returns ex.

  #### Example.

  Input:

  exp(1.0)

  Output:

  2.71828182846

- The log command computes the natural logarithm function.
  ln is a synonym for log.
  - log takes one argument:
    x, a number.
  - log(x) returns the natural logarithm of x.

  #### Example.

  Input:

  log(2.0)

  Output:

  0.69314718056

- The log10 computes the the base-10 logarithm.
  - log10 takes one argument:
    x, a number.
  - log10(x) returns the base-10 logarithm of x.

  #### Example.

  Input:

  log10(1000)

  Output:

  3

- The logb computes the logarithm to a specified base.
  - logb takes two arguments:
    x and b, non-zero numbers.
  - logb(x,b) returns the base-b logarithm of x.

  #### Example.

  Input:

  logb(10.0,2)

  Output:

  3.32192809489

- The standard trigonometric functions:
  - The sin command is the sine function.
  - The cos command is the cosine function.
  - The tan command is the tangent function (tan(x)= sin(x)/cos(x)).
  - The cot command is the cotangent function (cot(x)= cos(x)/sin(x)).
  - The sec command is the secant function (sec(x)= 1/cos(x)).
  - The csc command is the cosecant function (csc(x) = 1/sin(x)).
  - These commands take one argument: x, a number.
    The number x will by default represent an angle measured in radians, but you can set Xcas to use degrees (see Section 2.5.3) by setting the variable angle_radian to 0; resetting it to 1 will change the angle measure to radians again.
  - sin(x) returns the sine of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      sin(pi/4)
      Output:

      √

      2

      2

    - Input (with angle_radian equal to 0):
      sin(30)
      Output:

      1
      2

  - cos(x) returns the cosine of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      cos(pi/6)
      Output:

      √

      3

      2

    - Input (with angle_radian equal to 0):
      cos(90)
      Output:

      0

  - tan(x) returns the tangent of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      tan(pi/4)
      Output:

      1

    - Input (with angle_radian equal to 0):
      tan(60)
      Output:

      √

      3

  - cot(x) returns the cotangent of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      cot(pi/6)
      Output:

      2

      √

      3

      2

    - Input (with angle_radian equal to 0):
      cot(45)
      Output:

      1

  - sec(x) returns the secant of x.

    #### Example.

    - Input (with angle_radian equal to 1):
      sec(pi/3)
      Output:

      2

    - Input (with angle_radian equal to 0):
      sec(30)
      Output:

      2

      √

      3

  - csc(x) returns the cosecant of x.
    Examples.
    - Input (with angle_radian equal to 1):
      csc(pi/4)
      Output:

      2

      √

      2

    - Input (with angle_radian equal to 0):
      csc(30)
      Output:

      2

- The asin, acos, atan, acot, asec, acsc commands are the inverse trigonometric functions. The latter are defined by:
  - asec(x) = acos(1/x),
  - acsc(x) = asin(1/x),
  - acot(x) = atan(1/x).
  arcsin is a synonym for asin.
  arccos is a synonym for acos.
  arctan is a synonym for atan.
  - These functions take one argument: x, a number.
    They return a number which can represent an angle; by default, the angles will be in radians, but you can set Xcas to use degrees (see Section 2.5.3) by setting the variable angle_radian to 0; resetting it to 1 will change the angle measure to radians again.
  - asin(x) returns the arcsine of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      asin(1/2)
      Output:

      π
      6

    - Input (with angle_radian equal to 0):
      asin(1)
      Output:

      π
      2

  - acos(x) returns the arccosine of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      acos(sqrt(3)/2)
      Output:

      1
      6

      π

    - Input (with angle_radian equal to 0):
      acos(-1/2)
      Output:

      120

  - atan(x) returns the arctangent of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      atan(sqrt(3))
      Output:

      π
      3

    - Input (with angle_radian equal to 1):
      atan(1)
      Output:

      45

  - acot(x) returns the arccotangent of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      acot(sqrt(3))
      Output:

      π
      6

    - Input (with angle_radian equal to 0):
      acot(1/sqrt(3))
      Output:

      60

  - asec(x) returns the arcsecant of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      asec(1)
      Output:

      0

    - Input (with angle_radian equal to 0):
      asec(sqrt(2))
      Output:

      45

  - acsc(x) returns the arccosecant of x.

    #### Examples.

    - Input (with angle_radian equal to 1):
      acsc(1)
      Output:

      π
      2

    - Input (with angle_radian equal to 0):
      acsc(2)
      Output:

      30

- The sinh, cosh, and tanh commands compute the hyperbolic sine, hyperbolic cosine, and hyperbolic tangent functions.
  - These functions take one argument:
    x, a number.
  - sinh(x) returns the hyperbolic sine of x.

    #### Example.

    Input:

    sinh(1.0)

    Output:

    1.17520119364

  - cosh(x) returns the hyperbolic cosine of x.

    #### Example.

    Input:

    cosh(0)

    Output:

    1

  - tanh(x) returns the hyperbolic tangent of x.

    #### Example.

    Input:

    tanh(-1.0)

    Output:

    −0.761594155956

- The asinh, acosh, and atanh commands compute the inverse hyperbolic functions.
  arcsinh is a synonym for asinh.
  arccosh is a synonym for acosh.
  arctanh is a synonym for atanh.
  - These functions take one argument:
    x, a number.
  - asinh(x) returns the inverse hyperbolic sine of x.

    #### Example.

    Input:

    asinh(2)

    Output:

    ln

    ⎛
    ⎜
    ⎝

    2+

    √

    5

    ⎞
    ⎟
    ⎠

  - acosh(x) returns the inverse hyperbolic cosine of x.

    #### Example.

    Input:

    acosh(1)

    Output:

    0

  - atanh(x) returns the inverse hyperbolic tangent of x.

    #### Example.

    Input:

    atanh(1/2)

    Output:

    ln | ⎛ ⎝ | 3 | ⎞ ⎠

    2