The Haskell Road to Logic, Maths and Programming. Second Edition (Texts in Computing) by Kees Doets & Jan van Eijck
Author:Kees Doets & Jan van Eijck
Language: eng
Format: azw3
Publisher: UNKNOWN
Published: 2018-04-14T16:00:00+00:00
6.1 Basic Notions
A function is something that transforms an object given to it into another one. The objects that can be given to a function are called its arguments, and the results of the transformation are called values. The set of arguments is called the domain of the function. We say that a function is defined on its domain.
If f is a function andx one of its arguments, then the corresponding value is denoted byf (x). A function valuey = f (x) is called the image ofx underf. Thatf (x) = y can also be indicated byf : x−→y. The domain off is denoted bydom (f ). Its range is ran(f ) ={f (x)|x∈ dom (f )}.
Example 6.1 A function can be given as a rule or a prescription how to carry out the transformation.
•
First square, next add one is the function that transforms a realx∈ R into x2 + 1.
Lettingf stand for this function, it is customary to describe it by the equation
f (x) = x2 + 1.
The Haskell implementation uses the same equation:
f x = x^2 + 1
• The function described by |
x| = x ifx 0
−x ifx < 0
transforms a real into its absolute value. The Haskell implementation given in Prelude.hs follows this definition to the letter:
absReal x | x >= 0 = x | otherwise = -x
• The identity function 1A defined onA does not “transform” at all in the usual sense of the word: given an argumentx∈A, it outputsx itself. A polymorphic identity function is predefined in Haskell as follows:
id :: a -> a id x = x
Set theory has the following simple definition of the concept of a function.
Definition 6.2 A function is a relationf that satisfies the following condition.
(x, y)∈f∧ (x, z)∈f =⇒ y = z.
That is: for everyx∈ dom (f ) there is exactly oney∈ ran(f ) such that (x, y)∈f.
Ifx∈ dom (f ), thenf (x) is by definition the unique objecty∈ ran(f ) for which (x, y)∈f. Note that we use dom here in the sense defined for relations, but that the relation and the function-sense of the notion coincide: the domaindom (f ) of the function f is{x| ∃y((x, y)∈f )}; exactly as in the relation-case (cf. Definition 5.1 p. 162).
Similarly, the range off coincides with the range off as a relation. The set-theoretic and the computational view on functions are worlds apart, for computationally a function is an algorithm for computing values. However, in cases of functions with finite domains it is easy to switch back and forth between the two perspectives, as the following conversions demonstrate.
list2fct :: Eq a => [(a,b)] -> a -> b
list2fct [] _ = error "function not total" list2fct ((u,v):uvs) x | x == u = v
| otherwise = list2fct uvs x
fct2list :: (a -> b) -> [a] -> [(a,b)] fct2list f xs = [ (x, f x) | x <- xs ]
The range of a function, implemented as a list of pairs, is given by:
ranPairs :: Eq b => [(a,b)] -> [b] ranPairs
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Algebra | Calculus |
Combinatorics | Discrete Mathematics |
Finite Mathematics | Fractals |
Functional Analysis | Group Theory |
Logic | Number Theory |
Set Theory |
Modelling of Convective Heat and Mass Transfer in Rotating Flows by Igor V. Shevchuk(6200)
Weapons of Math Destruction by Cathy O'Neil(5778)
Factfulness: Ten Reasons We're Wrong About the World – and Why Things Are Better Than You Think by Hans Rosling(4454)
Descartes' Error by Antonio Damasio(3138)
A Mind For Numbers: How to Excel at Math and Science (Even If You Flunked Algebra) by Barbara Oakley(3075)
Factfulness_Ten Reasons We're Wrong About the World_and Why Things Are Better Than You Think by Hans Rosling(3025)
TCP IP by Todd Lammle(2982)
Applied Predictive Modeling by Max Kuhn & Kjell Johnson(2857)
Fooled by Randomness: The Hidden Role of Chance in Life and in the Markets by Nassim Nicholas Taleb(2833)
The Tyranny of Metrics by Jerry Z. Muller(2818)
The Book of Numbers by Peter Bentley(2744)
The Great Unknown by Marcus du Sautoy(2516)
Once Upon an Algorithm by Martin Erwig(2456)
Easy Algebra Step-by-Step by Sandra Luna McCune(2434)
Lady Luck by Kristen Ashley(2386)
Practical Guide To Principal Component Methods in R (Multivariate Analysis Book 2) by Alboukadel Kassambara(2358)
Police Exams Prep 2018-2019 by Kaplan Test Prep(2332)
All Things Reconsidered by Bill Thompson III(2241)
Linear Time-Invariant Systems, Behaviors and Modules by Ulrich Oberst & Martin Scheicher & Ingrid Scheicher(2210)
