Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are all pure functions in functional programming continuous?

I know that the set of Haskell functions is only a subset of all mathematical functions, because it is a programming language, so all of its functions must be computable. But is it true that all Haskell functions (and pure functions in general) are continuous, from a mathematical point of view?

like image 893
MainstreamDeveloper00 Avatar asked Jan 05 '16 17:01

MainstreamDeveloper00


People also ask

What are the characteristics of pure functions in functional programming?

Pure functions are deterministic and have no side effects. Deterministic: for same input x , output y should always be the same. Side effect: use of external dependency or variable mutations.

What is pure function in functional programming?

In computer programming, a pure function is a function that has the following properties: the function return values are identical for identical arguments (no variation with local static variables, non-local variables, mutable reference arguments or input streams), and.

Are all functions are continuous?

Theorem: There are no discontinuous functions. Theorem (classically equivalent form): All functions are continuous. When constructive mathematicians says that “all functions are continuous” they have something even better in mind. They are telling you that all functions are computably continuous.

What is not present in pure functional programming?

Persistency is required for functional programming; without it, the same computation could return different results. Functional programming may use persistent non-purely functional data structures, while those data structures may not be used in purely functional programs.


1 Answers

Computable functions are continuous in the sense of Scott continuity, mentioned in the second paragraph of the Wikipedia page you linked to.

An example of a function which is not continuous is (pseudo-Haskell)

isInfinite :: [a] -> Bool
isInfinite xs
    | {- xs is an infinite list x0 : x1 : x2 : ... -}        = True
    | {- xs is a finite list x0 : x1 : x2 : ... : xn : [] -} = False
    | {- xs is a list with diverging spine
                            x0 : x1 : x2 : ... : xn : _|_ -} = _|_

It fails to be continuous because

() : () : () : ...

is the supremum of the sequence

_|_
() : _|_
() : () : _|_
...

but

True = isInfinite (() : () : () : ...)

is not the supremum of the sequence

_|_ = isInfinite (_|_)
_|_ = isInfinite (() : _|_)
_|_ = isInfinite (() : () : _|_)
...

Computable functions are continuous, essentially because in a finite amount of time a function can only inspect a finite amount of its input. So if a computable function returns, say, True on a particular input, it must return True on every input in the set of inputs which agree with the original input on a certain finite collection of observations. Any increasing sequence which converges to the original input will eventually land and stay inside this set, so the sequence of values of the function on this increasing sequence will converge to True.

A continuous function is not necessarily computable. For example any order-preserving (i.e. f _|_ = _|_, or f is constant) function Integer -> Bool is continuous, since Integer is a flat domain. But of course only countably many of them are computable.

like image 95
Reid Barton Avatar answered Oct 18 '22 02:10

Reid Barton