




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to quantifiers in logic and perl programming language. It includes examples of truth tables for boolean functions and explanations of universally and existentially quantified statements. The document also covers the difference between logic and programming symbols and the process of translating english sentences into quantified statements.
Typology: Lecture notes
1 / 28
This page cannot be seen from the preview
Don't miss anything!





















sub printBool { my ($val) = @_; # &printBool($x) assigns $val=$x if ($val) { print 'true '; } else { print 'false'; } }
sub BoolFun { my( $v1, $v2 ) = @_; # &BoolFun($x,$y) assigns $v1=$x, $v2=$y return !( $v1 && $v2 ); }
print " b1 b2 f(b1, b2)\n"; print " ----- ----- --------------\n"; for ($b1=0; $b1<=1; $b1++) { for ($b2=0; $b2<=1; $b2++) { print " "; printBool( $b1 ); # print the first variable print " "; printBool( $b2 ); # print the second variable print " "; printBool( BoolFun( $b1, $b2 ) ); # print the result print "\n"; } } Perl example: printing a truth table Wednesday, September 08, 2010 1:15 PM Docsity.com
sub TRUE { 1 } sub FALSE { undef } if ($_[0]) { return "true "; } else { return "false"; } sub BoolText { } print BoolText($b1). " "
. BoolText($b2). " " . BoolText(! ($b1 && $b2)) . "\n"; foreach my $b2 (&FALSE, &TRUE) { } foreach my $b1 ( &FALSE, &TRUE ) { } My version Monday, September 13, 2010 3:08 PM Docsity.com
(1,2,3) is an array literal. @a = (); # sets @a to be empty. @a = (1,2,"hello"); # makes $a[2] eq "hello". It is perfectly legal to write (1,2,3)[2] which has value 3! Array literals Sunday, September 12, 2010 10:22 AM Docsity.com
Perl has a unique feature called parallel assignment. ($a, $b, $c)=(1,42, "hello"); One can write to set $a to 1, $b to 42, and $c to "hello". ($a,$b,@c)=(22,"hi","ho","there"); One can write to set $a to 22, $b to "hi", and @c to ("ho", "there") The last array consumes the remaining elements. Parallel assignment Sunday, September 12, 2010 10:25 AM Docsity.com
Copy the code from the truth table. Edit it to evaluate a truth table for three variables. Can find the code in the Examples heading for last Wed's lecture. Your first assignment: due Wed Your first assignment Sunday, September 12, 2010 10:33 AM Docsity.com
&&, and: in Perl : in logic We now have two concepts of "and" We use && to denote something to do , i.e., A && B is a command that computes a value (true or false). We use to denote "a statement about the world". A B is not a command, but rather, a description of state. What is the difference? Why are logic and programming symbols different? Wednesday, September 08, 2010 12:39 PM Docsity.com
Often, we want to make statements that are true over a set of things. For example, we want to make statements about what happens for every number. This is called "quantifying a statement". Quantifying your statements Saturday, September 11, 2010 6:22 PM Docsity.com
Every variable in a parameterized predicate has a domain : a set of reasonable values. x is in the domain of machines in our building. P(x)="machine x is working." x is in the domain of numbers. Q(x)="x>10" A "parameterized predicate" is a statement of the form P(x) where x is a variable. Parameterized predicates Saturday, September 11, 2010 4:57 PM Docsity.com
The notation means "for every x, P(x) is true". The construction is called a universal quantifier. The quantified statement is true if P(x) is indeed true for all x, and is false if P(x) is false for at least one x. Writing universally quantified statements Saturday, September 11, 2010 5:04 PM Docsity.com
The notation means "there exists x such that P(x) is true". The symbol is called an existential quantifier. The quantified statement is true if there are one or more values of x such that P(x) is true, and is false if P(x) is false for every x. Writing existentially quantified statements Saturday, September 11, 2010 5:04 PM Docsity.com
Distributive laws of quantifiers Saturday, September 11, 2010 5:10 PM Docsity.com
Identify the variables "For every walrus..." or "There is a llama…" Determine the quantifiers, e.g., Substitute them into the sentence. Then think of the remainder of the sentence as the predicate. To express an English sentence as a quantified statement, Expressing English as quantified statements Saturday, September 11, 2010 7:15 PM Docsity.com
"All students are smart" All students are smart P(s)="s is smart" Result: Example of expressing quantified statements Saturday, September 11, 2010 7:18 PM Docsity.com
Some walruses can sing to music. Some walruses P(w)="w can sing to music" Result: Example of translating English Saturday, September 11, 2010 7:20 PM Docsity.com