From accc2769ae1c4e948750aaa4f615a34334503d1f Mon Sep 17 00:00:00 2001
From: "Brady J. Garvin" <bgarvin@cse.unl.edu>
Date: Mon, 18 Sep 2023 14:19:32 -0500
Subject: [PATCH] Recorded work from Friday.

---
 .../features/expressions/simplification.js    | 24 +++++++------------
 1 file changed, 9 insertions(+), 15 deletions(-)

diff --git a/simplifier/src/features/expressions/simplification.js b/simplifier/src/features/expressions/simplification.js
index 4b00d91..bf016f6 100644
--- a/simplifier/src/features/expressions/simplification.js
+++ b/simplifier/src/features/expressions/simplification.js
@@ -1,15 +1,13 @@
 import { Expression } from './expressions.js';
 
-function booleanAssignments(variables) {
-  const results = [];
+function*booleanAssignments(variables) {
   for (let bits = 1 << variables.length; bits--;) {
     const assignments = new Map();
     for (let index = variables.length; index--;) {
       assignments.set(variables[index].name, ((bits >> index) & 1) !== 0);
     }
-    results.push(assignments);
+    yield assignments;
   }
-  return results;
 }
 
 function matches(expression, semantics, variables) {
@@ -21,16 +19,15 @@ function matches(expression, semantics, variables) {
   return true;
 }
 
-function expressionsOfSize(environment, operatorCount) {
-  const results = [];
+function*expressionsOfSize(environment, operatorCount) {
   if (operatorCount === 0) {
     for (const variable of environment.variables) {
-      results.push(variable);
+      yield variable;
     }
   } else {
     for (const operator of environment.unaryOperators) {
       for (const subexpression of expressionsOfSize(environment, operatorCount - 1)) {
-        results.push(new Expression(operator, [subexpression]));
+        yield new Expression(operator, [subexpression]);
       }
     }
     for (let leftOperatorCount = 0; leftOperatorCount < operatorCount; ++leftOperatorCount) {
@@ -38,24 +35,21 @@ function expressionsOfSize(environment, operatorCount) {
       for (const operator of environment.binaryOperators) {
         for (const leftSubexpression of expressionsOfSize(environment, leftOperatorCount)) {
           for (const rightSubexpression of expressionsOfSize(environment, rightOperatorCount)) {
-            results.push(new Expression(operator, [leftSubexpression, rightSubexpression]));
+            yield new Expression(operator, [leftSubexpression, rightSubexpression]);
           }
         }
       }
     }
   }
-  return results;
 }
 
-function expressionsUpToSize(environment, maximumOperatorCount) {
-  const results = [];
+function*expressionsUpToSize(environment, maximumOperatorCount) {
   for (const operator of environment.nullaryOperators) {
-    results.push(new Expression(operator, []));
+    yield new Expression(operator, []);
   }
   for (let operatorCount = 0; operatorCount <= maximumOperatorCount; ++operatorCount) {
-    results.push(...expressionsOfSize(environment, operatorCount));
+    yield* expressionsOfSize(environment, operatorCount);
   }
-  return results;
 }
 
 export function simplify(semantics, environment, maximumOperatorCount) {
-- 
GitLab