Boolean Expressions

Our current definition of the Beginning Student Scheme language omits two forms of expressions: <#61848#><#8437#>and<#8437#><#61848#> and <#61849#><#8438#>or<#8438#><#61849#> expressions. Adding them provides a case study of how to study new language construct. We must first understand their syntax, then their semantics, and finally their pragmatics. Here is the revised grammar:

#tabular8440#

The grammar says that <#61855#><#8452#>and<#8452#><#61855#> and <#61856#><#8453#>or<#8453#><#61856#> are keywords, each followed by two expressions. At first glance, the two look like (primitive or function) applications. To understand why they are not, we must look the pragmatics of these expressions first. Suppose we need to formulate a condition that determines whether the <#61857#><#8454#>n<#8454#><#61857#>-th fraction of <#61858#><#8455#>1<#8455#><#61858#> is <#61859#><#8456#>m<#8456#><#61859#>:

<#8461#>(and<#8461#> <#8462#>(not<#8462#> <#8463#>(=<#8463#> <#8464#>n<#8464#> <#8465#>0))<#8465#> 
     <#8466#>(=<#8466#> <#8467#>(/<#8467#> <#8468#>1<#8468#> <#8469#>n)<#8469#> <#8470#>m))<#8470#> 
We formulate the condition as an <#61860#><#8474#>and<#8474#><#61860#> combination of two boolean expressions, because we don't wish to divide by <#61861#><#8475#>0<#8475#><#61861#> accidentally. Next, assume <#61862#><#8476#>n<#8476#><#61862#> becomes <#61863#><#8477#>0<#8477#><#61863#> during the course of the evaluation. Then the expression becomes
<#8482#>(and<#8482#> <#8483#>(not<#8483#> <#8484#>(=<#8484#> <#8485#>0<#8485#> <#8486#>0))<#8486#> 
     <#8487#>(=<#8487#> <#8488#>(/<#8488#> <#8489#>1<#8489#> <#8490#>0)<#8490#> <#8491#>m))<#8491#> 
Now, if <#61864#><#8495#>and<#8495#><#61864#> were an ordinary operation, we would have to evaluate both subexpressions, which would trigger an error in the second one. For this reason, <#61865#><#8496#>and<#8496#><#61865#> is not a primitive operation, but a special expression. In short, we use <#61866#><#8497#>and<#8497#><#61866#> and <#61867#><#8498#>or<#8498#><#61867#> expressions to combine boolean computations that may have to short-cut an evaluation. Once we understand how <#61868#><#8499#>and<#8499#><#61868#> and <#61869#><#8500#>or<#8500#><#61869#> expressions should be evaluated, it is easy to formulate macthing rules. Better still, we can formulate expressions in our first language that are equivalent to these expressions:
<#8505#>(and<#8505#> <#72185#>#tex2html_wrap_inline72888#<#72185#> <#72186#>#tex2html_wrap_inline72890#<#72186#><#8508#>)<#8508#>
<#8509#>#tex2html_wrap_inline72892#<#8509#> 
<#8510#>(c<#8510#><#8511#>ond<#8511#> 
  <#8512#>[<#8512#><#72187#>#tex2html_wrap_inline72894#<#72187#> <#72188#>#tex2html_wrap_inline72896#<#72188#><#8515#>]<#8515#> 
  <#8516#>[<#8516#><#8517#>else<#8517#> <#8518#>false]<#8518#><#8519#>)<#8519#> 
and
<#8527#>(or<#8527#> <#72189#>#tex2html_wrap_inline72898#<#72189#> <#72190#>#tex2html_wrap_inline72900#<#72190#><#8530#>)<#8530#>
<#8531#>#tex2html_wrap_inline72902#<#8531#> 
<#8532#>(c<#8532#><#8533#>ond<#8533#> 
  <#8534#>[<#8534#><#72191#>#tex2html_wrap_inline72904#<#72191#> <#8536#>true]<#8536#> 
  <#8537#>[<#8537#><#8538#>else<#8538#> <#72192#>#tex2html_wrap_inline72906#<#72192#><#8540#>]<#8540#><#8541#>)<#8541#> 
These equivalences simplify what actually takes place in DrScheme but they are a perfectly appropriate model for now.