Skip to content

Commit f63c899

Browse files
claudehyperpolymath
authored andcommitted
proof(solo-core/idris): boundary splitters + var arithmetic (slice A3, toward #108)
Completes the substitution accounting algebra, all green under %default total: - usplit3 USnoc-boundary usage split by length (drops unused ulen-dg conjunct vs Coq usplit3) - uaddSplitBoundary2 USnoc-headed boundary sum split (heads add: q=q1+q2) - substVarSucc deeper-index subst commutes with one weakening shift (GT case needs minusZeroRight to bridge the stuck minus) Mirrors Coq usplit3 / uadd_split_boundary2 / subst_var_succ. With A1+A2+A3 the full accounting layer beneath hvSubst/htSubst is done. Refs #108
1 parent f90f2a6 commit f63c899

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

proofs/verification/idris/solo-core/Substitution.idr

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,3 +620,61 @@ substReassocMult dg1 dgr1 dg2 dgr2 dg du q1 q2 h1 h2 h3 =
620620
let (dgr ** (ha, hb)) = substReassocAdd dg1 dgr1 dg2 dgr2 dg du One q1 q2 h1 h2
621621
(rewrite uscaleOne dg2 in h3)
622622
in (dgr ** (rewrite sym (qMulOneL q2) in ha, rewrite sym (uscaleOne dgr2) in hb))
623+
624+
------------------------------------------------------------
625+
-- 4c (cont). USnoc-headed boundary splitters + var arithmetic
626+
------------------------------------------------------------
627+
628+
eqNotGT : (Prelude.EQ = Prelude.GT) -> Void
629+
eqNotGT Refl impossible
630+
631+
ltNotGT : (Prelude.LT = Prelude.GT) -> Void
632+
ltNotGT Refl impossible
633+
634+
lteFromEq : (d : Uvec) -> (k, m : Nat) -> ulen d = S k + m -> LTE m (ulen d)
635+
lteFromEq d k m hl =
636+
rewrite hl in lteSuccRight (rewrite plusCommutative k m in lteAddRight m)
637+
638+
||| Split a usage whose length puts the substituted variable at the `USnoc`
639+
||| boundary: `ulen d = S k + m` factors `d = uappend (USnoc dg q) di` with the
640+
||| top `m` entries in `di`. (Mirrors Coq `usplit3`; the `ulen dg = k` conjunct
641+
||| is unused downstream and dropped.)
642+
public export
643+
usplit3 : (d : Uvec) -> (k, m : Nat) -> ulen d = S k + m
644+
-> (dg : Uvec ** q : Q ** di : Uvec ** (d = uappend (USnoc dg q) di, ulen di = m))
645+
usplit3 d k m hl with (uappendSplit m d (lteFromEq d k m hl))
646+
_ | (UEmpty ** di ** (heq, hldi)) =
647+
void (sNotZ' (plusRightCancel (S k) Z m
648+
(trans (sym hl)
649+
(trans (cong ulen heq) (trans (uappendLen UEmpty di) hldi)))))
650+
_ | (USnoc dg q ** di ** (heq, hldi)) = (dg ** q ** di ** (heq, hldi))
651+
652+
||| USnoc-headed boundary split of a sum: the heads add (`q = q1 + q2`), the
653+
||| G-parts add, the I-parts add. (Mirrors Coq `uadd_split_boundary2`.)
654+
public export
655+
uaddSplitBoundary2 : (dg1 : Uvec) -> (q1 : Q) -> (di1 : Uvec)
656+
-> (dg2 : Uvec) -> (q2 : Q) -> (di2 : Uvec)
657+
-> (dg : Uvec) -> (q : Q) -> (di : Uvec)
658+
-> ulen di1 = ulen di2 -> ulen di = ulen di1
659+
-> uadd (uappend (USnoc dg1 q1) di1) (uappend (USnoc dg2 q2) di2)
660+
= Just (uappend (USnoc dg q) di)
661+
-> (uadd dg1 dg2 = Just dg, q = qAdd q1 q2, uadd di1 di2 = Just di)
662+
uaddSplitBoundary2 dg1 q1 di1 dg2 q2 di2 dg q di h12 hd heq =
663+
let (hhead, htail) = uaddSplitBoundary (USnoc dg1 q1) di1 (USnoc dg2 q2) di2 (USnoc dg q) di
664+
h12 hd heq
665+
(dd ** (hadd, heqd)) = uaddSnocSplit dg1 dg2 q1 q2 (USnoc dg q) hhead
666+
(hdg, hq) = usnocInj heqd
667+
in (rewrite hdg in hadd, hq, htail)
668+
669+
||| Substituting at a deeper index commutes with one extra weakening shift
670+
||| (mirrors Coq `subst_var_succ`); the engine behind `hvSubst`'s `HVThere` step.
671+
public export
672+
substVarSucc : (k : Nat) -> (u : Tm) -> (n : Nat)
673+
-> substAt (S k) (shiftn (S k) u) (Var (S n))
674+
= shift 0 (substAt k (shiftn k u) (Var n))
675+
substVarSucc k u n with (compare n k) proof eq
676+
substVarSucc k u n | LT = sym (shiftVarLemma 0 n)
677+
substVarSucc k u n | EQ = Refl
678+
substVarSucc Z u Z | GT = void (eqNotGT eq)
679+
substVarSucc (S j) u Z | GT = void (ltNotGT eq)
680+
substVarSucc k u (S n0) | GT = rewrite minusZeroRight n0 in sym (shiftVarLemma 0 n0)

0 commit comments

Comments
 (0)