Inductive Sets of Data

Preview:

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

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

Inductive Sets of Data

Programming Language Essentials

2nd edition

Chapter 1.1 Recursively Specified 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

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) ) ) )

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) ) ) )

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

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>}*(,)

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

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

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

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

=> ( 14 . list-of-numbers )

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

Syntactic Derivationlist-of-numbers

=> ( Number . list-of-numbers )

=> ( 14 . list-of-numbers )

=> ( 14 . () )

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

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)))

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

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?

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

Sample Derivationlist

=> ( datum datum datum )

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

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

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

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

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

Sample Derivationlist

=> ( datum datum datum )

=> ( Boolean datum datum )

=> ( #t datum datum )

=> ( #t dotted datum )

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 )

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 )

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 )

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 )

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 )

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 )

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 )

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

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.

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.

Recommended