<!-- Sema documentation — math
     Sema is a new AI-native, neurosymbolic programming language most models
     have not been trained on. Full corpus: https://sema.49.12.246.95.sslip.io/llms-full.txt
     Install language support: https://sema.49.12.246.95.sslip.io/install-skill/ -->

# math

> Native scalar and tensor scientific-math operations.

> Generated by `sema doc` from the compiler's authoritative native-signature registry.

# math (native)

Scientific stdlib namespace — bring it in with `import math` (LANGUAGE §5.32).

# unary

## `math.cos(x) -> float | Tensor`

Cosine of x.

- domain: finite real x (radians)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.cos(0.5)`

## `math.sin(x) -> float | Tensor`

Sine of x.

- domain: finite real x (radians)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.sin(0.5)`

## `math.tan(x) -> float | Tensor`

Tangent of x.

- domain: finite real x (radians)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.tan(0.5)`

## `math.acos(x) -> float | Tensor`

Arc cosine, in radians.

- domain: x in [-1, 1]
- shape: elementwise
- returns: `float | Tensor`
- example: `math.acos(0.5)`

## `math.asin(x) -> float | Tensor`

Arc sine, in radians.

- domain: x in [-1, 1]
- shape: elementwise
- returns: `float | Tensor`
- example: `math.asin(0.5)`

## `math.atan(x) -> float | Tensor`

Arc tangent, in radians.

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.atan(0.5)`

## `math.cosh(x) -> float | Tensor`

Hyperbolic cosine.

- domain: finite real x; result must stay finite
- shape: elementwise
- returns: `float | Tensor`
- example: `math.cosh(0.5)`

## `math.sinh(x) -> float | Tensor`

Hyperbolic sine.

- domain: finite real x; result must stay finite
- shape: elementwise
- returns: `float | Tensor`
- example: `math.sinh(0.5)`

## `math.tanh(x) -> float | Tensor`

Hyperbolic tangent.

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.tanh(0.5)`

## `math.acosh(x) -> float | Tensor`

Inverse hyperbolic cosine.

- domain: x &gt;= 1
- shape: elementwise
- returns: `float | Tensor`
- example: `math.acosh(1.5)`

## `math.asinh(x) -> float | Tensor`

Inverse hyperbolic sine.

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.asinh(0.5)`

## `math.atanh(x) -> float | Tensor`

Inverse hyperbolic tangent.

- domain: x in (-1, 1)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.atanh(0.5)`

## `math.exp(x) -> float | Tensor`

e raised to x.

- domain: finite real x; result must stay finite
- shape: elementwise
- returns: `float | Tensor`
- example: `math.exp(1.0)`

## `math.exp2(x) -> float | Tensor`

2 raised to x.

- domain: finite real x; result must stay finite
- shape: elementwise
- returns: `float | Tensor`
- example: `math.exp2(3.0)`

## `math.expm1(x) -> float | Tensor`

exp(x) - 1, accurate near zero.

- domain: finite real x; result must stay finite
- shape: elementwise
- returns: `float | Tensor`
- example: `math.expm1(0.5)`

## `math.ln(x) -> float | Tensor`

Natural logarithm.

- domain: x &gt; 0
- shape: elementwise
- returns: `float | Tensor`
- example: `math.ln(2.0)`

## `math.log2(x) -> float | Tensor`

Base-2 logarithm.

- domain: x &gt; 0
- shape: elementwise
- returns: `float | Tensor`
- example: `math.log2(8.0)`

## `math.log10(x) -> float | Tensor`

Base-10 logarithm.

- domain: x &gt; 0
- shape: elementwise
- returns: `float | Tensor`
- example: `math.log10(100.0)`

## `math.log1p(x) -> float | Tensor`

ln(1 + x), accurate near zero.

- domain: x &gt; -1
- shape: elementwise
- returns: `float | Tensor`
- example: `math.log1p(0.5)`

## `math.sqrt(x) -> float | Tensor`

Square root.

- domain: x &gt;= 0
- shape: elementwise
- returns: `float | Tensor`
- example: `math.sqrt(2.0)`

## `math.cbrt(x) -> float | Tensor`

Cube root (defined for negative x).

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.cbrt(-8.0)`

## `math.abs(x) -> float | Tensor`

Absolute value (float kernel).

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.abs(-2.5)`

## `math.fabs(x) -> float | Tensor`

Absolute value (float kernel; alias of abs).

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.fabs(-2.5)`

## `math.fract(x) -> float | Tensor`

Fractional part (x - trunc(x)).

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.fract(2.75)`

## `math.degrees(x) -> float | Tensor`

Radians to degrees.

- domain: finite real x (radians)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.degrees(1.0)`

## `math.rad2deg(x) -> float | Tensor`

Radians to degrees (alias of degrees).

- domain: finite real x (radians)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.rad2deg(1.0)`

## `math.radians(x) -> float | Tensor`

Degrees to radians.

- domain: finite real x (degrees)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.radians(180.0)`

## `math.deg2rad(x) -> float | Tensor`

Degrees to radians (alias of radians).

- domain: finite real x (degrees)
- shape: elementwise
- returns: `float | Tensor`
- example: `math.deg2rad(180.0)`

## `math.recip(x) -> float | Tensor`

Reciprocal 1/x.

- domain: x != 0
- shape: elementwise
- returns: `float | Tensor`
- example: `math.recip(4.0)`

## `math.sign(x) -> float | Tensor`

Sign of x as -1.0, 0.0 (signed zero), or 1.0.

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.sign(-3.5)`

## `math.sgn(x) -> float | Tensor`

Sign of x (alias of sign).

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.sgn(-3.5)`

## `math.erf(x) -> float | Tensor`

Gauss error function.

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.erf(0.5)`

## `math.erfc(x) -> float | Tensor`

Complementary error function 1 - erf(x).

- domain: finite real x
- shape: elementwise
- returns: `float | Tensor`
- example: `math.erfc(0.5)`

## `math.gamma(x) -> float | Tensor`

Gamma function Γ(x).

- domain: finite real x, not a nonpositive integer; result must stay finite
- shape: elementwise
- returns: `float | Tensor`
- example: `math.gamma(4.5)`

## `math.lgamma(x) -> float | Tensor`

Natural log of |Γ(x)|.

- domain: finite real x, not a nonpositive integer
- shape: elementwise
- returns: `float | Tensor`
- example: `math.lgamma(4.5)`

## `math.log(x, base?) -> float | Tensor`

Natural logarithm, or the base-`base` logarithm with two arguments.

- domain: x &gt; 0; base &gt; 0 and base != 1 when given
- shape: elementwise
- returns: `float | Tensor`
- example: `math.log(81.0, 3.0)`

# binary

## `math.atan2(y, x) -> float | Tensor`

Arc tangent of y/x using both signs to pick the quadrant.

- domain: finite reals (signed zeros respected)
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.atan2(0.75, -0.25)`

## `math.hypot(x, y) -> float | Tensor`

Euclidean norm sqrt(x² + y²) without intermediate overflow.

- domain: finite reals; result must stay finite
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.hypot(3.0, 4.0)`

## `math.copysign(magnitude, sign) -> float | Tensor`

Magnitude of the first argument with the sign of the second.

- domain: finite reals
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.copysign(3.0, -0.0)`

## `math.pow(base, exponent) -> float | Tensor`

base raised to exponent (float power).

- domain: finite reals; negative base needs an integral exponent; result must stay finite
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.pow(2.0, 10.5)`

## `math.fmod(x, y) -> float | Tensor`

C-style remainder with the sign of x.

- domain: finite reals, y != 0
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.fmod(-7.5, 2.0)`

## `math.remainder(x, y) -> float | Tensor`

IEEE 754 remainder (nearest-multiple, ties to even).

- domain: finite reals, y != 0
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.remainder(7.0, 2.0)`

## `math.nextafter(x, toward) -> float | Tensor`

Next representable f64 after x toward the second argument.

- domain: finite reals
- shape: elementwise (binary broadcast)
- returns: `float | Tensor`
- example: `math.nextafter(1.0, 2.0)`

# integer

## `math.factorial(n) -> int`

n! with checked i64 overflow.

- domain: int 0 &lt;= n &lt;= 20 (i64 result)
- shape: scalar
- returns: `int`
- example: `math.factorial(12)`

## `math.comb(n, k) -> int`

Binomial coefficient C(n, k) with checked i64 overflow.

- domain: ints n &gt;= 0, k &gt;= 0 (0 when k &gt; n)
- shape: scalar
- returns: `int`
- example: `math.comb(10, 3)`

## `math.perm(n, k?) -> int`

Partial permutations P(n, k) with checked i64 overflow.

- domain: ints n &gt;= 0, k &gt;= 0 (k defaults to n; 0 when k &gt; n)
- shape: scalar
- returns: `int`
- example: `math.perm(10, 3)`

## `math.gcd(values...) -> int`

Greatest common divisor of the arguments.

- domain: any i64 ints (absolute values; 0 with no arguments)
- shape: scalar
- returns: `int`
- example: `math.gcd(12, 18, 30)`

## `math.lcm(values...) -> int`

Least common multiple of the arguments with checked i64 overflow.

- domain: any i64 ints (0 if any argument is 0); checked overflow
- shape: scalar
- returns: `int`
- example: `math.lcm(4, 6)`

## `math.isqrt(n) -> int`

Integer square root: floor of the exact square root.

- domain: int n &gt;= 0
- shape: scalar
- returns: `int`
- example: `math.isqrt(17)`

# rounding

## `math.floor(x) -> int | Tensor`

Largest integer &lt;= x.

- domain: finite scalar (exact for int/rational; i64-checked result) or tensor (stays f64)
- shape: elementwise
- returns: `int | Tensor`
- example: `math.floor(2.75)`

## `math.ceil(x) -> int | Tensor`

Smallest integer &gt;= x.

- domain: finite scalar (exact for int/rational; i64-checked result) or tensor (stays f64)
- shape: elementwise
- returns: `int | Tensor`
- example: `math.ceil(2.25)`

## `math.trunc(x) -> int | Tensor`

Integer part of x (toward zero).

- domain: finite scalar (exact for int/rational; i64-checked result) or tensor (stays f64)
- shape: elementwise
- returns: `int | Tensor`
- example: `math.trunc(-2.75)`

## `math.round(x) -> int | Tensor`

Nearest integer, ties to even.

- domain: finite scalar (exact for int/rational; i64-checked result) or tensor (stays f64)
- shape: elementwise
- returns: `int | Tensor`
- example: `math.round(2.5)`

# tensor

## `math.tensor(data) -> Tensor`

Build a typed Tensor from rectangular nested data.

- domain: uniform nested numeric or bool data with optional matching f64/bool dtype; bounded rank/elements
- shape: constructor
- returns: `Tensor`
- keywords: `dtype`
- example: `math.tensor([1.0, 2.0], dtype="f64")`

## `math.matmul(a, b) -> Tensor`

Matrix product (or matrix·vector), shape-checked.

- domain: 2-D shapes (m,k)·(k,n), or matrix·vector; typed ShapeError otherwise
- shape: contraction
- returns: `Tensor`
- example: `math.matmul(math.eye(2), math.ones([2, 2]))`

## `math.dot(a, b) -> float`

Dot product of two vectors.

- domain: two equal-length 1-D vectors (bounded reduction work)
- shape: reduction
- returns: `float`
- example: `math.dot(math.tensor([1.0, 2.0]), math.tensor([3.0, 4.0]))`

## `math.zeros(shape) -> Tensor`

Tensor of zeros with the given shape.

- domain: nonnegative exact int or list/tuple of them (bounded elements)
- shape: constructor
- returns: `Tensor`
- example: `math.zeros([2, 3])`

## `math.ones(shape) -> Tensor`

Tensor of ones with the given shape.

- domain: nonnegative exact int or list/tuple of them (bounded elements)
- shape: constructor
- returns: `Tensor`
- example: `math.ones(3)`

## `math.eye(n) -> Tensor`

n×n identity matrix.

- domain: one nonnegative exact int dimension (bounded elements)
- shape: constructor
- returns: `Tensor`
- example: `math.eye(2)`

## `math.arange(stop) -> Tensor`

1-D tensor of 0.0..stop-1.

- domain: exact integer stop (negative yields an empty tensor; bounded elements)
- shape: constructor
- returns: `Tensor`
- example: `math.arange(4)`

# reduction

## `math.mean(values) -> int | rational | float | Tensor`

Mean; exact rational for exact inputs, float once any float enters, or deterministic complex tensor reduction.

- domain: non-empty iterable, or finite f64/complex tensor with optional integer axis/keepdims
- shape: reduction
- returns: `int | rational | float | Tensor`
- keywords: `axis`, `keepdims`
- example: `math.mean([1.0, 2.0, 4.0])`

## `math.sum(values, start?) -> int | rational | float | Tensor`

Sum; exact for exact inputs, float once any float enters, or deterministic complex tensor reduction.

- domain: iterable plus optional start, or finite f64/complex tensor with optional integer axis/keepdims
- shape: reduction
- returns: `int | rational | float | Tensor`
- keywords: `start`, `axis`, `keepdims`
- example: `math.sum([1, 2, 3], start=4)`

# constant

## `math.pi: float`

The circle constant π.

- domain: attribute read; not callable
- shape: scalar
- returns: `float`
- example: `math.pi`

## `math.e: float`

Euler's number e.

- domain: attribute read; not callable
- shape: scalar
- returns: `float`
- example: `math.e`

## `math.tau: float`

The circle constant τ = 2π.

- domain: attribute read; not callable
- shape: scalar
- returns: `float`
- example: `math.tau`

## `math.inf: float`

Positive infinity (f64).

- domain: attribute read; not callable
- shape: scalar
- returns: `float`
- example: `math.inf`

## `math.nan: float`

Quiet NaN (f64).

- domain: attribute read; not callable
- shape: scalar
- returns: `float`
- example: `math.nan`
