Discrrete mathematics for computer science structuralinduction

9 65 0
Discrrete mathematics for computer science structuralinduction

Đang tải... (xem toàn văn)

Thông tin tài liệu

Recursive Definitions and Structural Induction 3/22/19 Recursive Definitions • Common way of defining mathematical objects – Base case(s) – Constructor rule(s) – “Nothing else” (generally implicit) • Have already seen recursive definition of the Fibonacci numbers – F0=0, F1=1 – Fn+1 = Fn+Fn-1 (n ≥ 1) 3/22/19 The set of all strings of balanced parentheses • (), (()()), ()() but not )( or (() • Familiar “Counting rule”—an algorithm: – Start count at – When you see a “(“, add – When you see a “)”, subtract – Balanced if count never goes negative and ends at • But we want a structural definition 3/22/19 A Structural Definition • Base case: – The empty string εis balanced • Constructor rules: – C1: If x is balanced then so is (x), that is, the result of writing a “(“, then x, then “)” – C2: If x and y are balanced then so is xy • (Implicit “that’s-all” clause) – (No string is balanced unless it can be constructed using the base and constructor rules) • NB: x and y are variables whose values are strings 3/22/19 Some Balanced Strings ε: Base case ( ) : C1 rule, (x), where x =ε (( )): C1 rule, (x), where x = ( ) ( )( ): C2 rule, xy, where x = y = ( ) (( ))( )( ): C2 rule, xy, where x = (( )), y = ( )( ) … 3/22/19 Showing a String is Balanced • Is (( )( )) balanced? Yes, because – ε is balanced (base rule) – (ε) is balanced by first constructor rule, but that is just another way of writing () – ( )( ) is balanced by second constructor rule – (( )( )) is balanced by first constructor rule 3/22/19 Proof that every balanced string has equal numbers of “(“ and “)” • Suppose x is balanced Then it is balanced because of either the base rule or a constructor rule • If by the base rule, then x is ε and has left and right parentheses ✓ • If by the first constructor rule then x=(y) for some previously constructed balanced string y Then y has the same number of “(“ and “)”, say n Then x = (y) has one more “(“ and one more “)”, so n+1 of each ✓ 3/22/19 Every balanced string has equal numbers of “(“ and “)” • If by the second constructor rule then x=yz for some previously constructed balanced strings y and z Then y has the same number of “(” and “)”, say n, and z has the same number of “(” and “)”, say m Then x=yz has m+n “(” and m+n “)” ✓ 3/22/19 Structural Induction: The General Schema • To prove P(x) holds for all x in a recursively defined set S, prove – P(b) for each base case b∈S – P(c(x1,…,xk)) for each constructor c, assuming as the induction hypothesis that P(x1), …, and P(xk) all hold 3/22/19 ... Induction: The General Schema • To prove P(x) holds for all x in a recursively defined set S, prove – P(b) for each base case b∈S – P(c(x1,…,xk)) for each constructor c, assuming as the induction... balanced string has equal numbers of “(“ and “)” • If by the second constructor rule then x=yz for some previously constructed balanced strings y and z Then y has the same number of “(” and “)”,... then x is ε and has left and right parentheses ✓ • If by the first constructor rule then x=(y) for some previously constructed balanced string y Then y has the same number of “(“ and “)”, say

Ngày đăng: 22/03/2019, 12:13

Mục lục

  • Slide 1

  • Recursive Definitions

  • The set of all strings of balanced parentheses

  • A Structural Definition

  • Some Balanced Strings

  • Showing a String is Balanced

  • Slide 7

  • Every balanced string has equal numbers of “(“ and “)”

  • Structural Induction: The General Schema

Tài liệu cùng người dùng

Tài liệu liên quan