27
plt-2002-2 06/18/22 2.1-1 Inductive Sets of Data Programming Language Essentials 2nd edition Chapter 1.1 Recursively Specified Data

Inductive Sets of Data

  • Upload
    aderes

  • View
    35

  • Download
    0

Embed Size (px)

DESCRIPTION

Inductive Sets of Data. Programming Language Essentials 2nd edition Chapter 1.1 Recursively Specified Data. Inductive Specification. specific value is in the set. if some value is in the set, some other also is. S: smallest set of natural numbers with 0 in S if x in S then x+3 in S - PowerPoint PPT Presentation

Citation preview

Page 1: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-1

Inductive Sets of Data

Programming Language Essentials

2nd edition

Chapter 1.1 Recursively Specified Data

Page 2: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-2

Inductive Specification

specific value is in the set.

if some value is in the set, some other also is.

S: smallest set of natural numbers with

0 in S

if x in S then x+3 in S

M: multiples of 3

smallest guarantees uniqueness

Page 3: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-3

list-of-numbers?L: smallest set of values withempty list in Lif x in L and n a number, (n . x) in L

(define list-of-numbers? (lambda (x) (if (null? x) #t (if (number? (car x)) (list-of-numbers? (cdr x)) #f) ) ) )

Page 4: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-4

list-of-numbers?L: smallest set of values withempty list in Lif x in L and n a number, (n . x) in L

(define list-of-numbers? (lambda (x) (if (null? x) #t (if (and (pair? x) (number? (car x))) (list-of-numbers? (cdr x)) #f) ) ) )

Page 5: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-5

Backus-Naur Forml-of-nums: '()'

l-of-nums: '(' 'Number' '.' l-of-nums ')'

grammar

nonterminals l-of-nums

terminals '(' 'Number’ ‘.’ ‘)’

rules, productions l-of-nums: '()'

context-free

notations differ

Page 6: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-6

Extended Backus-Naur Forml-of-ns: '()' | '(' 'Number' '.' l-of-ns ')'

l-of-ns: '()'

: '(' 'Number' '.' l-of-ns ')'

l-of-ns: '(' 'Number'* ')'

parentheses for grouping

optional term?

zero or more term*

one or more term+

separated {<term>}*(,)

Page 7: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-7

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

Page 8: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-8

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

=> ( 14 . list-of-numbers )

Page 9: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-9

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

=> ( 14 . list-of-numbers )

=> ( 14 . () )

Page 10: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-10

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

=> ( 14 . list-of-numbers )

=> ( 14 . () )

order of substitution does not matter

done once only terminals remain

need to cheat about quoting terminals

Page 11: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-11

s-lists-list: '(' symbol-expression* ')'

symbol-expression: 'Symbol' | s-list

(a b c)

(an (((s-list)) (wth () lots) ((of) nests)))

Page 12: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-12

bintreebintree: 'Number' | '(' 'Symbol' bintree bintree ')'

1(foo 1 2)(bar 1 (foo 1 2))(baz (bar 1 (foo 1 2)) (biz 4 5))

search-tree: '()' | '(' 'Key' search-tree search-tree ')'

needs restriction for key ordering

Page 13: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-13

Scheme Datalist: '(' datum* ')'

dotted: '(' datum+ '.' datum ')'

vector: '#(' datum* ')'

datum: 'Number' | 'Symbol' | 'Boolean'

| 'String' | list | dotted | vector

what's missing?

Page 14: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-14

Sample Derivationlist

=> ( datum datum datum )

Page 15: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-15

Sample Derivationlist=> ( datum datum datum )=> ( Boolean datum datum )

Page 16: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-16

Sample Derivationlist=> ( datum datum datum )=> ( Boolean datum datum )=> ( #t datum datum )

Page 17: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-17

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

Page 18: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-18

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

=> ( #t ( datum+ . datum ) datum )

Page 19: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-19

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

=> ( #t ( datum+ . datum ) datum )

=> ( #t ( Symbol . datum ) datum )

Page 20: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-20

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

=> ( #t ( datum+ . datum ) datum )

=> ( #t ( Symbol . datum ) datum )

=> ( #t ( foo . datum ) datum )

Page 21: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-21

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

=> ( #t ( datum+ . datum ) datum )

=> ( #t ( Symbol . datum ) datum )

=> ( #t ( foo . datum ) datum )

=> ( #t ( foo . list ) datum )

Page 22: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-22

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

=> ( #t ( datum+ . datum ) datum )

=> ( #t ( Symbol . datum ) datum )

=> ( #t ( foo . datum ) datum )

=> ( #t ( foo . list ) datum )

=> ( #t ( foo . () ) datum )

Page 23: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-23

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

=> ( #t ( datum+ . datum ) datum )

=> ( #t ( Symbol . datum ) datum )

=> ( #t ( foo . datum ) datum )

=> ( #t ( foo . list ) datum )

=> ( #t ( foo . () ) datum )

=> ( #t ( foo . () ) Number )

Page 24: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-24

Sample Derivationlist=> ( datum datum datum )=> ( Boolean datum datum )=> ( #t datum datum )=> ( #t dotted datum )=> ( #t ( datum+ . datum ) datum )=> ( #t ( Symbol . datum ) datum )=> ( #t ( foo . datum ) datum )=> ( #t ( foo . list ) datum )=> ( #t ( foo . () ) datum )=> ( #t ( foo . () ) Number )=> ( #t ( foo . () ) 3 )

Page 25: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-25

Lambda Calculusexpr: 'Symbol'

| '(' 'lambda' '(' 'Symbol' ')' expr ')'

| '(' expr expr ')'

small language

variable references

function definition with single parameter

function call with one argument

http://www.cs.rit.edu/~ats/projects/oops/edu/doc/edu/rit/cs/oops/examples/Lambda.html

Page 26: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-26

Proof by Inductionbintree: 'Number' | '(' 'Symbol' bintree bintree ')'

has an odd number of nodes:(0) Hypothesis: trees of size <= k have odd number

of nodes. Show that this holds for any k.(1) k=0: there are no such bintrees. (0) true.(2) assume (0) true up to some k. Look at tree of

size k+1: bintree: 'Number' has one node. (0) true.| '(' 'Symbol' bintree bintree ')' has one plus size of two smaller tress, i.e., 1+odd+odd, nodes. (0) true.

Page 27: Inductive Sets of Data

plt-2002-2 04/21/23 2.1-27

Proof by Structural Induction

Strategy:

(0) some hypothesis.

(1) show (0) on a simple structure, i.e., on one without substructures.

(2) show (0) on a structure with substructures: if it is true on the substructures it is true on the composite.