WPILibC++ 2027.0.0-alpha-2
Loading...
Searching...
No Matches
variable.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <algorithm>
6#include <concepts>
7#include <initializer_list>
8#include <source_location>
9#include <type_traits>
10#include <utility>
11#include <vector>
12
13#include <Eigen/Core>
14#include <gch/small_vector.hpp>
15
21
22#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
24#endif
25
26namespace slp {
27
28// Forward declarations for friend declarations in Variable
29namespace detail {
30class AdjointExpressionGraph;
31} // namespace detail
32template <int UpLo = Eigen::Lower | Eigen::Upper>
33 requires(UpLo == Eigen::Lower) || (UpLo == (Eigen::Lower | Eigen::Upper))
36
37/**
38 * An autodiff variable pointing to an expression node.
39 */
41 public:
42 /**
43 * Constructs a linear Variable with a value of zero.
44 */
45 Variable() = default;
46
47 /**
48 * Constructs an empty Variable.
49 */
50 explicit Variable(std::nullptr_t) : expr{nullptr} {}
51
52 /**
53 * Constructs a Variable from a floating point type.
54 *
55 * @param value The value of the Variable.
56 */
57 Variable(std::floating_point auto value) // NOLINT
58 : expr{detail::make_expression_ptr<detail::ConstExpression>(value)} {}
59
60 /**
61 * Constructs a Variable from an integral type.
62 *
63 * @param value The value of the Variable.
64 */
65 Variable(std::integral auto value) // NOLINT
66 : expr{detail::make_expression_ptr<detail::ConstExpression>(value)} {}
67
68 /**
69 * Constructs a Variable pointing to the specified expression.
70 *
71 * @param expr The autodiff variable.
72 */
73 explicit Variable(const detail::ExpressionPtr& expr) : expr{expr} {}
74
75 /**
76 * Constructs a Variable pointing to the specified expression.
77 *
78 * @param expr The autodiff variable.
79 */
80 explicit Variable(detail::ExpressionPtr&& expr) : expr{std::move(expr)} {}
81
82 /**
83 * Assignment operator for double.
84 *
85 * @param value The value of the Variable.
86 * @return This variable.
87 */
88 Variable& operator=(double value) {
90
91 return *this;
92 }
93
94 /**
95 * Sets Variable's internal value.
96 *
97 * @param value The value of the Variable.
98 */
99 void set_value(double value) {
100 if (expr->is_constant(0.0)) {
102 } else {
103#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
104 // We only need to check the first argument since unary and binary
105 // operators both use it
106 if (expr->args[0] != nullptr) {
107 auto location = std::source_location::current();
109 stderr,
110 "WARNING: {}:{}: {}: Modified the value of a dependent variable",
111 location.file_name(), location.line(), location.function_name());
112 }
113#endif
114 expr->val = value;
115 }
116 }
117
118 /**
119 * Variable-Variable multiplication operator.
120 *
121 * @param lhs Operator left-hand side.
122 * @param rhs Operator right-hand side.
123 * @return Result of multiplication.
124 */
126 const Variable& rhs) {
127 return Variable{lhs.expr * rhs.expr};
128 }
129
130 /**
131 * Variable-Variable compound multiplication operator.
132 *
133 * @param rhs Operator right-hand side.
134 * @return Result of multiplication.
135 */
137 *this = *this * rhs;
138 return *this;
139 }
140
141 /**
142 * Variable-Variable division operator.
143 *
144 * @param lhs Operator left-hand side.
145 * @param rhs Operator right-hand side.
146 * @return Result of division.
147 */
149 const Variable& rhs) {
150 return Variable{lhs.expr / rhs.expr};
151 }
152
153 /**
154 * Variable-Variable compound division operator.
155 *
156 * @param rhs Operator right-hand side.
157 * @return Result of division.
158 */
160 *this = *this / rhs;
161 return *this;
162 }
163
164 /**
165 * Variable-Variable addition operator.
166 *
167 * @param lhs Operator left-hand side.
168 * @param rhs Operator right-hand side.
169 * @return Result of addition.
170 */
172 const Variable& rhs) {
173 return Variable{lhs.expr + rhs.expr};
174 }
175
176 /**
177 * Variable-Variable compound addition operator.
178 *
179 * @param rhs Operator right-hand side.
180 * @return Result of addition.
181 */
183 *this = *this + rhs;
184 return *this;
185 }
186
187 /**
188 * Variable-Variable subtraction operator.
189 *
190 * @param lhs Operator left-hand side.
191 * @param rhs Operator right-hand side.
192 * @return Result of subtraction.
193 */
195 const Variable& rhs) {
196 return Variable{lhs.expr - rhs.expr};
197 }
198
199 /**
200 * Variable-Variable compound subtraction operator.
201 *
202 * @param rhs Operator right-hand side.
203 * @return Result of subtraction.
204 */
206 *this = *this - rhs;
207 return *this;
208 }
209
210 /**
211 * Unary minus operator.
212 *
213 * @param lhs Operand for unary minus.
214 */
216 return Variable{-lhs.expr};
217 }
218
219 /**
220 * Unary plus operator.
221 *
222 * @param lhs Operand for unary plus.
223 */
225 return Variable{+lhs.expr};
226 }
227
228 /**
229 * Returns the value of this variable.
230 *
231 * @return The value of this variable.
232 */
233 double value() {
234 if (!m_graph_initialized) {
235 m_graph = detail::topological_sort(expr);
236 m_graph_initialized = true;
237 }
238 detail::update_values(m_graph);
239
240 return expr->val;
241 }
242
243 /**
244 * Returns the type of this expression (constant, linear, quadratic, or
245 * nonlinear).
246 *
247 * @return The type of this expression.
248 */
249 ExpressionType type() const { return expr->type(); }
250
251 private:
252 /// The expression node
255
256 /// Used to update the value of this variable based on the values of its
257 /// dependent variables
259
260 /// Used for lazy initialization of m_graph
261 bool m_graph_initialized = false;
262
263 friend SLEIPNIR_DLLEXPORT Variable abs(const Variable& x);
264 friend SLEIPNIR_DLLEXPORT Variable acos(const Variable& x);
265 friend SLEIPNIR_DLLEXPORT Variable asin(const Variable& x);
266 friend SLEIPNIR_DLLEXPORT Variable atan(const Variable& x);
268 const Variable& x);
269 friend SLEIPNIR_DLLEXPORT Variable cos(const Variable& x);
270 friend SLEIPNIR_DLLEXPORT Variable cosh(const Variable& x);
271 friend SLEIPNIR_DLLEXPORT Variable erf(const Variable& x);
272 friend SLEIPNIR_DLLEXPORT Variable exp(const Variable& x);
274 const Variable& y);
275 friend SLEIPNIR_DLLEXPORT Variable log(const Variable& x);
276 friend SLEIPNIR_DLLEXPORT Variable log10(const Variable& x);
277 friend SLEIPNIR_DLLEXPORT Variable pow(const Variable& base,
278 const Variable& power);
279 friend SLEIPNIR_DLLEXPORT Variable sign(const Variable& x);
280 friend SLEIPNIR_DLLEXPORT Variable sin(const Variable& x);
281 friend SLEIPNIR_DLLEXPORT Variable sinh(const Variable& x);
282 friend SLEIPNIR_DLLEXPORT Variable sqrt(const Variable& x);
283 friend SLEIPNIR_DLLEXPORT Variable tan(const Variable& x);
284 friend SLEIPNIR_DLLEXPORT Variable tanh(const Variable& x);
285 friend SLEIPNIR_DLLEXPORT Variable hypot(const Variable& x, const Variable& y,
286 const Variable& z);
287
289 template <int UpLo>
290 requires(UpLo == Eigen::Lower) || (UpLo == (Eigen::Lower | Eigen::Upper))
293};
294
295/**
296 * std::abs() for Variables.
297 *
298 * @param x The argument.
299 */
301 return Variable{detail::abs(x.expr)};
302}
303
304/**
305 * std::acos() for Variables.
306 *
307 * @param x The argument.
308 */
310 return Variable{detail::acos(x.expr)};
311}
312
313/**
314 * std::asin() for Variables.
315 *
316 * @param x The argument.
317 */
319 return Variable{detail::asin(x.expr)};
320}
321
322/**
323 * std::atan() for Variables.
324 *
325 * @param x The argument.
326 */
328 return Variable{detail::atan(x.expr)};
329}
330
331/**
332 * std::atan2() for Variables.
333 *
334 * @param y The y argument.
335 * @param x The x argument.
336 */
338 return Variable{detail::atan2(y.expr, x.expr)};
339}
340
341/**
342 * std::cos() for Variables.
343 *
344 * @param x The argument.
345 */
347 return Variable{detail::cos(x.expr)};
348}
349
350/**
351 * std::cosh() for Variables.
352 *
353 * @param x The argument.
354 */
356 return Variable{detail::cosh(x.expr)};
357}
358
359/**
360 * std::erf() for Variables.
361 *
362 * @param x The argument.
363 */
365 return Variable{detail::erf(x.expr)};
366}
367
368/**
369 * std::exp() for Variables.
370 *
371 * @param x The argument.
372 */
374 return Variable{detail::exp(x.expr)};
375}
376
377/**
378 * std::hypot() for Variables.
379 *
380 * @param x The x argument.
381 * @param y The y argument.
382 */
384 return Variable{detail::hypot(x.expr, y.expr)};
385}
386
387/**
388 * std::pow() for Variables.
389 *
390 * @param base The base.
391 * @param power The power.
392 */
394 const Variable& power) {
395 return Variable{detail::pow(base.expr, power.expr)};
396}
397
398/**
399 * std::log() for Variables.
400 *
401 * @param x The argument.
402 */
404 return Variable{detail::log(x.expr)};
405}
406
407/**
408 * std::log10() for Variables.
409 *
410 * @param x The argument.
411 */
413 return Variable{detail::log10(x.expr)};
414}
415
416/**
417 * sign() for Variables.
418 *
419 * @param x The argument.
420 */
422 return Variable{detail::sign(x.expr)};
423}
424
425/**
426 * std::sin() for Variables.
427 *
428 * @param x The argument.
429 */
431 return Variable{detail::sin(x.expr)};
432}
433
434/**
435 * std::sinh() for Variables.
436 *
437 * @param x The argument.
438 */
440 return Variable{detail::sinh(x.expr)};
441}
442
443/**
444 * std::sqrt() for Variables.
445 *
446 * @param x The argument.
447 */
449 return Variable{detail::sqrt(x.expr)};
450}
451
452/**
453 * std::tan() for Variables.
454 *
455 * @param x The argument.
456 */
458 return Variable{detail::tan(x.expr)};
459}
460
461/**
462 * std::tanh() for Variables.
463 *
464 * @param x The argument.
465 */
467 return Variable{detail::tanh(x.expr)};
468}
469
470/**
471 * std::hypot() for Variables.
472 *
473 * @param x The x argument.
474 * @param y The y argument.
475 * @param z The z argument.
476 */
478 const Variable& z) {
479 return Variable{slp::sqrt(slp::pow(x, 2) + slp::pow(y, 2) + slp::pow(z, 2))};
480}
481
482/**
483 * Make a list of constraints.
484 *
485 * The standard form for equality constraints is c(x) = 0, and the standard form
486 * for inequality constraints is c(x) ≥ 0. This function takes constraints of
487 * the form lhs = rhs or lhs ≥ rhs and converts them to lhs - rhs = 0 or
488 * lhs - rhs ≥ 0.
489 *
490 * @param lhs Left-hand side.
491 * @param rhs Right-hand side.
492 */
493template <typename LHS, typename RHS>
494 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
498 gch::small_vector<Variable> constraints;
499
500 if constexpr (ScalarLike<LHS> && ScalarLike<RHS>) {
501 constraints.emplace_back(lhs - rhs);
502 } else if constexpr (ScalarLike<LHS> && MatrixLike<RHS>) {
503 constraints.reserve(rhs.rows() * rhs.cols());
504
505 for (int row = 0; row < rhs.rows(); ++row) {
506 for (int col = 0; col < rhs.cols(); ++col) {
507 // Make right-hand side zero
508 constraints.emplace_back(lhs - rhs(row, col));
509 }
510 }
511 } else if constexpr (MatrixLike<LHS> && ScalarLike<RHS>) {
512 constraints.reserve(lhs.rows() * lhs.cols());
513
514 for (int row = 0; row < lhs.rows(); ++row) {
515 for (int col = 0; col < lhs.cols(); ++col) {
516 // Make right-hand side zero
517 constraints.emplace_back(lhs(row, col) - rhs);
518 }
519 }
520 } else if constexpr (MatrixLike<LHS> && MatrixLike<RHS>) {
521 slp_assert(lhs.rows() == rhs.rows() && lhs.cols() == rhs.cols());
522 constraints.reserve(lhs.rows() * lhs.cols());
523
524 for (int row = 0; row < lhs.rows(); ++row) {
525 for (int col = 0; col < lhs.cols(); ++col) {
526 // Make right-hand side zero
527 constraints.emplace_back(lhs(row, col) - rhs(row, col));
528 }
529 }
530 }
531
532 return constraints;
533}
534
535/**
536 * A vector of equality constraints of the form cₑ(x) = 0.
537 */
539 /// A vector of scalar equality constraints.
541
542 /**
543 * Concatenates multiple equality constraints.
544 *
545 * @param equality_constraints The list of EqualityConstraints to concatenate.
546 */
548 std::initializer_list<EqualityConstraints> equality_constraints) {
549 for (const auto& elem : equality_constraints) {
550 constraints.insert(constraints.end(), elem.constraints.begin(),
551 elem.constraints.end());
552 }
553 }
554
555 /**
556 * Concatenates multiple equality constraints.
557 *
558 * This overload is for Python bindings only.
559 *
560 * @param equality_constraints The list of EqualityConstraints to concatenate.
561 */
563 const std::vector<EqualityConstraints>& equality_constraints) {
564 for (const auto& elem : equality_constraints) {
565 constraints.insert(constraints.end(), elem.constraints.begin(),
566 elem.constraints.end());
567 }
568 }
569
570 /**
571 * Constructs an equality constraint from a left and right side.
572 *
573 * The standard form for equality constraints is c(x) = 0. This function takes
574 * a constraint of the form lhs = rhs and converts it to lhs - rhs = 0.
575 *
576 * @param lhs Left-hand side.
577 * @param rhs Right-hand side.
578 */
579 template <typename LHS, typename RHS>
580 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
583 EqualityConstraints(LHS&& lhs, RHS&& rhs)
584 : constraints{make_constraints(lhs, rhs)} {}
585
586 /**
587 * Implicit conversion operator to bool.
588 */
589 operator bool() { // NOLINT
590 return std::ranges::all_of(constraints, [](auto& constraint) {
591 return constraint.value() == 0.0;
592 });
593 }
594};
595
596/**
597 * A vector of inequality constraints of the form cᵢ(x) ≥ 0.
598 */
600 /// A vector of scalar inequality constraints.
602
603 /**
604 * Concatenates multiple inequality constraints.
605 *
606 * @param inequality_constraints The list of InequalityConstraints to
607 * concatenate.
608 */
610 std::initializer_list<InequalityConstraints> inequality_constraints) {
611 for (const auto& elem : inequality_constraints) {
612 constraints.insert(constraints.end(), elem.constraints.begin(),
613 elem.constraints.end());
614 }
615 }
616
617 /**
618 * Concatenates multiple inequality constraints.
619 *
620 * This overload is for Python bindings only.
621 *
622 * @param inequality_constraints The list of InequalityConstraints to
623 * concatenate.
624 */
626 const std::vector<InequalityConstraints>& inequality_constraints) {
627 for (const auto& elem : inequality_constraints) {
628 constraints.insert(constraints.end(), elem.constraints.begin(),
629 elem.constraints.end());
630 }
631 }
632
633 /**
634 * Constructs an inequality constraint from a left and right side.
635 *
636 * The standard form for inequality constraints is c(x) ≥ 0. This function
637 * takes a constraints of the form lhs ≥ rhs and converts it to lhs - rhs ≥ 0.
638 *
639 * @param lhs Left-hand side.
640 * @param rhs Right-hand side.
641 */
642 template <typename LHS, typename RHS>
643 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
646 InequalityConstraints(LHS&& lhs, RHS&& rhs)
647 : constraints{make_constraints(lhs, rhs)} {}
648
649 /**
650 * Implicit conversion operator to bool.
651 */
652 operator bool() { // NOLINT
653 return std::ranges::all_of(constraints, [](auto& constraint) {
654 return constraint.value() >= 0.0;
655 });
656 }
657};
658
659/**
660 * Equality operator that returns an equality constraint for two Variables.
661 *
662 * @param lhs Left-hand side.
663 * @param rhs Left-hand side.
664 */
665template <typename LHS, typename RHS>
666 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
667 (ScalarLike<RHS> || MatrixLike<RHS>) &&
668 (SleipnirType<LHS> || SleipnirType<RHS>)
669EqualityConstraints operator==(LHS&& lhs, RHS&& rhs) {
670 return EqualityConstraints{lhs, rhs};
671}
672
673/**
674 * Less-than comparison operator that returns an inequality constraint for two
675 * Variables.
676 *
677 * @param lhs Left-hand side.
678 * @param rhs Left-hand side.
679 */
680template <typename LHS, typename RHS>
681 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
682 (ScalarLike<RHS> || MatrixLike<RHS>) &&
683 (SleipnirType<LHS> || SleipnirType<RHS>)
684InequalityConstraints operator<(LHS&& lhs, RHS&& rhs) {
685 return rhs >= lhs;
686}
687
688/**
689 * Less-than-or-equal-to comparison operator that returns an inequality
690 * constraint for two Variables.
691 *
692 * @param lhs Left-hand side.
693 * @param rhs Left-hand side.
694 */
695template <typename LHS, typename RHS>
696 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
697 (ScalarLike<RHS> || MatrixLike<RHS>) &&
698 (SleipnirType<LHS> || SleipnirType<RHS>)
699InequalityConstraints operator<=(LHS&& lhs, RHS&& rhs) {
700 return rhs >= lhs;
701}
702
703/**
704 * Greater-than comparison operator that returns an inequality constraint for
705 * two Variables.
706 *
707 * @param lhs Left-hand side.
708 * @param rhs Left-hand side.
709 */
710template <typename LHS, typename RHS>
711 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
712 (ScalarLike<RHS> || MatrixLike<RHS>) &&
713 (SleipnirType<LHS> || SleipnirType<RHS>)
714InequalityConstraints operator>(LHS&& lhs, RHS&& rhs) {
715 return lhs >= rhs;
716}
717
718/**
719 * Greater-than-or-equal-to comparison operator that returns an inequality
720 * constraint for two Variables.
721 *
722 * @param lhs Left-hand side.
723 * @param rhs Left-hand side.
724 */
725template <typename LHS, typename RHS>
726 requires(ScalarLike<LHS> || MatrixLike<LHS>) &&
727 (ScalarLike<RHS> || MatrixLike<RHS>) &&
728 (SleipnirType<LHS> || SleipnirType<RHS>)
729InequalityConstraints operator>=(LHS&& lhs, RHS&& rhs) {
730 return InequalityConstraints{lhs, rhs};
731}
732
733} // namespace slp
734
735namespace Eigen {
736
737/**
738 * NumTraits specialization that allows instantiating Eigen types with Variable.
739 */
740template <>
741struct NumTraits<slp::Variable> : NumTraits<double> {
742 /// Real type.
744 /// Non-integer type.
746 /// Nested type.
748
749 /// Is complex.
750 static constexpr int IsComplex = 0;
751 /// Is integer.
752 static constexpr int IsInteger = 0;
753 /// Is signed.
754 static constexpr int IsSigned = 1;
755 /// Require initialization.
756 static constexpr int RequireInitialization = 1;
757 /// Read cost.
758 static constexpr int ReadCost = 1;
759 /// Add cost.
760 static constexpr int AddCost = 3;
761 /// Multiply cost.
762 static constexpr int MulCost = 3;
763};
764
765} // namespace Eigen
#define slp_assert(condition)
Abort in C++.
Definition assert.hpp:26
This class calculates the Hessian of a variable with respect to a vector of variables.
Definition hessian.hpp:29
This class calculates the Jacobian of a vector of variables with respect to a vector of variables.
Definition jacobian.hpp:25
An autodiff variable pointing to an expression node.
Definition variable.hpp:40
Variable(detail::ExpressionPtr &&expr)
Constructs a Variable pointing to the specified expression.
Definition variable.hpp:80
friend SLEIPNIR_DLLEXPORT Variable operator+(const Variable &lhs)
Unary plus operator.
Definition variable.hpp:224
friend SLEIPNIR_DLLEXPORT Variable operator*(const Variable &lhs, const Variable &rhs)
Variable-Variable multiplication operator.
Definition variable.hpp:125
Variable & operator=(double value)
Assignment operator for double.
Definition variable.hpp:88
Variable(std::nullptr_t)
Constructs an empty Variable.
Definition variable.hpp:50
Variable & operator-=(const Variable &rhs)
Variable-Variable compound subtraction operator.
Definition variable.hpp:205
friend SLEIPNIR_DLLEXPORT Variable operator-(const Variable &lhs)
Unary minus operator.
Definition variable.hpp:215
friend SLEIPNIR_DLLEXPORT Variable operator+(const Variable &lhs, const Variable &rhs)
Variable-Variable addition operator.
Definition variable.hpp:171
Variable & operator+=(const Variable &rhs)
Variable-Variable compound addition operator.
Definition variable.hpp:182
friend SLEIPNIR_DLLEXPORT Variable operator-(const Variable &lhs, const Variable &rhs)
Variable-Variable subtraction operator.
Definition variable.hpp:194
Variable & operator*=(const Variable &rhs)
Variable-Variable compound multiplication operator.
Definition variable.hpp:136
Variable(std::floating_point auto value)
Constructs a Variable from a floating point type.
Definition variable.hpp:57
friend SLEIPNIR_DLLEXPORT Variable operator/(const Variable &lhs, const Variable &rhs)
Variable-Variable division operator.
Definition variable.hpp:148
Variable()=default
Constructs a linear Variable with a value of zero.
Variable(std::integral auto value)
Constructs a Variable from an integral type.
Definition variable.hpp:65
void set_value(double value)
Sets Variable's internal value.
Definition variable.hpp:99
Variable & operator/=(const Variable &rhs)
Variable-Variable compound division operator.
Definition variable.hpp:159
ExpressionType type() const
Returns the type of this expression (constant, linear, quadratic, or nonlinear).
Definition variable.hpp:249
double value()
Returns the value of this variable.
Definition variable.hpp:233
Variable(const detail::ExpressionPtr &expr)
Constructs a Variable pointing to the specified expression.
Definition variable.hpp:73
This class is an adaptor type that performs value updates of an expression's adjoint graph.
Definition adjoint_expression_graph.hpp:21
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition SmallVector.h:1198
reference emplace_back(ArgTypes &&... Args)
Definition SmallVector.h:939
iterator insert(iterator I, T &&Elt)
Definition SmallVector.h:807
void reserve(size_type N)
Definition SmallVector.h:665
iterator end()
Definition SmallVector.h:271
Definition concepts.hpp:40
Definition concepts.hpp:13
Definition concepts.hpp:37
Definition variable.hpp:735
detail namespace with internal helper functions
Definition input_adapters.h:32
ExpressionPtr log10(const ExpressionPtr &x)
std::log10() for Expressions.
Definition expression.hpp:1333
ExpressionPtr tanh(const ExpressionPtr &x)
std::tanh() for Expressions.
Definition expression.hpp:1741
gch::small_vector< Expression * > topological_sort(const ExpressionPtr &root)
Generate a topological sort of an expression graph from parent to child.
Definition expression_graph.hpp:20
ExpressionPtr sqrt(const ExpressionPtr &x)
std::sqrt() for Expressions.
Definition expression.hpp:1642
ExpressionPtr tan(const ExpressionPtr &x)
std::tan() for Expressions.
Definition expression.hpp:1692
ExpressionPtr pow(const ExpressionPtr &base, const ExpressionPtr &power)
std::pow() for Expressions.
Definition expression.hpp:1420
ExpressionPtr exp(const ExpressionPtr &x)
std::exp() for Expressions.
Definition expression.hpp:1171
ExpressionPtr hypot(const ExpressionPtr &x, const ExpressionPtr &y)
std::hypot() for Expressions.
Definition expression.hpp:1233
ExpressionPtr atan(const ExpressionPtr &x)
std::atan() for Expressions.
Definition expression.hpp:911
ExpressionPtr erf(const ExpressionPtr &x)
std::erf() for Expressions.
Definition expression.hpp:1122
ExpressionPtr sinh(const ExpressionPtr &x)
std::sinh() for Expressions.
Definition expression.hpp:1592
ExpressionPtr acos(const ExpressionPtr &x)
std::acos() for Expressions.
Definition expression.hpp:813
ExpressionPtr cosh(const ExpressionPtr &x)
std::cosh() for Expressions.
Definition expression.hpp:1071
void update_values(const gch::small_vector< Expression * > &list)
Update the values of all nodes in this graph based on the values of their dependent nodes.
Definition expression_graph.hpp:78
ExpressionPtr atan2(const ExpressionPtr &y, const ExpressionPtr &x)
std::atan2() for Expressions.
Definition expression.hpp:972
ExpressionPtr cos(const ExpressionPtr &x)
std::cos() for Expressions.
Definition expression.hpp:1023
static ExpressionPtr make_expression_ptr(Args &&... args)
Creates an intrusive shared pointer to an expression from the global pool allocator.
Definition expression.hpp:48
ExpressionPtr log(const ExpressionPtr &x)
std::log() for Expressions.
Definition expression.hpp:1283
ExpressionPtr sin(const ExpressionPtr &x)
std::sin() for Expressions.
Definition expression.hpp:1543
ExpressionPtr abs(const ExpressionPtr &x)
std::abs() for Expressions.
Definition expression.hpp:763
ExpressionPtr asin(const ExpressionPtr &x)
std::asin() for Expressions.
Definition expression.hpp:862
Definition expression_graph.hpp:11
SLEIPNIR_DLLEXPORT Variable sinh(const Variable &x)
std::sinh() for Variables.
Definition variable.hpp:439
ExpressionType
Expression type.
Definition expression_type.hpp:18
gch::small_vector< Variable > make_constraints(LHS &&lhs, RHS &&rhs)
Make a list of constraints.
Definition variable.hpp:497
SLEIPNIR_DLLEXPORT Variable log10(const Variable &x)
std::log10() for Variables.
Definition variable.hpp:412
SLEIPNIR_DLLEXPORT Variable cos(const Variable &x)
std::cos() for Variables.
Definition variable.hpp:346
SLEIPNIR_DLLEXPORT Variable erf(const Variable &x)
std::erf() for Variables.
Definition variable.hpp:364
SLEIPNIR_DLLEXPORT Variable acos(const Variable &x)
std::acos() for Variables.
Definition variable.hpp:309
SLEIPNIR_DLLEXPORT Variable pow(const Variable &base, const Variable &power)
std::pow() for Variables.
Definition variable.hpp:393
SLEIPNIR_DLLEXPORT Variable log(const Variable &x)
std::log() for Variables.
Definition variable.hpp:403
SLEIPNIR_DLLEXPORT Variable sqrt(const Variable &x)
std::sqrt() for Variables.
Definition variable.hpp:448
SLEIPNIR_DLLEXPORT Variable atan(const Variable &x)
std::atan() for Variables.
Definition variable.hpp:327
SLEIPNIR_DLLEXPORT Variable abs(const Variable &x)
std::abs() for Variables.
Definition variable.hpp:300
void println(fmt::format_string< T... > fmt, T &&... args)
Wrapper around fmt::println() that squelches write failure exceptions.
Definition print.hpp:48
SLEIPNIR_DLLEXPORT Variable tanh(const Variable &x)
std::tanh() for Variables.
Definition variable.hpp:466
SLEIPNIR_DLLEXPORT Variable hypot(const Variable &x, const Variable &y)
std::hypot() for Variables.
Definition variable.hpp:383
SLEIPNIR_DLLEXPORT Variable atan2(const Variable &y, const Variable &x)
std::atan2() for Variables.
Definition variable.hpp:337
SLEIPNIR_DLLEXPORT Variable sin(const Variable &x)
std::sin() for Variables.
Definition variable.hpp:430
SLEIPNIR_DLLEXPORT Variable asin(const Variable &x)
std::asin() for Variables.
Definition variable.hpp:318
SLEIPNIR_DLLEXPORT Variable cosh(const Variable &x)
std::cosh() for Variables.
Definition variable.hpp:355
Definition PointerIntPair.h:280
A vector of equality constraints of the form cₑ(x) = 0.
Definition variable.hpp:538
gch::small_vector< Variable > constraints
A vector of scalar equality constraints.
Definition variable.hpp:540
EqualityConstraints(std::initializer_list< EqualityConstraints > equality_constraints)
Concatenates multiple equality constraints.
Definition variable.hpp:547
EqualityConstraints(const std::vector< EqualityConstraints > &equality_constraints)
Concatenates multiple equality constraints.
Definition variable.hpp:562
EqualityConstraints(LHS &&lhs, RHS &&rhs)
Constructs an equality constraint from a left and right side.
Definition variable.hpp:583
A vector of inequality constraints of the form cᵢ(x) ≥ 0.
Definition variable.hpp:599
InequalityConstraints(const std::vector< InequalityConstraints > &inequality_constraints)
Concatenates multiple inequality constraints.
Definition variable.hpp:625
InequalityConstraints(std::initializer_list< InequalityConstraints > inequality_constraints)
Concatenates multiple inequality constraints.
Definition variable.hpp:609
InequalityConstraints(LHS &&lhs, RHS &&rhs)
Constructs an inequality constraint from a left and right side.
Definition variable.hpp:646
gch::small_vector< Variable > constraints
A vector of scalar inequality constraints.
Definition variable.hpp:601
#define SLEIPNIR_DLLEXPORT
Definition symbol_exports.hpp:34
sign
Definition base.h:698