diff --git a/src/eval/evaluator_inc.cpp b/src/eval/evaluator_inc.cpp index f410afdc..7e196f5c 100644 --- a/src/eval/evaluator_inc.cpp +++ b/src/eval/evaluator_inc.cpp @@ -319,19 +319,28 @@ void IncrementalEvaluator::computeStatefulCells() { std::set write; stateful_cells.clear(); for (const auto& op : simple_loop.body.ops) { - if (op.type == Operation::Type::CLR || op.type == Operation::Type::FIL || + const auto target = op.target.value.asInt(); + if (op.type == Operation::Type::CLR || op.type == Operation::Type::FIL || op.type == Operation::Type::ROL || op.type == Operation::Type::ROR) { - // Set all cells affected by memory ops as stateful. auto bounds = ProgramUtil::getTargetMemoryRange(op); if (bounds.first == Number::INF || bounds.second == Number::INF) { continue; } + if (op.type == Operation::Type::FIL) { + read.insert(target); + } int64_t left = bounds.first.asInt(); int64_t right = bounds.second.asInt(); for (int64_t i = left; i < right; i++) { - read.insert(i); - write.insert(i); - stateful_cells.insert(i); + if (op.type == Operation::Type::ROL || op.type == Operation::Type::ROR) { + read.insert(i); + } + if (write.find(i) == write.end()) { + if (read.find(i) != read.end()) { + stateful_cells.insert(i); + } + write.insert(i); + } } continue; } @@ -339,7 +348,6 @@ void IncrementalEvaluator::computeStatefulCells() { if (meta.num_operands == 0) { continue; } - const auto target = op.target.value.asInt(); if (target == simple_loop.counter) { continue; } @@ -358,6 +366,11 @@ void IncrementalEvaluator::computeStatefulCells() { write.insert(target); } } + for (const auto& cell : read) { + if (write.find(cell) == write.end() && cell != simple_loop.counter) { + stateful_cells.insert(cell); + } + } } void IncrementalEvaluator::computeLoopCounterDependentCells() { diff --git a/tests/formula/formula.txt b/tests/formula/formula.txt index eea92521..02cc95ab 100644 --- a/tests/formula/formula.txt +++ b/tests/formula/formula.txt @@ -97,6 +97,7 @@ A054965: a(n) = logint(10^(n+1),3) A062815: a(n) = b(n+1), b(n) = n*n^n+b(n-1), b(0) = 0 A060508: a(n) = logint(2^n,n) A060576: a(n) = n!=1 +A077849: a(n) = c(n+2), b(n) = 2*b(n-1)+b(n-2)+b(n-3)+d(n-1), b(3) = 8, b(2) = 3, b(1) = 1, b(0) = 0, c(n) = b(n-1), c(3) = 3, c(2) = 1, c(1) = 0, c(0) = 0, d(n) = d(n-1), d(3) = 1, d(2) = 1, d(1) = 1, d(0) = 1 A078013: a(n) = -a(n-3)+a(n-1), a(4) = -1, a(3) = -1, a(2) = 0, a(1) = 0, a(0) = 1 A080099: a(n) = bitand(-binomial(floor((sqrtint(8*n+1)+1)/2),2)+n,floor((sqrtint(8*n+1)+1)/2)-1) A092242: a(n) = 2*bitxor(3*n-3,1)+3 diff --git a/tests/formula/pari-function.txt b/tests/formula/pari-function.txt index b2852522..d901e2af 100644 --- a/tests/formula/pari-function.txt +++ b/tests/formula/pari-function.txt @@ -6,3 +6,4 @@ A000247: a(n) = 2^n-n-2 A001286: a(n) = floor(((n-1)*n!)/2) A001715: (a(n) = truncate(b(n)/6)); (b(n) = if(n==0,1,n*b(n-1))) A006430: a(n) = truncate((floor(((-(1==n)+n)*(-(1==n)+n+1)*(-(1==n)+n+2)*(-(1==n)+n+3))/(-(1==n)+n+1))*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*((-(1==n)+n)*(23*n-23*(1==n)+963)+17544)+147952)+481675)-1052153)-7850914)-2900162)+60869272)+37067400)-179920800))/79833600) +A077849: (a(n) = c(n+2)); (b(n) = if(n==3,8,if(n==2,3,if(n==1,1,if(n==0,0,2*b(n-1)+b(n-2)+b(n-3)+d(n-1)))))); (c(n) = if(n==3,3,if(n==2,1,if(n==1,0,if(n==0,0,b(n-1)))))); (d(n) = if(n==3,1,if(n==2,1,if(n==1,1,if(n==0,1,d(n-1)))))) \ No newline at end of file diff --git a/tests/programs/oeis/077/A077849.asm b/tests/programs/oeis/077/A077849.asm new file mode 100644 index 00000000..206c724f --- /dev/null +++ b/tests/programs/oeis/077/A077849.asm @@ -0,0 +1,14 @@ +; A077849: Expansion of (1-x)^(-1)/(1 - 2*x - x^2 - x^3). +; 1,3,8,21,54,138,352,897,2285,5820,14823,37752,96148,244872,623645,1588311,4045140,10302237,26237926,66823230,170186624,433434405,1103878665,2811378360,7160069791,18235396608,46442241368,118279949136,301237536249,767197263003 + +mov $4,1 +add $0,2 +lpb $0 + sub $0,1 + ror $1,3 + add $1,$3 + add $1,$2 + add $1,$2 + add $1,$4 +lpe +mov $0,$2