Skip to content

Commit

Permalink
[rational] towards proving useful things
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Watters committed Nov 28, 2024
1 parent 3650866 commit 8bb7bc3
Show file tree
Hide file tree
Showing 3 changed files with 269 additions and 60 deletions.
38 changes: 25 additions & 13 deletions agda/Data/Vec/Snoc.agda
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,19 @@ open import Data.Product
open import Data.Nat
open import Data.Nat.Properties
open import Data.List.Snoc using (List; Tsil; []; _,-_; _-,_)
open import Data.Vec using (Vec; []) renaming (_∷_ to _,-_; _++_ to _<<<_)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality

private variable
X : Set

data Vec (X : Set) : Set where
[] : Vec X 0
_,-_ : {n} X Vec X n Vec X (suc n)

data Cev (X : Set) : Set where
[] : Cev X 0
_-,_ : {n} Cev X n X Cev X (suc n)

head : {n} (xs : Vec X n) {{_ : NonZero n}} X
head (x ,- xs) = x
head : {n} (xs : Cev X n) {{_ : NonZero n}} X
head (sx -, x) = x

_><<_ : {n m} Cev X n Vec X m Vec X (n + m)
[] ><< ys = ys
Expand All @@ -32,17 +29,32 @@ _><>_ : ∀ {n m} → Cev X n → Vec X m → Cev X (n + m)
_><>_ {n = n} sx [] rewrite +-identityʳ n = sx
_><>_ {n = n} {suc m} sx (x ,- xs) rewrite (+-suc n m) = (sx -, x) ><> xs

_<<<_ : {n m} Vec X n Vec X m Vec X (n + m)
_<<<_ [] ys = ys
_<<<_ (x ,- xs) ys = x ,- (xs <<< ys)
-- _<><_ : ∀ {n m} → Vec X n → Cev X m → Vec X (n + m)
-- _<><_ = {!!}

-- _>>>_ : ∀ {n m} → Cev X n → Cev X m → Cev X (n + m)
-- _>>>_ = {!!}

-- This is the inefficient way, but meh
rev : {n} Cev X n Vec X n
rev [] = []
rev {n = suc n} (sx -, x) rewrite +-comm 1 n = (rev sx) <<< (x ,- [])

data Any {X : Set} (P : X Set) : {n} Cev X n Set where
here : {n x} {sx : Cev X n} P x Any P (sx -, x)
there : {n x} {sx : Cev X n} Any P sx Any P (sx -, x)

_∈_ : {X : Set} X {n : ℕ} Cev X n Set
x ∈ sx = Any (x ≡_) sx

repeat : {n} (k : ℕ) Vec X n Vec X (k * n)
repeat zero xs = []
repeat (suc k) xs = xs <<< repeat k xs
-------------
-- Zippers --
-------------

-- record Zipper (X : Set) : Set where
-- constructor _,_
-- constructor _>[_]<_
-- field
-- front : Tsil X
-- focus : X
-- back : List X
-- open Zipper
15 changes: 15 additions & 0 deletions agda/Data/Vec/Util.agda
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{-# OPTIONS --safe --cubical-compatible #-}
module Data.Vec.Util where

open import Data.Vec
open import Data.Nat

private variable
X : Set

repeat : {n} (k : ℕ) Vec X n Vec X (k * n)
repeat zero xs = []
repeat (suc k) xs = xs ++ repeat k xs

head-nz : {n} {{_ : NonZero n}} Vec X n X
head-nz (x ∷ xs) = x
Loading

0 comments on commit 8bb7bc3

Please sign in to comment.