Imperative programming languages • Design based on Von Neumann machine • Computations performed through the execution of assignment statements • Examples: C, C++, Java, Fortran, Pascal, Ada, Cobol Sections 16.1, 16.2,16.3, 16.4 1 Functional programming languages • Design based on mathematical functions • Computations performed through the execution of function calls • Fundamental characteristics: no variables or assignment statements, no iteration (recursion instead), referential transparency • Examples: Lisp, Haskell, Scheme, ML Sections 16.1, 16.2,16.3, 16.4 2 Logic programming languages • Design based on predicate calculus (more precisely first-order predicate calculus) • Program is expressed in a form of symbolic logic • Logical inferencing process is used to produce results – (x) (mother(x) haschild(x)) – mother(cindy). • Also called declarative programming because program consists of a specification of results (declarations) rather than detailed procedures for producing results Sections 16.1, 16.2,16.3, 16.4 3 Logic Programming Languages • Provide: – syntax for expressing propositions (logic statement) – syntax for expressing relationship between propositions – interpreter that can infer new propositions from existing ones Sections 16.1, 16.2,16.3, 16.4 4 Brief intro to predicate calculus • First, what is a proposition? – logical statement that may or may not be true • Predicate calculus 1) provides a syntax for expressing collections of propositions 2) plus, provides a method for determining whether any facts can be inferred from the propositions Sections 16.1, 16.2,16.3, 16.4 5 First, the syntax for stating propositions • Two types of propositions – Atomic propositions – consist of a single compound term (definition on next slide) – Compound propositions - atomic propositions joined by connectives Sections 16.1, 16.2,16.3, 16.4 6 Compound Term • Looks like a mathematical function • Two parts: – Functor – function symbol that names a relation – Ordered list of parameters where a parameter is either a constant or a variable • Examples • motherof(cindy, baron) • isfather(jay) Sections 16.1, 16.2,16.3, 16.4 7 Connectives • • • • • Negation: or And: or Or: or Equivalence: or Implication: or Sections 16.1, 16.2,16.3, 16.4 8 Examples • professor(cindy) mother(cindy) • goes(cindy, work) goes(cindy, home) • (likes(cindy, chocolate) typeof(chocolate, godiva)) likes(cindy, godiva) • (likes(cindy, person) typeof(person, jay)) likes(cindy, jay) • student(jon) • The last one is an atomic proposition; the rest are compound propositions Sections 16.1, 16.2,16.3, 16.4 9 Quantifiers • Allows us to express a general position and include variables – professor(cindy) workshard(cindy) – (x) (professor(x) workshard(x)) • Universal quantifier - (x) P(x) means that for all x, P(x) is true • Existential quantifier – (x) P(x) means that there exists some value of x for which P(x) is true Sections 16.1, 16.2,16.3, 16.4 10 Propositions for English sentences • • • • Kim is female and a parent Someone is a female and a parent Everyone who is a mother has a child Given any number you can find another number which is less than it Sections 16.1, 16.2,16.3, 16.4 11 Clausal Form • Proposition is in clausal form if it looks like: A1 A2 .. An B1 B2 … Bm • There are no quantifiers and the only operators allowed are , , and • Example: likes(bob, fish) fish(trout) likes(bob, trout) Sections 16.1, 16.2,16.3, 16.4 12 Horn clauses • Clausal form that is appropriate for applying resolution – a method of inferring new propositions from existing propositions (the second thing provided by predicate calculus) • Clauses in which the right side consists of an atomic proposition or the right side is empty • Examples: likes(bob, fish) fish(trout) likes(bob, trout) likes(bob, fish) fish(trout) Sections 16.1, 16.2,16.3, 16.4 13 Method for inferring new propositions: Resolution • Inference rule that allows propositions to be inferred from given propositions • Example: P1 P1 P2 P2 P3 From this we can infer P3 • unification and instantiation for the resolution to succeed Sections 16.1, 16.2,16.3, 16.4 14 Unification • Finding values for variables that allow two propositions to match and the resolution process to succeed • Example: – mother(cindy, baron) – mother(x, y) haschild(x) These two propositions are unified by instantiating x to cindy and y to baron Note: value for x must be same on both sides of inference symbol Sections 16.1, 16.2,16.3, 16.4 15 Instantiation • Temporary assignment of a value to a variable • It is common for an instantiation to occur during resolution but then nothing gets proved – this requires backtracking and instantiating the variable to a different value • Example: sibling(x, y) ^ sibling(y, z) -> sibling(x, z) sibling(jay, tricia) sibling(cindy, mark) sibling(mark, celeste) First x is instantiated to jay and y is instantiated to tricia but then an instantiation can’t be found for z. Back track and try x = cindy and y = mark Sections 16.1, 16.2,16.3, 16.4 16 Logic programming languages • Programmer doesn’t specify how computation is to be done (no detailed procedures and specified control flow) • Programmer provides facts and rules • User provides queries • Inferencing engine uses facts and rules to answer queries Sections 16.1, 16.2,16.3, 16.4 17 First prolog example mother(cindy, baron). mother(ginny, cindy). parent(X, Y) :- mother(X, Y). parent(X, Y) :- father(X, Y). grandmother(X, Y) :- mother(X, Z), mother(Z, Y). Note: unlike our proposition examples, the consequent is on the left side. Sections 16.1, 16.2,16.3, 16.4 18 Declarative semantics • Can determine meaning of statement just by looking at statement • Imperative language – x = y * foo(x) //meaning depends on types of x and y and what foo does • Prolog – motherof(cindy, baron). – likes(jay, steak). Sections 16.1, 16.2,16.3, 16.4 19
© Copyright 2026 Paperzz