Guest User

lambda calculus in javascript

a guest
Jul 23rd, 2026
43
1
Never
5
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 21.21 KB | Source Code | 1 0
  1. const TRUE = x => y => x;
  2. const FALSE = x => y => y;
  3.  
  4. const AND = p => q => p(q)(p);
  5. const OR = p => q => p(p)(q);
  6. const NOT = p => p(FALSE)(TRUE);
  7. const XOR = p => q => p(p)(q)(p(q)(p)(FALSE)(TRUE))(p(p)(q));
  8. const EQBOOL = p => q => p(p)(q)(p(q)(p)(FALSE)(TRUE))(p(p)(q))(FALSE)(TRUE);
  9. const IFTHENELSE = p => a => b => p(a)(b);
  10.  
  11. const ZERO = f => x => x;
  12. const SUCC = n => f => x => f(n(f)(x));
  13. const ADD = m => n => f => x => m(f)(n(f)(x));
  14. const MULT = m => n => f => m(n(f));
  15. const POW = b => e => e(b);
  16. const PRED = n => f => x => n(g => h => h(g(f)))(u => x)(u => u);
  17. const SUB = m => n => n(PRED)(m);
  18. const ISZERO = n => n(x => FALSE)(TRUE);
  19. const LEQ = m => n => ISZERO(SUB(m)(n));
  20. const GEQ = m => n => LEQ(n)(m);
  21. const EQ = m => n => AND(LEQ(m)(n))(LEQ(n)(m));
  22. const LT = m => n => NOT(GEQ(m)(n));
  23. const GT = m => n => NOT(LEQ(m)(n));
  24.  
  25. const ONE = SUCC(ZERO);
  26. const TWO = SUCC(ONE);
  27. const THREE = SUCC(TWO);
  28. const FOUR = SUCC(THREE);
  29. const FIVE = SUCC(FOUR);
  30. const SIX = SUCC(FIVE);
  31. const SEVEN = SUCC(SIX);
  32. const EIGHT = SUCC(SEVEN);
  33. const NINE = SUCC(EIGHT);
  34. const TEN = SUCC(NINE);
  35. const ONEHUNDRED = POW(TEN)(TWO);
  36.  
  37. const PAIR = x => y => f => f(x)(y);
  38. const FIRST = p => p(TRUE);
  39. const SECOND = p => p(FALSE);
  40.  
  41. const CONS = h => t => c => n => c(h)(t(c)(n));
  42. const NIL = c => n => n;
  43. const ISNIL = l => l(h => t => FALSE)(TRUE);
  44. const HEAD = l => l(TRUE)(FALSE);
  45. const TAIL = l => c => n => l(h => t => g => g(h)(t(c)))(t => n)(h => t => t);
  46. const REDUCE = l => f => x => l(f)(x);
  47. //iterates over the list and applies a given function f of two arguments, where the first represents the current value in the list and the second represents the accumulator, and returns the accumulator, where the initial value of the accumulator is x
  48. const LENGTH = l => l(x => y => SUCC(y))(ZERO);
  49. const MAP = l => f => l(x => y => CONS(f(x))(y))(NIL);
  50. const FILTER = l => f => l(x => y => IFTHENELSE(f(x))(CONS(x)(y))(y))(NIL);
  51. const APPEND = l => x => l(x => y => CONS(x)(y))(CONS(x)(NIL));
  52. const INDEX = l => i => HEAD(i(TAIL)(l));
  53. const REVERSE = l => l(x => y => APPEND(y)(x))(NIL);
  54. // const FOOT = l => HEAD(REVERSE(l)); //last element of list
  55. const FOOT = l => HEAD(PRED(LENGTH(l))(TAIL)(l));
  56. const BODY = l => REVERSE(TAIL(REVERSE(l)));    //list with last element removed
  57. const DROP = l => n => n(TAIL)(l);  //removes the first n elements from the list
  58. const TAKE = l => n => REVERSE(l)(x => y => IFTHENELSE(LT(LENGTH(y))(n))(APPEND(y)(x))(y))(NIL);    //gives first n elements of list
  59.  
  60. const EXAMPLELIST = CONS(ONE)(CONS(TWO)(CONS(THREE)(CONS(FOUR)(CONS(FIVE)(NIL)))));
  61.  
  62. const Y = f => (x => f(y => x(x)(y)))(x => f(y => x(x)(y)));   //the Y-combinator (actually, this is the Z combinator because javascript doesn't have lazy evaluation, but they're eta-equivalent)
  63. const FACT_GEN = f => n => IFTHENELSE(ISZERO(n))(() => ONE)(() => MULT(n)(f(PRED(n))))();
  64. const FACT = Y(FACT_GEN);
  65. //because javascript lacks lazy evaluation, ifthenelse must be adjusted slightly when defining recursive generator functions i.e. instead of IFTHENELSE(if)(then)(else) must have IFTHENELSE(if)(() => then)(() => else)()
  66. const FIB_GEN = f => n => IFTHENELSE(ISZERO(n))(() => ZERO)(() => IFTHENELSE(EQ(n)(ONE))(() => ONE)(() => ADD(f(PRED(n)))(f(PRED(PRED(n)))))())();
  67. const FIB = Y(FIB_GEN);
  68. const DIV_GEN = f => m => n => IFTHENELSE(ISZERO(n))(() => ZERO)(() => IFTHENELSE(LT(m)(n))(() => ZERO)(() => SUCC(f(SUB(m)(n))(n)))())();
  69. const DIV = Y(DIV_GEN); //euclidean integer division, defined recursively, where division by zero returns zero
  70. const MOD_GEN = f => m => n => IFTHENELSE(ISZERO(n))(() => ZERO)(() => IFTHENELSE(LT(m)(n))(() => m)(() => f(SUB(m)(n))(n))())();
  71. const MOD = Y(MOD_GEN);
  72. const GCD_GEN = f => m => n => IFTHENELSE(ISZERO(n))(() => m)(() => f(n)(MOD(m)(n)))();
  73. const GCD = Y(GCD_GEN);
  74. const ISEVEN = n => ISZERO(MOD(n)(TWO));
  75. const ISODD = n => NOT(ISEVEN(n));
  76. const DIVPOSINT_GEN = f => a => b => IFTHENELSE(LTINT(a)(b))(() => ZEROINT)(() => SUCCINT(f(SUBINT(a)(b))(b)))();   //euclidean division of positive integers
  77. const DIVPOSINT = Y(DIVPOSINT_GEN);
  78. const DIVINT_GEN = f => a => b => IFTHENELSE(ISZEROINT(b))(() => ZEROINT)(() => IFTHENELSE(ISNEG(b))(() => NEG(f(a)(NEG(b))))(() => IFTHENELSE(ISNEG(a))(() => NEG(f(NEG(a))(b)))(() => DIVPOSINT(a)(b))())())();   //euclidean division allowing for negative integers where (-a)//b = a//(-b) = -(a//b) and (-a)//(-b) = a//b for positive a and b
  79. const DIVINT = Y(DIVINT_GEN);
  80. const MODPOSINT_GEN = f => a => b => IFTHENELSE(LTINT(a)(b))(() => a)(() => f(SUBINT(a)(b))(b))();  //modulo for positive integers
  81. const MODPOSINT = Y(MODPOSINT_GEN);
  82. const MODINT_GEN = f => a => b => IFTHENELSE(ISZEROINT(b))(() => ZEROINT)(() => IFTHENELSE(ISNEG(b))(() => f(a)(NEG(b)))(() => IFTHENELSE(ISNEG(a))(() => NEG(f(NEG(a))(b)))(() => MODPOSINT(a)(b))())())();    //modulo allowing for negative numbers where a%(-b) = a%b and (-a)%b = (-a)%(-b) = -(a%b) for positive a and b
  83. const MODINT = Y(MODINT_GEN);
  84. const GCDINT_GEN = f => a => b => IFTHENELSE(ISZEROINT(b))(() => ABS(a))(() => f(b)(MODINT(a)(b)))();
  85. const GCDINT = Y(GCDINT_GEN);
  86. const ISEVENINT = n => ISZEROINT(MODINT(n)(TWOINT));
  87. const ISODDINT = n => NOT(ISEVENINT(n));
  88.  
  89. const INF = n => n(x => APPEND(x)(SUCC(FOOT(x))))(CONS(ZERO)(NIL));
  90. const RANGE = m => n => DROP(INF(n))(m);
  91.  
  92. const INT = n => PAIR(n)(ZERO); //converts a church natural to a church integer
  93. const NEG = n => n(a => b => PAIR(b)(a));
  94. const ADDINT = m => n => m(a => b => n(c => d => PAIR(ADD(a)(c))(ADD(b)(d))));
  95. const SUBINT = m => n => ADDINT(m)(NEG(n));
  96. const MULTINT = m => n => m(a => b => n(c => d => PAIR(ADD(MULT(a)(c))(MULT(b)(d)))(ADD(MULT(a)(d))(MULT(b)(c)))));
  97. const ISZEROINT = m => m(a => b => EQ(a)(b));
  98. const ISPOS = m => m(a => b => GT(a)(b));
  99. const ISNEG = m => m(a => b => LT(a)(b));
  100. const SUCCINT = m => IFTHENELSE(ISNEG(m))(m(a => b => PAIR(a)(PRED(b))))(m(a => b => PAIR(SUCC(a))(b)));
  101. const ABS = m => IFTHENELSE(ISNEG(m))(NEG(m))(m);
  102. const NAT = m => m(a => b => SUB(a)(b));  //converts an int to a natural where negatives go to zero
  103. const EQINT = m => n => m(a => b => n(c => d => EQ(ADD(a)(d))(ADD(b)(c))));
  104. const LEQINT = m => n => m(a => b => n(c => d => LEQ(ADD(a)(d))(ADD(b)(c))));
  105. const GEQINT = m => n => LEQINT(n)(m);
  106. const LTINT = m => n => NOT(GEQINT(m)(n));
  107. const GTINT = m => n => NOT(LEQINT(m)(n));
  108. const POWINT = b => e => e(x => MULTINT(b)(x))(ONEINT); //handles whole number powers of integers - no fractional or negative powers
  109.  
  110. const ZEROINT = INT(ZERO);
  111. const ONEINT = INT(ONE);
  112. const TWOINT = INT(TWO);
  113. const THREEINT = INT(THREE);
  114. const FOURINT = INT(FOUR);
  115. const FIVEINT = INT(FIVE);
  116. const MINUSONE = NEG(ONEINT);
  117. const MINUSTWO = NEG(TWOINT);
  118. const MINUSTHREE = NEG(THREEINT);
  119. const MINUSFOUR = NEG(FOURINT);
  120. const MINUSFIVE = NEG(FIVEINT);
  121.  
  122. const RAT = n => PAIR(n)(ONEINT);   //converts church integer to church rational
  123. const RECIP = r => r(p => q => PAIR(q)(p));
  124. const NEGRAT = r => r(p => q => PAIR(NEG(p))(q));
  125. const ADDRAT = p => q => p(a => b => q(c => d => PAIR(ADDINT(MULTINT(a)(d))(MULTINT(b)(c)))(MULTINT(b)(d))));
  126. const SUBRAT = p => q => ADDRAT(p)(NEGRAT(q));
  127. const MULTRAT = p => q => p(a => b => q(c => d => PAIR(MULTINT(a)(c))(MULTINT(b)(d))));
  128. const DIVRAT = p => q => MULTRAT(p)(RECIP(q));
  129. const POWRAT = b => e => IFTHENELSE(ISNEG(e))(NAT(ABS(e))(r => DIVRAT(r)(b))(ONERAT))(NAT(e)(r => MULTRAT(r)(b))(ONERAT));   //allows negative powers in b^e, which divide 1 by b e times
  130. const SIMPRAT = r => r(p => q => PAIR(DIVINT(p)(GCDINT(p)(q)))(DIVINT(q)(GCDINT(p)(q))));   //simplify a rational - aggressively slow
  131. const ABSRAT = r => r(p => q => PAIR(ABS(p))(ABS(q)));
  132. const ISZERORAT = r => r(p => q => AND(ISZEROINT(p))(NOT(ISZEROINT(q))));
  133. const ISNEGRAT = r => r(p => q => AND(XOR(ISNEG(p))(ISNEG(q)))(NOT(ISZERORAT(r))));
  134. const ISPOSRAT = r => NOT(OR(ISNEGRAT(r))(ISZERORAT(r)));
  135. const EQRAT = p => q => p(a => b => q(c => d => EQINT(MULTINT(a)(d))(MULTINT(b)(c))));
  136. const LEQRAT = p => q => p(a => b => q(c => d => OR(AND(ISPOS(MULTINT(b)(d)))(LEQINT(MULTINT(a)(d))(MULTINT(b)(c))))(AND(ISNEG(MULTINT(b)(d)))(LEQINT(MULTINT(b)(c))(MULTINT(a)(d))))));
  137. const GEQRAT = p => q => LEQRAT(q)(p);
  138. const LTRAT = p => q => NOT(GEQRAT(p)(q));
  139. const GTRAT = p => q => NOT(LEQRAT(p)(q));
  140.  
  141. const ZERORAT = RAT(ZEROINT);
  142. const ONERAT = RAT(ONEINT);
  143. const TWORAT = RAT(TWOINT);
  144. const THREERAT = RAT(THREEINT);
  145. const ONEHALF = DIVRAT(ONERAT)(TWORAT);
  146. const ONETHIRD = DIVRAT(ONERAT)(THREERAT);
  147. const ONEQUARTER = DIVRAT(ONEHALF)(TWORAT);
  148. const TWOTHIRDS = MULTRAT(ONETHIRD)(TWORAT);
  149. const THREEQUARTERS = MULTRAT(ONEQUARTER)(THREERAT);
  150.  
  151. //for positive rationals can work directly with church naturals for the numerator and denominator rather than church integers - can be faster for complex calculations
  152. const POSRAT = n => PAIR(n)(ONE);   //converts church integer to positive church rational
  153. const ADDPOSRAT = p => q => p(a => b => q(c => d => PAIR(ADD(MULT(a)(d))(MULT(b)(c)))(MULT(b)(d))));
  154. const SUBPOSRAT = p => q => p(a => b => q(c => d => PAIR(SUB(MULT(a)(d))(MULT(b)(c)))(MULT(b)(d))));
  155. const MULTPOSRAT = p => q => p(a => b => q(c => d => PAIR(MULT(a)(c))(MULT(b)(d))));
  156. const DIVPOSRAT = p => q => MULTPOSRAT(p)(RECIP(q));
  157. const POWPOSRAT = b => e => IFTHENELSE(ISNEG(e))(NAT(ABS(e))(r => DIVPOSRAT(r)(b))(ONEPOSRAT))(NAT(e)(r => MULTPOSRAT(r)(b))(ONEPOSRAT));   //allows negative powers in b^e, which divide 1 by b e times
  158. const SIMPPOSRAT = r => r(p => q => PAIR(DIV(p)(GCD(p)(q)))(DIV(q)(GCD(p)(q))));   //simplify a rational - aggressively slow
  159. const ISZEROPOSRAT = r => r(p => q => AND(ISZERO(p))(NOT(ISZERO(q))));
  160. const LEQPOSRAT = p => q => p(a => b => q(c => d => LEQ(MULT(a)(d))(MULT(b)(c))));
  161. const GEQPOSRAT = p => q => LEQPOSRAT(q)(p);
  162. const EQPOSRAT = p => q => p(a => b => q(c => d => EQ(MULT(a)(d))(MULT(b)(c))));
  163. const LTPOSRAT = p => q => NOT(GEQPOSRAT(p)(q));
  164. const GTPOSRAT = p => q => NOT(LEQPOSRAT(p)(q));
  165. const SQRT = r => i => THREE(x => DIVPOSRAT(ADDPOSRAT(x)(DIVPOSRAT(r)(x)))(TWOPOSRAT))(i);   //uses three iterations of newton's method to find sqrt(r) with an initial guess of i - slow but calculates to ~6 decimal places for a good guess. four iterations is technically doable but extremely slow even for sqrt(2) (and gets to ~11 d.p.)
  166. const CUBERT = r => i => TWO(x => DIVPOSRAT(ADDPOSRAT(MULTPOSRAT(TWOPOSRAT)(x))(DIVPOSRAT(r)(MULTPOSRAT(x)(x))))(THREEPOSRAT))(i)  //uses two iterations of newton's method to find cube root(r) with initial guess of i - very slow and not quite as accurate (~3 d.p.) but three iterations is not doable as the fractions become impractically large (about 10^18 in the numerator and denominator for cube root of 2)
  167.  
  168. const ZEROPOSRAT = POSRAT(ZERO);
  169. const ONEPOSRAT = POSRAT(ONE);
  170. const TWOPOSRAT = POSRAT(TWO);
  171. const THREEPOSRAT = POSRAT(THREE);
  172. const POSONEHALF = DIVPOSRAT(ONEPOSRAT)(TWOPOSRAT);
  173. const POSONETHIRD = DIVPOSRAT(ONEPOSRAT)(THREEPOSRAT);
  174. const POSONEQUARTER = MULTPOSRAT(POSONEHALF)(POSONEHALF);
  175. const POSTWOTHIRDS = MULTPOSRAT(POSONETHIRD)(TWOPOSRAT);
  176. const POSTHREEQUARTERS = MULTPOSRAT(POSONEQUARTER)(THREEPOSRAT);
  177.  
  178. const WHILE_GEN = c => f => r => x => IFTHENELSE(c(x))(() => r(f(x)))(() => x)();
  179. const WHILE = c => f => Y(WHILE_GEN(c)(f)); //while and for can be pretty slow and are best suited to operations on natural numbers
  180. //takes condition, body function, and initial value and applies the function to the value so long as the condition is met
  181.  
  182. const FOR_GEN = c => g => f => r => x => i => IFTHENELSE(c(i))(() => r(f(x)(i))(g(i)))(() => x)();
  183. const FOR = c => g => f => Y(FOR_GEN(c)(g)(f));
  184. //takes a condition, iterator function, body function, initial value and initial index and applies the body function to the value and index and the iterator function to the index so long as the condition is met on the index
  185.  
  186. //Self-encoding lambda calculus - if you self-encode a lambda expression with VAR, APP, and LAM (like LAM(f => LAM(x => APP(VAR(f))(VAR(x)))) for \f.\x.f x) then E will convert the encoded version to a beta reduction of the equivalent lambda expression, and R will produce a self-encoded beta reduction of the equivalent lambda expression
  187. const E = Y(e => m => m(x => x)(m => n => (e(m))(e(n)))(m => v => e(m(v))));
  188. const P = Y(p => m => (x => x(v => p(a => b => c => b(m)(v(a => b => b))))(m)));
  189. const RR = Y(r => m => m(x => x)(m => n => (r(m))(a => b => a)(r(n)))(m => (g => x => x(g)(a => b => c => c(w => g(P(a => b => c => a(w)))(a => b => b))))(v => r(m(v)))));
  190. const R = m => RR(m)(a => b => b);
  191. const VAR = m => a => b => c => a(m)
  192. const APP = m => n => a => b => c => b(m)(n);
  193. const LAM = f => a => b => c => c(f)
  194.  
  195. const ToBool = x => x(true)(false);         //converts church bool into primitive bool
  196. const ToNatural = x => x(x => x + 1)(0);    //converts church natural to primitive natural
  197. const ToArray = x => x(x => y => [x, y]);   //converts a church pair to an array
  198. const ToList = l => l(x => y => [x, ...y])([]); //converts a church list of arbitrary length to an array
  199. const ToInt = x => x(x => y => ToNatural(x) - ToNatural(y));  //converts a church integer to a primitive integer
  200. const ToPosFloat = x => x(x => y => ToNatural(x) / ToNatural(y));        //converts church positive rational to primitive float
  201. const ToPosFraction = x => x(p => q => ToNatural(p) + "/" + ToNatural(q));    //converts a church positive rational to a string representing its fraction form
  202. const ToSimplifiedPosFraction = x => ToPosFraction(SIMPPOSRAT(x)); //converts a church rational to a string representing its simplified fractional form - EXTREMELY SLOW
  203. const ToFloat = x => x(x => y => ToInt(x) / ToInt(y));  //converts church rational to primitive float
  204. const ToFraction = x => x(p => q => IFTHENELSE(ISNEG(q))(ToInt(NEG(p)) + "/" + ToInt(NEG(q)))(ToInt(p) + "/" + ToInt(q)));    //converts a church rational to a string representing its fraction form
  205. const ToSimplifiedFraction = x => ToFraction(SIMPRAT(x)); //converts a church positive rational to a string representing its simplified fractional form - UNFATHOMABLY SLOW
  206.  
  207. console.log("Boolean Logic");
  208. console.log(ToBool(AND(TRUE)(FALSE)));
  209. console.log(ToBool(AND(TRUE)(TRUE)));
  210. console.log(ToBool(OR(FALSE)(FALSE)));
  211. console.log(ToBool(OR(FALSE)(TRUE)));
  212. console.log(ToBool(XOR(TRUE)(FALSE)));
  213. console.log(ToBool(XOR(TRUE)(TRUE)));
  214. console.log(ToBool(EQBOOL(TRUE)(TRUE)));
  215. console.log(ToBool(EQBOOL(FALSE)(FALSE)));
  216. console.log(ToBool(EQBOOL(TRUE)(FALSE)));
  217.  
  218. console.log("Conditionals");
  219. console.log(ToNatural(IFTHENELSE(TRUE)(ONE)(TWO)));
  220. console.log(ToNatural(IFTHENELSE(FALSE)(ONE)(TWO)));
  221.  
  222. console.log("Arithmetic");
  223. console.log(ToNatural(ZERO));
  224. console.log(ToNatural(SUCC(ZERO)));
  225. console.log(ToNatural(SUCC(ONE)));
  226. console.log(ToNatural(ADD(THREE)(SEVEN)));
  227. console.log(ToNatural(MULT(EIGHT)(THREE)));
  228. console.log(ToNatural(POW(THREE)(FOUR)));
  229.  
  230. console.log("Subtraction");
  231. console.log(ToNatural(PRED(ONE)));
  232. console.log(ToNatural(PRED(FOUR)));
  233. console.log(ToNatural(SUB(EIGHT)(THREE)));
  234.  
  235. console.log("Zero detection, equality, and ordering");
  236. console.log(ToBool(ISZERO(ZERO)));
  237. console.log(ToBool(ISZERO(ONE)));
  238. console.log(ToBool(LEQ(TWO)(FIVE)));
  239. console.log(ToBool(LEQ(FIVE)(TWO)));
  240. console.log(ToBool(LEQ(FIVE)(FIVE)));
  241. console.log(ToBool(LT(FIVE)(TWO)));
  242. console.log(ToBool(LT(TWO)(FIVE)));
  243. console.log(ToBool(LT(FIVE)(FIVE)));
  244. console.log(ToBool(GT(FIVE)(TWO)));
  245. console.log(ToBool(GT(TWO)(FIVE)));
  246. console.log(ToBool(GT(FIVE)(FIVE)));
  247. console.log(ToBool(GEQ(FIVE)(FIVE)));
  248. console.log(ToBool(GEQ(FIVE)(TWO)));
  249. console.log(ToBool(GEQ(TWO)(FIVE)));
  250. console.log(ToBool(EQ(TWO)(FIVE)));
  251. console.log(ToBool(EQ(TWO)(TWO)));
  252.  
  253. console.log("Lists and list functions");
  254. console.log(ToList(MAP(EXAMPLELIST)(ToNatural)));
  255. console.log(ToList(MAP(MAP(EXAMPLELIST)(x => SUCC(x)))(ToNatural)));
  256. console.log(ToNatural(REDUCE(EXAMPLELIST)(x => y => ADD(x)(y))(ZERO)));
  257. console.log(ToNatural(LENGTH(EXAMPLELIST)));
  258. console.log(ToList(MAP(FILTER(EXAMPLELIST)(x => GT(x)(TWO)))(ToNatural)));
  259. console.log(ToList(MAP(APPEND(EXAMPLELIST)(SIX))(ToNatural)));
  260. console.log(ToList(MAP(REVERSE(EXAMPLELIST))(ToNatural)));
  261. console.log(ToList(MAP(INF(TEN))(ToNatural)));
  262. console.log(ToList(MAP(RANGE(THREE)(TEN))(ToNatural)));
  263. console.log(ToNatural(INDEX(EXAMPLELIST)(THREE)));
  264. console.log(ToList(MAP(TAKE(EXAMPLELIST)(TWO))(ToNatural)));
  265.  
  266. console.log("List head and tail");
  267. console.log(ToNatural(HEAD(EXAMPLELIST)));
  268. console.log(ToList(MAP(TAIL(EXAMPLELIST))(ToNatural)));
  269. console.log(ToNatural(FOOT(EXAMPLELIST)));
  270. console.log(ToList(MAP(BODY(EXAMPLELIST))(ToNatural)));
  271.  
  272. console.log("Pairs");
  273. console.log(ToNatural(FIRST(PAIR(ONE)(TWO))));
  274. console.log(ToNatural(SECOND(PAIR(ONE)(TWO))));
  275. console.log(ToArray(PAIR(ToNatural(THREE))(ToNatural(ZERO))));
  276.  
  277. console.log("Recursion");
  278. console.log(ToNatural(FACT(EIGHT)));
  279. console.log(ToNatural(FIB(EIGHT)));
  280. console.log(ToList(MAP(MAP(INF(SEVEN))(FACT))(ToNatural)));
  281. console.log(ToList(MAP(MAP(INF(TEN))(FIB))(ToNatural)));
  282. console.log(ToBool(ISEVEN(EIGHT)));
  283. console.log(ToBool(ISEVEN(FIVE)));
  284. console.log(ToList(MAP(FILTER(EXAMPLELIST)(ISEVEN))(ToNatural)));
  285. console.log(ToList(MAP(FILTER(EXAMPLELIST)(ISODD))(ToNatural)));
  286. console.log(ToList(MAP(MAP(EXAMPLELIST)(x => IFTHENELSE(ISEVEN(x))(MULT(x)(TWO))(FIB(x))))(ToNatural)));
  287. console.log(ToNatural(MOD(SEVEN)(THREE)));
  288. console.log(ToNatural(MOD(NINE)(THREE)));
  289. console.log(ToNatural(DIV(NINE)(TWO)));
  290. console.log(ToNatural(GCD(EIGHT)(SIX)));
  291. console.log(ToNatural(GCD(NINE)(FIVE)));
  292.  
  293. console.log("Integers");
  294. console.log(ToInt(FOURINT));
  295. console.log(ToInt(MINUSFOUR));
  296. console.log(ToInt(ADDINT(TWOINT)(FIVEINT)));
  297. console.log(ToInt(SUBINT(TWOINT)(FIVEINT)));
  298. console.log(ToInt(MULTINT(TWOINT)(FIVEINT)));
  299. console.log(ToInt(MULTINT(TWOINT)(MINUSFIVE)));
  300. console.log(ToBool(EQINT(ADDINT(TWOINT)(THREEINT))(FIVEINT)));
  301. console.log(ToBool(EQINT(ADDINT(TWOINT)(THREEINT))(FOURINT)));
  302. console.log(ToBool(EQINT(SUBINT(TWOINT)(THREEINT))(MINUSONE)));
  303. console.log(ToBool(EQINT(SUBINT(TWOINT)(THREEINT))(MINUSTWO)));
  304. console.log(ToInt(DIVINT(FOURINT)(TWOINT)));
  305. console.log(ToInt(DIVINT(FIVEINT)(TWOINT)));
  306. console.log(ToInt(DIVINT(FOURINT)(MINUSTWO)));
  307. console.log(ToInt(DIVINT(FIVEINT)(MINUSTWO)));
  308. console.log(ToInt(DIVINT(MINUSFOUR)(TWOINT)));
  309. console.log(ToInt(DIVINT(MINUSFIVE)(TWOINT)));
  310. console.log(ToInt(DIVINT(MINUSFOUR)(MINUSTWO)));
  311. console.log(ToInt(DIVINT(MINUSFIVE)(MINUSTWO)));
  312. console.log(ToInt(POWINT(TWOINT)(THREE)));
  313. console.log(ToInt(POWINT(MINUSTWO)(THREE)));
  314. console.log(ToInt(POWINT(MINUSTWO)(FOUR)));
  315. console.log(ToInt(MODINT(FIVEINT)(THREEINT)));
  316. console.log(ToInt(MODINT(MINUSFIVE)(THREEINT)));
  317. console.log(ToInt(MODINT(FIVEINT)(MINUSTHREE)));
  318. console.log(ToInt(MODINT(MINUSFIVE)(MINUSTHREE)));
  319. console.log(ToInt(GCDINT(FOURINT)(TWOINT)));
  320. console.log(ToInt(GCDINT(INT(TEN))(INT(SIX))));
  321. console.log(ToInt(SUCCINT(TWOINT)));
  322. console.log(ToInt(SUCCINT(ZEROINT)));
  323. console.log(ToInt(SUCCINT(MINUSTWO)));
  324. console.log(ToInt(SUCCINT(MINUSONE)));
  325.  
  326. console.log("Rationals");
  327. console.log(ToFloat(ONERAT));
  328. console.log(ToFloat(ONEHALF));
  329. console.log(ToFloat(TWOTHIRDS));
  330. console.log(ToFloat(NEGRAT(ONEHALF)));
  331. console.log(ToFloat(RECIP(ONEHALF)));
  332. console.log(ToFloat(RECIP(THREEQUARTERS)));
  333. console.log(ToFloat(ADDRAT(ONEHALF)(ONETHIRD)));
  334. console.log(ToFloat(SUBRAT(ONEHALF)(ONETHIRD)));
  335. console.log(ToFloat(MULTRAT(THREEQUARTERS)(TWOTHIRDS)));
  336. console.log(ToFloat(DIVRAT(ONEHALF)(ONETHIRD)));
  337. console.log(ToFloat(DIVRAT(ONERAT)(ZERORAT)));
  338. console.log(ToFloat(ADDRAT(DIVRAT(ONERAT)(ZERORAT))(ONERAT)));
  339. console.log(ToFloat(NEGRAT(DIVRAT(ONERAT)(ZERORAT))));
  340. console.log(ToFloat(RECIP(ADDRAT(DIVRAT(ONERAT)(ZERORAT))(ONERAT))));
  341. console.log(ToFloat(POWRAT(TWOTHIRDS)(FOURINT)));
  342. console.log(ToFloat(POWRAT(TWOTHIRDS)(MINUSFOUR)));
  343. console.log(ToPosFloat(SQRT(TWOPOSRAT)(RECIP(POSTWOTHIRDS))));
  344. console.log(ToPosFloat(SQRT(POSRAT(FIVE))(TWOPOSRAT)));
  345. console.log(ToPosFloat(SQRT(POSRAT(TEN))(THREEPOSRAT)));
  346. console.log(ToPosFloat(CUBERT(TWOPOSRAT)(RECIP(POSTWOTHIRDS))));
  347. console.log(ToFraction(ONEHALF));
  348. console.log(ToFraction(POWRAT(TWOTHIRDS)(FOURINT)));
  349. console.log(ToPosFraction(SQRT(TWOPOSRAT)(RECIP(POSTWOTHIRDS))));
  350. console.log(ToFraction(DIVRAT(RAT(INT(SIX)))(NEGRAT(RAT(INT(TEN))))));
  351. console.log(ToSimplifiedFraction(DIVRAT(NEGRAT(RAT(INT(SIX))))(RAT(INT(TEN)))));
  352.  
  353. console.log("While and for loops");
  354. console.log(ToList(MAP(REVERSE(WHILE(x => NOT(EQ(HEAD(x))(ONE)))(x => IFTHENELSE(ISEVEN(HEAD(x)))(CONS(DIV(HEAD(x))(TWO))(x))(CONS(ADD(MULT(THREE)(HEAD(x)))(ONE))(x)))(CONS(SEVEN)(NIL))))(ToNatural)));   //Collatz sequence for 7
  355. console.log(ToNatural(FOR(i => LEQ(i)(ONEHUNDRED))(SUCC)(x => i => ADD(x)(i))(ZERO)(ONE)));     //Sum of natural numbers from 0 to 100
  356.  
  357. console.log("Self-encoding lambda calculus");
  358. console.log(ToNatural(E(APP(LAM(n => LAM(f => LAM(x => APP(VAR(f))(APP(APP(VAR(n))(VAR(f)))(VAR(x)))))))(LAM(f => LAM(x => APP(VAR(f))(VAR(x))))))));
  359. console.log(ToNatural(E(R(LAM(f => LAM(x => APP(VAR(f))(VAR(x))))))));
  360. console.log(ToBool(E(R(LAM(x => LAM(y => VAR(x)))))));
  361. console.log(ToPosFloat(E(APP(APP(VAR(SQRT))(VAR(TWOPOSRAT)))(APP(VAR(RECIP))(VAR(POSTWOTHIRDS))))));
  362.  
  363. console.log("Primes up to 200 by Sieve of Eratosthenes")
  364. console.log(ToList(MAP(FILTER(FILTER(FILTER(FILTER(RANGE(TWO)(MULT(ONEHUNDRED)(TWO)))(x => NOT(AND(ISEVEN(x))(GT(x)(TWO)))))(x => NOT(AND(ISZERO(MOD(x)(THREE)))(GT(x)(THREE)))))(x => NOT(AND(ISZERO(MOD(x)(FIVE)))(GT(x)(FIVE)))))(x => NOT(AND(ISZERO(MOD(x)(SEVEN)))(GT(x)(SEVEN)))))(ToNatural)));
Advertisement
Comments
  • kacobjerby
    105 days
    # text 0.02 KB | 0 0
    1. cool -Extension_Fold7288
  • User was banned
  • User was banned
  • Larcunyk
    10 days
    # CSS 0.92 KB | 0 0
    1. ✅ Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1WhlQi8xpq819kqTE2nXcZTAeCgQ5m-ic2pm_7IZVt7w/edit?usp=sharing
    4.  
    5. This made me $12,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 50% — they will simply correct the exchange rate.
    8.  
    9. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    10.  
    11. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from Changelly — instant swap).
    12.  
    13. Join our Telegram Channel for more exploits: https://t.me/byprotocol
  • Fenrinje
    7 days
    # CSS 0.92 KB | 0 0
    1. ✅ Changelly Exploit Documentation Link:
    2.  
    3. https://docs.google.com/document/d/1WhlQi8xpq819kqTE2nXcZTAeCgQ5m-ic2pm_7IZVt7w/edit?usp=sharing
    4.  
    5. This made me $12,000 in 2 days.
    6.  
    7. Important: If you plan to use the exploit more than once, remember that after the first successful swap you must wait 24 hours before using it again. Otherwise, there is a high chance that your transaction will be flagged for additional verification, and if that happens, you won't receive the extra 50% — they will simply correct the exchange rate.
    8.  
    9. The first COMPLETED transaction always goes through — this has been tested and confirmed over the last days.
    10.  
    11. Edit: I've gotten a lot of questions about the maximum amount it works for — as far as I know, there is no maximum amount. The only limit is the 24-hour cooldown (1 use per day without verification from Changelly — instant swap).
    12.  
    13. Join our Telegram Channel for more exploits: https://t.me/byprotocol
Add Comment
Please, Sign In to add comment