mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps] Sequence: fix confusion between sequence index in store and
sequence name
This commit is contained in:
committed by
EmilieNumworks
parent
2f5f94ade0
commit
ca1daeb527
@@ -53,8 +53,15 @@ void TemplatedSequenceContext<T>::step(SequenceStore * sequenceStore, SequenceCo
|
||||
u = u && u->isDefined() ? u : nullptr;
|
||||
Sequence * v = sequenceStore->numberOfFunctions() > 1 ? sequenceStore->functionAtIndex(1) : nullptr;
|
||||
v = v && v->isDefined() ? v : nullptr;
|
||||
/* Switch u & v if the name of u is v */
|
||||
if (u != nullptr && u->name()[0] == SequenceStore::k_sequenceNames[1][0]) {
|
||||
Sequence * temp = u;
|
||||
u = v;
|
||||
v = temp;
|
||||
}
|
||||
|
||||
/* TODO: explain */
|
||||
/* Approximate u & v at the new rank. We evaluate u twice in case its
|
||||
* expression depends on v. */
|
||||
m_values[0][0] = u ? u->approximateToNextRank<T>(m_rank, sqctx) : NAN;
|
||||
m_values[1][0] = v ? v->approximateToNextRank<T>(m_rank, sqctx) : NAN;
|
||||
m_values[0][0] = u ? u->approximateToNextRank<T>(m_rank, sqctx) : NAN;
|
||||
|
||||
@@ -14,34 +14,45 @@ void check_sequences_defined_by(double result[2][10], Sequence::Type typeU, cons
|
||||
SequenceStore store;
|
||||
SequenceContext sequenceContext(&globalContext, &store);
|
||||
|
||||
Sequence * u = store.addEmptyFunction();
|
||||
Sequence * v = store.addEmptyFunction();
|
||||
u->setType(typeU);
|
||||
Sequence * u = nullptr;
|
||||
Sequence * v = nullptr;
|
||||
if (definitionU) {
|
||||
u = store.addEmptyFunction();
|
||||
assert(u->name()[0] == 'u');
|
||||
u->setType(typeU);
|
||||
u->setContent(definitionU);
|
||||
if (conditionU1) {
|
||||
u->setFirstInitialConditionContent(conditionU1);
|
||||
}
|
||||
if (conditionU2) {
|
||||
u->setSecondInitialConditionContent(conditionU2);
|
||||
}
|
||||
}
|
||||
if (conditionU1) {
|
||||
u->setFirstInitialConditionContent(conditionU1);
|
||||
}
|
||||
if (conditionU2) {
|
||||
u->setSecondInitialConditionContent(conditionU2);
|
||||
}
|
||||
v->setType(typeV);
|
||||
if (definitionV) {
|
||||
if (store.numberOfFunctions() == 0) {
|
||||
Sequence * tempU = store.addEmptyFunction();
|
||||
v = store.addEmptyFunction();
|
||||
store.removeFunction(tempU);
|
||||
v = store.functionAtIndex(0);
|
||||
} else {
|
||||
assert(store.numberOfFunctions() == 1);
|
||||
v = store.addEmptyFunction();
|
||||
}
|
||||
v->setType(typeV);
|
||||
v->setContent(definitionV);
|
||||
}
|
||||
if (conditionV1) {
|
||||
v->setFirstInitialConditionContent(conditionV1);
|
||||
}
|
||||
if (conditionV2) {
|
||||
v->setSecondInitialConditionContent(conditionV2);
|
||||
if (conditionV1) {
|
||||
v->setFirstInitialConditionContent(conditionV1);
|
||||
}
|
||||
if (conditionV2) {
|
||||
v->setSecondInitialConditionContent(conditionV2);
|
||||
}
|
||||
}
|
||||
for (int j = 0; j < 10; j++) {
|
||||
if (u->isDefined()) {
|
||||
if (u && u->isDefined()) {
|
||||
double un = u->evaluateAtAbscissa((double)j, &sequenceContext);
|
||||
assert((std::isnan(un) && std::isnan(result[0][j])) || (un == result[0][j]));
|
||||
}
|
||||
if (v->isDefined()) {
|
||||
if (v && v->isDefined()) {
|
||||
double vn = v->evaluateAtAbscissa((double)j, &sequenceContext);
|
||||
assert((std::isnan(vn) && std::isnan(result[1][j])) || (vn == result[1][j]));
|
||||
}
|
||||
@@ -134,6 +145,14 @@ QUIZ_CASE(sequence_evaluation) {
|
||||
// u(n+2) = v(n+1)+u(n+1)+v(n)+u(n)+n, u(1) = 0, u(0) = 0; v(n+1) = u(n)+n, v(0)=0
|
||||
double result17[2][10] = {{0.0, 0.0, 0.0, 2.0, 7.0, 19.0, 46.0, 105.0, 233.0, 509.0}, {0.0, 0.0, 1.0, 2.0, 5.0, 11.0, 24.0, 52.0, 112.0, 241.0}};
|
||||
check_sequences_defined_by(result17, Sequence::Type::DoubleRecurrence, "v(n+1)+v(n)+u(n+1)+u(n)+n", "0", "0", Sequence::Type::SingleRecurrence, "u(n)+n", "0");
|
||||
}
|
||||
|
||||
// u(n) = n; v undefined
|
||||
double result18[2][10] = {{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}, {NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN}};
|
||||
check_sequences_defined_by(result18, Sequence::Type::Explicit, "n");
|
||||
|
||||
// u undefined; v(n) = n
|
||||
double result19[2][10] = {{NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN, NAN}, {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}};
|
||||
check_sequences_defined_by(result19, Sequence::Type::Explicit, nullptr, nullptr, nullptr, Sequence::Type::Explicit, "n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user