Sorawee Porncharoenwase <sorawee.pwase@gmail.com>
A language for writing recursively computable functions (or simply recursive functions), which are functions in recursion theory that consume natural numbers and produce a natural number. See Chapter 6 of Computability and Logic (George Boolos, John P. Burgess, and Richard Jeffrey) for details.
To make it clear what constructs and functions are used as a basis to define recursive functions, we need to explicitly import them with the import statement:
import<construct-1>,<construct-2>,...,<construct-n>;
Following are core constructs:
z and s functions (zero constant function and successor function, with arity 1)
id_<place>^<arity> where <place> and <arity> are natural numbers (identity/projection functions, with arity <arity>)
Cn[<f>, <g-1>, ..., <g-m>] (composition)
Pr[<f>, <g>] (primitive recursion)
Mn[<f>] (minimization)
Furthermore, following derived functions (presented in the book) are also provided for convenience.
const_<n> where <n> is a natural number (constant function, with arity 1)
sum and prod (addition and multiplication, with arity 2)
pred (predecessor function, with arity 1)
monus (subtraction on natural numbers, with arity 2)
sgn and ~sgn (zero predicate and its negated form, with arity 1)
We can define recursive functions using = where the LHS is an identifier name and the RHS is an expression that builds a recursive function. For example:
sum=Pr[id_1^1,Cn[s,id_3^3]];prod=Pr[z,Cn[sum,id_1^3,id_3^3]];
defines sum to be the (primitive) recursive function Pr[id_1^1, Cn[s, id_3^3]] and prod to be the (primitive) recursive function Pr[z, Cn[sum, id_1^3, id_3^3]]
We can print results from function invocation by using the print statement.
printsum(10,23);
Running the program will result in 33.
We can use the check construct to test that our recursive functions are correct on given inputs. For example:
checksum(10,23)=33;
checks that sum(10, 23) should have the result 33.
Comment can be written by using #....
importPr,Cn,s,id,z,const;sum=Pr[id_1^1,Cn[s,id_3^3]];printsum(2,23);#shouldbe25prod=Pr[z,Cn[sum,id_1^3,id_3^3]];printprod(3,3);#shouldbe9fact=Cn[Pr[const_1,Cn[prod,Cn[s,id_2^3],id_3^3]],id_1^1,id_1^1];printfact(fact(3));#shouldbe720printfact(Cn[s,s](4));#shouldbe720checkfact(3)=6;
Thanks to Matthias Felleisen for giving me advice on Racket macrology back in 2018.