108 throw CGException(
"The first element in each path must be the same.");
116 throw CGException(
"Invalid path! It must start with either an addition or subtraction.");
120 throw CGException(
"Invalid path! It must end with a non null node.");
123 throw CGException(
"Invalid paths! They must end with the same node.");
136 std::array<std::vector<CG<Base>*>, 2>
replace;
142 for (
size_t j = 0;
j <
paths.size(); ++
j) {
144 replace[
j] = std::vector<CG<Base>*>(
p.size(),
nullptr);
155 for (
size_t i = 1;
i <
p.size() - 1; ++
i) {
156 const auto* node =
p[
i].node;
157 if (node ==
nullptr) {
158 throw CGException(
"Failed to combine multiple occurrences of a variable into one expression");
161 auto op = node->getOperationType();
163 if (
op == CGOpCode::Add) {
166 }
else if (
op == CGOpCode::Sub) {
167 if (
p[
i - 1].argIndex == 1)
172 }
else if (
op == CGOpCode::UnMinus) {
175 }
else if (
op == CGOpCode::Mul) {
176 CPPADCG_ASSERT_UNKNOWN(
p[
i].argIndex == 0 ||
p[
i].argIndex == 1);
177 const auto&
pArgs = node->getArguments();
180 }
else if (
op == CGOpCode::Div) {
181 CPPADCG_ASSERT_UNKNOWN(
p[
i].argIndex == 0);
184 }
else if (
op == CGOpCode::Alias) {
189 CPPADCG_ASSERT_UNKNOWN(
false);
197 for (
size_t i1 =
p.size() - 1;
i1 > 0; --
i1) {
199 if (
p[
i].node->getOperationType() == CGOpCode::Mul ||
200 p[
i].node->getOperationType() == CGOpCode::UnMinus ||
201 p[
i].node->getOperationType() == CGOpCode::Div ||
202 p[
i].node->getOperationType() == CGOpCode::Alias) {
222 std::vector<CG<Base>>
indep(this->_independentVariables.size());
223 for (
size_t i = 0;
i <
indep.size(); ++
i)