...
- a boolean constant
true
andfalse
; - a symbol
S
representing a boolean variable; (make-Not X)
whereX
is aboolExp
;(make-And X Y) where X
andY
are {{boolExp}}s;(make-Or X Y) where X
andY
are {{boolExp}}s;(make-Implies X Y) where ={{X
andY
are {{boolExp}}s; or(make-If X Y Z)
whereX
,Y
, andZ
are {{boolExp}}s.
...
- a boolean constant
true
orfalse
; - a symbol
S
; (list 'not X)
whereX
is abool-SchemeExp
;(list op X Y)
whereop
is'and
,'or
, or'implies
whereX
andY
are ={{bool-SchemeExp=}}s;(list 'if X Y Z)
whereX
,Y
, andZ
are ={{bool-SchemeExp=}}s.
The provided functions parse
and unparse
have the following signatures.
...
Since the reduction rules for this phase are Church-Rosser, you can write the
function convert-to-if
using simple structural recursion. For each of the
boolean operators And
, Or
, Not
, and Implies
, reduce the component
expressions first and then applying the matching reduction (except for if
for which there is no top-level reduction).
...
We suggest simply traversing the tree using the structural recursion template
for type boolExp
and converting all structures (other than =ifs=if}}s) to the
corresponding {{if
structures.
Write an inductive data definition and template for boolean formulas in if
form,
naming this type ifExp
. (Note: make-If
is the only constructor, other
than variables and constants for ifExp
Code Block |
---|
a ={{boolExp=}} is either: * a boolean value ={{true=}} and ={{false=}}; * a symbol ={{s=}} representing a boolean variable; * ={{(make-Not M)=}} where ={{M=}} is a ={{boolExp=}}; * ={{(make-And M N)}} where ={{M=}} and ={{N=}} are ={{boolExps=}}; * ={{(make-Or M N)}} where ={{M=}} and ={{N=}} are ={{boolExps=}}; * =(make-Implies M N) where =M= and =N= are =boolExps=; or * =(make-If M N P)= where =M=, =N=, and =P= are =boolExps=. The provided function ={{parse: input -> boolExp=}} takes a Scheme expression and returns the corresponding ={{boolExp=}}. ----+Normalization An =ifExp= is _normalized_ iff every sub-expression in =test= position is either a variable (symbol) or a constant (=true= or =false=). We call this type =norm-ifExp=. For example, the =ifExp= |
...