<commit_before>SKI via Iota
~~
' Note: The first LambAda lessons might be useful to understand
' the behavior and syntax available in this playground.
'
' Iota is defined as \x x S K and is available as "u" in LambAda.
' We can hence reconstruct S, K and I:

i = u u       ' = \x x
k = u (u i)   ' = \a \b a
s = u k       ' = \a \b \c a c (b c)

' Let's put them to the test:
s k i "Hello World"

~~~
BCMY via SKI
~~
b = s (k s) k                       ' = \a \b \c a (b c)
c = s (s (k s) (s (k k) s)) (k k)   ' = \a \b \c a c b
m = s i i                           ' = \x x x
y = b m (c b (s i i))               ' = \f m (\x f (x x))

' Let's put them to the test:
c b k y "Hello World"

~~~
Booleans
~~
' Constructors
true = k    ' = \a \b a
false = k i ' = \a \b b

' Helpers
if = i
not = c (c i false) true   ' = \b b false true
and = c c false            ' = \a \b a b False
or = c i true              ' = \a \b a True b
implies = c c true         ' = \a \b a b True
xor = c (b s (c b not)) i  ' = \a \b a (not b) b
eq = b (b not) xor         ' = \a \b not $ xor a b

' Let's put them to the test (using predefined helpers):
allTrue = all i
allFalse = all not
strConss [
    if (allTrue [
        true,
        not false,
        and true true,
        or true true,
        or true false,
        or false true,
        implies false false,
        implies false true,
        implies true true,
        xor false true,
        xor true false,
        eq false false,
        eq true true
    ]) "expected" "unexpected",
    newLine,
    if (allFalse [
        false,
        not true,
        and false false,
        and false true,
        and true false,
        or false false,
        implies true false,
        xor false false,
        xor true true,
        eq false true,
        eq true false
    ]) "expected" "unexpected"
  ]



~~~
Natural Numbers (Church)
~~
' Constructors
zero = k i   ' = \f \x x
succ = s b   ' = \n \f \x f (n f x)

' Helpers
pred = c (b c (b (b c) (c (b c (b (b b) (c b (b (b (c i)) (c i))))) k))) i  ' = \n \f \x n (\g \h h (g f)) (k x) i
add = b s (b b)                                                             ' = \m \n \f \x m f (n f x)
mul = b                                                                     ' = \m \n \f \x m (n f) x
pow = c i                                                                   ' = \m \n n m

one = succ zero
two = succ one
three = add two one
four = mul two two
five = pred (mul two three)
six = mul two three
seven = pred (pow two three)
eight = pow two three
nine = pow three two

' Test by converting to predefined natural numbers
print = \n strFromN $ n Succ Zero
strJoin (map print [
    zero, one, two, three, four,
    five, six, seven, eight, nine
  ])
  newLine


~~~
Natural Numbers (Scott)
~~
' Constructors
zero = k          ' = \a \b a
succ = b k (c i)  ' = \n \a \b b n

pred = c (c i zero) i  ' = \n n zero i
mul = \n \m m Zero (\dm add n (mul n dm))

add = \a \b b a (\n add (succ n) n) ' \a \b b a (\n add (succ n) n)

' Let's put them to the test (using predefined helpers):
allTrue = all i
allFalse = all not
strConss [
    if (allTrue [
        true,
        not false,
        and true true,
        or true true,
        or true false,
        or false true,
        implies false false,
        implies false true,
        implies true true,
        xor false true,
        xor true false,
        eq false false,
        eq true true
    ]) "expected" "unexpected",
    newLine,
    if (allFalse [
        false,
        not true,
        and false false,
        and false true,
        and true false,
        or false false,
        implies true false,
        xor false false,
        xor true true,
        eq false true,
        eq true false
    ]) "expected" "unexpected"
  ]
<commit_msg>lessons<commit_after>SKI via Iota
~~
' Note: The first LambAda lessons might be useful to understand
' the behavior and syntax available in this playground.
'
' Iota is defined as \x x S K and is available as "u" in LambAda.
' We can hence reconstruct S, K and I:

i = u u       ' = \x x
k = u (u i)   ' = \a \b a
s = u k       ' = \a \b \c a c (b c)

' Let's put them to the test:
s k i "Hello World"

~~~
BCMY via SKI
~~
b = s (k s) k                       ' = \a \b \c a (b c)
c = s (s (k s) (s (k k) s)) (k k)   ' = \a \b \c a c b
m = s i i                           ' = \x x x
y = b m (c b (s i i))               ' = \f m (\x f (x x))

' Let's put them to the test:
c b k y "Hello World"

~~~
Booleans
~~
' Constructors
true = k    ' = \a \b a
false = k i ' = \a \b b

' Helpers
if = i
not = c (c i false) true   ' = \b b false true
and = c c false            ' = \a \b a b False
or = c i true              ' = \a \b a True b
implies = c c true         ' = \a \b a b True
xor = c (b s (c b not)) i  ' = \a \b a (not b) b
eq = b (b not) xor         ' = \a \b not $ xor a b

' Let's put them to the test (using predefined helpers):
allTrue = all i
allFalse = all not
strConss [
    if (allTrue [
        true,
        not false,
        and true true,
        or true true,
        or true false,
        or false true,
        implies false false,
        implies false true,
        implies true true,
        xor false true,
        xor true false,
        eq false false,
        eq true true
    ]) "expected" "unexpected",
    newLine,
    if (allFalse [
        false,
        not true,
        and false false,
        and false true,
        and true false,
        or false false,
        implies true false,
        xor false false,
        xor true true,
        eq false true,
        eq true false
    ]) "expected" "unexpected"
  ]



~~~
Natural Numbers (Church)
~~
' Constructors
zero = k i   ' = \f \x x
succ = s b   ' = \n \f \x f (n f x)

' Helpers
pred = c (b c (b (b c) (c (b c (b (b b) (c b (b (b (c i)) (c i))))) k))) i  ' = \n \f \x n (\g \h h (g f)) (k x) i
add = b s (b b)                                                             ' = \m \n \f \x m f (n f x)
mul = b                                                                     ' = \m \n \f \x m (n f) x
pow = c i                                                                   ' = \m \n n m

one = succ zero
two = succ one
three = add two one
four = mul two two
five = pred (mul two three)
six = mul two three
seven = pred (pow two three)
eight = pow two three
nine = pow three two

' Test by converting to predefined natural numbers
print = \n strFromN $ n Succ Zero
strConss (map print [
    zero, one, two, three, four,
    five, six, seven, eight, nine
  ])


~~~
Natural Numbers (Scott)
~~
' Constructors
zero = k          ' = \a \b a
succ = b k (c i)  ' = \n \a \b b n

' Helpers
pred = c (c i zero) i                             ' = \n n zero i
add = s (b c (c i)) (b add succ)                  ' = \n \m m n (\dm add (succ n) dm)
mul = b (c (c i zero)) (s (b b add) mul)          ' = \n \m m zero (\dm add n (mul n dm))
pow = b (c (c i (succ zero))) (s (b b mul) pow)   ' = \n \m m (succ zero) (\dm mul n (pow n dm))

one = succ zero
two = succ one
three = add two one
four = mul two two
five = pred (mul two three)
six = mul two three
seven = pred (pow two three)
eight = pow two three
nine = pow three two

' Test by converting to predefined natural numbers
print = strFromN    ' strFromN expects Scott-encoded numbers already
strConss (map print [
    zero, one, two, three, four,
    five, six, seven, eight, nine
  ])

{'fraction_non_alphanumeric': 0.1141472607349576, 'fraction_numerical': 0.0, 'mean_word_length': 1.4186197916666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1519706', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2534, 'n_words': 1224}