Causes and E fg ects Andreas Zeller 1 bug.c double bug(double - - PDF document

causes and e fg ects
SMART_READER_LITE
LIVE PREVIEW

Causes and E fg ects Andreas Zeller 1 bug.c double bug(double - - PDF document

Causes and E fg ects Andreas Zeller 1 bug.c 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]; } 2 2 What do we do now? We can follow Platon and


slide-1
SLIDE 1

Andreas Zeller

Causes and Efgects

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

3

Where is the error which causes this failure?

1 2

What do we do now? We can follow Platon and say: Hey, let’s just verify this compiler, let’s do more abstraction, let’s do more of the same. (This is what I learned in school: The state of the art is bad, but if

  • nly people would do

it our way, than the world would be a

3

slide-2
SLIDE 2

4

Locating Errors

An 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”?

// Get #years, #days since 1980 days = ...; year = 1980; while (days > 365) { if (IsLeapYear(year)) { if (days > 366) { days -= 366; year += 1; } } else { days -= 365; year += 1; } }

6

Locating Causes

An aspect of the execution causes a failure if it can be altered such that the failure no longer occurs:

  • Input (“11 14”)
  • Variables (“argc = 2”)
  • Statements (“Line 37”)

Note that a cause need not be an error!

4 http://www.aeroxp.org/2009/01/ lesson-on-infinite-loops/ http://www.youtube.com/watch? v=fYTJ9v2vsaE 5 6

slide-3
SLIDE 3

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?

7

Aristotle

(384-322 BC)

8

Aristotle on Causality

Aristotle 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

9

7 8 9

slide-4
SLIDE 4

Example

Creating 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

10

William of Ockham

(1288-1349)

11

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

12

10 11 12

slide-5
SLIDE 5

David Hume

(1711-1776)

13

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

  • f causation, and all that our idea of

causation can amount to.

14

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”

15

13 14 15

slide-6
SLIDE 6

Counterfactuals

16

  • We may define a cause to be an object

followed by another, and where all the

  • bjects, similar to the first, are followed by
  • bjects 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

17

Alternate world Effect does not occur

Causality

Actual world Effect does occur Causes

18

bug.c

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]; } ✘

Hume also gave an alternate definition of causality, though - a counterfactual one. “Counterfactual” means to reason about the opposite of the current fact (the cause)

16 17 18

slide-7
SLIDE 7

19

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

20

Alternate world empty.c: GCC works fine

Causes as Difgerences

Actual world bug.c: GCC crashes Cause: bug.c

More possible causes

21

GCC code invocation me Linux electricity

  • xygen

19 20 21

slide-8
SLIDE 8

David Lewis

(1941-2001)

22

Lewis on Causation

23

  • 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.

Possible Worlds

24

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

22 23 24

slide-9
SLIDE 9

25

Actual Causes

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

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

27

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

25 26 27

slide-10
SLIDE 10

28

Isolating Causes

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]; } ✘

29

Isolating Causes

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]; }

Actual cause narrowed down

30

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

28 29 30

slide-11
SLIDE 11

31

Isolating Causes

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]; } ✘

32

Isolating Causes

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]; }

Actual cause of the GCC crash

33

Alternate world Actual world

Isolating Causes

Mixed world

✔ ✘

Test

?

31 32 33

slide-12
SLIDE 12

34

Alternate world Actual world

Isolating Causes

Mixed world

✔ ✘

Test

?

“+ 1.0”

Search Space

35

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

Search Space

36

Input State Code OS Compiler Processor FBI E.T. Them!

34 35 36

slide-13
SLIDE 13

Ockham’s Razor

37

  • Whenever you have

competing theories for how some effect comes to be, pick the simplest.

Ockham’s Razor

38

In our context:

  • Whenever you have the choice between

multiple causes, pick the one whose alternate world is closer.

Search Space

39

close far away far out

Input State Code OS Compiler Processor FBI E.T. Them!

37 38 39

slide-14
SLIDE 14

Hanlon’s Razor

40

  • Never explain

by malice which is adequately explained by stupidity

Verifying Causes

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

41

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

42

Causes and Efgects

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

Napoleon, Goethe, Richard Feinman, Robert Heinlein

40 41 42

slide-15
SLIDE 15

Verifying Causes

So it wasn’t the configuration after all

43

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

Verifying Causes

Avoid post hoc ergo propter hoc fallacies

44

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

Verifying Causes

45

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

43 44 45

slide-16
SLIDE 16

Is variable a zero?

46

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

What’s going on?

47

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

What’s going on?

48

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

46 47 48

slide-17
SLIDE 17

What’s going on?

49

double a; a = compute_value(); printf("a = %f\n", a); We have isolated the format "%d" as the actual failure cause

Preemption

50

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?

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

51

49 50 51

slide-18
SLIDE 18

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

52

Concepts

53

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

54 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

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

52 53 54