Artificial Intelligence Lecture 2: The Haskell Programming Language

Slides:



Advertisements
Similar presentations
Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Advertisements

Programming Languages Structure
October 27, 2009Introduction to Cognitive Science Lecture 13: The Computational Approach 1 AI – The Movie Many people will leave the cinema after seeing.
Dr. Muhammed Al-Mulhem ICS An Introduction to Functional Programming.
Startup – Chapter 1.
The College of Saint Rose CIS 433 – Programming Languages David Goldschmidt, Ph.D. from Concepts of Programming Languages, 9th edition by Robert W. Sebesta,
The Turing machine Olena Lastivka. Definition Turing machine is a theoretical device that manipulates symbols on a strip of tape according to a table.
September 19, 2012Introduction to Artificial Intelligence Lecture 5: Functional Programming with Haskell 1 Functional Programming Symbolic AI is based.
Spring 2006ICOM 4036 Programming Laguages Lecture 2 1 The Nature of Computing Prof. Bienvenido Velez ICOM 4036 Lecture 2.
How Solvable Is Intelligence? A brief introduction to AI Dr. Richard Fox Department of Computer Science Northern Kentucky University.
1 The main topics in AI Artificial intelligence can be considered under a number of headings: –Search (includes Game Playing). –Representing Knowledge.
The Nature of Computing INEL 4206 – Microprocessors Lecture 3 Bienvenido Vélez Ph. D. School of Engineering University of Puerto Rico - Mayagüez.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
The Nature of Computing INEL 4206 – Microprocessors Lecture 2 Bienvenido Vélez Ph. D. School of Engineering University of Puerto Rico - Mayagüez.
CS 127 Introduction to Computer Science. What is a computer?  “A machine that stores and manipulates information under the control of a changeable program”
1-1 An Introduction to Functional Programming Sept
January 26, 2016Introduction to Artificial Intelligence Lecture 1: What is Artificial Intelligence? 1 Welcome to CS 470/670 – Introduction to Artificial.
MARC ProgramEssential Computing for Bioinformatics 1 The Nature of Computing Prof. Bienvenido Velez ICOM 4995 Lecture 3.
1. COMPUTERS AND PROGRAMS Rocky K. C. Chang September 6, 2015 (Adapted from John Zelle’s slides)
1 PROGRAMMING IN HASKELL An Introduction Based on lecture notes by Graham Hutton The book “Learn You a Haskell for Great Good” (and a few other sources)
Overview of Artificial Intelligence (1) Artificial intelligence (AI) Computers with the ability to mimic or duplicate the functions of the human brain.
Sub-fields of computer science. Sub-fields of computer science.
Functional Programming
Programming Languages 2nd edition Tucker and Noonan
Functional Programming
Software Development Environment
CSC 533: Programming Languages Spring 2016
Advanced Computer Systems
Knowledge Representation Techniques
CSC 533: Programming Languages Spring 2015
CS 3723 Programming Languages
Functional Programming Languages
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
CS 3304 Comparative Languages
dr Robert Kowalczyk WMiI UŁ
Topic: Programming Languages and their Evolution + Intro to Scratch
Introduction to formal languages and automata
Chapter 1 The Big Picture
Theory of Computation Lecture 4: Programs and Computable Functions II
Topics Introduction to Repetition Structures
MC301 DESIGN OF MECHATRONICS SYSTEMS
CS 326 Programming Languages, Concepts and Implementation
Functional Programming
课程名 编译原理 Compiling Techniques
Functional Programming
Ch. 11 Theory of Computation
CSCI/CMPE 3334 Systems Programming
Developing Applications
Modeling Computation:
CS190/295 Programming in Python for Life Sciences: Lecture 1
Introduction Artificial Intelligent.
Artificial Intelligence introduction(2)
Procedural versus Functional Programming
Theory of Computation Turing Machines.
Programming Languages 2nd edition Tucker and Noonan
Chapter 1 Introduction(1.1)
High Level Programming Languages
Pattern Matching Pattern matching allows us to do things like this:
Von Neumann Architecture
Principles of Programming Languages
강의 내용 및 방법 접근방법 리포트 시험 Lambda Calculus, Proof of Correctness
The Nature of Computing
Functional Programming
CSE S. Tanimoto Lambda Calculus
Functional Programming and Haskell
Theory of Computation Lecture 4: Programs and Computable Functions II
Artificial Intelligence
Chapter 15 Functional Programming 6/1/2019.
Functional Programming and Haskell
Presentation transcript:

Artificial Intelligence Lecture 2: The Haskell Programming Language Artificial Intelligence (AI) September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language AI – The History • AI is as old as computing, whose theory started in the 1930 with Alan Turing, Alonzo Church, and others • 1941 Konrad Zuse, Germany, general purpose computer • 1943 Britain (Turing and others) Colossus, for decoding • 1945 ENIAC, US. John von Neumann a consultant • 1956 Dartmouth Conference organized by John McCarthy (inventor of LISP) • The term Artificial Intelligence was coined at Dartmouth, which was intended as a two month study. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language AI – The Achievements Computers land 200 ton jumbo jets unaided every few minutes. Search systems like Google are not perfect but provide very effective information retrieval. Robots cut slots for hip joints better than surgeons. The chess program Deep Blue beat world champion Kasparov in 1997. Medical expert systems can outperform doctors in many areas of diagnosis Self-driving cars are beginning to enter the market. IBM’s Watson beats humans at Jeopardy. Programs such as Siri communicate via natural language. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial vs. Human Intelligence Today’s computers can do many well-defined tasks (for example, arithmetic operations), much faster and more accurate than human beings. However, the computers’ interaction with their environment is not very sophisticated yet. How can we test whether a computer has reached the general intelligence level of a human being? Turing Test: Can a computer convince a human interrogator that it is a human? But before thinking of such advanced kinds of machines, we will start developing our own extremely simple “intelligent” machines. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Why AI? One of major divisions in AI (and you can see it in the definitions on the previous slide) is between Those who think AI is the only serious way of finding out how we work (since opening heads does not yet give much insight into this) and • Those who want computers to do very smart things, independently of how we work. This is the important distinction between Cognitive Scientists vs. Engineers. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Symbolism vs. Connectionism There is another major division in the field of Artificial Intelligence: Symbolic AI represents information through symbols and their relationships. Specific Algorithms are used to process these symbols to solve problems or deduce new knowledge. Connectionist AI represents information in a distributed, less explicit form within a network. Biological processes underlying learning, task performance, and problem solving are imitated. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Paradigms of Computation You all know the Turing machine, conceived by Alan Turing as a theoretical Model of automatic computation. It uses a tape head that reads and writes symbols on an infinite tape. Based on the currently read symbol and the machine’s current state, the head moves to the left or right or writes a new symbol, and the state is updated. These state transition rules constitute the program. It is believed (but has not been proven) that this machine can compute all functions that can be computed in principle. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Turing Machines Turing machines inspired the construction of the first computers, which were based on the von-Neumann architecture. Here, digital memory stores the program and data, including the machine state. A Central Processing Unit (CPU) sequentially executes individual instructions in the program through memory read and write operations. This fundamental architecture is still shared by most of today’s computers. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Imperative Programming This architecture is also reflected in most modern programming languages such as Java, C, C++, C#, Python, or Matlab. Their programs consist of sequences of instructions, each of which changes the system’s state, such as the values of variables or other memory content. Such languages are called imperative languages. Object-oriented programming provides mechanisms for encapsulation of functional program and data units but is still based on the imperative paradigm. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Lambda () Calculus Roughly at the same time when Turing developed his Turing machine, Alonzo Church devised a different paradigm of computation, called lambda calculus. It is based on anonymous functions described by lambda expressions. By mechanisms such as composition and recursion, lambda expressions can represent complex computations. It can be shown that Turing machines and lambda calculus have identical computational power, which is believed to be universal (Church-Turing thesis, 1937). September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Lambda () Calculus Lambda calculus provides a more abstract, mathematical description of an algorithm. Such descriptions are typically more concise and elegant than those provided by Turing machines. On the other hand, Turing-machine style computation can be directly translated into hardware, which is much more difficult for lambda calculus. Nevertheless, there are programming languages that are based on lambda calculus, and they are referred to as functional languages. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Functional Programming The most striking feature of purely functional programming is that there is no state. This means that our variables are not variable, i.e., cannot change their values! In other words, they are immutable and only represent some constant value. The execution of a program only involves the evaluation of functions. This sounds weird – what are the advantages and disadvantages of functional programming? September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Functional Programming The advantage of having no state is that functions have no side effects. Therefore, we can be sure that whenever we evaluate a function with the same inputs, we will get the same output, and nothing in our system changed due to this evaluation. This prevents most of the bugs that commonly occur in imperative programming. You will learn about other advantages during the next few lectures… September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Functional Programming The main problem with strictly preventing side effects is that user input and output during program execution become impossible. To enable such user interaction, we have to sometimes allow state changes. It is then important to separate such “impure” code from the rest of the program. There are many functional languages, with some being as old as the earliest imperative ones. Examples are: LISP, Scheme, Haskell, Erlang, R, Clojure, Scala, OCaml, and F#. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Functional Programming Functional programming is not the best solution to every problem, just like object-oriented programming is not, either. In the context of symbolic AI, you will see how functional programming allows you to write very concise, readable, and reusable code. Even if you rarely or never use it again afterwards, it will give you a different perspective on programming and may change the way you program. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language In this course, we will use Haskell, because its purity forces you to use functional programming principles. Get the latest Haskell Platform at Haskell.org. Free Haskell tutorials: http://learnyouahaskell.com/ http://book.realworldhaskell.org/ I recommend that you read Chapters 1 and 2 of “Learn you a Haskell” and experiment with the language a bit. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Download the Haskell Platform at: https://www.haskell.org/ There are no perfect Haskell IDEs, but some good plugins for editors such as Atom, Sublime Text, or IntelliJ. For our purposes, a simple text editor plus console a good enough. For Windows, Notepad++ with the NppExec plugin gives you syntax highlighting and integrated coding, testing, and profiling. September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Example scripts for Notepad++: Compiling: ghc -O -o main.exe $(FULL_CURRENT_PATH) cmd /C main.exe Interactive testing/debugging: ghci $(FULL_CURRENT_PATH) Profiling: ghc -O -prof -auto-all $(FULL_CURRENT_PATH) $(NAME_PART) +RTS -p –RTS cmd /C more $(NAME_PART).prof September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Demo Session (I) Here is the protocol of our demo session with GHCi: *Main> 3 + 4 7 *Main> 2^1000 10715086071862673209484250490600018105614048117055336074437503883703510511249361224931983788156958581275946729175531468251871452856923140435984577574698574803934567774824230985421074605062371141877954182153046474983581941267398767559165543946077062914571196477686542167660429831652624386837205668069376 *Main> "hello" "hello" September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Demo Session (II) *Main> :t "hello" "hello" :: [Char] *Main> :t 3 3 :: Num a => a *Main> :t 3.5 3.5 :: Fractional a => a *Main> [3, 2, 1] [3,2,1] *Main> 4:[3, 2, 1] [4,3,2,1] *Main> 4:3:5:[] [4,3,5] September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Demo Session (III) *Main> (2, 3) (2,3) *Main> (2, 3) == (3, 2) False *Main> [2, 3] == [3, 2] *Main> (5, 'a') (5,'a') *Main> :t head head :: [a] -> a *Main> head [4, 6, 1] 4 September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Demo Session (IV) *Main> :t tail tail :: [a] -> [a] *Main> tail [4, 6, 1] [6,1] *Main> let mult a b = a*b *Main> mult 6 7 42 *Main> :t mult mult :: Num a => a -> a -> a *Main> head "hello" 'h' September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Demo Session (V) *Main> (mult 6) 8 48 *Main> let supermult = mult 6 *Main> supermult 5 30 *Main> :t supermult supermult :: Num a => a -> a *Main> even 7 False *Main> :t filter filter :: (a -> Bool) -> [a] -> [a] September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language

Artificial Intelligence Lecture 2: The Haskell Programming Language Demo Session (VI) *Main> :t even even :: Integral a => a -> Bool *Main> [1..10] [1,2,3,4,5,6,7,8,9,10] *Main> filter even [1..10] [2,4,6,8,10] *Main> :t map map :: (a -> b) -> [a] -> [b] *Main> map even [1..10] [False,True,False,True,False,True,False,True,False,True] September 6, 2018 Artificial Intelligence Lecture 2: The Haskell Programming Language