From caf6f66bf130d696512105cf8f96b152f967d6b7 Mon Sep 17 00:00:00 2001 From: Christian Krause Date: Sun, 3 Nov 2024 14:20:28 +0100 Subject: [PATCH] fix formulas --- src/form/formula_gen.cpp | 12 +++++++----- src/form/formula_gen.hpp | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/form/formula_gen.cpp b/src/form/formula_gen.cpp index f268c7c7..dcb5f31e 100644 --- a/src/form/formula_gen.cpp +++ b/src/form/formula_gen.cpp @@ -291,7 +291,8 @@ bool FormulaGenerator::generateSingle(const Program& p) { simplifyFormulaUsingVariants(formula, numTerms); // evaluate program and add initial terms to formula - if (!addInitialTerms(numCells, numTerms)) { + const int64_t offset = ProgramUtil::getOffset(p); + if (!addInitialTerms(numCells, offset, numTerms)) { return false; } @@ -365,7 +366,8 @@ void FormulaGenerator::prepareForPostLoop( } bool FormulaGenerator::addInitialTerms( - int64_t numCells, const std::map& numTerms) { + int64_t numCells, int64_t offset, + const std::map& numTerms) { // calculate maximum offset int64_t maxNumTerms = 0; for (auto it : numTerms) { @@ -374,7 +376,7 @@ bool FormulaGenerator::addInitialTerms( maxNumTerms = std::max(maxNumTerms, it.second); } // evaluate program and add initial terms to formula - for (int64_t offset = 0; offset < maxNumTerms; offset++) { + for (int64_t n = 0; n < maxNumTerms; n++) { try { incEval.next(true, true); // skip final iteration and post loop code } catch (const std::exception&) { @@ -384,9 +386,9 @@ bool FormulaGenerator::addInitialTerms( const auto state = incEval.getLoopStates().at(incEval.getPreviousSlice()); for (int64_t cell = 0; cell < numCells; cell++) { auto name = getCellName(cell); - if (offset < numTerms.at(name)) { + if (n < numTerms.at(name)) { Expression func(Expression::Type::FUNCTION, name, - {ExpressionUtil::newConstant(offset)}); + {ExpressionUtil::newConstant(n + offset)}); Expression val(Expression::Type::CONSTANT, "", state.get(cell)); formula.entries[func] = val; Log::get().debug("Added intial term: " + func.toString() + " = " + diff --git a/src/form/formula_gen.hpp b/src/form/formula_gen.hpp index 7951084f..c238d905 100644 --- a/src/form/formula_gen.hpp +++ b/src/form/formula_gen.hpp @@ -41,7 +41,7 @@ class FormulaGenerator { void prepareForPostLoop(int64_t numCells, const std::map& preloopExprs); - bool addInitialTerms(int64_t numCells, + bool addInitialTerms(int64_t numCells, int64_t offset, const std::map& numTerms); std::string newName();