Skip to content

Commit e064bc4

Browse files
committed
Revise README structure and expand on substitution/logic ops
Reorganized and clarified sections to improve logical flow and readability. Expanded details on substitutions, syntactic sugar operations, quantification, and propositional logic, providing additional explanations and examples. Removed redundant content on operations for conciseness.
1 parent 2cff5f2 commit e064bc4

File tree

1 file changed

+48
-19
lines changed

1 file changed

+48
-19
lines changed

README.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ primary:
8080

8181
## Semantics
8282

83-
### Exceptions
83+
### Exceptions and Errors
8484

8585
When you give input, either via the REPL or using `source`, each statement of the input is parsed into an AST. If any
8686
statement is invalid, none of the statements are executed. The parser will return a list of parser exceptions which will
@@ -89,7 +89,7 @@ be printed to the console.
8989
During execution, if any statement is invalid, the execution will stop and the error will be printed to the console. The
9090
execution will not continue after the error.
9191

92-
### Statements
92+
## Statements
9393

9494
A statement is either
9595

@@ -196,7 +196,7 @@ An expression statement is simply an expression that is evaluated.
196196

197197
he ID of the BDD node that represents the expression is printed to the console.
198198

199-
### Expressions
199+
## Expressions
200200

201201
All expressions are evaluated to form BDDs. An expression is either
202202

@@ -233,6 +233,51 @@ Note the following:
233233
- Variables are substituted simultaneously, i.e. a variable introduced by a substitution will not be substituted
234234
again by another substitution in the same statement
235235

236+
Substitutions are a very powerful construct and subsume the following common operations:
237+
238+
- Evaluating a BDD under some propositional assignment
239+
- Renaming a BDD with a different set of variables
240+
241+
Internally, they work in the following way:
242+
243+
- Construct the body expression as a BDD
244+
- Reverse the body into a canonical expression using only and, or, and not
245+
- Traverse the body expression and replace each variable with the corresponding expression from the substitution
246+
- Construct the final BDD from the resulting expression
247+
248+
In all these steps, we do a large amount of caching to eliminate redundant work, so the substitution operation should
249+
not cause exponential blow-up.
250+
251+
### Syntactic Sugar Operations
252+
253+
These operations are syntactic sugar on actual operations on BDDs. They are provided for convenience and readability.
254+
255+
- Implication: `P -> Q` is equivalent to `!P | Q`
256+
- Equivalence: `P == Q` is equivalent to `(P & Q) | (!P & !Q)`
257+
- Inequality: `P != Q` is equivalent to `(P & !Q) | (!P & Q)`
258+
259+
Note that both the abstract syntax tree and run-time BDD representations use pointers that allow sharing across
260+
subformulae. Thus, the equivalence and inequality do not cause exponential blow-up in the size of the ASTs or number of
261+
BDDs.
262+
263+
### Quantification
264+
265+
Quantification is used to eliminate variables from a BDD.
266+
267+
- `exists x P` is equivalent to `(sub {x: true} P) | (sub {x: false} P)`
268+
- `forall x P` is equivalent to `(sub {x: true} P) & (sub {x: false} P)`
269+
270+
Note that these operations are implemented directly and are thus more efficient than using substitutions to achieve the same effect.
271+
272+
The quantification operations can support multiple variables with a single operation:
273+
- e.g. `exists (x y) P` is equivalent to `exists x (exists y P)`
274+
275+
This is more efficient than performing multiple quantification operations in a row, as it does a single traversal of the BDD
276+
277+
### Propositional Logic Operations
278+
279+
OR, AND, NOT operations are used to manipulate and combine BDDs.
280+
236281
## Example Interaction
237282

238283
```
@@ -285,22 +330,6 @@ The true and false leaves are represented by ids 1 and 0 respectively.
285330
Each required BDD is recursively constructed, ensuring that the reductions are done correctly during construction such
286331
that each reduced BDD has a unique ID within the graph.
287332

288-
## Operations
289-
290-
These operations are provided to manipulate the BDDs:
291-
292-
- OR, AND, NOT, Exists and Forall quantification
293-
294-
These operations are syntactic sugar on the above operations:
295-
296-
- Implication: `P -> Q` is equivalent to `!P | Q`
297-
- Equivalence: `P == Q` is equivalent to `(P & Q) | (!P & !Q)`
298-
- Inequality: `P != Q` is equivalent to `(P & !Q) | (!P & Q)`
299-
300-
Note that both the abstract syntax tree and run-time BDD representations use pointers that allow sharing across
301-
subformulae. Thus, the equivalence and inequality do not cause exponential blow-up in the size of the ASTs or number of
302-
BDDs.
303-
304333
# Repository Layout
305334

306335
The project is a tree-walk interpreter, so it has three internal parts:

0 commit comments

Comments
 (0)