Chapter 1

Sections 1.1 - 1.5

  • Computer Science can be thought of as problem solving by way of mathematics, engineering, natural sciences and …
  • Algorithm - the problem solution written in a specific language organized (sequentially) in a line-by-line fashion
  • Languages have several levels:
    • machine language – the lowest level - written in binary for a specific machine or specific task
    • assembly language – easier formatting for machine-level language
    • high-level languages – easier to write/read algorithms, portable to other machines
    • examples of high-level languages include:
      • Python (the language we will use in this course)
      • Java
      • C++
      • FORTRAN
    • computer algebra systems (CAS), such as Mathematica, Maple and Sage, are built using high-level languages such as C++ and Python
  • Interpreters and Compilers – programs that translate high-level language expressions into a low-level language version specific to the machine processor.
    • an interpreter processes the algorithm on a line-by-line basis, and errors are immediately evident
    • a compiler creates an interpretation of the whole algorithm, creating and object code or executable, that may be used repeatedly without further interpretation
  • Python is one of several modern languages that uses a combination of these processes.
    • Python code is first compiled to a lower level resulting in byte code
    • The byte code is interpreted by a program called a virtual machine
    • It is viewed as an interpreted language
  • The Python interpreter can be run in on of two modes:
    • shell mode – expressions are typed one line at a time and the interpreter gives an immediate response
    • program mode – an entire set of Python instruction lines are used to create a Python file, called the source code, and the Python interpreter acts on all lines sequentially.
  • Common features of high-level language progams:
    • input
    • output
    • mathematics and logic
    • conditional execution
    • repetition and/or iteration

Sections 1.6 - 1.12

\(\boxdot\) Debugging
  • Debugging – finding and fixing the bugs (errors) in a program

    • error types:
      • syntax – rules of the program and Python expression structure; a program will not run if there is a syntax error
      • runtime – errors that occur during the running of the program; the process will stop when an exception is raised (a runtime error has occured); runtime errors are synonymous with exceptions (division by zero is an example of a runtime error)
      • semantic – the execution process is complete, but the result is incorrect (coding 3.1415+r**2 instead of 3.1415*r**2 for the area of a circle formula is an example)
    • finding & fixing:
      • syntax errors are almost instantaneously evident during the program composition phase and the fix can be done ‘on the spot’
      • exceptions are raised during the execution of the program along with some explanation and a reference to the location
      • semantic errors often require experimental processes and/or ‘working backwards’ in the code to find the cause(s) of an incorrect result
\(\boxdot\) Natural & Formal Languages
  • Natural languages – spoken by people and evolved naturally (there is “room for error”)
  • Formal languages – designed by people for specific purposes with strict rules of syntax
\(\boxdot\) Last Bits
  • Syntax rules – two types:
    • tokens – the elements that make up the language; e.g. \(e^x\) is a correct token in the formal language of mathematics whereas \(e^?\) is not
    • structure – the proper arrangement of tokens
  • Parsing – the process of reading an expression, identifying the tokens, and understanding the structure in order to grasp the semantics of the expression