aboutsummaryrefslogtreecommitdiff
path: root/Functor/Monoidal/Instance/Nat/Push.agda
blob: 2ccfc27dfb445ba2aa07bef0123b8d7f12471953 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
{-# OPTIONS --without-K --safe #-}

module Functor.Monoidal.Instance.Nat.Push where

open import Categories.Category.Instance.Nat using (Nat)
open import Data.Bool.Base using (Bool; false)
open import Data.Subset.Functional using (Subset; ⁅_⁆; )
open import Function.Base using (_∘_; case_of_; _$_; id)
open import Function.Bundles using (Func; _⟶ₛ_; _⟨$⟩_)
open import Level using (0ℓ; Level)
open import Relation.Binary using (Rel; Setoid)
open import Functor.Instance.Nat.Push using (Values; Push; Push₁; Push-identity)
open import Categories.Category.Instance.SingletonSet using (SingletonSetoid)
open import Categories.NaturalTransformation using (NaturalTransformation; ntHelper)
open import Data.Vec.Functional using (Vector; []; _++_; head; tail)
open import Data.Vec.Functional.Properties using (++-cong)
open import Categories.Category.Monoidal.Instance.Setoids using (Setoids-Cartesian)
open import Categories.Category.BinaryProducts using (module BinaryProducts)
open import Categories.Category.Cartesian using (Cartesian)
open Cartesian (Setoids-Cartesian {0} {0}) using (products)
open import Category.Cocomplete.Finitely.Bundle using (FinitelyCocompleteCategory)
open import Categories.Category.Instance.Nat using (Nat-Cocartesian)
open import Categories.Category.Cocartesian using (Cocartesian; module BinaryCoproducts)
open import Categories.Category.Product using (_⁂_)
open import Categories.Functor using () renaming (_∘F_ to _∘′_)
open Cocartesian Nat-Cocartesian using (module Dual; i₁; i₂; -+-; _+₁_; +-assoc; +-assocʳ; +-assocˡ; +-comm; +-swap; +₁∘+-swap)
open import Data.Product.Relation.Binary.Pointwise.NonDependent using (_×ₛ_)
open import Data.Nat.Base using (ℕ; _+_)
open import Data.Fin.Base using (Fin)
open import Data.Product.Base using (_,_; _×_; Σ)
open import Data.Fin.Preimage using (preimage; preimage-⊥; preimage-cong₂)
open import Functor.Monoidal.Instance.Nat.Preimage using (preimage-++)
open import Data.Sum.Base using ([_,_]; [_,_]′; inj₁; inj₂)
open import Data.Sum.Properties using ([,]-cong; [,-]-cong; [-,]-cong; [,]-∘; [,]-map)
open import Data.Circuit.Merge using (merge-with; merge; merge-⊥; merge-[]; merge-cong₁; merge-cong₂; merge-suc; _when_; join-merge; merge-preimage-ρ; merge-⁅⁆)
open import Data.Circuit.Value using (Value; join; join-comm; join-assoc)
open import Data.Fin.Base using (splitAt; _↑ˡ_; _↑ʳ_) renaming (join to joinAt)
open import Data.Fin.Properties using (splitAt-↑ˡ; splitAt-↑ʳ; splitAt⁻¹-↑ˡ; splitAt⁻¹-↑ʳ; ↑ˡ-injective; ↑ʳ-injective; _≟_; 2↔Bool)
open import Relation.Binary.PropositionalEquality as  using (_≡_; _≢_; _≗_; module ≡-Reasoning)
open BinaryProducts products using (-×-)
open Value using (U)
open Bool using (false)

open import Function.Bundles using (Equivalence)
open import Category.Monoidal.Instance.Nat using (Nat,+,0)
open import Category.Instance.Setoids.SymmetricMonoidal {0} {0} using (Setoids-×)
open import Categories.Functor.Monoidal.Symmetric Nat,+,0 Setoids-× using (module Lax)
open Lax using (SymmetricMonoidalFunctor)
open import Categories.Morphism Nat using (_≅_)
open import Function.Bundles using (Inverse)
open import Data.Fin.Permutation using (Permutation; _⟨$⟩ʳ_; _⟨$⟩ˡ_)
open Dual.op-binaryProducts using () renaming (assocˡ∘⟨⟩ to []∘assocʳ; swap∘⟨⟩ to []∘swap)
open import Relation.Nullary.Decidable using (does; does-⇔; dec-false)



open Func
Push-ε : SingletonSetoid {0} {0} ⟶ₛ Values 0
to Push-ε x = []
cong Push-ε x ()

++ₛ : {n m : }  Values n ×ₛ Values m ⟶ₛ Values (n + m)
to ++ₛ (xs , ys) = xs ++ ys
cong ++ₛ (≗xs , ≗ys) = ++-cong _ _ ≗xs ≗ys

∣_∣ : {c  : Level}  Setoid c   Set c
∣_∣ = Setoid.Carrier

open merge-++
    : {n m : }
      (xs :  Values n )
      (ys :  Values m )
      (S₁ : Subset n)
      (S₂ : Subset m)
     merge (xs ++ ys) (S₁ ++ S₂)
     join (merge xs S₁) (merge ys S₂)
merge-++ {zero} {m} xs ys S₁ S₂ = begin
    merge (xs ++ ys) (S₁ ++ S₂)       ≡⟨ merge-cong₂ (xs ++ ys) (λ _  ≡.refl)     merge (xs ++ ys) S₂               ≡⟨ merge-cong₁ (λ _  ≡.refl) S₂     merge ys S₂                       ≡⟨ ≡.cong (λ h  join h (merge ys S₂)) (merge-[] xs S₁)     join (merge xs S₁) (merge ys S₂)    where
    open ≡-Reasoning
merge-++ {suc n} {m} xs ys S₁ S₂ = begin
    merge (xs ++ ys) (S₁ ++ S₂)                                                   ≡⟨ merge-suc (xs ++ ys) (S₁ ++ S₂)     merge-with (head xs when head S₁) (tail (xs ++ ys)) (tail (S₁ ++ S₂))         ≡⟨ join-merge (head xs when head S₁) (tail (xs ++ ys)) (tail (S₁ ++ S₂))     join (head xs when head S₁) (merge (tail (xs ++ ys)) (tail (S₁ ++ S₂)))
        ≡⟨ ≡.cong (join (head xs when head S₁)) (merge-cong₁ ([,]-map  splitAt n) (tail (S₁ ++ S₂)))     join (head xs when head S₁) (merge (tail xs ++ ys) (tail (S₁ ++ S₂)))
        ≡⟨ ≡.cong (join (head xs when head S₁)) (merge-cong₂ (tail xs ++ ys) ([,]-map  splitAt n))     join (head xs when head S₁) (merge (tail xs ++ ys) (tail S₁ ++ S₂))           ≡⟨ ≡.cong (join (head xs when head S₁)) (merge-++ (tail xs) ys (tail S₁) S₂)     join (head xs when head S₁) (join (merge (tail xs) (tail S₁)) (merge ys S₂))  ≡⟨ join-assoc (head xs when head S₁) (merge (tail xs) (tail S₁)) _     join (join (head xs when head S₁) (merge (tail xs) (tail S₁))) (merge ys S₂)
        ≡⟨ ≡.cong (λ h  join h (merge ys S₂)) (join-merge (head xs when head S₁) (tail xs) (tail S₁))     join (merge-with (head xs when head S₁) (tail xs) (tail S₁)) (merge ys S₂)    ≡⟨ ≡.cong (λ h  join h (merge ys S₂)) (merge-suc xs S₁)     join (merge xs S₁) (merge ys S₂)                                                where
    open ≡-Reasoning

open Fin
⁅⁆-≟ : {n : } (x y : Fin n)   x  y  does (x  y)
⁅⁆-≟ zero zero = ≡.refl
⁅⁆-≟ zero (suc y) = ≡.refl
⁅⁆-≟ (suc x) zero = ≡.refl
⁅⁆-≟ (suc x) (suc y) = ⁅⁆-≟ x y

Push-++
    : {n n′ m m′ : }
      (f : Fin n  Fin n′)
      (g : Fin m  Fin m′)
      (xs :  Values n )
      (ys :  Values m )
     merge xs  preimage f  ⁅_⁆ ++ merge ys  preimage g  ⁅_⁆
     merge (xs ++ ys)  preimage (f +₁ g)  ⁅_⁆
Push-++ {n} {n′} {m} {m′} f g xs ys i = begin
    ((merge xs  preimage f  ⁅_⁆) ++ (merge ys  preimage g  ⁅_⁆)) i ≡⟨⟩
    [ merge xs  preimage f  ⁅_⁆ , merge ys  preimage g  ⁅_⁆ ]′ (splitAt n′ i)
        ≡⟨ [,]-cong left right (splitAt n′ i)     [ (λ x  merge (xs ++ ys) _) , (λ x  merge (xs ++ ys) _) ]′ (splitAt n′ i)
        ≡⟨ [,]-∘ (merge (xs ++ ys)  (preimage (f +₁ g))) (splitAt n′ i)     merge (xs ++ ys) (preimage (f +₁ g) ([ ⁅⁆++⊥ , ⊥++⁅⁆ ]′ (splitAt n′ i))) ≡⟨⟩
    merge (xs ++ ys) (preimage (f +₁ g) ((⁅⁆++⊥ ++ ⊥++⁅⁆) i)) ≡⟨ merge-cong₂ (xs ++ ys) (preimage-cong₂ (f +₁ g) (⁅⁆-++ i))     merge (xs ++ ys) (preimage (f +₁ g)  i )   where
    open ≡-Reasoning
    left : (x : Fin n′)  merge xs (preimage f  x )  merge (xs ++ ys) (preimage (f +₁ g) ( x  ++ ))
    left x = begin
        merge xs (preimage f  x )                                   ≡⟨ join-comm U (merge xs (preimage f  x ))         join (merge xs (preimage f  x )) U                          ≡⟨ ≡.cong (join (merge _ _)) (merge-⊥ ys)         join (merge xs (preimage f  x )) (merge ys )               ≡⟨ ≡.cong (join (merge _ _)) (merge-cong₂ ys (preimage-⊥ g))         join (merge xs (preimage f  x )) (merge ys (preimage g ))  ≡⟨ merge-++ xs ys (preimage f  x ) (preimage g )         merge (xs ++ ys) ((preimage f  x ) ++ (preimage g ))       ≡⟨ merge-cong₂ (xs ++ ys) (preimage-++ f g)         merge (xs ++ ys) (preimage (f +₁ g) ( x  ++ ))                 right : (x : Fin m′)  merge ys (preimage g  x )  merge (xs ++ ys) (preimage (f +₁ g) ( ++  x ))
    right x = begin
        merge ys (preimage g  x )                                   ≡⟨⟩
        join U (merge ys (preimage g  x ))                          ≡⟨ ≡.cong (λ h  join h (merge _ _)) (merge-⊥ xs)         join (merge xs ) (merge ys (preimage g  x ))               ≡⟨ ≡.cong (λ h  join h (merge _ _)) (merge-cong₂ xs (preimage-⊥ f))         join (merge xs (preimage f )) (merge ys (preimage g  x ))  ≡⟨ merge-++ xs ys (preimage f ) (preimage g  x )         merge (xs ++ ys) ((preimage f ) ++ (preimage g  x ))       ≡⟨ merge-cong₂ (xs ++ ys) (preimage-++ f g)         merge (xs ++ ys) (preimage (f +₁ g) ( ++  x ))                 ⁅⁆++⊥ : Vector (Subset (n′ + m′)) n′
    ⁅⁆++⊥ x =  x  ++     ⊥++⁅⁆ : Vector (Subset (n′ + m′)) m′
    ⊥++⁅⁆ x =  ++  x     open     open Equivalence

    ⁅⁆-++
        : (i : Fin (n′ + m′))
         [ (λ x   x  ++ ) , (λ x   ++  x ) ]′ (splitAt n′ i)   i     ⁅⁆-++ i x with splitAt n′ i in eq₁
    ... | inj₁ i′ with splitAt n′ x in eq₂
    ...   | inj₁ x′ = begin
                 i′  x′                   ≡⟨ ⁅⁆-≟ i′ x′                 does (i′  x′)              ≡⟨ does-⇔  (i′  x′) (i′ ↑ˡ m′  x′ ↑ˡ m′)                 does (i′ ↑ˡ m′  x′ ↑ˡ m′)  ≡⟨ ⁅⁆-≟ (i′ ↑ˡ m′) (x′ ↑ˡ m′)                  i′ ↑ˡ m′  (x′ ↑ˡ m′)     ≡⟨ ≡.cong₂ ⁅_⁆ (splitAt⁻¹-↑ˡ eq₁) (splitAt⁻¹-↑ˡ eq₂)                  i  x                               where
                 : Equivalence (≡.setoid (i′  x′)) (≡.setoid (i′ ↑ˡ m′  x′ ↑ˡ m′))
                 .to = ≡.cong (_↑ˡ m′)
                 .from = ↑ˡ-injective m′ i′ x′
                 .to-cong ≡.refl = ≡.refl
                 .from-cong ≡.refl = ≡.refl
    ...   | inj₂ x′ = begin
                false                       ≡⟨ dec-false (i′ ↑ˡ m′  n′ ↑ʳ x′) ↑ˡ≢↑ʳ                 does (i′ ↑ˡ m′  n′ ↑ʳ x′)  ≡⟨ ⁅⁆-≟ (i′ ↑ˡ m′) (n′ ↑ʳ x′)                  i′ ↑ˡ m′  (n′ ↑ʳ x′)     ≡⟨ ≡.cong₂ ⁅_⁆ (splitAt⁻¹-↑ˡ eq₁) (splitAt⁻¹-↑ʳ eq₂)                  i  x                                   where
                ↑ˡ≢↑ʳ : i′ ↑ˡ m′  n′ ↑ʳ x′
                ↑ˡ≢↑ʳ  = case ≡.trans (≡.sym (splitAt-↑ˡ n′ i′ m′)) (≡.trans (≡.cong (splitAt n′) ) (splitAt-↑ʳ n′ m′ x′)) of λ { () }
    ⁅⁆-++ i x | inj₂ i′ with splitAt n′ x in eq₂
    ⁅⁆-++ i x | inj₂ i′ | inj₁ x′ = ≡.trans (≡.cong ([  ,  i′  ]′) eq₂) $ begin
        false                       ≡⟨ dec-false (n′ ↑ʳ i′  x′ ↑ˡ m′) ↑ʳ≢↑ˡ         does (n′ ↑ʳ i′  x′ ↑ˡ m′)  ≡⟨ ⁅⁆-≟ (n′ ↑ʳ i′) (x′ ↑ˡ m′)          n′ ↑ʳ i′  (x′ ↑ˡ m′)     ≡⟨ ≡.cong₂ ⁅_⁆ (splitAt⁻¹-↑ʳ eq₁) (splitAt⁻¹-↑ˡ eq₂)          i  x                           where
        ↑ʳ≢↑ˡ : n′ ↑ʳ i′  x′ ↑ˡ m′
        ↑ʳ≢↑ˡ  = case ≡.trans (≡.sym (splitAt-↑ʳ n′ m′ i′)) (≡.trans (≡.cong (splitAt n′) ) (splitAt-↑ˡ n′ x′ m′)) of λ { () }
    ⁅⁆-++ i x | inj₂ i′ | inj₂ x′ = begin
        [  ,  i′  ] (splitAt n′ x) ≡⟨ ≡.cong ([  ,  i′  ]) eq₂          i′  x′                     ≡⟨ ⁅⁆-≟ i′ x′         does (i′  x′)                ≡⟨ does-⇔  (i′  x′) (n′ ↑ʳ i′  n′ ↑ʳ x′)         does (n′ ↑ʳ i′  n′ ↑ʳ x′)    ≡⟨ ⁅⁆-≟ (n′ ↑ʳ i′) (n′ ↑ʳ x′)          n′ ↑ʳ i′  (n′ ↑ʳ x′)       ≡⟨ ≡.cong₂ ⁅_⁆ (splitAt⁻¹-↑ʳ eq₁) (splitAt⁻¹-↑ʳ eq₂)          i  x                             where
         : Equivalence (≡.setoid (i′  x′)) (≡.setoid (n′ ↑ʳ i′  n′ ↑ʳ x′))
         .to = ≡.cong (n′ ↑ʳ_)
         .from = ↑ʳ-injective n′ i′ x′
         .to-cong ≡.refl = ≡.refl
         .from-cong ≡.refl = ≡.refl

⊗-homomorphism : NaturalTransformation (-×- ∘′ (Push  Push)) (Push ∘′ -+-)
⊗-homomorphism = ntHelper record
    { η = λ (n , m)  ++ₛ {n} {m}
    ; commute = λ { {n , m} {n′ , m′} (f , g) {xs , ys} i  Push-++ f g xs ys i }
    }

++-↑ˡ
    : {n m : }
      (X :  Values n )
      (Y :  Values m )
     (X ++ Y)  i₁  X
++-↑ˡ {n} {m} X Y i = ≡.cong [ X , Y ]′ (splitAt-↑ˡ n i m)

++-↑ʳ
    : {n m : }
      (X :  Values n )
      (Y :  Values m )
     (X ++ Y)  i₂  Y
++-↑ʳ {n} {m} X Y i = ≡.cong [ X , Y ]′ (splitAt-↑ʳ n m i)

++-assoc
    : {m n o : }
      (X :  Values m )
      (Y :  Values n )
      (Z :  Values o )
     ((X ++ Y) ++ Z)  +-assocʳ {m}  X ++ (Y ++ Z)
++-assoc {m} {n} {o} X Y Z i = begin
    ((X ++ Y) ++ Z) (+-assocʳ {m} i)                                    ≡⟨⟩
    ((X ++ Y) ++ Z) ([ i₁  i₁ , _ ]′ (splitAt m i))                    ≡⟨ [,]-∘ ((X ++ Y) ++ Z) (splitAt m i)     [ ((X ++ Y) ++ Z)  i₁  i₁ , _ ]′ (splitAt m i)                    ≡⟨ [-,]-cong (++-↑ˡ (X ++ Y) Z  i₁) (splitAt m i)     [ (X ++ Y)  i₁ , _ ]′ (splitAt m i)                                ≡⟨ [-,]-cong (++-↑ˡ X Y) (splitAt m i)     [ X , ((X ++ Y) ++ Z)  [ _ , _ ]′  splitAt n ]′ (splitAt m i)     ≡⟨ [,-]-cong ([,]-∘ ((X ++ Y) ++ Z)  splitAt n) (splitAt m i)     [ X , [ (_ ++ Z)  i₁  i₂ {m} , _ ]′  splitAt n ]′ (splitAt m i)  ≡⟨ [,-]-cong ([-,]-cong (++-↑ˡ (X ++ Y) Z  i₂)  splitAt n) (splitAt m i)     [ X , [ (X ++ Y)  i₂ , _ ]′  splitAt n ]′ (splitAt m i)           ≡⟨ [,-]-cong ([-,]-cong (++-↑ʳ X Y)  splitAt n) (splitAt m i)     [ X , [ Y , ((X ++ Y) ++ Z)  i₂ ]′  splitAt n ]′ (splitAt m i)    ≡⟨ [,-]-cong ([,-]-cong (++-↑ʳ (X ++ Y) Z)  splitAt n) (splitAt m i)     [ X , [ Y , Z ]′  splitAt n ]′ (splitAt m i)                       ≡⟨⟩
    (X ++ (Y ++ Z)) i                                                     where
    open Bool
    open Fin
    open ≡-Reasoning

Preimage-unitaryˡ
    : {n : }
      (X : Subset n)
     (X ++ [])  (_↑ˡ 0)  X
Preimage-unitaryˡ {n} X i = begin
    [ X , [] ]′ (splitAt _ (i ↑ˡ 0))  ≡⟨ ≡.cong ([ X , [] ]′) (splitAt-↑ˡ n i 0)     [ X , [] ]′ (inj₁ i)              ≡⟨⟩
    X i                                 where
    open ≡-Reasoning

Push-assoc
    : {m n o : }
      (X :  Values m )
      (Y :  Values n )
      (Z :  Values o )
     merge ((X ++ Y) ++ Z)  preimage (+-assocˡ {m})   ⁅_⁆
     X ++ (Y ++ Z)
Push-assoc {m} {n} {o} X Y Z i = begin
    merge ((X ++ Y) ++ Z) (preimage (+-assocˡ {m})  i )         ≡⟨ merge-preimage-ρ ↔-mno ((X ++ Y) ++ Z)  i      merge (((X ++ Y) ++ Z)  (+-assocʳ {m})) ( i )              ≡⟨⟩
    merge (((X ++ Y) ++ Z)  (+-assocʳ {m})) (preimage id  i )  ≡⟨ merge-cong₁ (++-assoc X Y Z) (preimage id  i )     merge (X ++ (Y ++ Z)) (preimage id  i )                     ≡⟨ Push-identity i     (X ++ (Y ++ Z)) i                                               where
    open Inverse
    module +-assoc = _≅_ (+-assoc {m} {n} {o})
    ↔-mno : Permutation ((m + n) + o) (m + (n + o))
    ↔-mno .to = +-assocˡ {m}
    ↔-mno .from = +-assocʳ {m}
    ↔-mno .to-cong ≡.refl = ≡.refl
    ↔-mno .from-cong ≡.refl = ≡.refl
    ↔-mno .inverse = (λ { ≡.refl  +-assoc.isoˡ _ }) , λ { ≡.refl  +-assoc.isoʳ _ }
    open ≡-Reasoning

preimage-++′
    : {n m o : }
      (f : Vector (Fin o) n)
      (g : Vector (Fin o) m)
      (S : Subset o)
     preimage (f ++ g) S  preimage f S ++ preimage g S
preimage-++′ {n} f g S = [,]-∘ S  splitAt n

Push-unitaryʳ
    : {n : }
      (X :  Values n )
      (i : Fin n)
     merge (X ++ []) (preimage (id ++ (λ ()))  i )  X i
Push-unitaryʳ {n} X i = begin
    merge (X ++ []) (preimage (id ++ (λ ()))  i )               ≡⟨ merge-cong₂ (X ++ []) (preimage-++′ id (λ ())  i )     merge (X ++ []) (preimage id  i  ++ preimage (λ ())  i )  ≡⟨⟩
    merge (X ++ []) ( i  ++ preimage (λ ())  i )              ≡⟨ merge-++ X []  i  (preimage (λ ())  i )     join (merge X  i ) (merge [] (preimage (λ ())  i ))       ≡⟨ ≡.cong (join (merge X  i )) (merge-[] [] (preimage (λ ())  i ))     join (merge X  i ) U                                        ≡⟨ join-comm (merge X  i ) U     merge X  i                                                  ≡⟨ merge-⁅⁆ X i     X i   where
    open ≡-Reasoning
    t : Fin (n + 0)  Fin n
    t = id ++ (λ ())

Push-swap
    : {n m : }
      (X :  Values n )
      (Y :  Values m )
     merge (X ++ Y)  preimage (+-swap {m})  ⁅_⁆  Y ++ X
Push-swap {n} {m} X Y i = begin
    merge (X ++ Y) (preimage (+-swap {m})  i )      ≡⟨ merge-preimage-ρ n+m↔m+n (X ++ Y)  i      merge ((X ++ Y)  +-swap {n})  i                ≡⟨ merge-⁅⁆ ((X ++ Y)  (+-swap {n})) i     ((X ++ Y)  +-swap {n}) i                         ≡⟨ [,]-∘ (X ++ Y) (splitAt m i)     [ (X ++ Y)  i₂ , (X ++ Y)  i₁ ]′ (splitAt m i)  ≡⟨ [-,]-cong (++-↑ʳ X Y) (splitAt m i)     [ Y , (X ++ Y)  i₁ ]′ (splitAt m i)              ≡⟨ [,-]-cong (++-↑ˡ X Y) (splitAt m i)     [ Y , X ]′ (splitAt m i)                          ≡⟨⟩
    (Y ++ X) i                                          where
    open ≡-Reasoning
    open Inverse
    module +-swap = _≅_ (+-comm {m} {n})
    n+m↔m+n : Permutation (n + m) (m + n)
    n+m↔m+n .to = +-swap.to
    n+m↔m+n .from = +-swap.from
    n+m↔m+n .to-cong ≡.refl = ≡.refl
    n+m↔m+n .from-cong ≡.refl = ≡.refl
    n+m↔m+n .inverse = (λ { ≡.refl  +-swap.isoˡ _ }) , (λ { ≡.refl  +-swap.isoʳ _ })

open SymmetricMonoidalFunctor
Push,++,[] : SymmetricMonoidalFunctor
Push,++,[] .F = Push
Push,++,[] .isBraidedMonoidal = record
    { isMonoidal = record
        { ε = Push-ε
        ; ⊗-homo = ⊗-homomorphism
        ; associativity = λ { {m} {n} {o} {(X , Y) , Z} i  Push-assoc X Y Z i }
        ; unitaryˡ = λ { {n} {_ , X} i  merge-⁅⁆ X i }
        ; unitaryʳ = λ { {n} {X , _} i  Push-unitaryʳ X i }
        }
    ; braiding-compat = λ { {n} {m} {X , Y} i  Push-swap X Y i }
    }