SUNY Geneseo Department of Computer Science


Boolean Logic

{Date}

CSci 141, Fall 2004
Prof. Doug Baldwin

Return to List of Lectures

Previous Lecture


Misc

No Friday office hours this week

(And I will be off campus after about 10:30 tomorrow)

Questions?

Reading Summary

Sections 5.1 - 5.3

Boolean logic, a way of testing truth/falsity

Logic

Conjunction = and, notated ^

Disjunction = or, v

Negation = !, -,

Implication, e.g., p -> q

(Truth tables)

Law of excluded middle: p v ~p is always true

Double negation: ~(~p) = p

Simplification

Commutative law

Associative law

Vacuous cases

de Morgan's Law explains how to simplify negation in front of parentheses, e.g.,

Distributive Law

p, q can be statements in Java

Boolean algebra can lead to clearer, shorter, more direct expressions in programs

Applications of Logic

Cylinders (from graphics / geometry)

[Point (x,y,z) and Cylinder of Height h and Radius r]

    if (  0 < z  &&  z < h  &&  x*x + y*y < r*r  )
    if (   (    x*x + y*y == r*r
             && z > 0
             && z < h )
        || (    x*x + y*y <= r*r
             && ( z == 0 || z == h )) )

A robot problem: Move a robot forward until it either is on a red tile or to a wall.

    // in some subclass of Robot:
    while (    this.colorOfTile() != java.awt.Color.red
            && this.okToMove() ) )
        this.move()

Non-Programming Applications of Logic

Databases

(Name) (Course) (Average)
John Doe Csci 141 95
Sally Soe Math 100 99
Jane Dokes Csci 141 92
John Doe Math 100 86

Hardware

[Arithmetic Unit Produces Boolean "Zero" and "Negative" Signals]

Next

Introduction to Recursion

Read Sections 6.1 - 6.3


Next Lecture