Professor Dan Ryan
daniel.ryan@utoronto.ca
https://slides.com/djjr/info-jigs
View on Google Drive
A jig is a sort of "meta-tool" that woodworkers use to hold a piece of work in a particular way so that their tools can produce a desired transformation.
When dealing with information how we arrange it, how we hold it in place, has a big effect on how easy it is to manipulate and even how easy it is to think about.
"This is Water" video
In what year will I die?
What's for dinner tonight?
How does this novel I am reading end?
Heads or tails?
In what year will I die?
Say I'm 60 now. At the extreme, humans live to, say, 120. So there are, at the outside, 60 possible years of my death.
What's for dinner tonight?
Let's see. If we are eating in and not shopping, we might prepare one of the ready-made meals we have, several kinds of eggs, French toast or pancakes, several kinds of soup, we have a number of meats and vegetable that could be combined…. All told, several dozen possibilities. But many are extremely unlikely - we don't like them, they run counter to cultural norms, they're too difficult to prepare. Each of those things reduces the uncertainty.
How does this novel I am reading end?
Well, *I* don't know how it ends; I've not finished reading it, but there is no uncertainty about how it ends. It ends like it ends. Maybe there's a difference between THE and MY uncertainty?
Heads or tails?
We can just flip the coin once and we will know.
In what year will I die?
Maybe my genome, my family history, my current health, and ....
What's for dinner tonight?
What is the decision process? What is the total set of relevant data going into it?
How does this novel I am reading end?
It is what it is.
Heads or tails?
We can just flip the coin once and we will know.
In what year will I die?
Perhaps if I had access to my genome, my family history, my current health, and lots of science I could "compute" this?
What's for dinner tonight?
Who gets to decide? How do they decide? Or should I just wait until tonight and find out?How does this novel I am reading end?
How does this novel I am reading end?
Read on.
Heads or tails?
We can just flip the coin once and we will know.
that information is measurable and that there is an answer to "what's the smallest amount of information?"
I picked a card. How uncertain are you about my pick?
STOP+THINK: Can I give you any more information without telling you?
Imagine a deck of 64 cards. Four suits of 16 cards. Two red, two black as usual.
I select one card.
What's the maximum number of possibilities you can resolve with one question? Two?
If one question can decide between two possibilities and two questions can decide between four possibilities, how many questions does it take to decide among three possibilities?
If one question can decide between two possibilities and two questions can decide between four possibilities, how many questions does it take to decide among three possibilities?
Before we continue, let's do a quick bit of math review for a tool we'll need in the following video. Think back to when you learned about exponents in school or our review of them in the Counting and Complexity module:
5×5×5=53=125
We can ask "to what power do you raise 5 to get 125?" Answer 3. We call 3 the logarithm base 5 of 125. We'd write this log5(125)=3.
Nothing too fancy about it: logarithm is just the opposite of raising a number to some power.
The other thing we want to recall from that module is how we count up the number of options when we make sequential choices. Suppose we have two letters A and B and we form three-letter words with them. How many different words are there?
STOP+THINK: The Hawaiian alphabet has 13 letters: five vowels (a e i o u) and eight consonants (h l k w m n p) and a "glottal stop" called 'okina. Use the "is it before or after" method to determine how many bits are required to represent a letter in this alphabet.
We'd reason like this: there are 2 ways to select the first letter, 2 ways to select the second letter, and 2 ways to select the third letter. And so there are, altogether 2×2×2=23=8 different three-letter words we can form using the letters A and B:
AAA AAB ABA ABB BAA BAB BBA BBB
A pattern that might remind us a little of when we wrote out truth tables.
Let's watch another in that series of videos from Khan Academy (9m52s).
Read more at the Computer History Museum and more on the slides below
4 x 16 x 16 =1024 bits
Read more about magnetic core memory here
Video with closeups of ferrite core memory board (8m2s)
(1918-2016) MIT professor credited with founding field of "system dynamics," influencing the development of global sustainability models, and received patent for magnetic core memory.
Memory composed of bits can be treated as words of different sizes.
Generally multiples of 2, starting with 8.
16 bit words,
32 bit words,
64 bit words,
128 bit words...
H 0100 1000 E 0100 0101 L 0100 1100 L 0100 1100 O 0100 1111 _ 0010 0000 U 0101 0101 N 0100 1110 I 0100 1001 V 0101 0110 E 0100 0101 R 0101 0010 S 0101 0011 E 0100 0101
H 48x=72 E 45x=69 L 4Cx=76 L 4Cx=76 O 4Fx=79 _ 40x=64 U 55x=85 N 4Ex=78 I 49x=73 V 56x=86 E 45x=69 R 52x=82 S 53x=83 E 45x=69
{
const x = 5;
var y = 'axe'
var z = [4,9]
}
Each line is a "declaration" of a name
const means "constant"
var means "variable"
The initial values can be numbers, character strings, or even sets of numbers
What kind of name?
name
=
initial value
{ const x = 5; var y = 'axe' var z = [4,9] }
0 0 0 0 0 1 0 1
0 1 1 0 0 0 0 1
0 1 1 1 1 0 0 0
0 1 1 0 0 1 0 1
0 0 0 0 0 1 0 0
0 0 0 0 1 0 0 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
physical memory
Name | Kind of Name | Base Address |
---|---|---|
x
y
z
constant
variable
variable
0
1
4
name table
0 0 0 0 0 0 0 0
0010 1100 0011 1101 0100 1010 0011 1101
0000 0000 0000 0000 0000 0000 0000 0000
See also:
0010 1100 0011 1101 0100 1010 0011 1101
0000 0000 0000 0000 0000 0000 0000 0000
0010 1100 0011 1101 0100 1010 0011 1101
0000 0000 0000 0000 0000 0000 0000 0000
a set of values that bits can represent
and
a set of operations that can be done to these values
0010110000111101 0100101000111101
742214205
44,61,74,61
2C3D4A3D
'D','a','t','a'
false,false,true,false,true,true,false,false,
false,false,true,true,true,true,false,true,
false,true,false,false,true,false,true,false,
false,false,true,true,true,true,false,true
'Data'
https://stackoverflow.com/questions/48304498/are-wrappers-of-a-primitive-type-primitives-types-too
15, 34.65
"word", "hello you", "Say 'this'", ""
TRUE, FALSE
null
undefined
https://upload.wikimedia.org/wikipedia/commons/1/10/Python_3._The_standard_type_hierarchy.png
Operations
x.enqueue(newItem,priority)
y = x.dequeue()
x = new priorityQueue()
Write a pseudocode version of the protocol for a priority queue.
Hospital emergency room…
Basic rule: first come, first served.
BUT we move more serious cases toward the front of the line. Assume three levels of seriousness: low, medium, and high.
Write a pseudocode version of the protocol for a priority queue.
Wait for newcomer to arrive
Assess serious of newcomer’s illness
Find last person in the queue
Compare seriousness
If new more serious, consider next in queue
If new same or less, insert person in queue
Repeat until newcomer is in queue
Wait for newcomer to arrive
Assess serious of newcomer’s illness
Find last person in the queue
Compare seriousness
If new more serious, consider next in queue
If new same or less, insert person in queue
Repeat until newcomer is in queue
Operations
enqueue(newItem)
dequeue()
FIRST COME, FIRST SERVED
Operations
push(newItem)
pop()
LAST DISH CLEANED IS FIRST DISH USED
Stack Simulation
Last In, First Out
Useful when keeping track of interruptions.
First In, First Out
Useful when things have to wait to be serviced.
LIFO or FIFO?
Random access by index: bin #14
Has a name, for example, myArray
Has zero or more elements
Each element is referred to by an index which indicates its position.
The index typically starts from 0 for the first element
e.g., myArray[4]
myArray = [78, 91, 1, 0, -29]
We can list the elements in square brackets separated by commas
3 | 6 | 12 | 0 | 32 | 6 | 909 | 1 | 88 |
---|
x
[0] [1] [2] [3] [4] [5] [6] [7] [8]
x[index] x.push(newItem)
x.length
0
1
2
3
"Who Knows?"
12
null
343.938
"alpha"
"carrot"
"777"
"Zebra"
"Who Knows?"
12
null
343.938
Keys
"alpha"
"carrot"
"777"
"Zebra"
Values
"Who Knows?"
12
null
343.938
myMap["carrot"] = 12
myMap.carrot = 12
"alpha"
"carrot"
"777"
"Zebra"
"Who Knows?"
12
null
343.938
myMap
address = {"numStreet" : "6931 Greenwood Ave",
"city" : "Oakland",
"state" : "CA",
"postalCode" : "94602"
}
address = {"numStreet" : "6931 Greenwood Ave",
"city" : "Oakland",
"state" : "CA",
"postalCode" : "94602"
}
property
value
{
}
,
:
property
value
any?
more?
{
}
,
:
property
value
Which are valid objects?
x = {}
x = {'name': 'Simrit'}
x = {name: 'Simrit'}
x = {'name': 'Harold', 'job': 'supervisor', 'degree': 'yes'}
x = {'name': 'Aretha',}
address
state
Oakland
city
6931 Greenwood Ave
CA
94602
postalCode
numStreet
address =
"state":
"Oakland",
"city":
"6931 Greenwood Ave",
"CA",
"94602"}
"postalCode":
{"numStreet":
address =
"property":
"value",
"property":
"value",
"value",
"value"}
"property":
{"property":
address =
"state":
"Oakland",
"city":
"6931 Greenwood Ave",
"CA",
"94602"}
"postalCode":
{"numStreet":
address.numStreet = "6931 Greenwood Ave"
1. An object is something inside of curly brackets
2. The "something" is zero or more property : value pairs separated by commas
3. Properties are strings
4. Values can be numbers, strings, Booleans, arrays of anything, or objects
a = {}
myObject = {"brothers": ["Paul", "Jack"]}
yourObject = {"ID": "3493843", "courses": ["math","chem","soc"], "GPA": 3.46}
anObject = {"objects": [{"name": "bob", "age": 32}, {"name": "alan", "age": 28},
{"name": "siri", "age": 35} ] }
a = {}
myObject = {"brothers": ["Paul", "Jack"]}
yourObject = {"ID": "3493843", "courses": ["math","chem","soc"], "GPA": 3.46}
anObject = {"objects": [{"name": "bob", "age": 32}, {"name": "alan", "age": 28},
{"name": "siri", "age": 35} ] }
myObject.brothers[1] =
"Jack"
a = {}
myObject = {"brothers": ["Paul", "Jack"]}
yourObject = {"ID": "3493843", "courses": ["math","chem","soc"], "GPA": 3.46}
anObject = {"objects": [{"name": "bob", "age": 32}, {"name": "alan", "age": 28},
{"name": "siri", "age": 35} ] }
anObject.objects[2].name=
"siri"
a = {}
myObject = {"brothers": ["Paul", "Jack"]}
yourObject = {"ID": "3493843", "courses": ["math","chem","soc"], "GPA": 3.46}
anObject = {"objects": [{"name": "bob", "age": 32}, {"name": "alan", "age": 28},
{"name": "siri", "age": 35} ] }
yourObject.courses.length=
3
Which are valid objects?
x = {"friends": ["amy","bill","chaia"]}
x = {"name": "Simrit","age": 29}
x = {["Simrit", "Raifia", "Jack"]}
x = {"name": "Harold", "job": false, "degree": true}
x = {"a": {"x": "yes", "b': ["a","b","c"]}, "b": [1,2,8,9]}
root = tree[0]
{"tree": [{"value": 6,
"left": 1,"right": 2},
{"value": 4,
"left": null,"right": null},
{"value": 10,
"left": 3,"right": 4},
{"value": 8,
"left": null,"right": null},
{"value": 18,
"left": null,"right": null}]}
6
4
10
8
18
index into the array tree[ ]
{"LL": [{"value": 6,"next": 1}, {"value": 4,"next": 2}, {"value": 10,"next": 4}, {"value": 8,"next": null}, {"value": 18,"next": 3} ] }
6
4
10
8
18
element 0 of the array
ALI
BETH
CARA
DOV
ELLIE
{'name': 'ALI',
'next': 'BETH'
}
ALI
BETH
CARA
DOV
ELLIE
{'name': 'BETH',
'next': 'CARA'
}
{'name': 'CARA',
'next': 'DOV'
}
{'name': 'DOV',
'next': 'ELLIE'
}
{'name': 'ELLIE',
'next': null
}
myClass = {"pupils": [{"name": "ali", "next": 1},
{"name": "Beth", "next": 2},
{"name": "Cara", "next": 3},
{"name": "Dov", "next": 4},
{"name": "Ellie","next": null}
]
}
What is myClass.pupils[2].next?
What is myClass.pupils[myClass.pupils[2].next].name?
5
5,7,14,4,1,83, 0, 8
8
0
83
7
1
4
14
5
Build binary search tree from 5,7,14,4,1,83, 0, 8
8
0
83
7
1
4
14
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
5
8
0
83
7
1
4
14
Build binary search tree from 5,7,14,4,1,83, 0, 8
1
0
1
w=0.7
w=-1.0
w=0.2
reLU
A few tidbits about arrays in JavaScript
Different ways to add element to (the end of) an array
x[x.length] = 99;
An array can report its own length
var x = [44, 76, 59]
console.log(x.length); // 3
console.log(x) // [44,76,59,99]
x.push(101);
console.log(x) // [44,76,59,99,101]
https://codepen.io/djjrjr/pen/yLomwYN
A few tidbits about arrays in JavaScript
An array can slice itself up
var x = [44, 76, 59, 99, 101]
console.log(x.slice(2)); // [59, 99, 101]
console.log(x.slice(2,4)); // [59, 99]
Dot Notation
x={"p": "val"}
x.p
LValue x.p = 'HELLO'
x = {"p":"HELLO"}
y={"a": {"b": ['a','b','c']},
"delta": 78}
x=y.delta
something = something
LVALUE = RVALUE
LOCATION = expression
Hey Dan, is
{"a": {"b": ["a","b", "c"]} }
same as
{"a": {"b": [{"a": null}, {"b": null}, {"c": null}]} }
create a class for a type of object
Class of Object called "NODE"
{"value" : _____,
"right": null,
"left": null}
Interpet the bit
Group and interpret bits
Abstract structure on grouped bits
Read my resume as a one-hot vector
Suppose I have a group of kids and a priority queue where the priority depends on age (younger kids go first).
They arrive in this order:
Amy 7
Billy 5
Cardy 9
Disan 11
Ember 8
What order will they be served?
Amy
Billy Amy
Billy Amy Cardy
Billy Amy Cardy Disan
Billy Amy Ember Cardy Disan
Solution
Kids, stack, and a priority queue by age.
They arrive in this order:
Amy 7 Billy 5 Cardy 9 Disan 11 Ember 8 Flo 6
Push 'em all on the stack, pop them from the stack and put them in the queue as they come off. What order will they be served?
Amy
Billy Amy
Cardy Billy Amy
Disan Cardy Billy Amy
Flo Ember Disan Cardy Billy Amy
Ember Disan Cardy Billy Amy Flo
Disan Cardy Billy Amy Flo Ember
Cardy Billy Amy Flo Ember Disan
Billy Amy Flo Ember Cardy Disan
Amy Billy Flo Ember Cardy Disan
Billy Flo Amy Ember Cardy Disan
Solution
8
data
00
next
9
data
06
next
3
data
null
next
2
data
08
next
5
data
02
next
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D
1
2
3
7
6
9
5
4
8
10
root
1
2
3
7
6
9
5
4
8
10
root
A specially constructed tree with nodes having at most two children. Useful for storing ordered objects in a manner that's easy to search.
See Filho pp 77ff
whitespace
space