math
Mathematical functions for symbolic expressions.
This module provides common mathematical operations used in optimization problems, including trigonometric functions, exponential functions, and smooth approximations of non-differentiable operations. All functions are element-wise and preserve the shape of their inputs.
Function Categories
- Trigonometric:
Sin,Cos,Tan- Standard trigonometric functions - Inverse Trigonometric:
Asin,Acos,Atan,Atan2- Inverse trig functions - Exponential and Roots:
Exp,Log,Sqrt,Square- Exponential, logarithm, square root, and squaring operations - Absolute Value:
Abs- Element-wise absolute value function - Smooth Approximations:
PositivePart,Huber,SmoothReLU- Smooth, differentiable approximations of non-smooth functions like max(0, x) and absolute value - Reductions:
Max,Min- Maximum and minimum over elements - Smooth Maximum:
LogSumExp- Log-sum-exp function, a smooth approximation to maximum
Example
Using trigonometric functions in dynamics::
import openscvx as ox
# Pendulum dynamics: theta_ddot = -g/L * sin(theta)
theta = ox.State("theta", shape=(1,))
theta_dot = ox.State("theta_dot", shape=(1,))
g, L = 9.81, 1.0
theta_ddot = -(g / L) * ox.Sin(theta)
Smooth penalty functions for constraints::
# Soft constraint using smooth ReLU
x = ox.Variable("x", shape=(3,))
penalty = ox.SmoothReLU(ox.Norm(x) - 1.0) # Penalize norm > 1
Abs
¶
Bases: Expr
Element-wise absolute value function for symbolic expressions.
Computes the absolute value (|x|) of each element in the operand. Preserves the shape of the input expression. The absolute value function is convex and DCP-compliant in CVXPy.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply absolute value to |
Example
Define an Abs expression:
x = Variable("x", shape=(3,))
abs_x = Abs(x) # Element-wise |x|
Source code in openscvx/symbolic/expr/math.py
Acos
¶
Bases: Expr
Element-wise arccosine (inverse cosine) function for symbolic expressions.
Computes the arccosine of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply arccosine function to |
Note
Acos is only supported for JAX lowering. CVXPy lowering will raise NotImplementedError since inverse trigonometric functions are not DCP-compliant.
Source code in openscvx/symbolic/expr/math.py
Asin
¶
Bases: Expr
Element-wise arcsine (inverse sine) function for symbolic expressions.
Computes the arcsine of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply arcsine function to |
Note
Asin is only supported for JAX lowering. CVXPy lowering will raise NotImplementedError since inverse trigonometric functions are not DCP-compliant.
Source code in openscvx/symbolic/expr/math.py
Atan
¶
Bases: Expr
Element-wise arctangent (inverse tangent) function for symbolic expressions.
Computes the arctangent of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply arctangent function to |
Note
Atan is only supported for JAX lowering. CVXPy lowering will raise NotImplementedError since inverse trigonometric functions are not DCP-compliant.
Source code in openscvx/symbolic/expr/math.py
Atan2
¶
Bases: Expr
Element-wise two-argument arctangent for symbolic expressions.
Computes atan2(y, x) element-wise using two operands and supports
broadcasting like NumPy.
Attributes:
| Name | Type | Description |
|---|---|---|
y |
Y-coordinate expression (numerator) |
|
x |
X-coordinate expression (denominator) |
Note
Atan2 is only supported for JAX lowering. CVXPy lowering will raise NotImplementedError since inverse trigonometric functions are not DCP-compliant.
Source code in openscvx/symbolic/expr/math.py
__init__(y: Union[Expr, float, int, np.ndarray], x: Union[Expr, float, int, np.ndarray])
¶
check_shape() -> Tuple[int, ...]
¶
Atan2 broadcasts input shapes like NumPy.
Source code in openscvx/symbolic/expr/math.py
Bilerp
¶
Bases: Expr
2D bilinear interpolation for symbolic expressions.
Performs bilinear interpolation on a regular 2D grid. Given grid points (xp, yp) and corresponding values fp, computes the bilinearly interpolated value at query point (x, y). For values outside the grid, boundary values are returned (clamping, no extrapolation).
This is useful for incorporating 2D tabulated data (e.g., engine thrust as a function of altitude and Mach number, aerodynamic coefficients as a function of angle of attack and sideslip) into trajectory optimization.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Query x-coordinate (symbolic expression) |
|
y |
Query y-coordinate (symbolic expression) |
|
xp |
1D array of x grid coordinates (must be increasing), length N |
|
yp |
1D array of y grid coordinates (must be increasing), length M |
|
fp |
2D array of values with shape (N, M), where fp[i, j] is the value at grid point (xp[i], yp[j]) |
Example
Interpolate engine thrust from altitude and Mach number::
import openscvx as ox
import numpy as np
# Grid coordinates
alt_grid = np.array([0, 5000, 10000, 15000, 20000]) # meters
mach_grid = np.array([0.0, 0.5, 1.0, 1.5, 2.0])
# Thrust values: thrust_table[i, j] = thrust at (alt_grid[i], mach_grid[j])
thrust_table = np.array([...]) # shape (5, 5)
altitude = ox.State("altitude", shape=(1,))
mach = ox.State("mach", shape=(1,))
thrust = ox.Bilerp(altitude[0], mach[0], alt_grid, mach_grid, thrust_table)
Note
- xp and yp must be strictly increasing
- fp must have shape (len(xp), len(yp))
- For query points outside the grid, boundary values are returned
- This node is only supported in JAX lowering (dynamics/cost), not CVXPy
Source code in openscvx/symbolic/expr/math.py
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 | |
__init__(x: Union[Expr, float, int, np.ndarray], y: Union[Expr, float, int, np.ndarray], xp: Union[Expr, float, int, np.ndarray], yp: Union[Expr, float, int, np.ndarray], fp: Union[Expr, float, int, np.ndarray])
¶
Initialize a 2D bilinear interpolation node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[Expr, float, int, ndarray]
|
Query x-coordinate. Can be a scalar symbolic expression. |
required |
y
|
Union[Expr, float, int, ndarray]
|
Query y-coordinate. Can be a scalar symbolic expression. |
required |
xp
|
Union[Expr, float, int, ndarray]
|
1D array of x grid coordinates. Must be increasing. |
required |
yp
|
Union[Expr, float, int, ndarray]
|
1D array of y grid coordinates. Must be increasing. |
required |
fp
|
Union[Expr, float, int, ndarray]
|
2D array of values with shape (len(xp), len(yp)). |
required |
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Canonicalize by canonicalizing all operands.
Source code in openscvx/symbolic/expr/math.py
check_shape() -> Tuple[int, ...]
¶
Output shape is scalar (single interpolated value).
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple[int, ...]
|
Empty tuple (scalar output) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If grid arrays have invalid shapes |
Source code in openscvx/symbolic/expr/math.py
Cinterp
¶
Bases: Expr
1D cubic spline interpolation for symbolic expressions.
Computes a cubic spline through data points (xp, fp) and evaluates it at query point x. Spline coefficients are precomputed at construction time via scipy so that JAX evaluation reduces to a segment lookup and polynomial eval.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Query point at which to evaluate the spline (symbolic expression). |
|
xp |
1D array of breakpoints (must be strictly increasing). |
|
fp |
1D array of values at the breakpoints (same length as xp). |
|
method |
Spline method used — |
|
coeffs |
Precomputed polynomial coefficients, shape (4, n_segments).
Row k contains the degree-k coefficients, so the value in segment i
at local coordinate t = x - xp[i] is
|
Example
Interpolate a discrete reference path::
import openscvx as ox
import numpy as np
s_data = np.linspace(0, 2 * np.pi, 20)
px_data = np.cos(s_data)
progress = ox.State("progress", shape=(1,))
px = ox.Cinterp(progress[0], s_data, px_data)
Use PCHIP for monotonicity-preserving interpolation::
alt_data = np.array([0, 5000, 10000, 15000, 20000])
rho_data = np.array([1.225, 0.736, 0.414, 0.195, 0.089])
altitude = ox.State("altitude", shape=(1,))
rho = ox.Cinterp(altitude[0], alt_data, rho_data, method="pchip")
Note
xp must be strictly increasing.
Extrapolation behavior
For query points outside [xp[0], xp[-1]], boundary segment
polynomials are extrapolated (consistent with scipy defaults).
Source code in openscvx/symbolic/expr/math.py
1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 | |
Cos
¶
Bases: Expr
Element-wise cosine function for symbolic expressions.
Computes the cosine of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply cosine function to |
Example
Define a Cos expression:
theta = Variable("theta", shape=(3,))
cos_theta = Cos(theta)
Source code in openscvx/symbolic/expr/math.py
Exp
¶
Bases: Expr
Element-wise exponential function for symbolic expressions.
Computes e^x for each element in the operand, where e is Euler's number. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply exponential function to |
Example
Define an Exp expression:
x = Variable("x", shape=(3,))
exp_x = Exp(x)
Source code in openscvx/symbolic/expr/math.py
Huber
¶
Bases: Expr
Huber penalty function for symbolic expressions.
The Huber penalty is a smooth approximation to the absolute value function that is quadratic for small values (|x| < delta) and linear for large values (|x| >= delta). This makes it more robust to outliers than squared penalties while maintaining smoothness.
The Huber function is defined as: - (x^2) / (2*delta) for |x| <= delta - |x| - delta/2 for |x| > delta
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Expression to apply Huber penalty to |
|
delta |
Threshold parameter controlling the transition point (default: 0.25) |
Example
Define a Huber penalty expression:
residual = y_measured - y_predicted
penalty = Huber(residual, delta=0.5)
Source code in openscvx/symbolic/expr/math.py
__init__(x: Union[Expr, float, int, np.ndarray], delta: float = 0.25)
¶
Initialize a Huber penalty operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[Expr, float, int, ndarray]
|
Expression to apply Huber penalty to |
required |
delta
|
float
|
Threshold parameter for quadratic-to-linear transition (default: 0.25) |
0.25
|
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Linterp
¶
Bases: Expr
1D linear interpolation for symbolic expressions.
Computes the linear interpolant of data points (xp, fp) evaluated at x, equivalent to jax.numpy.interp(x, xp, fp). For values outside the data range, the boundary values are returned (no extrapolation).
This is useful for incorporating tabulated data (e.g., atmospheric properties, engine thrust curves, aerodynamic coefficients) into trajectory optimization dynamics and constraints.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Query point(s) at which to evaluate the interpolant (symbolic expression) |
|
xp |
1D array of x-coordinates of data points (must be increasing) |
|
fp |
1D array of y-coordinates of data points (same length as xp) |
Example
Interpolate atmospheric density from altitude table::
import openscvx as ox
import numpy as np
# US 1976 Standard Atmosphere data
alt_data = np.array([0, 5000, 10000, 15000, 20000]) # meters
rho_data = np.array([1.225, 0.736, 0.414, 0.195, 0.089]) # kg/m^3
altitude = ox.State("altitude", shape=(1,))
rho = ox.Linterp(altitude[0], alt_data, rho_data)
# rho can now be used in dynamics expressions
drag = 0.5 * rho * v**2 * Cd * S
Note
- xp must be strictly increasing
- For query points outside [xp[0], xp[-1]], boundary values are returned
Source code in openscvx/symbolic/expr/math.py
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 | |
__init__(x: Union[Expr, float, int, np.ndarray], xp: Union[Expr, float, int, np.ndarray], fp: Union[Expr, float, int, np.ndarray])
¶
Initialize a 1D linear interpolation node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[Expr, float, int, ndarray]
|
Query point(s) at which to evaluate the interpolant. Can be a scalar or array symbolic expression. |
required |
xp
|
Union[Expr, float, int, ndarray]
|
1D array of x-coordinates of data points. Must be increasing. Can be a numpy array or Constant expression. |
required |
fp
|
Union[Expr, float, int, ndarray]
|
1D array of y-coordinates of data points. Must have same length as xp. Can be a numpy array or Constant expression. |
required |
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Canonicalize by canonicalizing all operands.
check_shape() -> Tuple[int, ...]
¶
Output shape matches the query point shape.
The interpolation is element-wise over x, so the output has the same shape as the query points.
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
Tuple[int, ...]
|
Shape of the query point x |
Raises:
| Type | Description |
|---|---|
ValueError
|
If xp and fp have different lengths or are not 1D |
Source code in openscvx/symbolic/expr/math.py
Log
¶
Bases: Expr
Element-wise natural logarithm function for symbolic expressions.
Computes the natural logarithm (base e) of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply logarithm to |
Example
Define a Log expression:
x = Variable("x", shape=(3,))
log_x = Log(x)
Source code in openscvx/symbolic/expr/math.py
LogSumExp
¶
Bases: Expr
Log-sum-exp function for symbolic expressions.
Computes the log-sum-exp (LSE) of multiple operands, which is a smooth, differentiable approximation to the maximum function. The log-sum-exp is defined as:
logsumexp(x₁, x₂, ..., xₙ) = log(exp(x₁) + exp(x₂) + ... + exp(xₙ))
This function is numerically stable and is commonly used in optimization as a smooth alternative to the non-differentiable maximum function. It satisfies the inequality:
max(x₁, x₂, ..., xₙ) ≤ logsumexp(x₁, x₂, ..., xₙ) ≤ max(x₁, x₂, ..., xₙ) + log(n)
The log-sum-exp is convex and is particularly useful for: - Smooth approximations of maximum constraints - Soft maximum operations in neural networks - Relaxing logical OR operations in STL specifications
Attributes:
| Name | Type | Description |
|---|---|---|
operands |
List of expressions to compute log-sum-exp over |
Example
Define a LogSumExp expression:
x = Variable("x", shape=(3,))
y = Variable("y", shape=(3,))
z = Variable("z", shape=(3,))
lse = LogSumExp(x, y, z) # Smooth approximation to max(x, y, z)
Use in STL relaxation:
import openscvx as ox
# Relax: Or(φ₁, φ₂) using log-sum-exp
phi1 = ox.Norm(x - goal1) - 0.5
phi2 = ox.Norm(x - goal2) - 0.5
relaxed_or = LogSumExp(phi1, phi2) >= 0
Source code in openscvx/symbolic/expr/math.py
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 | |
__init__(*args: Union[Expr, float, int, np.ndarray])
¶
Initialize a log-sum-exp operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Union[Expr, float, int, ndarray]
|
Two or more expressions to compute log-sum-exp over |
()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than two operands are provided |
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Canonicalize log-sum-exp: flatten nested LogSumExp, fold constants.
Source code in openscvx/symbolic/expr/math.py
check_shape() -> Tuple[int, ...]
¶
LogSumExp broadcasts shapes like NumPy, preserving element-wise shape.
Source code in openscvx/symbolic/expr/math.py
Max
¶
Bases: Expr
Element-wise maximum function for symbolic expressions.
Computes the element-wise maximum across two or more operands. Supports broadcasting following NumPy rules. During canonicalization, nested Max operations are flattened and constants are folded.
Attributes:
| Name | Type | Description |
|---|---|---|
operands |
List of expressions to compute maximum over |
Example
Define a Max expression:
x = Variable("x", shape=(3,))
y = Variable("y", shape=(3,))
max_xy = Max(x, y, 0) # Element-wise max(x, y, 0)
Source code in openscvx/symbolic/expr/math.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 | |
__init__(*args: Union[Expr, float, int, np.ndarray])
¶
Initialize a maximum operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Union[Expr, float, int, ndarray]
|
Two or more expressions to compute maximum over |
()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than two operands are provided |
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Canonicalize max: flatten nested Max, fold constants.
Source code in openscvx/symbolic/expr/math.py
check_shape() -> Tuple[int, ...]
¶
Max broadcasts shapes like NumPy.
Source code in openscvx/symbolic/expr/math.py
Min
¶
Bases: Expr
Element-wise minimum function for symbolic expressions.
Computes the element-wise minimum across two or more operands. Supports broadcasting following NumPy rules. During canonicalization, nested Min operations are flattened and constants are folded.
Attributes:
| Name | Type | Description |
|---|---|---|
operands |
List of expressions to compute minimum over |
Example
Define a Min expression:
x = Variable("x", shape=(3,))
y = Variable("y", shape=(3,))
min_xy = Min(x, y, 10) # Element-wise min(x, y, 10)
Source code in openscvx/symbolic/expr/math.py
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 | |
__init__(*args: Union[Expr, float, int, np.ndarray])
¶
Initialize a minimum operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Union[Expr, float, int, ndarray]
|
Two or more expressions to compute minimum over |
()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If fewer than two operands are provided |
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Canonicalize min: flatten nested Min, fold constants.
Source code in openscvx/symbolic/expr/math.py
check_shape() -> Tuple[int, ...]
¶
Min broadcasts shapes like NumPy.
Source code in openscvx/symbolic/expr/math.py
PositivePart
¶
Bases: Expr
Positive part function for symbolic expressions.
Computes max(x, 0) element-wise, effectively zeroing out negative values while preserving positive values. This is also known as the ReLU (Rectified Linear Unit) function and is commonly used as a penalty function building block in optimization.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Expression to apply positive part function to |
Example
Define a PositivePart expression:
constraint_violation = x - 10
penalty = PositivePart(constraint_violation) # Penalizes x > 10
Source code in openscvx/symbolic/expr/math.py
Sin
¶
Bases: Expr
Element-wise sine function for symbolic expressions.
Computes the sine of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply sine function to |
Example
Define a Sin expression:
theta = Variable("theta", shape=(3,))
sin_theta = Sin(theta)
Source code in openscvx/symbolic/expr/math.py
SmoothReLU
¶
Bases: Expr
Smooth approximation to the ReLU (positive part) function.
Computes a smooth, differentiable approximation to max(x, 0) using the formula: sqrt(max(x, 0)^2 + c^2) - c
The parameter c controls the smoothness: smaller values give a sharper transition, while larger values produce a smoother approximation. As c approaches 0, this converges to the standard ReLU function.
This is particularly useful in optimization contexts where smooth gradients are required, such as in penalty methods for constraint handling (CTCS).
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Expression to apply smooth ReLU to |
|
c |
Smoothing parameter (default: 1e-8) |
Example
Define a smooth ReLU expression:
constraint_violation = x - 10
penalty = SmoothReLU(constraint_violation, c=1e-6)
Source code in openscvx/symbolic/expr/math.py
__init__(x: Union[Expr, float, int, np.ndarray], c: float = 1e-08)
¶
Initialize a smooth ReLU operation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Union[Expr, float, int, ndarray]
|
Expression to apply smooth ReLU to |
required |
c
|
float
|
Smoothing parameter controlling transition sharpness (default: 1e-8) |
1e-08
|
Source code in openscvx/symbolic/expr/math.py
canonicalize() -> Expr
¶
Sqrt
¶
Bases: Expr
Element-wise square root function for symbolic expressions.
Computes the square root of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply square root to |
Example
Define a Sqrt expression:
x = Variable("x", shape=(3,))
sqrt_x = Sqrt(x)
Source code in openscvx/symbolic/expr/math.py
Square
¶
Bases: Expr
Element-wise square function for symbolic expressions.
Computes the square (x^2) of each element in the operand. Preserves the shape of the input expression. This is more efficient than using Power(x, 2) for some optimization backends.
Attributes:
| Name | Type | Description |
|---|---|---|
x |
Expression to square |
Example
Define a Square expression:
v = Variable("v", shape=(3,))
v_squared = Square(v) # Equivalent to v ** 2
Source code in openscvx/symbolic/expr/math.py
Tan
¶
Bases: Expr
Element-wise tangent function for symbolic expressions.
Computes the tangent of each element in the operand. Preserves the shape of the input expression.
Attributes:
| Name | Type | Description |
|---|---|---|
operand |
Expression to apply tangent function to |
Example
Define a Tan expression:
theta = Variable("theta", shape=(3,))
tan_theta = Tan(theta)
Note
Tan is only supported for JAX lowering. CVXPy lowering will raise NotImplementedError since tangent is not DCP-compliant.