Janus provides a comprehensive set of math functions that work seamlessly with both numeric (double) and symbolic (SymbolicScalar) types. When called with a janus::SymbolicScalar argument, C++ automatically finds the correct overload via ADL (Argument-Dependent Lookup), so you can write sin(x) or janus::sin(x) interchangeably. These functions are the foundation for writing generic template code that compiles to both fast numeric execution and symbolic graph construction.
Quick Start
template <typename Scalar>
Scalar my_function(const Scalar& x, const Scalar& y) {
}
double result = my_function(1.0, 2.0);
auto expr = my_function(x, y);
Umbrella header that includes the entire Janus public API.
T sin(const T &x)
Computes sine of x.
Definition Trig.hpp:21
SymbolicScalar sym(const std::string &name)
Create a named symbolic scalar variable.
Definition JanusTypes.hpp:90
T pow(const T &base, const T &exponent)
Computes the power function: base^exponent.
Definition Arithmetic.hpp:72
T exp(const T &x)
Computes the exponential function e^x.
Definition Arithmetic.hpp:131
Core API
Trigonometric
- janus::sin(x), janus::cos(x), janus::tan(x)
- janus::asin(x), janus::acos(x), janus::atan(x), janus::atan2(y, x)
Exponential & Logarithmic
- janus::exp(x), janus::log(x), janus::log10(x)
- janus::pow(base, exp), janus::sqrt(x)
Hyperbolic
- janus::sinh(x), janus::cosh(x), janus::tanh(x)
Utility
- janus::abs(x), janus::fabs(x)
- janus::floor(x), janus::ceil(x)
- janus::fmin(a, b), janus::fmax(a, b)
Control Flow
- janus::where(condition, if_true, if_false) - Branch-free conditional that works in both numeric and symbolic mode
Usage Patterns
ADL (Argument-Dependent Lookup)
When you call a math function with a janus::SymbolicScalar argument, C++ automatically finds the correct function via ADL:
casadi::MX SymbolicScalar
CasADi MX symbolic scalar.
Definition JanusTypes.hpp:70
T sin(const T &x)
Computes sine of x.
Definition Trig.hpp:21
T pow(const T &base, const T &exponent)
Computes the power function: base^exponent.
Definition Arithmetic.hpp:72
For mixed types or explicit calls:
Branch-Free Conditionals with janus::where
Use janus::where instead of if/else to ensure your code works in symbolic mode:
template <typename Scalar>
Scalar safe_sqrt(const Scalar& x) {
}
auto where(const Cond &cond, const T1 &if_true, const T2 &if_false)
Select values based on condition (ternary operator) Returns: cond ? if_true : if_false Supports mixed...
Definition Logic.hpp:43
T sqrt(const T &x)
Computes the square root of a scalar.
Definition Arithmetic.hpp:46
In numeric mode, this compiles to efficient branchless select instructions (where possible). In symbolic mode, it builds a valid conditional node in the computation graph.
Convenience Header
For cleaner code, use the convenience header:
Convenience header bringing common Janus symbols into scope.
SymbolicScalar sym(const std::string &name)
Create a named symbolic scalar variable.
Definition JanusTypes.hpp:90
See Also