# Foundations of the gerku language ## Abstract We outline here the theoretical foundation that inspired the development of the `gerku` language. In [1] a method is presented to automatically derive ๐œ†-functions (or, equivalently, Combinatory Logic terms) from the definition of iterative functions. The method relies on encoding data types with ๐œ†-functions (or CL terms) in a specific way so that deriving the ๐œ†-function (or CL term) to compute an iterative function is completely automatic. We will only present the general idea here, using practical examples. The original papers (see bibliography) provide a more formal description. The last section contains a full example on how to write a program that reverses a given list. The `gerku` project objectives are: - to prove that the same results hold in Concatenative Combinatory Logic (see [3]) - to create an interpreter to execute programs automatically derived from their iterative definition. ## Data types We define a *data type* ๐““ as a pair of sets: ``` ๐““ = โŸจ{*carriers*}, {*constructors*}โŸฉ ``` Let's define some common data types. ### Natural numbers (โ„•) Natural numbers (โ„•) are defined by Peano's axioms: - 0 is a natural number; - if ๐‘› is a natural number then ๐’”(๐‘›) is a natural number; - nothing else is a natural number. Any natural number can be represented as ๐’”(๐’”( ... ๐’”(๐’”(0)) ... )). The *constructors* of natural numbers are the two functions 0:โ„• and ๐’”:โ„•โญขโ„•. We can say that the data type for natural numbers is: ``` ๐““ = โŸจ{โ„•}, {๐’”:โ„•โญขโ„• , 0:โ„•}โŸฉ ``` ### Pairs (โ„™) The carrier set of a data type contains all the elements of the data type but can also contain other elements that are not generated by the constructors but are given a priori. Let's call them *atoms*. ``` ๐““ = โŸจ{๐”ธ,โ„™}, {pair:๐”ธร—๐”ธโญขโ„™}โŸฉ ``` The `pair()` constructor is often abbreviated using angle brackets `โŸจโŸฉ`. ### Booleans (๐”น) ``` ๐““ = โŸจ{๐”น}, {true:๐”น , false:๐”น}โŸฉ ``` ### Lists (๐•ƒ) Lists that can be defined by axioms similar to the ones we have used for Naturals: - nil is a list; - if ๐‘™ is a list and ๐‘Ž is an atom, then cons(๐‘Ž,๐‘™) is a list; - nothing else is a list. Any list is represented by a term like: ``` cons(๐‘Žโ‚, (cons(๐‘Žโ‚‚, ... cons(๐‘Žโ‚™,nil) ... ))) ``` The data type for the lists is: ``` ๐““ = โŸจ{๐”ธ,๐•ƒ}, {cons:๐”ธโญข๐•ƒโญข๐•ƒ , nil:๐•ƒ}โŸฉ ``` We can abbreviate a list using the following notation `[๐‘Žโ‚ ๐‘Žโ‚‚ ... ๐‘Žโ‚™]`. ## Iterative functions We will focus on the class of *iterative functions* which is closed under composition. ### Iterative functions on โ„• A function `๐‘“` on Naturals is said to be *iterative* if it can be defined as follows: ``` ๐‘“(0) = โ„Žโ‚€ ๐‘“(๐’”(n)) = โ„Žโ‚(๐‘“(n)) ``` If this definition is possible, we'll have that: ``` ๐‘“(n) = โ„Žโ‚(โ„Žโ‚( ... โ„Žโ‚(โ„Žโ‚€) ... )) = โ„Žโ‚โฟ(โ„Žโ‚€) โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€ n times โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ ``` for example: ``` ๐‘“(3) = โ„Žโ‚(๐‘“(2)) = โ„Žโ‚(โ„Žโ‚(๐‘“(1))) = โ„Žโ‚(โ„Žโ‚(โ„Žโ‚(๐‘“(0)))) = โ„Žโ‚(โ„Žโ‚(โ„Žโ‚(โ„Žโ‚€)))) ``` Typical examples of iterative functions are the addition and the multiplication on Naturals: ``` add(m,0) = m add(m,๐’”(n)) = ๐’”(add(m,n)) mult(m,0) = 0 mult(m,๐’”(n)) = add(m,mult(m,n)) ``` ### Iterative functions on โ„™ The pair data type has only one constructor, meaning that the iterative scheme will only have one case. Two fundamental functions are the *projectors* that extract the elements from a pair: ``` ฮ โ‚(โŸจ๐‘Žโ‚,๐‘Žโ‚‚โŸฉ) = ๐‘Žโ‚ ฮ โ‚‚(โŸจ๐‘Žโ‚,๐‘Žโ‚‚โŸฉ) = ๐‘Žโ‚‚ ``` It's easy to see that they are iterative. ### Iterative functions on ๐•ƒ A function ๐‘“ on lists is said to be *iterative* if it can be defined as follows: ``` ๐‘“(nil) = โ„Žโ‚€ ๐‘“(cons(a,l)) = โ„Žโ‚(a,๐‘“(l)) ``` If this definition is possible, for a list of length n we'll have that: ``` ๐‘“(l) = โ„Žโ‚(๐‘Žโ‚, โ„Žโ‚(๐‘Žโ‚‚, ... โ„Žโ‚(๐‘Žโ‚™,โ„Žโ‚€) ... )) โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ n times โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ ``` Some examples of iterative functions on lists: ``` len(nil) = 0 len(cons(a,l)) = succ(len(l)) head(nil) = ๐œ€ head(cons(a,l)) = ๐’ฐโ‚(a,head(l)) ``` The auxiliary function ๐’ฐโ‚() returns the first among its arguments. ## Primitive Recursive functions Let's restrict our attention on Naturals. The reasoning below can be generalized to any data type. A function ๐‘“ on Naturals is said to be *primitive recursive* if it can be defined as follows: ``` ๐‘“(0) = ๐‘”โ‚€ ๐‘“(๐’”(n)) = ๐‘”โ‚(n,๐‘“(n)) ``` The key difference with *iterative* functions is that the recursive step depends not only on `๐‘“(n)` but also on `n` itself. An important property (proven in [2]) is that: > For any primitive recursive function `๐‘“()` , there exists an iterative function `๐น()` that (using tuples) produces the same result. In other words: `โˆƒ๐บโ‚€,๐บโ‚` such that ``` ๐น(0) = ๐บโ‚€ ๐น(๐’”(n)) = ๐บโ‚(๐น(n)) ``` and `โˆ€nโˆˆโ„• ๐‘“(n) = ๐น(n)` This means that working with iterative functions does not restrict us in any way. Let's show how this works with the factorial. ``` fact(0) = 1 fact(๐’”(n)) = mult(๐’”(n),fact(n)) ``` We can choose the following iterative functions: ``` ๐บโ‚€ = โŸจ0,1โŸฉ ๐บโ‚(y) = โŸจ๐’”(ฮ โ‚(y)), mult(๐’”(ฮ โ‚(y)), ฮ โ‚‚(y))โŸฉ ``` and define the function `๐น':โ„•โญขโ„™`: ``` ๐น'(0) = ๐บโ‚€ = โŸจ0,1โŸฉ ๐น'(๐’”(n)) = ๐บโ‚(๐น'(n)) = โŸจ๐’”(ฮ โ‚(๐น'(n))), mult(๐’”(ฮ โ‚(๐น'(n))), ฮ โ‚‚(๐น'(n)))โŸฉ ``` which follows the iterative scheme (everything depends on `๐น'(n)`, not on `n` ). We can now define `๐น(x) = ฮ โ‚‚(๐น'(x))` which, being the composition of iterative functions, is iterative and provides the factorial of `x`. To show how this works, let's evaluate `F'(3)` by applying three times `๐บโ‚` to `๐บโ‚€`: ``` F'(0) = ๐บโ‚€ = โŸจ0,1โŸฉ F'(1) = ๐บโ‚(๐บโ‚€) = โŸจ๐’”(ฮ โ‚(โŸจ0,1โŸฉ)), mult(๐’”(ฮ โ‚(โŸจ0,1โŸฉ)), ฮ โ‚‚(โŸจ0,1โŸฉ)โŸฉ = โŸจ๐’”(0), mult(๐’”(0),1)โŸฉ = โŸจ1, 1โŸฉ F'(2) = ๐บโ‚(๐บโ‚(๐บโ‚€)) = โŸจ๐’”(ฮ โ‚(โŸจ1,1โŸฉ)), mult(๐’”(ฮ โ‚(โŸจ1,1โŸฉ)), ฮ โ‚‚(โŸจ1,1โŸฉ)โŸฉ = โŸจ๐’”(1), mult(๐’”(1),1)โŸฉ = โŸจ2, 2โŸฉ F'(3) = ๐บโ‚(๐บโ‚(๐บโ‚(๐บโ‚€)) = โŸจ๐’”(ฮ โ‚(โŸจ2,2โŸฉ)), mult(๐’”(ฮ โ‚(โŸจ2,2โŸฉ)), ฮ โ‚‚(โŸจ2,2โŸฉ)โŸฉ = โŸจ๐’”(2), mult(๐’”(2),2)โŸฉ = โŸจ3, 6โŸฉ ``` It's interesting to note what happens here: instead of using the *implicit* stack provided by the recursion scheme, we manage an explicit varaible (one element of the pair) to keep track of the partial results until we reach the desired outcome. We can use the same technique to define the *predecessor* function `๐‘:โ„•โญขโ„•` : ``` ๐‘(0) = 0 ๐‘(๐’”(n)) = n ``` which is primitive recursive (its value depends on `n`, not on `๐‘(n)` as it is required by the iterative scheme). ``` ๐‘'(0) = ๐บโ‚€ = โŸจ0,0โŸฉ ๐‘'(๐’”(n)) = ๐บโ‚(p'(n)) = โŸจ๐’”(ฮ โ‚(๐‘'(n))),ฮ โ‚(๐‘'(n))โŸฉ ๐‘(x) = ฮ โ‚‚(๐‘'(x)) ``` Let's calculate the predecessor of 3: ``` ๐‘'(0) = ๐บโ‚€ = โŸจ0,0โŸฉ ๐‘'(1) = ๐บโ‚(๐บโ‚€) = โŸจ๐’”(ฮ โ‚(โŸจ0,0โŸฉ)), ฮ โ‚(โŸจ0,0โŸฉ)โŸฉ = โŸจ1,0โŸฉ ๐‘'(2) = ๐บโ‚(๐บโ‚(๐บโ‚€)) = โŸจ๐’”(ฮ โ‚(โŸจ1,0โŸฉ)), ฮ โ‚(โŸจ1,0โŸฉ)โŸฉ = โŸจ2,1โŸฉ ๐‘'(3) = ๐บโ‚(๐บโ‚(๐บโ‚(๐บโ‚€)) = โŸจ๐’”(ฮ โ‚(โŸจ2,1โŸฉ)), ฮ โ‚(โŸจ2,1โŸฉ)โŸฉ = โŸจ3,2โŸฉ ๐‘(3) = ฮ โ‚‚(๐‘'(3)) = ฮ โ‚‚(โŸจ3,2โŸฉ) = 2 ``` ## Automatic Synthesis of data constructors Since data are represented as functions, we need to define a method to derive the ๐œ†-function (or CL terms) that encode those functions. The method is summarized in proposition 5.3 in [1], we'll use it to derive the CL terms for the constructors of some data type. The resulting encoding are similar, if not exactly the same, as those commonly known as Curch-encodings [4]. In the following, combinators are in bold, variables in italics. ### Constructors of Booleans ๐”น For Booleans proposition 5.3 gives: ``` ๐ญ๐ซ๐ฎ๐ž ๐‘ก ๐‘“ = ๐‘ก ๐Ÿ๐š๐ฅ๐ฌ๐ž ๐‘ก ๐‘“ = ๐‘“ ``` ### Constructors of Naturals โ„• For Naturals proposition 5.3 gives: ``` ๐ŸŽ ๐‘  ๐‘ง = ๐‘ง ๐ฌ ๐‘› ๐‘  ๐‘ง = ๐‘  (๐‘› ๐‘  ๐‘ง) ``` ### Constructors of lists ๐•ƒ For Lists proposition 5.3 gives: ``` ๐œ๐จ๐ง๐ฌ ๐‘Ž ๐‘ฃ ๐‘ ๐‘› = ๐‘ ๐‘Ž (๐‘ฃ ๐‘ ๐‘›) ๐ง๐ข๐ฅ ๐‘ ๐‘› = ๐‘› ``` ## Automatic Synthesis of programs This is the main result (proven in [1]) that we want to leverage in `gerku`: > By properly representing data types with ๐œ†-functions (or CL terms), any iterative function can be automatically translated into a program that computes that function. This means that writing a program is a four steps process: - Properly define the data types - Define an encoding for the data types constructors (determine the corresponding ๐œ†-function or CL terms) - Write the iterative definitions for the functions to be computed by the program - Convert the functions to ๐œ†-function (or CL terms) Let's write a program that reverses a given list. ### Step 1 The first step is to properly define the data type (which we already did): ``` ๐““ = โŸจ{๐”ธ,๐•ƒ}, {cons:๐”ธโญข๐•ƒโญข๐•ƒ, nil:๐•ƒ}โŸฉ ``` ### Step 2 We have already defined the combinators for list constructors in the previous section: ``` ๐œ๐จ๐ง๐ฌ ๐‘Ž ๐‘ฃ ๐‘ ๐‘› = ๐‘ ๐‘Ž (๐‘ฃ ๐‘ ๐‘›) ๐ง๐ข๐ฅ ๐‘ ๐‘› = ๐‘› ``` ### Step 3 Next step is to define the iterative functions we need. We first define a *reverse cat* function that concatenates two lists in the following way: ``` rcat([๐‘Ž ๐‘ ๐‘], [๐‘‘ ๐‘’]) = [๐‘‘ ๐‘’ ๐‘Ž ๐‘ ๐‘] ``` It is an iterative function: ``` rcat(q,nil) = ๐’ฐโ‚(q) rcat(q,cons(a,l)) = cons(a,rcat(q,l)) = ``` The auxiliary function `๐’ฐโ‚()` returns the first among its arguments. Now we can define `rev()` in terms of `rcat()`: ``` rev(nil) = nil rev(cons(a,l)) = rcat(cons(a,nil),rev(l)) ``` Let's check that it works: ``` rev([๐‘Ž ๐‘ ๐‘]) = rcat([๐‘Ž], rev([๐‘ ๐‘])) = rcat([๐‘Ž], rcat([๐‘] ,rev([๐‘]))) = rcat([๐‘Ž], rcat([๐‘] ,rcat([๐‘],rev([])))) = rcat([๐‘Ž], rcat([๐‘] ,rcat([๐‘],[]))) = rcat([๐‘Ž], rcat([๐‘] ,[๐‘])) = rcat([๐‘Ž], [๐‘ ๐‘]) = [๐‘ ๐‘ ๐‘Ž] ``` The function `rev()` is iterative since it is defined using only iterative functions. ### Step 4 Now we use Definition 5.5 in [1] to automatically derive our programs. That, for lists, states that given the function: ``` ๐‘“(nil) = โ„Žโ‚€ ๐‘“(cons(a,l)) = โ„Žโ‚(a,๐‘“(l)) ``` the corresponding *program* is: ``` ๐Ÿ ๐ฟ = ๐ฟ ๐‡โ‚ ๐‡โ‚€ ``` where `๐ฟ` is the encoding of the list and ๐‡โ‚€, ๐‡โ‚ are the *programs* corresponding to the functions `โ„Žโ‚€`, `โ„Žโ‚`. Let's first identify the terms `๐‡โ‚€` and `๐‡โ‚` that correspond to the iterative definition of the function: ``` ๐ซ๐œ๐š๐ญ ๐‘„ ๐ง๐ข๐ฅ = ๐‡โ‚€ ๐‘„ = ๐‘„ โ‡’ ๐‡โ‚€ = ๐ˆ (๐ˆ ๐‘ฅ = ๐‘ฅ) ๐ซ๐œ๐š๐ญ ๐‘„ (๐œ๐จ๐ง๐ฌ ๐‘Ž ๐ฟ) = ๐‡โ‚ ๐‘„ ๐‘Ž (๐ซ๐œ๐š๐ญ ๐‘„ ๐ฟ) = ๐œ๐จ๐ง๐ฌ ๐‘Ž (๐ซ๐œ๐š๐ญ ๐‘„ ๐ฟ) โ‡’ ๐‡โ‚ ๐‘„ = ๐œ๐จ๐ง๐ฌ ``` From definition 5.5 it must be: ``` ๐ซ๐œ๐š๐ญ ๐‘„ ๐ฟ = ๐ฟ (๐‡โ‚ ๐‘„) (๐‡โ‚€ ๐‘„) = ๐ฟ ๐œ๐จ๐ง๐ฌ ๐‘„ ``` Let's check that this is correct. Remembering the definitions of `๐œ๐จ๐ง๐ฌ` and `๐ง๐ข๐ฅ` found prevously. ``` ๐ซ๐œ๐š๐ญ [๐‘Ž ๐‘ ๐‘] [๐‘‘ ๐‘’] = [๐‘‘ ๐‘’] ๐œ๐จ๐ง๐ฌ [๐‘Ž ๐‘ ๐‘] = ๐œ๐จ๐ง๐ฌ ๐‘‘ [๐‘’] ๐œ๐จ๐ง๐ฌ [๐‘Ž ๐‘ ๐‘] = ๐œ๐จ๐ง๐ฌ ๐‘‘ ([๐‘’] ๐œ๐จ๐ง๐ฌ [๐‘Ž ๐‘ ๐‘]) = ๐œ๐จ๐ง๐ฌ ๐‘‘ (๐œ๐จ๐ง๐ฌ ๐‘’ ๐ง๐ข๐ฅ ๐œ๐จ๐ง๐ฌ [๐‘Ž ๐‘ ๐‘]) = ๐œ๐จ๐ง๐ฌ ๐‘‘ (๐œ๐จ๐ง๐ฌ ๐‘’ (๐ง๐ข๐ฅ ๐œ๐จ๐ง๐ฌ [๐‘Ž ๐‘ ๐‘])) = ๐œ๐จ๐ง๐ฌ ๐‘‘ (๐œ๐จ๐ง๐ฌ ๐‘’ ([๐‘Ž ๐‘ ๐‘])) = ๐œ๐จ๐ง๐ฌ ๐‘‘ (๐œ๐จ๐ง๐ฌ ๐‘’ [๐‘Ž ๐‘ ๐‘]) = ๐œ๐จ๐ง๐ฌ ๐‘‘ ([๐‘’ ๐‘Ž ๐‘ ๐‘]) = ๐œ๐จ๐ง๐ฌ ๐‘‘ [๐‘’ ๐‘Ž ๐‘ ๐‘] = [d ๐‘’ ๐‘Ž ๐‘ ๐‘] ``` Let's move to `๐ซ๐ž๐ฏ`. ``` ๐ซ๐ž๐ฏ ๐ง๐ข๐ฅ = ๐ง๐ข๐ฅ โ‡’ ๐‡โ‚€ = ๐ง๐ข๐ฅ ๐ซ๐ž๐ฏ (๐œ๐จ๐ง๐ฌ ๐‘Ž ๐ฟ) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐ž๐ฏ ๐ฟ) โ‡’ ๐‡โ‚ ๐‘Ž = ๐ซ๐œ๐š๐ญ [๐‘Ž] ``` We are not there yet as we need an explicit term for `๐‡โ‚` . For this we can use the combinators `๐` and `๐‚` defined as follows: ``` ๐ ๐‘ฅ ๐‘ฆ ๐‘ง = ๐‘ฅ (๐‘ฆ ๐‘ง) ๐‚ ๐‘ฅ ๐‘ฆ ๐‘ง = ๐‘ฅ ๐‘ง ๐‘ฆ ``` and get: ``` ๐‡โ‚ ๐‘Ž = ๐ซ๐œ๐š๐ญ [๐‘Ž] = ๐ซ๐œ๐š๐ญ (๐œ๐จ๐ง๐ฌ ๐‘Ž ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ ๐‘Ž) = ๐ซ๐œ๐š๐ญ ((๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘Ž) = ๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘Ž โ‡’ ๐‡โ‚ = ๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ``` We can now derive the program for `๐ซ๐ž๐ฏ`: ``` ๐ซ๐ž๐ฏ ๐ฟ = ๐ฟ ๐‡โ‚ ๐‡โ‚€ = ๐ฟ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ ``` Let's check its correctness: ``` ๐ซ๐ž๐ฏ [๐‘Ž ๐‘ ๐‘] = [๐‘Ž ๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ = ๐œ๐จ๐ง๐ฌ ๐‘Ž [๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ = (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐‘Ž ([๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘Ž ([๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ ((๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘Ž) ([๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ ๐‘Ž) ([๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ (๐œ๐จ๐ง๐ฌ ๐‘Ž ๐ง๐ข๐ฅ) ([๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ [๐‘Ž] ([๐‘ ๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐œ๐จ๐ง๐ฌ ๐‘ [๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ) = ๐ซ๐œ๐š๐ญ [๐‘Ž] ((๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐‘ ([๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘ ([๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ ((๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘) ([๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ ๐‘) ([๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ (๐œ๐จ๐ง๐ฌ ๐‘ ๐ง๐ข๐ฅ) ([๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] ([๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐œ๐จ๐ง๐ฌ ๐‘ ๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] ((๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ)) ๐‘ (๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ))) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘ (๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ))) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ซ๐œ๐š๐ญ ((๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ) ๐‘) (๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ))) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ ๐‘) (๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ))) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ซ๐œ๐š๐ญ (๐œ๐จ๐ง๐ฌ ๐‘ ๐ง๐ข๐ฅ) (๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ))) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ซ๐œ๐š๐ญ [๐‘] (๐ง๐ข๐ฅ (๐ ๐ซ๐œ๐š๐ญ (๐‚ ๐œ๐จ๐ง๐ฌ ๐ง๐ข๐ฅ))) ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ซ๐œ๐š๐ญ [๐‘] (๐ง๐ข๐ฅ))) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] (๐ซ๐œ๐š๐ญ [๐‘] ๐ง๐ข๐ฅ)) = ๐ซ๐œ๐š๐ญ [๐‘Ž] (๐ซ๐œ๐š๐ญ [๐‘] [๐‘]) = ๐ซ๐œ๐š๐ญ [๐‘Ž] [๐‘ ๐‘] = [๐‘ ๐‘ ๐‘Ž] ``` ## Conclusion We have summarized here the key aspects of the theory behind the `gerku` programming language. It is still not proven if the same results will hold for Concatenative Combinators (and if yes, under which assumptions). That's the objective of the entire project. ## Bibliography [1] "*Automatic synthesis of typed ฮ›-programs on term algebras*", Corrado Bรถhm, Alessandro Berarducci, in "*Theoretical Computer Science*", Volume 39, 1985, Pages 135-154, https://doi.org/10.1016/0304-3975(85)90135-5. [2] "*Reducing recursion to iteration by means of pairs and N-tuples*", Corrado Bรถhm, in proceedings "*Foundations of Logic and Functional Programming*", 1988, Springer Berlin Heidelberg. https://link.springer.com/chapter/10.1007%2F3-540-19129-1_3 [3] *The Theory of Concatenative Combinators*, Brent Kerby (bkerby at byu dot net). Completed June 19, 2002. Updated February 5, 2007. http://tunes.org/~iepos/joy.html [4] *Church encoding*, https://en.wikipedia.org/wiki/Church_encoding