Upload
steven-flynn
View
224
Download
0
Embed Size (px)
Citation preview
Installment 8
Empty Bags and Identity Crises
報告人: 李興漢
Bag Multiset An unordered collection, possibly
containing duplicates
Identity 0 is the identity with respect to “+” 0 is the number that X+0=0+X=X
for all numbers X
Arithmetic operator “+”
Let B be a “bag” of N numbers.
SUM := 0;For each X in B do
SUM := SUM + X;
If N is 0 (the bag B is empty)the SUM of no number at all is 0the product of no number at all is 0the count of no number at all is 0the AVG of no number at all is ? (0/0) undefined
MAXIMUM and MINIMUNMAX := “minus infinity”For each X in B doIf X > MAX then MAX :=X;
What is X > MAX ?
MIN := “plus infinity”
What is X < MIN ?
SQL, defines both the MAX and the MIN of an empty bag to be null
Logical Operator The identity with respect to OR is false
p OR false= false OR p = p for all truth-valued expressions p
Example: “X>Y OR false” means exactly the same as “X>Y”
Logical operator EXISTS An iterated OR Applied to an empty bag yields false
EXISTS := false; For each X in B do If X>3 then EXISTS := true;
Logical Operator The identity with respect to AND is true
Logical operator FORALL Applied to an empty bag yields true Example: “all giraffes living at the bottom of
the sea are bright purple”
A consequence of the SQL errors
SELECT p.*FROM PWHERE P.WEIGHT > ALL
(SELECT P.WEIGHT FROM P WHERE P.CITY=‘Paris’ );
SELECT p.*FROM PWHERE P.WEIGHT >
(SELECT MAX(P.WEIGHT) FROM P WHERE P.CITY=‘Paris’ );
null
empty
Evaluate to true for every part
Evaluate to unknown for every part
No part selected
All parts selected
Cartesian ProductSELECT …FROM DEPT, EMPWHERE …;
The argument bag of scalars in SUM is allowed to be empty,so the argument bag of tables in FROM should be allowed to be empty
SELECT CURRENT_TIMEFROM ;
SELECT CURRENT_TIMEFROM EMP;
SELECT CURRENT_TIME ;
SELECT CURRENT_TIMEWHERE 1=0;
Cartesian product
?
Conclusion Not all dyadic operators have
identities. Ex: Subtraction
• There is no number Z, such that Z-X=X for all numbers X.
• subtraction don’t have left identity,but have right identity,namely 0, Z-0 = Z for all numbers Z
Ex: exclusive OR
Technical correspondenceArgument: 1.The sum of an empty bag of numbers should be zero.
COUNTER : =0For each X in B do begin; If COUNTER =0 then SUM:=X; else SUM:=SUM+X; COUNTER := COUNTER +1;END;
2.The product of no numbers at all to be 15*4=5+5+5+5,
if the sum is 0, how do we get the product to be 1?
SUM <>0
Technical correspondence Response: 1. He was not using the code to
prove that the sum of an empty bag should be zero—he was using it only to motivate the subsequent discussion.
2. Ex: n0, 0! ,the results are 1