1. Nested Functions
How do we evaluate a complex
formula?
What are DeMorgan’s Laws?
CS 105 Spring 2011
#1
2. Grade Example
• Suppose there is
2% extra credit
(column AK)
• Solution 1: create
column AN for
“Points + EC”
Y
Y
=IF(AK2=“Y”,AI2*102%,AI2)
Then use
• Solution 2:
=VLOOKUP(AN2,AL2:AM12,TRUE)
Y
=VLOOKUP( IF(AK2=“Y”,AI2*102%,AI2) ,AL2:AM12,TRUE)
CS 105 Spring 2011
#2
3. Nested Functions
• In order to evaluate a complex formula like
=VLOOKUP(IF(AK2=“Y”,AI2*102%,AI2),AL2:AM12,TRUE)
start by evaluating the inner parts
• The overall formula can be evaluated once the
values of the inner sub-expressions are known
• A more complex example:
IF(ISERROR(VLOOKUP(value,range,col)),”No”,”Yes”)
3
2
1
CS 105 Spring 2011
#3
4. DeMorgan’s Laws
• Consider the following formulas:
a) NOT(AND(X, Y))
b) AND(NOT(X), NOT(Y))
c) NOT(OR(X, Y))
d) OR(NOT(X), NOT(Y))
• The formulas (a) and (d) are equivalent, and so are
formulas (b) and (c)
• We can verify this with truth tables:
X
Y
AND(X,Y)
NOT(AND(X,Y))
NOT(X)
NOT(Y)
OR(NOT(X), NOT(Y))
0
0
0
1
1
1
1
0
1
0
1
1
0
1
1
0
0
1
0
1
1
1
1
1
0
0
0
0
CS 105 Spring 2011
#4
5. Example: College Admissions
• A college grants admissions based on three criteria:
SAT score (S), Letter score (L), and References (R)
S
L
R
Decision
1300
AND
8.5
AND
8.25
Strong accept
1200
AND
8.0
AND
7.80
Accept
1200
OR
7.5
OR
7.00
Reject
…
Manual
…
ELSE
• Which of these formulas is correct?
IF(AND(S>=1300,L>=8.5,R>=8.25),
"Strong accept",
IF(AND(S>=1200, L>=8, R>=7.8),
"Accept",
IF(OR(S<1200, L<7.5, R<7),
"Reject", "Manual")))
IF(OR(S<1200,L<7.5,R<7),
"Reject",
IF(OR(L<8,R<7.8),"Manual",
IF(OR(S<1300,L<8.5,R<8.25),
"Accept",
"Strong accept")))
CS 105 Spring 2011
#5
6. Testing Your Knowledge
• How do we evaluate a complex
formula?
• What are DeMorgan’s Laws?
CS 105 Spring 2011
#6