@@ -259,6 +259,12 @@ size_t getBadOpsCount(const Program &p) {
259
259
return num_ops;
260
260
}
261
261
262
+ bool isBetterIndirectMemory (const Program &existing, const Program &optimized) {
263
+ return (ProgramUtil::hasIndirectOperand (existing) &&
264
+ !ProgramUtil::hasIndirectOperand (optimized) &&
265
+ !ProgramUtil::hasOp (optimized, Operation::Type::SEQ));
266
+ }
267
+
262
268
std::string Finder::isOptimizedBetter (Program existing, Program optimized,
263
269
const OeisSequence &seq) {
264
270
static const std::string not_better;
@@ -318,6 +324,11 @@ std::string Finder::isOptimizedBetter(Program existing, Program optimized,
318
324
} else if (optimized_bad_count > existing_bad_count) {
319
325
return not_better; // worse
320
326
}
327
+ if (isBetterIndirectMemory (existing, optimized)) {
328
+ return " Simpler" ;
329
+ } else if (isBetterIndirectMemory (optimized, existing)) {
330
+ return not_better; // worse
331
+ }
321
332
322
333
// ======= EVALUATION CHECKS =========
323
334
@@ -353,22 +364,20 @@ std::string Finder::isOptimizedBetter(Program existing, Program optimized,
353
364
const auto existing_steps = evaluator.eval (existing, tmp, num_terms, false );
354
365
355
366
// compare number of successfully computed terms
356
- int64_t existing_terms = static_cast <int64_t >(
357
- static_cast <double >(existing_steps.runs ) * THRESHOLD_BETTER);
358
- int64_t optimized_terms = optimized_steps.runs ;
359
- if (optimized_terms > existing_terms) {
367
+ double existing_terms = existing_steps.runs ;
368
+ double optimized_terms = optimized_steps.runs ;
369
+ if (optimized_terms > (existing_terms * THRESHOLD_BETTER)) {
360
370
return " Better" ;
361
- } else if (optimized_terms < existing_terms ) {
371
+ } else if (existing_terms > ( optimized_terms * THRESHOLD_BETTER) ) {
362
372
return not_better; // worse
363
373
}
364
374
365
375
// compare number of execution cycles
366
- int64_t existing_total = existing_steps.total ;
367
- int64_t optimized_total = static_cast <int64_t >(
368
- static_cast <double >(optimized_steps.total ) * THRESHOLD_FASTER);
369
- if (optimized_total < existing_total) {
376
+ double existing_total = existing_steps.total ;
377
+ double optimized_total = optimized_steps.total ;
378
+ if (existing_total > (optimized_total * THRESHOLD_FASTER)) {
370
379
return " Faster" ;
371
- } else if (optimized_total > existing_total) {
380
+ } else if (optimized_total > ( existing_total * THRESHOLD_FASTER) ) {
372
381
return not_better; // worse
373
382
}
374
383
0 commit comments