causes and effects - universität des saarlandes · causes and effects to prove causality, one...

64
Andreas Zeller Causes and Eects

Upload: others

Post on 17-Oct-2019

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Andreas Zeller

Causes and Effects

Page 2: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

2

double bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

bug.c

Page 3: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

3

Where is the error which causes this failure?

Page 4: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

4

Locating ErrorsAn error is a deviation from what is correct, right, or true:

• Input (“The URL must be well-formed”)

• Variables (“link is zero”)

• Statements (“even(2) must return true”)

How do we know one of these is correct?

How can we say “The defect is here”?

Page 5: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

5

Locating CausesAn aspect of the execution causes a failureif it can be altered such that the failureno longer occurs:

• Input (“11 14”)

• Variables (“argc = 2”)

• Statements (“Line 37”)

Note that a cause need not be an error!

Page 6: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Causality

The notion of causality is deeply linked to fundamental questions of philosophy:

• What is it that makes things happen?

• Can we predict the future from causes?

• If everything has a cause, what is the ultimate cause of events in the past?

6

Page 7: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Aristotle(384-322 BC)

7

Page 8: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Aristotle on CausalityAristotle suggested four types of causes:

• The material of which things come

• The form which things have when they are perfected

• The moving cause or actual agent

• The purpose or function of such things

8

Page 9: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

ExampleCreating a silver chalice for a religious ceremony

• Material cause – the silver

• Formal cause – the design of the chalice

• Efficient cause – the silversmith

• Final cause – the religious ceremony

9

Page 10: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

William of Ockham(1288-1349)

10

Page 11: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Ockham on Causality

• The only way in which we can establish any causal connection between one thing and another is the observation that when one of these occurs, the other also occurs at the same time and at or near the same place.

• This is the only way to establish causality

11

Page 12: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

David Hume(1711-1776)

12

Page 13: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Hume on Causality• When we see that two events always occur

together, we tend to form an expectation that when the first occurs, the second will soon follow.

• This constant conjunction and the expectation thereof is all that we can know of causation, and all that our idea of causation can amount to.

13

Page 14: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Causality as Illusion

• Just because the sun has risen every day since the beginning of the Earth does not mean that it will rise again tomorrow.

• Bertrand Russell: “causation = superstition”

14

Page 15: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Counterfactuals

15

• We may define a cause to be an object followed by another, and where all the objects, similar to the first, are followed by objects similar to the second. Or, in other words, where, if the first object had not been, the second never had existed. (Hume, 1748)

• Hume never explored this alternative

Page 16: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

16

Alternateworld

Effect does not occur

CausalityActual world

Effect does occur

Causes

Page 17: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

17

bug.cdouble bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

Page 18: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

18

double bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

✔empty.c

Page 19: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

19

Alternateworld

empty.c: GCC works fine

Causes as DifferencesActual world

bug.c: GCC crashesCause:bug.c

Page 20: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

More possible causes

20

GCC code invocation me

Linux electricity oxygen

Page 21: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

David Lewis(1941-2001)

21

Page 22: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Lewis on Causation

22

• C o→ E means “If C had been the case, E would have been the case”

• C causes E if C o→ E and ¬C o→ ¬E hold.

• C o→ E holds if some C-world where E holds is closer to the actual world than is any C-world where E does not hold.

Page 23: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Possible Worlds

23

C o→ E holds if some C-world where E holds is closer to the actual world than is any C-world where E does not hold.

‣ A world with an alternate GCC input is closer than a world without oxygen

‣ A world with GCC fixed may be closer than a world with an alternate GCC input

Page 24: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

24

Actual Causes

Actual cause

“The” cause (actual cause) is a minimal difference

Page 25: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

25

double bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

✔Isolating Causes

Page 26: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

26

double bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

✔Isolating Causes

Page 27: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

27

Isolating Causesdouble bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

Page 28: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

28

Isolating Causesdouble bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

Actual cause narrowed down

Page 29: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

29

double bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

✔Isolating Causes

Page 30: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

30

Isolating Causesdouble bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

Page 31: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

31

Isolating Causesdouble bug(double z[], int n) { int i, j;

i = 0; for (j = 0; j < n; j++) { i = i + j + 1; z[i] = z[i] * (z[0] + 1.0); } return z[n];}

Actual cause of the GCC crash

Page 32: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

32

Alternate worldActual world

Isolating Causes

Mixed world

✔✘

Test ?

Page 33: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

33

Alternate worldActual world

Isolating Causes

Mixed world

✔✘

Test ?

“+ 1.0”

Page 34: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Search Space

34

The choice of an initial set of differences determines the search space for causes:

• the input (data, configuration, …)

• the program state

• the program code

Sets a common context between worlds

Page 35: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Search Space

35

Input State Code

OS Compiler Processor

FBI E.T. Them!

Page 36: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Ockham’s Razor

36

• Whenever you have competing theories for how some effect comes to be, pick the simplest.

Page 37: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Ockham’s Razor

37

In our context:

• Whenever you have the choice between multiple causes, pick the one whose alternate world is closer.

Page 38: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Search Space

38

close

far away

far out

Input State Code

OS Compiler Processor

FBI E.T. Them!

Page 39: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Hanlon’s Razor

39

• Never explain by malice which is adequately explained by stupidity

Page 40: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Verifying Causes

Do we know the configuration in .psharprc causes the failure?

40

$ ./psharp db.p#.psharprc: 37: no such interpreter.psharprc: 37: bailing outSegmentation fault

Page 41: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

41

Causes and Effects

To prove causality, one must show that

• the effect occurs when the cause occurs

• the effect does not occur when the cause does not.

This is the only way to prove causality

Page 42: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Verifying Causes

So it wasn’t the configuration after all

42

$ mv ~/.psharprc ~/.psharprc.orig$ ./psharp db.p#Segmentation fault

Page 43: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Verifying Causes

Avoid post hoc ergo propter hoc fallacies

43

$ ./psharp db.p#.psharprc: 37: no such interpreter.psharprc: 37: bailing outSegmentation fault

Page 44: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Verifying Causes

44

a = compute_value();printf("a = %d\n", a);

a = 0

Page 45: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Is variable a zero?

45

a = compute_value();a = 1;printf("a = %d\n", a);

a = 0

Page 46: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

What’s going on?

46

double a;a = compute_value();a = 1;printf("a = %d\n", a);

a = 0

Page 47: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

What’s going on?

47

double a;a = compute_value();printf("a = %f\n", a);

a = 3.14…

Page 48: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

What’s going on?

48

double a;a = compute_value();printf("a = %f\n", a);

We have isolated the format "%d"as the actual failure cause

Page 49: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Preemption

49

Billy and Suzy throw rocks at a bottle. Suzy throws first so that her rock arrives first and shatters the glass. Without Suzy's throw, Billy's throw would have shattered the bottle.

• Does Suzy’s throw cause the shattering?

Page 50: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Alteration

• C influences E if C can be altered to C’ such that E’ occurs instead of E (Lewis; 1999)

• If Suzy had not thrown the stone, the bottle would have shattered in a different manner

• Therefore, Suzy’s throw influenced and caused the original shattering

50

Page 51: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

What’s the Failure?• Every failure has some aspects that we

consider relevant

• This choice influences the search for causes

• If the entire state of the program is part of the failure, we get very detailed causes

• If just one aspect is relevant, we get simpler causes – sometimes too simple

51

Page 52: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Concepts

52

A cause is an event preceding another event (the effect) without which the effect would not have occurred

A cause can be seen as a difference between a world where the effect occurs and a world where it does not

An actual cause means a minimal difference

Page 53: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

53

If C is a cause and E is its effect,then C must precede E.

yes noyes no✗

Page 54: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

54

If C is a circumstance that causes a failure, then it is possible to change C such that the failure no longer occurs.

yes noyes no✗

Page 55: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

55

If some cause C is an actual cause, then altering C induces the smallest possible

difference in the effect.

yes noyes no✗

Page 56: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

56

Every failure cause impliesa possible fix.

yes noyes no✗

Page 57: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

57

For every failure, there is exactly one actual cause.

yes noyes no✗

Page 58: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

58

For every defect, there is exactly one correction.

yes noyes no✗

Page 59: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

59

A failure cause can be determined without executing the program.

yes noyes no✗

Page 60: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

60

A failure is the difference to the closest possible world in which the cause does

not occur.

yes noyes no✗

Page 61: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

61

If I observe two runs (one passing, one failing) with a minimal difference in input, then I have found an actual failure

cause.

yes noyes no✗

Page 62: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

62

A minimal and successful correction proves that the altered code was the

actual failure cause.

yes noyes no✗

Page 63: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

Quiz

63

Increasing the common context between the possible worlds results in

smaller causes.

yes noyes no✗

Page 64: Causes and Effects - Universität des Saarlandes · Causes and Effects To prove causality, one must show that • the effect occurs when the cause occurs • the effect does not

64

This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit

http://creativecommons.org/licenses/by/1.0

or send a letter to Creative Commons, 559 Abbott Way, Stanford, California 94305, USA.