Download Algorithm

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Concepts of Programming Languages
IT 327, Fall 2016
MW 9:35 – 10:50 AM (Section 1)
MW 11:00 – 12:15 PM (Section 2)
STV 139A
Instructor: Dr. Chung-Chih Li
Home page of the Class
1
Concepts of Programming Languages
This is not a survey course
Then, what is it?
What do you expect?
What do you want to learn from this class?
2
In order to understand the universe,
we have to understand the language in which
the universe is written,
and mathematics is the language.
-- Galileo Galilei (1564 -1642) --
In order to understand Information Technology,
we have to understand the language in which
Information Technology is written,
and the Programming Language is the language.
-5/5/2017
-ITK 327
3
What is a computer?
A machine that can compute!
What is a machine?
What is computation?
Why bother?
Because, the way we understand and
formalize them directly shapes the design of
programming languages.
4
Computer -A machine that can compute!
Machine -A device that follows a certain fixed
causal rules.
Computation -A sequence of procedures that
manipulate data.
5
design:
Difference Engine No. 1 (1821-1832)
Analytical Engine
(1834-1840)
Difference Engine No. 2 (1840-1849)
http://www.computerhistory.org/babbage/
Charles Babbage (1791-1871)
Difference Engine No. 2
(2002)
Difference Engine No. 1
5/5/2017
6
Gottfried W.V. Leibniz
(1646-1716)
Leibniz’s Dream
“Sir! Let’s sit down and
compute!! ”
http://sunsite.informatik.rwth-aachen.de/phil/filosofer/leibniz.html
7
Logic and Thought and Computing
Aristotle (384 - 322 BC)
L E J Brouwer (1881-1966)
http://www.klima-luft.de/steinicke/ngcic/persons/aristoteles.htm
8
Completeness theorem
Incompleteness theorem
Recursive theory
Computable functions are
recursively definable
function
Kurt Gödel
(1906-1978)
http://www-groups.dcs.st-and.ac.uk/~history/PictDisplay/Godel.html
9
Alonzo Church
1903-1995
Lambda Calculus
Computable functions are
Lambda-term definable
http://www.princeton.edu/pr/pwb/03/0505/7a.shtml
10
Alan Turing (1912-1954)
– The Enigma
The man who invented the
computer.
Computable functions are
Turing machine computable
Image from http://ei.cs.vt.edu/~history/Turing.html
11
Ludwig Wittgenstein (1889-1951)
Wittgenstein says:
“Turing Machines are
human that compute.”
http://www.ags.uci.edu/~bcarver/wgallery.html
12
Church-Turing Thesis: all algorithms are computable
1. Logic
Logical languages
e.g. PROLOG
2. Recursive, λ-terms
Functional languages
e.g. LISP, ML
3. Turing machines
Imperative languages
e.g. Algol-60, Fortran, C
?????
OOP, (e.g. Small Talk, JAVA, C++)
What is it? Really?
13
Imperative Languages
• C
int fact(int n) {
int sofar = 1;
while (n>0) sofar *= n--;
return sofar;
}
Using instructions to command the machine to
do something, with branches, iterations, control
flows, and side-effects,.
14
Functional Languages
• ML
fun fact x =
if x <= 0 then 1 else x * fact(x-1);
• LISP
defun fact (x)
(if (<= x 0) 1 (* x (fact (- x 1)))))
Function definition, Recursion, no side-effect
15
Logical Languages
grandparent(X, sean).
X = john.
• PROLOG
parent(A,B) :parent(A,B) :-
dad(A,B).
mom(A,B).
grandparent(A,B) :parent(A,C), parent(C,B).
parent(X, leon).
X = dennis.
X = sandy.
dad(dennis, sean).
dad(dennis, leon).
dad(john, dennis).
mom(sandy, leon).
Rules (logic) and facts
mom(sandy,sean).
16
Logical Languages
• PROLOG
fact(X,1) :X =:= 1.
fact(X,Fact) :X > 1,
NewX is X - 1,
fact(NewX,NF),
Fact is X * NF.
fact(4,X).
X = 24.
fact(5,30).
false.
17
OOP (Object-oriented Programming)
A new programming paradigm after ’80s.
Problem solving  Procedure finding
But
Why should I have to write the same procedure to
do the same job over and over again?
Fact:
Different problems usually consist of many
common smaller problems.
Problem solving  Solution arranging
18
OOP
• Java
public class MyInt {
private int value;
public MyInt(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public MyInt getFact() {
return new MyInt(fact(value));
}
private int fact(int n) {
int sofar = 1;
while (n > 1) sofar *= n--;
return sofar;
}
}
19