Midterm 2 for CECS 342

5.0(1)
studied byStudied by 22 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/166

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

167 Terms

1
New cards

What is a Turning Machine?

An abstract machine model to reason about computation

2
New cards

ƛ- terms are built using only

variables, applications, and ƛ-expressions

3
New cards

Apply one B-reduction step to the ƛ-expression (ƛy, (x y)x)z

(x z)x

4
New cards

When was the turning machine invented

1936

5
New cards

What are the two things that the turning machine has

Moveable read/write head and finite stakes

6
New cards

The turning machine has infinite tapes with cells containing what?

symbols

7
New cards

In the program order for the turning machine what is step 1

State In

8
New cards

What is an exampleIn the program order for the turning machine what is step 2

Symbol In/Out

9
New cards

In the program order for the turning machine what is step 3

L/R

10
New cards

In the program order for the turning machine what is step 4

State Out

11
New cards

What is an example of a “State In“

inc

12
New cards

What is an example of a “Symbol In/Out“

0 or 1

13
New cards

What is an example of “L/R“

R or L

14
New cards

What is an example of “State Out“

stop or inc

15
New cards

What does a lambda expression look like in haskell?

\x → x * x

16
New cards

Beta Reduction is ?

the process of calculating a result from the application of a function to an expression

17
New cards

What is this (\x → x * x) ?

Lambda Expression

18
New cards

(\x → x x) => 3 × 3 is called what ?

Beta Reduction

19
New cards

What is pebble stones ?

A wooden board and put pebbles on it to perform calculus

20
New cards

What is the pebble stones based off of

roman numerals

21
New cards

In the pebble stones calculator what is the pebble called

calculi

22
New cards

What is the first thing a ƛ-term can be

variable (x,yz)

23
New cards

What is the second thing a ƛ-term can be

application (P Q)

24
New cards

What is the third thing a ƛ-term can be

ƛ-abstraction (ƛx. P)

25
New cards

Who came up with ƛ-Calculus

Alonzo Church

26
New cards

What year did Alonzo Church come up with ƛ-calculus

1930’s

27
New cards

What does syntax mean

how you write it

28
New cards

What does semantics mean

what it does, mean , and do

29
New cards

when you do a lambada expression + beta reduction what do you get

Turning Machine

30
New cards

What is a redex

Reduction Expression

31
New cards

Haskell is lambda but with what

  • sugar syntax for easy on the eyes

  • Built in stuff (speed)

  • Static types (safety)

32
New cards

What is a lambda term really

a sequence of strings

33
New cards

What is 0 as a ƛ- expression

ƛf. ƛx. * x

34
New cards

What is 1 as a ƛ- expression

ƛf. ƛx. * fx

35
New cards

What is 2 as a ƛ-expression

ƛf. ƛx. f(fx)

36
New cards

What is the increment function in ƛ-expression

ƛn. ƛf. ƛx. (nf)(fx)

37
New cards

Does ƛ-calculus have sequence of operations

no

38
New cards

What is alpha congruence

changing variable to be unique to not be confused

39
New cards

What is this called when we change the variable from this (ƛf. ƛx x) → (ƛg. ƛy. y)

alpha congruence

40
New cards

What number is this in ƛ- calculus

ƛf. ƛx. x

0

41
New cards

What number is this in ƛ-calculus

ƛf. ƛx. fx

1

42
New cards

What number is this in ƛ - calculus

ƛf. ƛx. f(fx)

2

43
New cards

What is this in ƛ- calculus

ƛn. ƛf. ƛx. (nf) (fx)

inc

44
New cards

what does alphabetically represent

letters

45
New cards

What does lexicographically

dictionary order

46
New cards

When looking at evaluation strategies what is this an example of

(\x → x x)(1 + 2) => (\x - > x x)3 =B> 3*3 => 9

rightmost / innermost

47
New cards

When looking at evaluation strategies what is this an example of

(\x → x x)(1+2) => (1+2) (1+2) => 3 + (1+2) =>

3 * 3 => 9

leftmost / outermost

48
New cards

What evaluation strategy does hakell use?

leftmost / outermost (lazy evaluation)

49
New cards

lambda calculus do recursion True or False

False

50
New cards

What is addition in ƛ-calculus in haskell

\m n f x → m f (n f x)

51
New cards

what is mutiplication in ƛ-calculus in haskell

\m n f x → m (n f) x

52
New cards

In haskell what does this evaluate to

(\x => x * x)(1+2)

9

53
New cards

In haskell what does this evaluate to

head [1,2,3]

(\x → x * x) (head [])

exception

54
New cards

In haskell what does this evaluate to

head [1,2,3]

(\x → 7) (head [])

7

55
New cards

In haskell what does this evaluate to

map (2*) [1,2,3]

[2,4,6]

56
New cards

In haskell what does this evaluate to

head(map (2*) [1,2,3])

2

57
New cards

in haskell what does this evaluate to

head(map (2*) [1, head [], 3])

2

58
New cards

What does this evaluate to in haskell

take 10 (map (2*) [1 . .]])

[2,4,6,8,10,12,14,16,18,20]

59
New cards

What does this evaluate to in haskell

head (2*1 : map (2*) [2,3])

2

60
New cards

What is a redex

left hand side of a reduction rule (a lambda applied to something)

61
New cards

What does it mean to be in normal form

A ƛ-expression with no redex

62
New cards

What does it mean to be in weak head normal form (WHNF)

if it has a ƛ-abstraction (or constructor or partially applied built in function in haskell) also no redex on the outside

63
New cards

What is computation

reduction of a ƛ-expression to normal form (or WHNF)

64
New cards

What is the Church-Rosser Theorem

The ƛ-calculus is confluent (flowing or merging some strategies faster than others)

65
New cards

What is the evaluation strategy of Applicative Order

right-most/inner most redex first

66
New cards

What is the evaluation strategy of call-by-value

like applicative order, but no reductions inside ƛ-abstractions

67
New cards

What is the evaluation strategy of normal order

left-most/outer-most redex first

68
New cards

What is the evaluation strategy of call-by-name

normal order, but stop at WHNF (no reductions inside ƛ-abstractions)

69
New cards

What is the evaluation strategy of call-by-need

call-by-name + memoization (optimization technique used primarily to speed up)

70
New cards

What is the evaluation strategy of lazy evaluation

an implementation of call-by-need with thunks (A thunk is an object in heap memory storing the state of the delayed evaluation of a function) used by haskell

71
New cards

Consider the following C code snippet:

int n = 0;

void count(int k) {

printf(“count: %d\n”, n += k);

}

Where will memory for the C-string “count: %d\n“ be allocated

static memory because there is no change in size

72
New cards

Consider the following C code snippet:

int n = 0;

void count(int k) {

printf(“count: %d\n”, n += k);

}

Where will the memory for the variable n be allocated?

static memory because global variables go there

73
New cards

Consider the following C code snippet:

int n = 0;

void count(int k) {

printf(“count: %d\n”, n += k);

}

Where will the memory for the variable k be allocated

on the stack

74
New cards

What form is this in

ƛy. (ƛx. x)y

WHNF

75
New cards

What form is this in

(ƛy. y)x

not normal

76
New cards

What does functional programming mean

functions that are evaluated are the main way of gaining and transforming data, functional programming is stateless. Rather than assigning values which can then be mutated like what happens in imperative languages, the value returned by a function is only dependent on its input.

77
New cards

What does imperative programming mean

a list of steps that need to be executed, there needs to be some way of keeping track of everything computed to that point. That’s (obviously) where variables come in. They are keeping the “state” of where the program is at which then can control where the program should go to next which continues to modify the state.

78
New cards

What is Haskell’s default evaluation strategy

lazy evaluation aka normal form

79
New cards

What is the next redex in normal order (left most/ outer most) of the lambda-expression

(ƛy. (ƛx. x) y) ((ƛz. z) 3)

(ƛy. (ƛx. x) y) ((ƛz. z) 3)

80
New cards

Do beta reduction on this lambda-expression

(ƛy. (ƛx. x) y) ((ƛz. z) 3)

(ƛx. x)(ƛz. z)3

81
New cards

Evaluate the ƛ-expression ƛy. (ƛx. x) y to WHNF

ƛy. (ƛx. x)y

82
New cards

What is the next redex in applicative order (right most/ inner most) of the lambda-expression (ƛy. (ƛx. x)y) ((ƛz. z) 3)

(ƛz. z)3

83
New cards

What is the first memory allocation type

static

84
New cards

what is the second memory allocation type

automatic allocation (stack)

85
New cards

what is the third memory allocation

dynamic (heap)

86
New cards

Where do global variables go

  1. static

  2. automatic allocation

  3. dynamic

1

87
New cards

Which memory does not change in size

  1. static

  2. automatic allocation

  3. dynamic

1

88
New cards

Which memory is allocated at loadtime and it is fixed in size during runtime

  1. static

  2. automatic allocation

  3. dynamic

1

89
New cards

What is another word for stack

automatic allocation

90
New cards

to pop on the stack what do we do

decrement

91
New cards

to push on the stack what do we do

increment

92
New cards

what is an analogy or a reference that relates to the stack

pop/push or buffet style

93
New cards

In memory where is local variables stored

  1. static

  2. automatic allocation

  3. dynamic

2

94
New cards

In memory where are return addresses stored

  1. static

  2. automatic allocation

  3. dynamic

2

95
New cards

What is stackoverflow

It is uncontrolled recursion (should be linear or logarithmic) and when big stuff goes in there that is not supposed too

96
New cards

How long does it take to allocate and deallocate in automatic allocation

A few nanoseconds

97
New cards

True or False does each processor have its own stack

True

98
New cards

How long does the heap take

it takes a few microseconds

99
New cards

Which one is bigger in terms of memory heap or ram

heap and could possibly have more

100
New cards

what are two things the heap is known for

holding large items and being persistent