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:Ξ» )