12
Installment 8 Empty Bags and Identity Crises 報報報 報報報

Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

Embed Size (px)

Citation preview

Page 1: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

Installment 8

Empty Bags and Identity Crises

報告人: 李興漢

Page 2: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

Bag Multiset An unordered collection, possibly

containing duplicates

Page 3: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

Identity 0 is the identity with respect to “+” 0 is the number that X+0=0+X=X

for all numbers X

Page 4: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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

Page 5: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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

Page 6: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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;

Page 7: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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”

Page 8: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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

Page 9: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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

?

Page 10: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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

Page 11: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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

Page 12: Installment 8 Empty Bags and Identity Crises 報告人: 李興漢

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