# 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()) = 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