SlideShare a Scribd company logo
1 of 11
Analyzing Structures CS 5010 Program Design Paradigms “Bootcamp” Week 03, Lesson 3 TexPoint fonts used in EMF.  Read the TexPoint manual before you delete this box.: AAA 1
Template for recursive/mixed data ;; A Foo is one of ;; -- (make-foo1 Number FooFoo) ;; -- (make-foo2 Foo Boolean) ;; -- (make-foo3 Number Boolean) (define-struct foo1 (field1 field2 field3)) (define-struct foo2 (field1 field2)) (define-struct foo3 (field1 field2)) (define (foo-fn f)   (cond     [(foo1? f) (... (foo1-field1 f)                     (foo-fn (foo1-field2 f))                     (foo-fn (foo1-field3 f)))]     [(foo2? f) (... (foo-fn (foo2-field1 f))                     (foo2-field2 f))]     [else (... (foo3-field1 f)                (foo3-field2 f))]))
Which variant do we have? In  this case, it's easy– we have predicates Sometimes not so easy for SoS, we had to distinguish between strings and non-strings. Before, we had adam? and eve? Today's topic: How to design predicates
An Example Problem We are given a list of bird observations. Each observation consists of 3 parts: 	beak, wings, belly We have a table for converting an observation to a species:
Determining the species
Example Problem: Goal Given a list of observations, we are to produce a list of species.
Simple-Minded Solution: Truth Tables ;; observation2species : Observation -> Species ;; given an observation, determine the species ;; examples/tests: below ;; strategy: decision tree (truth table) (define (observation2species obs)   (cond     [(or  ;; star-bellied sneetches:       (and (yellow? (observation-beak obs))            (red? (observation-wings obs))            (star? (observation-belly obs)))       (and (black? (observation-beak obs))            (red? (observation-wings obs))            (star? (observation-belly obs)))       (and (black? (observation-beak obs))            (blue? (observation-wings obs))            (star? (observation-belly obs))))      "Star-Bellied Sneetch"]  [(or ;; plain-bellied sneetches:       (and (yellow? (observation-beak obs))            (red? (observation-wings obs))            (plain? (observation-belly obs)))       (and (black? (observation-beak obs))            (red? (observation-wings obs))            (plain? (observation-belly obs)))            (and (black? (observation-beak obs))            (blue? (observation-wings obs))            (plain? (observation-belly obs))))      "Plain-Bellied Sneetch"]     [else "Yellow-Bellied Blackbird"]))
A cleverer approach: a decision tree beak Yellow Black wings Blue Red Yellow-Bellied belly Plain Star Plain-Bellied Star-Bellied
Code using Decision Tree ;; observation2species : Observation -> Species ;; strategy: decision tree (define (observation2species obs)   (if (yellow? (observation-beak obs))       (if (black? (observation-wings obs))           "Yellow-Bellied Blackbird"           (not-ybb-to-species obs))       (not-ybb-to-species obs)))  ;; not-ybb-to-species : Observation -> Species ;; Given an observation THAT IS KNOWN NOT TO BE A YBB ;; determine which species of sneetch it is. (define (not-ybb-to-species obs)   (if (plain? (observation-belly obs))       "Plain-Bellied-Sneetch"       "Star-Bellied-Sneetch")) A side-condition like this is called an INVARIANT
Decision Trees vs. Truth Tables Truth table code is boring, but reliable Decision Tree: may take effort to get right! Testing is vital! Decision Tree: shorter Have to figure out order of tests Decision Tree: sometimes necessary what if you couldn't see the blackbird's belly? this happens often in practice.
Summary Use wishlist functions to discriminate between cases. Use truth tables or decision trees to figure out what's what. Test, test, test!

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Lesson 05 Analyzing Structures

  • 1. Analyzing Structures CS 5010 Program Design Paradigms “Bootcamp” Week 03, Lesson 3 TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: AAA 1
  • 2. Template for recursive/mixed data ;; A Foo is one of ;; -- (make-foo1 Number FooFoo) ;; -- (make-foo2 Foo Boolean) ;; -- (make-foo3 Number Boolean) (define-struct foo1 (field1 field2 field3)) (define-struct foo2 (field1 field2)) (define-struct foo3 (field1 field2)) (define (foo-fn f) (cond [(foo1? f) (... (foo1-field1 f) (foo-fn (foo1-field2 f)) (foo-fn (foo1-field3 f)))] [(foo2? f) (... (foo-fn (foo2-field1 f)) (foo2-field2 f))] [else (... (foo3-field1 f) (foo3-field2 f))]))
  • 3. Which variant do we have? In this case, it's easy– we have predicates Sometimes not so easy for SoS, we had to distinguish between strings and non-strings. Before, we had adam? and eve? Today's topic: How to design predicates
  • 4. An Example Problem We are given a list of bird observations. Each observation consists of 3 parts: beak, wings, belly We have a table for converting an observation to a species:
  • 6. Example Problem: Goal Given a list of observations, we are to produce a list of species.
  • 7. Simple-Minded Solution: Truth Tables ;; observation2species : Observation -> Species ;; given an observation, determine the species ;; examples/tests: below ;; strategy: decision tree (truth table) (define (observation2species obs) (cond [(or ;; star-bellied sneetches: (and (yellow? (observation-beak obs)) (red? (observation-wings obs)) (star? (observation-belly obs))) (and (black? (observation-beak obs)) (red? (observation-wings obs)) (star? (observation-belly obs))) (and (black? (observation-beak obs)) (blue? (observation-wings obs)) (star? (observation-belly obs)))) "Star-Bellied Sneetch"] [(or ;; plain-bellied sneetches: (and (yellow? (observation-beak obs)) (red? (observation-wings obs)) (plain? (observation-belly obs))) (and (black? (observation-beak obs)) (red? (observation-wings obs)) (plain? (observation-belly obs))) (and (black? (observation-beak obs)) (blue? (observation-wings obs)) (plain? (observation-belly obs)))) "Plain-Bellied Sneetch"] [else "Yellow-Bellied Blackbird"]))
  • 8. A cleverer approach: a decision tree beak Yellow Black wings Blue Red Yellow-Bellied belly Plain Star Plain-Bellied Star-Bellied
  • 9. Code using Decision Tree ;; observation2species : Observation -> Species ;; strategy: decision tree (define (observation2species obs) (if (yellow? (observation-beak obs)) (if (black? (observation-wings obs)) "Yellow-Bellied Blackbird" (not-ybb-to-species obs)) (not-ybb-to-species obs))) ;; not-ybb-to-species : Observation -> Species ;; Given an observation THAT IS KNOWN NOT TO BE A YBB ;; determine which species of sneetch it is. (define (not-ybb-to-species obs) (if (plain? (observation-belly obs)) "Plain-Bellied-Sneetch" "Star-Bellied-Sneetch")) A side-condition like this is called an INVARIANT
  • 10. Decision Trees vs. Truth Tables Truth table code is boring, but reliable Decision Tree: may take effort to get right! Testing is vital! Decision Tree: shorter Have to figure out order of tests Decision Tree: sometimes necessary what if you couldn't see the blackbird's belly? this happens often in practice.
  • 11. Summary Use wishlist functions to discriminate between cases. Use truth tables or decision trees to figure out what's what. Test, test, test!

Editor's Notes

  1. Welcome to Week 3, Lesson 2: Recursive Data Definitions EverywhereIn this lesson, we will see some of the many ways in which recursive data definitions can arise.