1 / 27

Inductive Sets of Data

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

aderes
Download Presentation

Inductive Sets of Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Inductive Sets of Data • Programming Language Essentials • 2nd edition • Chapter 1.1 Recursively Specified Data

  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

  3. list-of-numbers? • L: smallest set of values with • empty list in L • if 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 • ) ) ) )

  4. list-of-numbers? • L: smallest set of values with • empty list in L • if 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 • ) ) ) )

  5. Backus-Naur Form • l-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

  6. Extended Backus-Naur Form • l-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>}*(,)

  7. Syntactic Derivation • list-of-numbers • => ( Number . list-of-numbers )

  8. Syntactic Derivation • list-of-numbers • => ( Number . list-of-numbers ) • => ( 14 . list-of-numbers )

  9. Syntactic Derivation • list-of-numbers • => ( Number . list-of-numbers ) • => ( 14 . list-of-numbers ) • => ( 14 . () )

  10. Syntactic Derivation • list-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

  11. s-list • s-list: '(' symbol-expression* ')' • symbol-expression: 'Symbol' | s-list • (a b c) • (an (((s-list)) (wth () lots) ((of) nests)))

  12. bintree • bintree: '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

  13. Scheme Data • list: '(' datum* ')' • dotted: '(' datum+ '.' datum ')' • vector: '#(' datum* ')' • datum: 'Number' | 'Symbol' | 'Boolean' • | 'String' | list | dotted | vector • what's missing?

  14. Sample Derivation • list => ( datum datum datum )

  15. Sample Derivation • list => ( datum datum datum ) • => ( Boolean datum datum )

  16. Sample Derivation • list => ( datum datum datum ) • => ( Boolean datum datum ) • => ( #t datum datum )

  17. Sample Derivation • list => ( datum datum datum ) • => ( Boolean datum datum ) • => ( #t datum datum ) • => ( #t dotted datum )

  18. Sample Derivation • list => ( datum datum datum ) • => ( Boolean datum datum ) • => ( #t datum datum ) • => ( #t dotted datum ) • => ( #t ( datum+ . datum ) datum )

  19. Sample Derivation • list => ( datum datum datum ) • => ( Boolean datum datum ) • => ( #t datum datum ) • => ( #t dotted datum ) • => ( #t ( datum+ . datum ) datum ) • => ( #t ( Symbol . datum ) datum )

  20. Sample Derivation • list => ( datum datum datum ) • => ( Boolean datum datum ) • => ( #t datum datum ) • => ( #t dotted datum ) • => ( #t ( datum+ . datum ) datum ) • => ( #t ( Symbol . datum ) datum ) • => ( #t ( foo . datum ) datum )

  21. Sample Derivation • list => ( 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 )

  22. Sample Derivation • list => ( 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 )

  23. Sample Derivation • list => ( 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 )

  24. Sample Derivation • list => ( 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 )

  25. Lambda Calculus • expr: '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

  26. Proof by Induction • bintree: '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. • 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.

  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.

More Related