Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Generators in Class
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SOFT Core
SOFT 260
Generators in Class
Commits
49ce4615
Commit
49ce4615
authored
1 year ago
by
Brady James Garvin
Browse files
Options
Downloads
Patches
Plain Diff
Converted "generate"-step helper functions to generator functions.
parent
4459ee3c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
simplifier/src/features/expressions/simplification.js
+9
-15
9 additions, 15 deletions
simplifier/src/features/expressions/simplification.js
with
9 additions
and
15 deletions
simplifier/src/features/expressions/simplification.js
+
9
−
15
View file @
49ce4615
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
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment