packages feed

phino-0.0.156: test-resources/evaluate-packs/upcasts-a-cut-branch-to-the-tuple-an-unfolded-branch-was-reminted-into.yaml

# SPDX-FileCopyrightText: Copyright (c) 2025 Objectionary.com
# SPDX-License-Identifier: MIT
---
# yamllint disable rule:line-length
# The fork of 'bytes.array' from #1921, spelled as a pipeline. The left branch
# 'Ξ¦.rec( ΞΎ.n )' leads back to the same fork, so its 'unfold' line, which says
# 'defer: true', has '--acyclic=proven' cut the firing and answers the copy
# with the looped bare symbol '𝜎3'. The right branch is the 'with' object of
# a tuple, whose Ο† builds a copy of 'Ξ¦.tuple' with three arguments; its
# 'unfold' line morphs that Ο† into the real tuple. The 'rewrite' line then
# shrinks the tuple into a call of 'Ξ¦.tuple' with every argument reminted:
# the tail 'Φ.items' as a deferred copy, the head as the symbol '𝜎2' it ends
# in and the length as the symbol the firing of 'L_plus' answers (#1923);
# 'stay' and 'symbolize' see the unfolded term, the two lines of the 'upcast'
# block take the two terms as one pair and cast the smaller, the bare symbol,
# into the shape of the larger by the paths 'tail', 'head' and 'length', and
# the 'join' line pairs the two metas the block wrote symbol by symbol. The
# program reads 'length' off the answer.
symbolic: |
  - Ξ»: L_fork
    morph:
      𝑛1: $.a
      𝑛2: $.b
    unfold:
      𝑛3: {of: 𝑛1, defer: true}
      𝑛4: {of: 𝑛2, defer: true}
    rewrite:
      𝑛5:
        of: 𝑛3
        rules: &shape
          - name: shrunk
            pattern: ⟦ tail ↦ 𝑒1, head ↦ 𝑒2, length ↦ 𝑒3, !B ⟧
            result: Ξ¦.tuple( tail ↦ 𝑒4, head ↦ 𝑒5, length ↦ 𝑒6 )
            where:
              - meta: 𝑒4
                function: remint
                args: [𝑒1]
              - meta: 𝑒5
                function: remint
                args: [𝑒2]
              - meta: 𝑒6
                function: remint
                args: [𝑒3]
      𝑛6:
        of: 𝑛4
        rules: *shape
    stay:
      𝑛7: 𝑛5
      𝑛8: 𝑛6
    symbolize:
      𝑛9: 𝑛7
      𝑛10: 𝑛8
    upcast:
      𝑛11: 𝑛9
      𝑛12: 𝑛10
    join:
      𝑛13: [𝑛11, 𝑛12]
    𝑛: ⟦ Ο† ↦ 𝑛13 ⟧
  - Ξ»: L_plus
    𝑛: Ξ¦.number( Ο† ↦ ⟦ Ξ» ‍ 𝜎 ⟧ )
location: 'Q.y'
acyclic: proven
input: |
  ⟦
    fork(a, b) ↦ ⟦ Ξ» ‍ L_fork ⟧,
    tuple(tail, head, length) ↦ ⟦⟧,
    number(Ο†) ↦ ⟦ plus(x) ↦ ⟦ Ξ» ‍ L_plus ⟧ ⟧,
    items ↦ ⟦
      length ↦ Ξ¦.number( ⟦ Ξ» ‍ 𝜎1 ⟧ ),
      with(ρ, x) ↦ ⟦ Ο† ↦ Ξ¦.tuple( tail ↦ ΞΎ.ρ, head ↦ ΞΎ.x, length ↦ ΞΎ.ρ.length.plus( 1 ) ) ⟧
    ⟧,
    rec(n) ↦ ⟦ Ο† ↦ Ξ¦.fork( Ξ¦.rec( ΞΎ.n ), Ξ¦.items.with( ΞΎ.n ) ) ⟧,
    y ↦ Ξ¦.rec( ⟦ Ο† ↦ ⟦ Ξ» ‍ 𝜎2 ⟧ ⟧ ).Ο†.Ο†.length
  ⟧
result: '𝜎11:λ'
protocol: |
  𝕄(Ξ¦.y):
    𝑛·0Β·1 := Ξ¦.rec( n ↦ 𝜎2:Ξ»:Ο† )
    𝑛·0Β·2 := Ξ¦.fork( a ↦ Ξ¦.rec( 𝜎2:Ξ»:Ο† ) )
    𝑛·0Β·3 := 𝑛·0Β·2( b ↦ Ξ¦.items.with( 𝜎2:Ξ»:Ο† ) )
    𝔼(L_fork):
      𝕄(Ξ¦.a🌡0):
        𝑛·1Β·1 := Ξ¦.rec( n ↦ 𝜎2:Ξ»:Ο† )
      𝑛1Β·1 := 𝑛·1Β·1  # 𝕄(ΞΎ.a)
      𝕄(Ξ¦.a🌡1):
        𝑛·1Β·2 := Ξ¦.items.with( x ↦ 𝜎2:Ξ»:Ο† )
      𝑛2Β·1 := 𝑛·1Β·2  # 𝕄(ΞΎ.b)
      𝕄(Ξ¦.a🌡2):
        𝑛·1Β·3 := Ξ¦.fork( a ↦ Ξ¦.rec( 𝜎2:Ξ»:Ο† ) )
        𝑛·1Β·4 := 𝑛·1Β·3( b ↦ Ξ¦.items.with( 𝜎2:Ξ»:Ο† ) )
      𝑛3Β·1 := 𝑛·1Β·4  # 𝕄(𝑛1.Ο†)
      looped(𝑛·1Β·4) := 𝜎3  # 𝔼(𝑛1), proven
      𝑛3Β·1 := 𝜎3:Ξ»  # 𝔼(𝑛1)
      𝕄(Ξ¦.a🌡3):
        𝑛·1Β·5 := Ξ¦.tuple( tail ↦ Ξ¦.items )
        𝑛·1Β·6 := 𝑛·1Β·5( head ↦ 𝜎2:Ξ»:Ο† )
        𝑛·1Β·7 := 𝑛·1Β·6( length ↦ Ξ¦.items.length.plus( 1 ) )
      𝑛4Β·1 := 𝑛·1Β·7  # 𝕄(𝑛2.Ο†)
      𝑛4Β·1 := 𝑛·1Β·7  # 𝔼(𝑛2)
      𝑛5Β·1 := 𝑛3Β·1  # 𝑛3
      deferred(𝜎4) := Ξ¦.items  # 𝕄(Ξ¦.items)
      𝕄(Ξ¦.items.length.plus( 1 )):
        𝑛·1Β·8 := Ξ¦.number( Ο† ↦ 𝜎1:Ξ» )
        𝑛·1Β·9 := ⟦ x ↦ βˆ…, Ξ» ‍ L_plus ⟧( x ↦ 1 )
      𝔼(L_plus):  # 𝔼(Ξ¦.items.length.plus( 1 ))
        𝑛·2Β·1 := Ξ¦.number( Ο† ↦ 𝜎5:Ξ» )  # 𝑛
        𝕄(𝑛·2Β·1):
          𝑛·2Β·2 := Ξ¦.number( Ο† ↦ 𝜎5:Ξ» )
        𝑛·2Β·3 := 𝑛·2Β·2  # 𝕄(𝑛·2Β·1)
      𝑛6Β·1 := Ξ¦.tuple( tail ↦ 𝜎4:Ξ», head ↦ 𝜎2:Ξ», length ↦ 𝜎5:Ξ» )  # 𝑛4
      𝑛7Β·1 := 𝑛5Β·1  # 𝑛5
      𝑛8Β·1 := Ξ¦.tuple( tail ↦ 𝜎4:Ξ», head ↦ 𝜎2:Ξ», length ↦ 𝜎5:Ξ» )  # 𝑛6
      𝑛9Β·1 := 𝑛7Β·1  # 𝑛7
      𝑛10Β·1 := Ξ¦.tuple( tail ↦ 𝜎4:Ξ», head ↦ 𝜎2:Ξ», length ↦ 𝜎5:Ξ» )  # 𝑛8
      upcast(𝜎3) := Ξ¦.tuple( tail ↦ 𝜎6:Ξ», head ↦ 𝜎7:Ξ», length ↦ 𝜎8:Ξ» )
        𝜎6 := 𝜎3.tail
        𝜎7 := 𝜎3.head
        𝜎8 := 𝜎3.length
      𝑛11Β·1 := Ξ¦.tuple( tail ↦ 𝜎6:Ξ», head ↦ 𝜎7:Ξ», length ↦ 𝜎8:Ξ» )  # 𝑛9
      𝑛12Β·1 := Ξ¦.tuple( tail ↦ 𝜎4:Ξ», head ↦ 𝜎2:Ξ», length ↦ 𝜎5:Ξ» )  # 𝑛10
      𝔻(𝜎9:Ξ») ∈ { 𝔻(𝜎6:Ξ»), 𝔻(𝜎4:Ξ») }
      𝔻(𝜎10:Ξ») ∈ { 𝔻(𝜎7:Ξ»), 𝔻(𝜎2:Ξ») }
      𝔻(𝜎11:Ξ») ∈ { 𝔻(𝜎8:Ξ»), 𝔻(𝜎5:Ξ») }
      𝑛13Β·1 := Ξ¦.tuple( tail ↦ 𝜎9:Ξ», head ↦ 𝜎10:Ξ», length ↦ 𝜎11:Ξ» )  # [𝑛11, 𝑛12]
      𝑛·1Β·10 := Ξ¦.tuple( tail ↦ 𝜎9:Ξ», head ↦ 𝜎10:Ξ», length ↦ 𝜎11:Ξ» ):Ο†  # 𝑛
      𝑛·1Β·11 := Ξ¦.tuple( tail ↦ 𝜎9:Ξ», head ↦ 𝜎10:Ξ», length ↦ 𝜎11:Ξ» ):Ο†  # 𝕄(𝑛·1Β·10)
    𝑛·0Β·4 := Ξ¦.tuple( tail ↦ 𝜎9:Ξ» )
    𝑛·0Β·5 := 𝑛·0Β·4( head ↦ 𝜎10:Ξ» )
    𝑛·0Β·6 := 𝑛·0Β·5( length ↦ 𝜎11:Ξ» )