What is a mathematical defintion for a curried procedure?

98 Views Asked by At

What it means to curry a function in computer programming?

In the field of computer programming, the word curry is used to describe functions $f$ such that for any positive whole number $n$ the following two things are equivalent:

  1. Calling function $f$ exactly one time on $n$ separate arguments (input)

  2. Calling function $f$ $n$ separate times, with each function call accepting exactly one argument.

  3. Some combination of the above. e.g. the number of calls to $f$ could be $\lfloor \frac{n}{2} \rfloor$

y = f(1, 2, 3, 4, 5)
y = f(1)(2)(3)(4)(5)
y = f(1, 2)(3, 4, 5)
y = f(1, 2, 3, 4)(5)
y = f(1)(2, 3, 4, 5)

One application in computer programming of currying is to construct a tree of functions which return other functions.

For example, one can implement multi-function dispatching in terms of single-dispatching at each level of the tree.


How might we extend this concept of currying a function to the field of mathematics?

A response to this question is a formal definition of a transformation which curries functions.


Please assume that a function, in general, is defined to be a set of ordered pairs.

$\text{There exists }$ $\text{ a set }$ $\mathbb{DOM}(f)$ $\text{ such that }$ $f \subseteq \mathbb{DOM}(f) \times \mathbb{DOM}(f)$
There exists a set named $\mathbb{DOM}(f)$ such that $f$ is a subset of the Cartesian product of $\mathbb{DOM}(f)$ and $\mathbb{DOM}(f)$

Perhaps there exists a set $\mathbb{A}$ and there exists a set $\mathbb{B}$ such that:

$\mathbb{A} \cap \mathbb{B} = \emptyset$

$\mathbb{A} \subseteq \mathbb{D}$.

$\mathbb{B} \subseteq \mathbb{D}$.

However, talking about one set (or domain), $\mathbb{D}$ for a function, is sufficient even if the set of inputs and the set of outputs have no overlap.


For example, consider the example in which we take function $f$ to be a finite subset of the square-root function such as the following:

$f = \begin{Bmatrix}(1, 1), (4, 2), (9, 3), (16, 4)\end{Bmatrix}$

$f = \begin{Bmatrix}(k^{2}, k) \in \mathbb{N}: k \in \{1, 2, 3, 4\} \end{Bmatrix}$

$\forall k \in \{1, 2, 3, 4\}$, $\quad$ $f = \sqrt[2]{k}$


DEFINITION

We define a transformation $\mathbb{T}$ such that:

For any two sets $\mathcal{ELEMS}$ and $\mathcal{TUPS}$, if there exists $k \in \mathbb{N}$ such that $\mathcal{TUPS} = \mathcal{ELEMS}^{k}$ then we have all three of the following properties:
- $\mathcal{TUPS} \subseteq \mathbb{T}(A)$.
- $\forall k \in \mathbb{N}$ $ELEMS^{K} \subseteq \mathbb{T}(A)$
- $\mathcal{ELEMS} \subseteq \mathbb{T}(A)$


Now we wish to define a transformation $\mathbb{K}$ such that for any function $f$, $\mathbb{K}(f)$ is a function such that $f$ is curried.

Let us define $\mathcal{LEFT}(f) = \begin{Bmatrix} a: a \in \mathcal{DOM}(f) \text{ and } \exists b \in \mathcal{DOM}(f) : (a, b) \in f \end{Bmatrix}$

Let us define $\mathcal{RIGHT}(f) = \begin{Bmatrix} b: b \in \mathcal{DOM}(f) \text{ and } \exists a \in \mathcal{DOM}(f) : (a, b) \in f \end{Bmatrix}$

Then, $\mathbb{K}(f)$ is a mapping from $\mathbb{T}\begin{pmatrix}\mathcal{LEFT}(f)\end{pmatrix}$ to $\mathbb{T}\begin{pmatrix}\mathcal{RIGHT}(f)\end{pmatrix}$ such that what exactly?

If $y = f(1, 2, 3, 4)$, then ...

  • $y = \mathbb{K}(f)(1, 2, 3, 4)$
  • $y = \mathbb{K}(f)(1, 2)(3, 4)$
  • $y = \mathbb{K}(f)(1)(2, 3, 4)$
  • $y = \mathbb{K}(f)(1)(2)(3)(4)$
1

There are 1 best solutions below

7
On

Instead of the heavy notation that you have invented, just look at the fundamental concept of how sets of functions can be expressed as cardinals: $$f:A\rightarrow B$$ can be identified with the exponential $$f:B^A$$ by the simple expedient of listing every single value of $f(x)$ ranging over the domain $A$, hence a $A$-fold Cartesian product of copies of $B$.

Once you understand that, it's simply a matter of noticing that $$\begin{align}A\rightarrow (B\rightarrow C)&\cong(B\rightarrow C)^A \\&\cong\left(C^B\right)^A \\&\cong C^{A\times B} \\&\cong(A\times B)\rightarrow C\end{align}$$ with nothing more than cardinal arithmetic. Don't overcomplicate things.