codereport / jello

A Python script for wrapping Jellyfish (a fork of Jelly) so you can more easily play with the language.
MIT License
48 stars 4 forks source link

BUG: 1-2-2 dyadic chain #14

Closed tom-huntington closed 4 months ago

tom-huntington commented 5 months ago

I was expecting Φ₁ (or some specialization fn (f,g,h) = x,y -> g(f(x),h(x,y)))

> 1 2 :: add1 * l
          ‘   × ḷ
   ‘   1 2 ➡️  2
   ‘×  1 2 ➡️  4
   ‘×ḷ 1 2 ➡️  2
    This is a 1-2-2 dyadic chain (ΔΔ)
              └┬┘ ⋮
               Δ  ⋮
               └┬─┘
                Δ

Anyway thanks!

tom-huntington commented 5 months ago

I guess there are no 2y122 combinators.

You can get around this by explicitly adding a l

> 1 2 :: l add1 * r
         ḷ  ‘   × ṛ
   ḷ    1 2 ➡️  1
   ḷ‘   1 2 ➡️  2
   ḷ‘×  1 2 ➡️  4
   ḷ‘×ṛ 1 2 ➡️  4
    This is a 2-1-2-2 dyadic chain (B₁Φ₁)
              └┬┘   ⋮
              B₁    ⋮
               └─┬──┘
                Φ₁
codereport commented 4 months ago

Yea, what you did with the l and r is probably the best way to do that.

tom-huntington commented 4 months ago

@codereport sorry for the confusion.

I mean the combinator tree is wrong: ΔΔ is wrong

    This is a 1-2-2 dyadic chain (ΔΔ)
              └┬┘ ⋮
               Δ  ⋮
               └┬─┘
                Δ

Jelly is actually creating combinators that have no name. There is no spelling for the combinator representing the 1-2-2 dyadic chain.

fn Φ₁(f,g,h) = x,y -> g(f(x,y),h(x,y))
fn ??(f,g,h) = x,y -> g(f(x),h(x,y)

As I said it's easy to get a correct combinator tree because you can just rewrite with phi1 and C (i.e. Φ₁ and l).

pepe silvia You can get the combinator tree right, always using `l` or `r` explicitly before accessing the original arguments with a monadic function i.e. make the leaves be dyadic for dyadic chains. This is like a more regular subset of Jelly, that would make the rules less confusing. (You could also always use `id` on monadic chains when accessing the initial argument) ``` This is a 2-1-2-2 dyadic chain (B₁Φ₁) └┬┘ ⋮ B₁ ⋮ └─┬──┘ Φ₁ ``` I found this problem when trying to solve a problem with a large confusing combinator tree. This was just the minimal reproducible example. <\details>
codereport commented 4 months ago

Ah I see, ok - I will take a look at this :+1:

codereport commented 4 months ago

If we look at the possible 2y122 / 2y221 combinators (which are specializations of Φ₁), we get:

g(f(x),h(x,y))  -- Φ.₂
g(f(y),h(x,y))  -- Φ.₄
g(f(x,y),h(x))  -- Φ.₆
g(f(x,y),h(y))  -- Φ.₈

So we will call this the Φ.₂ combinator. I have added it to Jello and now you get:

image