# 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`.