Download presentation
Presentation is loading. Please wait.
Published bySteven Flynn Modified over 9 years ago
1
Installment 8 Empty Bags and Identity Crises 報告人: 李興漢
2
Bag Multiset An unordered collection, possibly containing duplicates
3
Identity 0 is the identity with respect to “ + ” 0 is the number that X+0=0+X=X for all numbers X
4
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 0 the product of no number at all is 0 the count of no number at all is 0 the AVG of no number at all is ? (0/0) undefined
5
MAXIMUM and MINIMUN MAX := “ minus infinity ” For each X in B do If 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
6
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;
7
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 ”
8
A consequence of the SQL errors SELECT p.* FROM P WHERE P.WEIGHT > ALL (SELECT P.WEIGHT FROM P WHERE P.CITY= ‘ Paris ’ ); SELECT p.* FROM P WHERE 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
9
Cartesian Product SELECT … FROM DEPT, EMP WHERE … ; 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_TIME FROM ; SELECT CURRENT_TIME FROM EMP; SELECT CURRENT_TIME ; SELECT CURRENT_TIME WHERE 1=0; Cartesian product ?
10
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
11
Technical correspondence Argument: 1.The sum of an empty bag of numbers should be zero. COUNTER : =0 For 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 1 5*4=5+5+5+5, if the sum is 0, how do we get the product to be 1? SUM <>0
12
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: n 0, 0!,the results are 1
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.