1 CS 106 Computing Fundamentals II Chapter 32 “Boolean Expressions” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106.

Slides:



Advertisements
Similar presentations
TRUTH TABLES Section 1.3.
Advertisements

Chapter 3 section 2. Please form your groups The 1 st column represents all possibilities for the statement that can be either True or False. The 2 nd.
Logic ChAPTER 3 1. Truth Tables and Validity of Arguments
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Basic Elements of Programming A VB program is built from statements, statements from expressions, expressions from operators and operands, and operands.
Boolean Algebra Computer Science AND (today is Monday) AND (it is raining) (today is Monday) AND (it is not raining) (today is Friday) AND (it is.
Snick  snack CPSC 121: Models of Computation 2010/11 Winter Term 2 Propositional Logic, Continued Steve Wolfman, based on notes by Patrice Belleville.
Chapter 3 Introduction to Logic © 2008 Pearson Addison-Wesley. All rights reserved.
3.2 – Truth Tables and Equivalent Statements
TRUTH TABLES. Introduction Statements have truth values They are either true or false but not both Statements may be simple or compound Compound statements.
Chapter 1 Section 1.4 More on Conditionals. There are three statements that are related to a conditional statement. They are called the converse, inverse.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Computer Science 101 The Boolean System. George Boole British mathematician ( ) Boolean algebra –Logic –Set theory –Circuits –Conditions in if.
CS 285- Discrete Mathematics Lecture 2. Section 1.1 Propositional Logic Propositions Conditional Statements Truth Tables of Compound Propositions Translating.
Chapter 1 The Logic of Compound Statements. Section 1.1 Logical Form and Logical Equivalence.
Exercises A-Declare a variable of double type with initial value=0.0; B- Declare a constant of String type with initial value=“Good” C- Declare a variable.
1 CS 106 Computing Fundamentals II Chapter 25 “Variables, Assignment Statement” Herbert G. Mayer, PSU CS Status 7/4/2013 Initial content copied verbatim.
1 CS 106 Computing Fundamentals II Chapter 7 “Showing Developer Tab” Herbert G. Mayer, PSU CS status 6/17/2013 Initial content copied verbatim from CS.
BY: MISS FARAH ADIBAH ADNAN IMK. CHAPTER OUTLINE: PART III 1.3 ELEMENTARY LOGIC INTRODUCTION PROPOSITION COMPOUND STATEMENTS LOGICAL.
CSci 2011 Textbook ^Discrete Mathematics and Its Applications,  Rosen  6th Edition  McGraw Hill  2006.
Conditional Control Flow By Muhammad Ahsan Qadar SACS Programming Fundamentals Workshop 1.
Dale Roberts Program Control using Java - Boolean Expressions Dale Roberts, Lecturer Computer Science, IUPUI Department of.
Mt263f-11 Discrete Structures Li Tak Sing( 李德成 ) Room A
Fall 2002CMSC Discrete Structures1 Let’s get started with... Logic !
Chapter 5 Decisions. Outline and Objectives Relational and Logical Operators If Blocks Select Case Blocks.
Logical Form and Logical Equivalence Lecture 2 Section 1.1 Fri, Jan 19, 2007.
Logic Disjunction A disjunction is a compound statement formed by combining two simple sentences using the word “OR”. A disjunction is true when at.
1 CS 106 Computing Fundamentals II Chapter 61 “Loops” Herbert G. Mayer, PSU CS Status 7/29/2013 Initial content copied verbatim from CS 106 material developed.
VBScript Language. What is VBScript Based on the Visual Basic family of languages Supports object oriented features Interpreted Loosely Typed Implicitly.
3.3: Truth Tables. Types of Statements Negation: ~p Conjunction: p ˄ q (p and q) Disjunction: p V q (p or q, or both) Conditional: p → q (if p, then q)
Boolean Algebra. Logical Statements A proposition that may or may not be true:  Today is Monday  Today is Sunday  It is raining.
Boolean Logic. Boolean Operators (T/F) xyx AND y FFF FTF TFF TTT xyx OR y FFF FTT TFT TTT xNOT x FT TF.
Boolean Logic Logical Operators Comparison Operators Truth tables.
© 2010 Pearson Prentice Hall. All rights reserved. CHAPTER 3 Logic.
CS1022 Computer Programming & Principles Lecture 1 Logic and Proof.
Warmup Answer the following True/False questions in your head: I have brown hair AND I am wearing glasses I am male OR I am wearing sneakers I am NOT male.
How do I show that two compound propositions are logically equivalent?
Logical Form and Logical Equivalence Lecture 1 Section 1.1 Wed, Jan 12, 2005.
Introductory Logic PHI 120 Presentation: "Truth Tables – Validity vs. Soundness" This PowerPoint Presentation contains a large number of slides, a good.
1 CS 106 Computing Fundamentals II Chapter 23 “Controls And Events” Herbert G. Mayer, PSU CS Status 7/5/2013 Initial content copied verbatim from CS 106.
Relational and Boolean Operators CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Programming Lecture Note - 2 Visual Basic Programming Fundamentals.
Boolean Logic.
Simplifying Boolean Expressions. Boolean Operators (T/F) xyx AND y FFF FTF TFF TTT xyx OR y FFF FTT TFT TTT xyx XOR y FFF FTT TFT TTF xNOT x FT TF.
TRUTH TABLES. Introduction The truth value of a statement is the classification as true or false which denoted by T or F. A truth table is a listing of.
Logic and Boolean Algebra. Logic statements  Real life statements  “I use public transportation when the car is broken and I have to go to work”  “All.
Fundamental Logic Gates And, Or, Not. Logic Gates: The Basics Regulate the flow of electricity within circuits to perform desired functionalities Each.
ECE 103 Engineering Programming Chapter 4 Operators Herbert G. Mayer, PSU CS Status 6/19/2015 Initial content copied verbatim from ECE 103 material developed.
1 CS 106 Computing Fundamentals II Chapter 28 “Scope” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106 material developed.
CS 139 – Programming Fundamentals Lecture 08A. Relational/comparison Operators Relational Operator Meaning > is greater than < is less than >= is greater.
Spring 2003CMSC Discrete Structures1 Let’s get started with... Logic !
 2012 Pearson Education, Inc. Slide Chapter 3 Introduction to Logic.
3/6/20161 Let’s get started with... Logic !. 3/6/20162 Logic Crucial for mathematical reasoningCrucial for mathematical reasoning Used for designing electronic.
CS 106 Logic and Conditionals (Boolean Expressions)
Assign Yourself and Do Now Thursday, January 10, 2013.
Aspatial Selection. Table Queries Table queries are a very common GIS aspatial operation Selects a subset of records based on values of specific attributes.
1 CS 106 Computing Fundamentals II Chapter 42 “Sub Procedures And Functions” Herbert G. Mayer, PSU CS Status 8/5/2013 Initial content copied verbatim from.
Logical Operators (Connectives) We will examine the following logical operators: Negation (NOT,  ) Negation (NOT,  ) Conjunction (AND,  ) Conjunction.
Boolean Algebra & Logic Gates
Rational Expressions. relational operators. logical operators
CS 106 Computing Fundamentals II Chapter 77 “Algorithm”
CS 106 Computing Fundamentals II Chapter 33 “Conditional Statements”
Boolean logic Taken from notes by Dr. Neil Moore
CS 106 Computing Fundamentals II Chapter 71 “Indexing”
Controlling Program Flow
CS 106 Computing Fundamentals II Chapter 64 “For Loop Variations”
Controlling Program Flow
CS 106 Computing Fundamentals II Chapter 69 “Event Loop”
Herbert G. Mayer, PSU CS Status 7/19/2015
Truth tables Mrs. Palmer.
Presentation transcript:

1 CS 106 Computing Fundamentals II Chapter 32 “Boolean Expressions” Herbert G. Mayer, PSU CS Status 7/14/2013 Initial content copied verbatim from CS 106 material developed by CS professors: Cynthia Brown & Robert Martin

2 Syllabus Enlarging Our Repertoire Enlarging Our Repertoire Tests And Choices Tests And Choices Expressions Expressions Boolean Data Type Boolean Data Type Relational Operators Relational Operators Logical Operators Logical Operators And And Or Or

3 Enlarging our Repertoire You know how to write VB statements that change the values of variables, including properties of objectsYou know how to write VB statements that change the values of variables, including properties of objects Our next type of statement is a conditional: it allows us to change what the program does based on the outcome of a test, i.e. based on conditionsOur next type of statement is a conditional: it allows us to change what the program does based on the outcome of a test, i.e. based on conditions 3

4 Tests and Choices To allow a program to make choices based on conditions we need to introduce a new programming constructTo allow a program to make choices based on conditions we need to introduce a new programming construct But first we look at how we program the tests that will determine which branch our program takesBut first we look at how we program the tests that will determine which branch our program takes 4

5 Expressions A VBA expression computes a valueA VBA expression computes a value Arithmetic expressions include simple numbers and expressions built with arithmetic operators, with ( and ), and functions, such asArithmetic expressions include simple numbers and expressions built with arithmetic operators, with ( and ), and functions, such as 44 varA + 12 String expressions include simple strings and expressions built with the string operator & and possibly string functionsString expressions include simple strings and expressions built with the string operator & and possibly string functions “Hello, I’m a string.” “Your cost is “ & FormatCurrency(iceCreamTotal) 5

6 Boolean Data Type A Boolean variable has one of two possible values: True and FalseA Boolean variable has one of two possible values: True and False A Boolean expression is an expression that can evaluate to True or FalseA Boolean expression is an expression that can evaluate to True or False Constants True and False are the simplest Boolean expressionsConstants True and False are the simplest Boolean expressions More interesting examples are created by, for example, comparing two thingsMore interesting examples are created by, for example, comparing two things Complex Boolean expressions are built up out of simple ones using Boolean operationsComplex Boolean expressions are built up out of simple ones using Boolean operations 6

7 Relational Operators Relational Operators are used to create simple Boolean expressionsRelational Operators are used to create simple Boolean expressions They include:They include: =equal? not equal? <less than? <=less than or equal? >greater than? >= greater than or equal? 7

8 True - False Expressions Dim varA, varB, varC As Double varA = 1‘.000 etc. is implied varB = 2 varC = 2 varA < varB ‘is true varA <= varB ‘is true varC < varB ‘is false varC <= varB ‘is true varB = varC ‘is true‘note dual role of = operator 8

9 Logical Operators More complex Boolean expressions are built using Boolean operators.More complex Boolean expressions are built using Boolean operators. The most common Boolean operators are And, Or, and NotThe most common Boolean operators are And, Or, and Not Another Boolean operator is the exclusive or operation, XorAnother Boolean operator is the exclusive or operation, Xor Not reverses the truth of its argument:Not reverses the truth of its argument: Not (True) = False and vice-versaNot (True) = False and vice-versa 9

10 And The result of a boolean AND operation is true if and only if both of its arguments are trueThe result of a boolean AND operation is true if and only if both of its arguments are true This is called a truth table. The letters X and Y represent Boolean expressions. We have to look at all possible combinations of T and F for X and YThis is called a truth table. The letters X and Y represent Boolean expressions. We have to look at all possible combinations of T and F for X and Y XYX And Y TTT TFF FTF FFF 10

11 Or Or yields true if at least one of its arguments is true XYX Or Y TTT TFT FTT FFF 11

12 More Complex Expressions These can be worked out using truth tables Consider (Not X) Or (X and Y) XYNot XX And YNot X Or (X And Y) TTFTT TFFFF FTTFT FFTFT 12

13 Another Example Show Not (A And B) is logically equivalent to (Not A) Or (Not B) ABA And BNot (A And B) TTTF TFFT FTFT FFFT ABNot ANot B(Not A) Or (Not B) TTFFF TFFTT FTTFT FFTTT 13

14 Some Pointers Some common relational expressions do not translate directly into VBA. For example, A < B <= C would be written as (A < B) And (B <= C)Some common relational expressions do not translate directly into VBA. For example, A < B <= C would be written as (A < B) And (B <= C) Be careful with And and Or. Both operands of an And expression are evaluated even if the first one is false, and both parts of an Or expression are evaluated even if the first one is trueBe careful with And and Or. Both operands of an And expression are evaluated even if the first one is false, and both parts of an Or expression are evaluated even if the first one is true example: ( X = 0 ) Or ( Y / X < 5 ) (could cause runtime error if X = 0) 14

15 Other Uses for Logic Logical expressions are a part of database queries. If you will be using databases and writing queries, understanding how to form logical expressions will be very usefulLogical expressions are a part of database queries. If you will be using databases and writing queries, understanding how to form logical expressions will be very useful You can use logic to form advanced queries in GoogleYou can use logic to form advanced queries in Google We’ll limit ourselves to three operators: And, Or, and NotWe’ll limit ourselves to three operators: And, Or, and Not 15