Midterm 2 for CECS 342

studied byStudied by 20 people
5.0(1)
Get a hint
Hint

What is a Turning Machine?

1 / 166

encourage image

There's no tags or description

Looks like no one added any tags here yet for you.

167 Terms

1

What is a Turning Machine?

An abstract machine model to reason about computation

New cards
2

ƛ- terms are built using only

variables, applications, and ƛ-expressions

New cards
3

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

(x z)x

New cards
4

When was the turning machine invented

1936

New cards
5

What are the two things that the turning machine has

Moveable read/write head and finite stakes

New cards
6

The turning machine has infinite tapes with cells containing what?

symbols

New cards
7

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

State In

New cards
8

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

Symbol In/Out

New cards
9

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

L/R

New cards
10

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

State Out

New cards
11

What is an example of a “State In“

inc

New cards
12

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

0 or 1

New cards
13

What is an example of “L/R“

R or L

New cards
14

What is an example of “State Out“

stop or inc

New cards
15

What does a lambda expression look like in haskell?

\x → x * x

New cards
16

Beta Reduction is ?

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

New cards
17

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

Lambda Expression

New cards
18

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

Beta Reduction

New cards
19

What is pebble stones ?

A wooden board and put pebbles on it to perform calculus

New cards
20

What is the pebble stones based off of

roman numerals

New cards
21

In the pebble stones calculator what is the pebble called

calculi

New cards
22

What is the first thing a ƛ-term can be

variable (x,yz)

New cards
23

What is the second thing a ƛ-term can be

application (P Q)

New cards
24

What is the third thing a ƛ-term can be

ƛ-abstraction (ƛx. P)

New cards
25

Who came up with ƛ-Calculus

Alonzo Church

New cards
26

What year did Alonzo Church come up with ƛ-calculus

1930’s

New cards
27

What does syntax mean

how you write it

New cards
28

What does semantics mean

what it does, mean , and do

New cards
29

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

Turning Machine

New cards
30

What is a redex

Reduction Expression

New cards
31

Haskell is lambda but with what

  • sugar syntax for easy on the eyes

  • Built in stuff (speed)

  • Static types (safety)

New cards
32

What is a lambda term really

a sequence of strings

New cards
33

What is 0 as a ƛ- expression

ƛf. ƛx. * x

New cards
34

What is 1 as a ƛ- expression

ƛf. ƛx. * fx

New cards
35

What is 2 as a ƛ-expression

ƛf. ƛx. f(fx)

New cards
36

What is the increment function in ƛ-expression

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

New cards
37

Does ƛ-calculus have sequence of operations

no

New cards
38

What is alpha congruence

changing variable to be unique to not be confused

New cards
39

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

alpha congruence

New cards
40

What number is this in ƛ- calculus

ƛf. ƛx. x

0

New cards
41

What number is this in ƛ-calculus

ƛf. ƛx. fx

1

New cards
42

What number is this in ƛ - calculus

ƛf. ƛx. f(fx)

2

New cards
43

What is this in ƛ- calculus

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

inc

New cards
44

what does alphabetically represent

letters

New cards
45

What does lexicographically

dictionary order

New cards
46

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

New cards
47

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

New cards
48

What evaluation strategy does hakell use?

leftmost / outermost (lazy evaluation)

New cards
49

lambda calculus do recursion True or False

False

New cards
50

What is addition in ƛ-calculus in haskell

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

New cards
51

what is mutiplication in ƛ-calculus in haskell

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

New cards
52

In haskell what does this evaluate to

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

9

New cards
53

In haskell what does this evaluate to

head [1,2,3]

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

exception

New cards
54

In haskell what does this evaluate to

head [1,2,3]

(\x → 7) (head [])

7

New cards
55

In haskell what does this evaluate to

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

[2,4,6]

New cards
56

In haskell what does this evaluate to

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

2

New cards
57

in haskell what does this evaluate to

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

2

New cards
58

What does this evaluate to in haskell

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

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

New cards
59

What does this evaluate to in haskell

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

2

New cards
60

What is a redex

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

New cards
61

What does it mean to be in normal form

A ƛ-expression with no redex

New cards
62

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

New cards
63

What is computation

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

New cards
64

What is the Church-Rosser Theorem

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

New cards
65

What is the evaluation strategy of Applicative Order

right-most/inner most redex first

New cards
66

What is the evaluation strategy of call-by-value

like applicative order, but no reductions inside ƛ-abstractions

New cards
67

What is the evaluation strategy of normal order

left-most/outer-most redex first

New cards
68

What is the evaluation strategy of call-by-name

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

New cards
69

What is the evaluation strategy of call-by-need

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

New cards
70

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

New cards
71

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

New cards
72

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

New cards
73

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

New cards
74

What form is this in

ƛy. (ƛx. x)y

WHNF

New cards
75

What form is this in

(ƛy. y)x

not normal

New cards
76

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.

New cards
77

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.

New cards
78

What is Haskell’s default evaluation strategy

lazy evaluation aka normal form

New cards
79

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)

New cards
80

Do beta reduction on this lambda-expression

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

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

New cards
81

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

ƛy. (ƛx. x)y

New cards
82

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

New cards
83

What is the first memory allocation type

static

New cards
84

what is the second memory allocation type

automatic allocation (stack)

New cards
85

what is the third memory allocation

dynamic (heap)

New cards
86

Where do global variables go

  1. static

  2. automatic allocation

  3. dynamic

1

New cards
87

Which memory does not change in size

  1. static

  2. automatic allocation

  3. dynamic

1

New cards
88

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

  1. static

  2. automatic allocation

  3. dynamic

1

New cards
89

What is another word for stack

automatic allocation

New cards
90

to pop on the stack what do we do

decrement

New cards
91

to push on the stack what do we do

increment

New cards
92

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

pop/push or buffet style

New cards
93

In memory where is local variables stored

  1. static

  2. automatic allocation

  3. dynamic

2

New cards
94

In memory where are return addresses stored

  1. static

  2. automatic allocation

  3. dynamic

2

New cards
95

What is stackoverflow

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

New cards
96

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

A few nanoseconds

New cards
97

True or False does each processor have its own stack

True

New cards
98

How long does the heap take

it takes a few microseconds

New cards
99

Which one is bigger in terms of memory heap or ram

heap and could possibly have more

New cards
100

what are two things the heap is known for

holding large items and being persistent

New cards

Explore top notes

note Note
studied byStudied by 25 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 29 people
Updated ... ago
4.5 Stars(2)
note Note
studied byStudied by 14 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 4 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
note Note
studied byStudied by 7 people
Updated ... ago
5.0 Stars(2)
note Note
studied byStudied by 16 people
Updated ... ago
5.0 Stars(1)

Explore top flashcards

flashcards Flashcard44 terms
studied byStudied by 59 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard61 terms
studied byStudied by 2 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard238 terms
studied byStudied by 4 people
Updated ... ago
4.0 Stars(1)
flashcards Flashcard87 terms
studied byStudied by 5 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard97 terms
studied byStudied by 7 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard273 terms
studied byStudied by 33 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard94 terms
studied byStudied by 6 people
Updated ... ago
5.0 Stars(1)
flashcards Flashcard22 terms
studied byStudied by 30 people
Updated ... ago
5.0 Stars(1)