Skip to content

Commit 21967d4

Browse files
authored
Fix PARI test fails for A077849 and improve IE for memory operations (#633)
1 parent ea41487 commit 21967d4

File tree

4 files changed

+35
-6
lines changed

4 files changed

+35
-6
lines changed

src/eval/evaluator_inc.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,27 +319,35 @@ void IncrementalEvaluator::computeStatefulCells() {
319319
std::set<int64_t> write;
320320
stateful_cells.clear();
321321
for (const auto& op : simple_loop.body.ops) {
322-
if (op.type == Operation::Type::CLR || op.type == Operation::Type::FIL ||
322+
const auto target = op.target.value.asInt();
323+
if (op.type == Operation::Type::CLR || op.type == Operation::Type::FIL ||
323324
op.type == Operation::Type::ROL || op.type == Operation::Type::ROR) {
324-
// Set all cells affected by memory ops as stateful.
325325
auto bounds = ProgramUtil::getTargetMemoryRange(op);
326326
if (bounds.first == Number::INF || bounds.second == Number::INF) {
327327
continue;
328328
}
329+
if (op.type == Operation::Type::FIL) {
330+
read.insert(target);
331+
}
329332
int64_t left = bounds.first.asInt();
330333
int64_t right = bounds.second.asInt();
331334
for (int64_t i = left; i < right; i++) {
332-
read.insert(i);
333-
write.insert(i);
334-
stateful_cells.insert(i);
335+
if (op.type == Operation::Type::ROL || op.type == Operation::Type::ROR) {
336+
read.insert(i);
337+
}
338+
if (write.find(i) == write.end()) {
339+
if (read.find(i) != read.end()) {
340+
stateful_cells.insert(i);
341+
}
342+
write.insert(i);
343+
}
335344
}
336345
continue;
337346
}
338347
const auto& meta = Operation::Metadata::get(op.type);
339348
if (meta.num_operands == 0) {
340349
continue;
341350
}
342-
const auto target = op.target.value.asInt();
343351
if (target == simple_loop.counter) {
344352
continue;
345353
}
@@ -358,6 +366,11 @@ void IncrementalEvaluator::computeStatefulCells() {
358366
write.insert(target);
359367
}
360368
}
369+
for (const auto& cell : read) {
370+
if (write.find(cell) == write.end() && cell != simple_loop.counter) {
371+
stateful_cells.insert(cell);
372+
}
373+
}
361374
}
362375

363376
void IncrementalEvaluator::computeLoopCounterDependentCells() {

tests/formula/formula.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ A054965: a(n) = logint(10^(n+1),3)
9797
A062815: a(n) = b(n+1), b(n) = n*n^n+b(n-1), b(0) = 0
9898
A060508: a(n) = logint(2^n,n)
9999
A060576: a(n) = n!=1
100+
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
100101
A078013: a(n) = -a(n-3)+a(n-1), a(4) = -1, a(3) = -1, a(2) = 0, a(1) = 0, a(0) = 1
101102
A080099: a(n) = bitand(-binomial(floor((sqrtint(8*n+1)+1)/2),2)+n,floor((sqrtint(8*n+1)+1)/2)-1)
102103
A092242: a(n) = 2*bitxor(3*n-3,1)+3

tests/formula/pari-function.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ A000247: a(n) = 2^n-n-2
66
A001286: a(n) = floor(((n-1)*n!)/2)
77
A001715: (a(n) = truncate(b(n)/6)); (b(n) = if(n==0,1,n*b(n-1)))
88
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)
9+
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))))))
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; A077849: Expansion of (1-x)^(-1)/(1 - 2*x - x^2 - x^3).
2+
; 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
3+
4+
mov $4,1
5+
add $0,2
6+
lpb $0
7+
sub $0,1
8+
ror $1,3
9+
add $1,$3
10+
add $1,$2
11+
add $1,$2
12+
add $1,$4
13+
lpe
14+
mov $0,$2

0 commit comments

Comments
 (0)