Chapter 1 Problem Solving, Programming, and Calculation.

Slides:



Advertisements
Similar presentations
PROOF BY CONTRADICTION
Advertisements

1.1The Principle of Mathematical Induction 1.2Divisibility Chapter Summary Case Study Mathematical Induction 1.
Giving a formal meaning to “Specialization” In these note we try to give a formal meaning to specifications, implementations, their comparisons. We define.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
0 PROGRAMMING IN HASKELL Chapter 10 - Declaring Types and Classes.
String is a synonym for the type [Char].
The Game of Algebra or The Other Side of Arithmetic The Game of Algebra or The Other Side of Arithmetic © 2007 Herbert I. Gross by Herbert I. Gross & Richard.
TECHNIQUES OF INTEGRATION
INF 212 ANALYSIS OF PROG. LANGS Type Systems Instructors: Crista Lopes Copyright © Instructors.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 4 By Herb I. Gross and Richard A. Medeiros next.
Chapter 2: Algorithm Discovery and Design
Introduction to Computers and Programming. Some definitions Algorithm: –A procedure for solving a problem –A sequence of discrete steps that defines such.
Chapter 5 Polymorphic and Higher-Order Functions.
Introduction to Computers and Programming. Some definitions Algorithm: Algorithm: A procedure for solving a problem A procedure for solving a problem.
Chapter 2: Algorithm Discovery and Design
Introduction Solving inequalities is similar to solving equations. To find the solution to an inequality, use methods similar to those used in solving.
Algebra Problems… Solutions Algebra Problems… Solutions © 2007 Herbert I. Gross Set 6 By Herb I. Gross and Richard A. Medeiros next.
Introduction to Computer Science. A Quick Puzzle Well-Formed Formula  any formula that is structurally correct  may be meaningless Axiom  A statement.
Logic Gates Circuits to manipulate 0’s and 1’s. 0’s and 1’s used for numbers Also to make decisions within the computer. In that context, 1 corresponds.
Warm Up Explain how to simplify the expression 27 ÷ (9 + 6) + 7 = f
Introduction While it may not be efficient to write out the justification for each step when solving equations, it is important to remember that the properties.
Solving Systems of Linear Equations by Graphing
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Simpson Rule For Integration.
1 Introduction to Abstract Mathematics Chapter 4: Sequences and Mathematical Induction Instructor: Hayk Melikya 4.1- Sequences. 4.2,
1.8: Intro to Equations Equation: A mathematical sentence that uses the equal ( = ) sign. Ex: 3x=12, -1(x + 5) = 8, Open Sentence: An equation.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
 The functions that we have met so far can be described by expressing one variable explicitly in terms of another variable.  For example,, or y = x sin.
Operators, Functions and Modules1 Pattern Matching & Recursion.
Chapter 4 Section 1 Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley.
Stephen P. Carl - CS 2421 Recursion Reading : Chapter 4.
Numerical Methods Part: Simpson Rule For Integration.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
3 DIFFERENTIATION RULES. The functions that we have met so far can be described by expressing one variable explicitly in terms of another variable. 
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation An Introduction to XML.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
Multiplying Whole Numbers © Math As A Second Language All Rights Reserved next #5 Taking the Fear out of Math 9 × 9 81 Extending Single Digit Multiplication.
Lee CSCE 314 TAMU 1 CSCE 314 Programming Languages Haskell: Types and Classes Dr. Hyunyoung Lee.
In section 11.9, we were able to find power series representations for a certain restricted class of functions. Here, we investigate more general problems.
Section 2.3 Properties of Solution Sets
Chapter 4 Section 1. Objectives 1 Copyright © 2012, 2008, 2004 Pearson Education, Inc. Solving Systems of Linear Equations by Graphing Decide whether.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
CS201: Data Structures and Discrete Mathematics I
The Commutative Property Using Tiles © Math As A Second Language All Rights Reserved next #4 Taking the Fear out of Math.
Computers, Variables and Types Engineering 1D04, Teaching Session 2.
Time Complexity. Solving a computational program Describing the general steps of the solution –Algorithm’s course Use abstract data types and pseudo code.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
Copyright © Curt Hill Proofs An Introduction.
Multiplication of Common Fractions © Math As A Second Language All Rights Reserved next #6 Taking the Fear out of Math 1 3 ×1 3 Applying.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Copyright © Cengage Learning. All rights reserved. CHAPTER 8 RELATIONS.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
Mathematical Induction. The Principle of Mathematical Induction Let S n be a statement involving the positive integer n. If 1.S 1 is true, and 2.the truth.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
String is a synonym for the type [Char].
Chapter 5 Recursion as a Problem-Solving Technique
Copyright © Cengage Learning. All rights reserved.
Fundamentals & Ethics of Information Systems IS 201
Chapter 10 Thinking in Objects
Algorithm Discovery and Design
Introduction Solving inequalities is similar to solving equations. To find the solution to an inequality, use methods similar to those used in solving.
Types and Classes in Haskell
PROGRAMMING IN HASKELL
Building Java Programs
This Lecture Substitution model
Theory of Computation Lecture 23: Turing Machines III
Presentation transcript:

Chapter 1 Problem Solving, Programming, and Calculation

Introduction  Be sure to understand your problem well.  Find a solution that is correct. But there may be several solutions that trade off efficiency (in time, space, number of processors, etc.) and clarity.  In this text Haskell is used to express solutions to problems of many kinds.  Haskell is a functional language quite unlike most conventional programming languages (such as C, C++, Java, Visual Basic, etc.).  To best understand Haskell, understand the concept of computation by calculation.

Computation by Calculation  Computation by calculation is a simple concept that everyone should be familiar with, since it’s not unlike ordinary arithmetic calculation. For example: 3 * (9 + 5)  3 * 14  42  However, since we want computers to perform these tasks, we are also interested in issues such as efficiency: 3 * (9 + 5)  3*9 + 3*5  *5   42  Same answer, but the former was more efficient than the latter, since it took a fewer number of steps.

Abstraction  We are also interested in abstraction: the process of recognizing a repeating pattern, and capturing it succinctly in one place instead of many.  For example: 3*(9+5) 4*(6+2) 7*(8+1)... This repeating pattern can be captured as a function: easy x y z = x*(y+z) Then each instance can be replaced by: easy easy easy  We can also perform calculations with symbols. For example, we can prove that easy a b c = easy a c b : easy a b c  a*(b+c){ unfold }  a*(c+b){ commutativity of + }  easy a c b { fold }

Expressions, Values, and Types  The objects on which we calculate are called expressions.  When no more unfolding (of either a primitive or user-defined function) is possible, the resulting expression is called a value.  Every expression (and therefore every value) has a type. (A type is a collection of expressions with common attributes.)  We write exp :: T to say that expression exp has type T.  Examples: Atomic expressions: 42 :: Integer, ’a’ :: Char, True :: Bool Structured expressions: [1,2,3] :: [Integer] - a list of integers (’b’,4) :: (Char,Integer) – a pair consisting of a character and an integer Functions: (+) :: Integer -> Integer -> Integer easy :: Integer -> Integer -> Integer -> Integer

Abstraction  Our derivation of the function easy is a good example of the use of the abstraction principle: separating a repeating pattern from the particular instances in which it appears. In particular, the example demonstrates functional abstraction.  Naming is an even simpler kind of abstraction: let pi = in 2*pi*r1 + 2*pi*r2  Data abstraction is the use of data structures to store common values on which common operations may be applied in an abstract manner.  The “circle areas” example from the text demonstrates all three kinds of abstraction.

“Circle Areas” Example  Original program: totalArea = pi*r1^2 + pi*r2^2 + pi*r3^2  A more abstract program: totalArea = listSum [circArea r1, circArea r2, circArea r3] listSum [] = 0 listSum (a:as) = a + listSum as circArea r = pi*r^2  The new program is longer than the old – in what ways is it better? The code for the area of a circle has been isolated (using functional abstraction), thus minimizing errors and facilitating change and reuse. The number of circles has been generalized (via data abstraction) from three to an arbitrary number, thus anticipating change and reuse.

Proof by Calculation  Proof that the new totalArea is equivalent to the old: listSum [circArea r1, circArea r2, circArea r3]  { unfold listSum } circArea r1 + listSum [circArea r2, circArea r3]  { unfold listSum } circArea r1 + circArea r2 + listSum [circArea r3]  { unfold listSum } circArea r1 + circArea r2 + circArea r3 + listSum []  { unfold listSum } circArea r1 + circArea r2 + circArea r3 + 0  { unfold circArea (three places) } pi*r1^2 + pi*r2^2 + pi*r3^2 + 0  { simple arithmetic } pi*r1^2 + pi*r2^2 + pi*r3^2