summaryrefslogtreecommitdiff
path: root/cs/6.0001 Introduction to Computer Science and Programming in Python.md
blob: 469b45550754e10d31391c1c6d955f8a743374bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# Lecture 1 - What is computation ?

Computers does 2 things only:
- Calculate
- Remember Calculations

Computational problem solving & Computational complexities

From Ambiguous problem statement to computational formulation of a method

Declarative vs Imperative Knowledge
Declarative: Like an axiom - Statement of Facts
Imperative: Like an algorithm - Sequence & Flow control - Computations

John Von Newmann & Alan Turing
Fixed program computer(Arithmetic logic Unit) - 1941 - Atanasoff & Berry
Manchester Mark 1 - University of Manchester
Stored program computer
Interpreter for instrutions - Now computers can program themselves

Flow control, Flowcharts
Programming Langs

Church-Turing Thesis - Defines the concept of Computability - The Nature of Computation
Lambda calculus - Computable and effectivelly calculable
if solvable by algo solvable by turing machine and vice versa
Universality of Computation

Halting problem - if you can prove a program will run forever or not ? no said Turing

Low lvl vs High lvl
Interpreted vs Compiled

Syntax, Static sementics (syntatical validity), Sementics(meaning)

Turing: We can compute anything using 6 primitives
Read, Write, Move Left, Move Right, Scan, Do nothing

Using Tape he showed can compute anything
modern langs evolved from primitives

primitives -> expressions -> values ->  meaning

Primitve constructs(Syntax):
- English: Words
- Prog langs: Numbers, Strings, Simple operators

Static Sementics (Invalidity):
- English: I are hungry
- Prog langs: 3+"hi"

Sementics
- English: more than one meaning
- Prog langs: only one meaning

Everything in Python is an object:
- Scalar(int,float,bool(true/false),None,str)
- non-scalar(type())

<expr> = <var>

x % y = Remainder when x/y
x ** y = x to power of y

# Lecture 2 - Branching and Iteration

== vs = comparaison vs assignement

a variable is just a name, object can be assigned to more than 1 var
can assign multiples var in one line <><>=<><>

Operators can be combined to form expressions, the value of the expression is an object of some type()

## Arithmetic Operators
- +  : Addition
- -  : Subtraction
- *  : Multiplication
- /  : Division
- %  : Modulo (remainder)
- ** : Exponent
- // : Floor division

## Comparaison Operators - Compare 2 value and return true or false
- == : Equal to
- != : Nor equal to
- >  : Greater than
- <  : Less than
- >= : Greater than or equal to
- <= : Lesser than or equal to

## Assignement Operators - Assign value to var
- =  : Assignement
- += : Addition assignement
- -= : Substraction assignement
- *= : Multiplication assignement*
- /= : Division assignement
- %= : Modulo assignement
- //= : Floor division assignement
- **= : Exponentiation assignement**

## Logical Operators - To combine conditional statements
- AND
- OR
- NOT

## Bitwise Operator - Operate on Binary numbers
## Membership Operator - Check if value is part of sequence
- in
- not in
## Identity Operator - Check if 2 object refer to the same memory location
- is
- is not

Variables can't start with a number
Variables are case sensitive
Keywords(reserved words) can't be used
Identatation sementically meaningfull

Strait Line Programs VS Branching Programs (ex: with conditional expresion)


slicing = sequence[start:stop:step]
'abc'[:] = 'abc'[0:len('abc')]

when convert float to int : truncated not rounded

fstring - to format strings

f"Hello {name}, you are {age} yrs old"
can include any expression in bracket
f"The area of a circle with radius {sum(radius)} is {math.pi * radius}"

## Conditional Statement
- if : execute if true
- if, elif, else

## Looping Statement
- for - Iterate over a sequence
- while - Repeat a block of code as long as condition is true

## Control statement
- break - exit current loop
- continue - skip rest of current iteration and follow to the next iteration in loop
- pass - null does nothing

range(start,stop,increment)

PEP8 - https://peps.python.org/pep-0008/

# Lecture 3 - String Manipulation, Guess and Check, Approximations, Bisection

Algo:
- Guess and check - exhaustive enumeration
- Bisection Search - a example of succesive approximation method
- Approximation - most common: Newton-Raphson Method

# Lecture 4 - Decomposition, Abstraction, and Functions