CS 251 Fall 2019 CS 251 Fall 2019 Principles of Programming - - PowerPoint PPT Presentation

cs 251 fall 2019 cs 251 fall 2019 principles of
SMART_READER_LITE
LIVE PREVIEW

CS 251 Fall 2019 CS 251 Fall 2019 Principles of Programming - - PowerPoint PPT Presentation

CS 251 Fall 2019 CS 251 Fall 2019 Principles of Programming Languages Principles of Programming Languages Ben Wood Ben Wood Deductive Programming and Unification https://cs.wellesley.edu/~cs251/f19/ Prolog terms atoms cs251


slide-1
SLIDE 1

CS 251 Fall 2019 Principles of Programming Languages

Ben Wood

λ

CS 251 Fall 2019

Principles of Programming Languages

Ben Wood

λ

https://cs.wellesley.edu/~cs251/f19/

Deductive Programming and Unification

slide-2
SLIDE 2

Prolog terms

  • atoms

cs251 'hello world' carrots

  • Variables

X ABC Course Course_number

  • compound terms: functor(arg, U, ments)

major(cs111) prereq(cs230, cs251)

slide-3
SLIDE 3

Prolog facts and rules

  • facts

major(cs111). major(cs230). major(cs235). major(cs251). elective(cs304). prereq(cs111, cs230). prereq(cs230, cs235). prereq(cs230, cs251). prereq(cs230, cs304).

  • rules: head :- body.

core(C) :- major(C), prereq(cs230, C).

– conjuction: , disjunction: ;

slide-4
SLIDE 4

Prolog queries

?- elective(cs304). true. ?- elective(cs235). false . ?- core(cs235). true. ?- prereq(cs230, C). C = cs235 ; C = cs251 ; C = cs 304 ; false.

slide-5
SLIDE 5

Unification (Prolog =)

Find environment(s)/substitution(s) under which two terms are equivalent. Ex Example Te Terms to unify Un Unifying Environme ment a = a a = X X ↦ a p(X) = p(a) X ↦ a p(X) = p(Y) X ↦ Y X = a, p(a) = p(X) X ↦ a X = a, X = Y X ↦ a, Y ↦ a

slide-6
SLIDE 6

Prolog examples: courses.pl

  • Basics
  • Unification
  • Un

Unification/Proof search algorithm demo

slide-7
SLIDE 7

Applications

  • Prolog (&friends):

– AI, NLP, logic, mechanized verification

  • Datalog (non-Turing complete subset):

– data analytics, program analysis

  • Unification:

– ML type inference – Codder – proof systems, mechanized verification – …

slide-8
SLIDE 8

Codder example (CS 111 checker)

# Pattern def sumList(_xs_): ___ _sum_ = 0 ___ for _elem_ in _xs_: ___ _sum_ += _elem_ ___ ___ return _sum_