25 | ||| If we model the idea of a container (S !> P) as a box
26 | ||| ┌──────┐
27 | ||| │ s:S │
28 | ||| ├──────┤
29 | ||| │ Ps │
30 | ||| └──────┘
31 | ||| then `pushDown` is interpreted as keeping the box frame in place while
32 | ||| pushing down the container: pruning any part of the container that goes
33 | ||| out of the box, and using `Unit` for anything new that appears:
34 | ||| ┌──────┐
35 | ||| │ Unit │
36 | ||| ├──────┤
37 | ||| │ s:S │
38 | ||| └──────┘
39 | ||| Ps
151 | ||| The following is the proof that for any container `c` there is an
152 | ||| isomorphism in `Cont` between `c` and `CartesianClosure UnitCont c`
153 | ||| This holds in any monoidal closed category: `X ≅ [I, X]`
164 | ||| For a overview of this interaction from the categorical perspective, see
165 | ||| the Poly book (https://arxiv.org/abs/2312.00990) (Section 6.3.4)
167 | ||| Interaction between composition and tensor product
168 | ||| Swaps the operations, and middle two containers
169 | ||| Not an isomorphism!
176 | ||| Tensor product embeds into composition
177 | ||| A special case of `duoidal`
184 | ||| Specific distributive law we need
194 | ||| "State" as defined in https://arxiv.org/abs/2403.13001 and open games
195 | |||
196 | ||| ┌─────────────┐
197 | ||| │ ├──► (x : c.Shp)
198 | ||| │ State │
199 | ||| │ ├◄── c.Pos x
200 | ||| └─────────────┘
205 | ||| Given a shape of any container, state can be defined
221 | ||| "Costate" as defined in https://arxiv.org/abs/2403.13001 and open games
222 | |||
223 | ||| ┌─────────────┐
224 | ||| (x : c.Shp) ──►┤ │
225 | ||| │ Costate │
226 | ||| c.Pos x ◄──┤ │
227 | ||| └─────────────┘
260 | ||| Wraps a dependent lens `c =%> d`
261 | ||| into one of type `c >@ Scalar =%> d >@ Scalar`
262 | ||| Needed because `c >@ Scalar` isn't automatically reduced to `c`
275 | ||| Wraps a dependent lens `c =%> d`
276 | ||| into one of type `c >< Scalar =%> d >< Scalar`
277 | ||| Needed because `c >< Scalar` isn't automatically reduced to `c`
287 | ||| A lens from a container specialised to a shape to the container itself
292 | ||| A vector of positive length is a non-empty list
298 | -- ||| Technically this is Unit, but hard to prove
299 | -- public export
300 | -- foldOverNaperianShapeComp : {shape : List Cont} ->
301 | -- (allNap : All IsNaperian shape) =>
302 | -- (Tensor shape).Shp
303 | -- foldOverNaperianShapeComp {shape = []} = ()
304 | -- foldOverNaperianShapeComp {allNap = ((MkIsNaperian pos) :: ns)}
305 | -- = () <| \_ => foldOverNaperianShapeComp
306 | --
307 | -- public export
308 | -- naperianHancockShape : {shape : List Cont} ->
309 | -- (allNap : All IsNaperian shape) =>
310 | -- (HancockTensor shape).Shp = Unit
311 | -- naperianHancockShape = believe_me ()
312 | --
313 | -- public export
314 | -- foldOverNaperianShapeHancock : {shape : List Cont} ->
315 | -- (allNap : All IsNaperian shape) =>
316 | -- (HancockTensor shape).Shp
317 | -- foldOverNaperianShapeHancock {shape = []} = ()
318 | -- foldOverNaperianShapeHancock {allNap = ((MkIsNaperian _) :: _)}
319 | -- = ((), foldOverNaperianShapeHancock)
322 | -- public export
323 | -- tensorIsNaperianShape : {shape : List Cont} ->
324 | -- (allNap : All IsNaperian shape) =>
325 | -- IsNaperian (Tensor shape)
326 | -- tensorIsNaperianShape {shape = []} = MkIsNaperian ()
327 | -- tensorIsNaperianShape {shape = (_ :: ss), allNap = ((MkIsNaperian pos) :: ns)}
328 | -- = let tg = tensorIsNaperianShape {shape = ss}
329 | -- in ?tensorIsNaperianShape_rhs_1
330 | -- --in rewrite naperianShpEq @{tg}
331 | -- --in (rewrite (EmptyExtEq {c=(Nap pos)})
332 | -- --in let tg = MkIsNaperian in ?tensorIsNaperianShape_rhs_2)
334 | -- public export
335 | -- transformToHancock : {shape : List Cont} ->
336 | -- All IsNaperian shape =>
337 | -- Tensor shape =%> HancockTensor shape
338 | -- transformToHancock {shape = []} = id
339 | -- transformToHancock {shape = (_ :: ss)} @{((MkIsNaperian pos) :: ns)}
340 | -- = let f = (%!) (transformToHancock {shape = ss} @{ns})
341 | -- (_ ** h) = f (foldOverNaperianShapeComp {shape=ss})
342 | -- in !% \(() <| content) => (((), foldOverNaperianShapeHancock) **
343 | -- \(p, fld) => (p ** ?hhh))
344 | -- -- (((), rewrite -- foldOverNaperianShapeHancock {shape=ss} @{ns} in ()) **
345 | -- -- \(p, fld) => (p ** ?bnn))
347 | -- need to organise this
387 | ||| Traverses a binary tree container in order, producing a list container
392 | -- Need to do some rewriting for preorder
397 | --preorderBinTreeNode (NodeS lt rt) n with (strengthenN {m=numNodes lt} n)
398 | -- _ | Left p = ?whl
399 | -- _ | Right FZ = ?whn
400 | -- _ | Right (FS g) = ?whr
416 | -- public export
417 | -- traverseLeaf : (x : BinTreeShape) -> FinBinTreeLeaf x -> Fin (numLeaves x)
418 | -- traverseLeaf LeafS Done = FZ
419 | -- traverseLeaf (NodeS lt rt) (GoLeft x) = weakenN (numLeaves rt) (traverseLeaf lt x)
420 | -- traverseLeaf (NodeS lt rt) (GoRight x) = shift (numLeaves lt) (traverseLeaf rt x)
421 | --