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