# Grain

Paradigm(s) not specified User:Grom 2021 Turing complete Unimplemented `.grain`

Grain is a theoretical programming language in which all functions can be infinitely recursively derived from combinations of other functions.

User:Grom believes it could be possible to implement such a language in an efficient and relatively deterministic manner without rounded floating points.

Essentially the language boils down to two concepts/problems:

The first is how to create varied functional effects from large integers. This will be achieved via a function called the granulator (herein simply "𝔾").

The second is to, given any number `A`, produce an ordered combination of functions (integers) that when applied successively (ie: `f(g(h(j(x))))` ) maps the domain of `𝔾(A)` to the codomain of `𝔾(A)`

ie:

``` A(x) = f(g(h(i(x)))) ```

```𝕄(A)(x) = f(g(h(i(x)))) ```

```𝕄(A) = (f, g, h, i) ```

```𝕄'(f(x), g(x), h(x), i(x)) = A(x) ```

The function that produces this combination of functions will herein be referred to as the Master Function, or simply "𝕄".

## Formal Definition of 𝕄 and 𝔾

For all integers x,

- 𝔾(𝕄(x)) is a function which exists in the co-domain of 𝔾.

- 𝔾(x) shares the same mapping as 𝔾(𝕄(x))

- 𝕄(x) does not contain x

More succinctly:

``` ∀x∈ℤ (∀n∈ℤ 𝔾(x)(n) = 𝔾(𝕄(x))(n) ⋀ (𝕄(x) ⋂ x = ∅) ⋀ (𝔾(𝕄(x)) ⋂ 𝔾 ≠ ∅))```

## Properties of the Master Function

### - O(1) time

(The resulting function composition can be computed mathematically (as opposed to iteratively) directly from func with 𝕄(func) )

## Evidence of viability

To prove that some non zero amount of viable Master Functions exist, consider some 𝕄 wherein:

``` ∀x∈ℤ ```

```𝔾(x) ∈ {f(n) = n+1, g(n) = n-1, h(n) = n+2, i(n) = n-2} ```

``` ∀x∈ℤ (𝔾(x)(n) = n+1 = f(n) | 𝔾(𝕄(x))(n) = g(h(n)) = n+2-1 = n+1) ```

```∀x∈ℤ (𝔾(x)(n) = n-1 = g(n) | 𝔾(𝕄(x))(n) = f(i(n)) = n-2+1 = n-1) ```

```∀x∈ℤ (𝔾(x)(n) = n+2 = h(n) | 𝔾(𝕄(x))(n) = f(f(n)) = n+1+1 = n+2) ```

```∀x∈ℤ (𝔾(x)(n) = n-2 = i(n) | 𝔾(𝕄(x))(n) = g(g(n)) = n-1-1 = n-2) ```

This is not a very interesting 𝕄 or 𝔾, not only is 𝔾 of finite cardinality, but `∀x∈ℤ card|𝕄(x)| = 2`.