@@ -80,7 +80,7 @@ primary:
80
80
81
81
## Semantics
82
82
83
- ### Exceptions
83
+ ### Exceptions and Errors
84
84
85
85
When you give input, either via the REPL or using ` source ` , each statement of the input is parsed into an AST. If any
86
86
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.
89
89
During execution, if any statement is invalid, the execution will stop and the error will be printed to the console. The
90
90
execution will not continue after the error.
91
91
92
- ### Statements
92
+ ## Statements
93
93
94
94
A statement is either
95
95
@@ -196,7 +196,7 @@ An expression statement is simply an expression that is evaluated.
196
196
197
197
he ID of the BDD node that represents the expression is printed to the console.
198
198
199
- ### Expressions
199
+ ## Expressions
200
200
201
201
All expressions are evaluated to form BDDs. An expression is either
202
202
@@ -233,6 +233,51 @@ Note the following:
233
233
- Variables are substituted simultaneously, i.e. a variable introduced by a substitution will not be substituted
234
234
again by another substitution in the same statement
235
235
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
+
236
281
## Example Interaction
237
282
238
283
```
@@ -285,22 +330,6 @@ The true and false leaves are represented by ids 1 and 0 respectively.
285
330
Each required BDD is recursively constructed, ensuring that the reductions are done correctly during construction such
286
331
that each reduced BDD has a unique ID within the graph.
287
332
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
-
304
333
# Repository Layout
305
334
306
335
The project is a tree-walk interpreter, so it has three internal parts:
0 commit comments