Skip to content

Instantly share code, notes, and snippets.

View gallais's full-sized avatar

G. Allais gallais

View GitHub Profile
module Instrumented where
import Control.Monad.State
data Counters = Counters
{ swaps :: !Int
, comparisons :: !Int
}
type Instrumented = State Counters
@gallais
gallais / FF.v
Created December 29, 2017 12:40
Proving FFs extensionally equal
Require Import ZArith.
Local Open Scope Z_scope.
Section FF.
Parameter A : Type.
Parameter (a b c d : A).
Definition FF := Z -> Z -> A.
@gallais
gallais / Impredicative.v
Created February 14, 2018 16:51
Using Impredicativity to beat the positivity checker
Inductive T :=
| Var : nat -> T
| App : T -> T -> T.
Inductive S e : Prop :=
| def: forall R, (forall i, R i -> S i) ->
(forall e', R e' -> S (App e e')) -> S e.
Definition def' :
forall e, (forall e', S e' -> S (App e e')) -> S e.
@gallais
gallais / Names.agda
Created June 2, 2018 20:27
Names with offsets
open import Data.String.Base
open import Data.Nat.Base
open import Data.List.Base
open import Relation.Binary.PropositionalEquality
infix 5 _at_
record Variable : Set where
constructor _at_
field name : String
@gallais
gallais / atleastn.agda
Last active September 15, 2018 11:25
lists of size at least n
open import Data.Nat
module atleastn (n : ℕ) {a} (A : Set a) where
open import Data.List using (List; length)
open import Data.Vec
record SizedList : Set a where
field list : List A
size : length list ≥ n
@gallais
gallais / generic-injective.agda
Created September 29, 2018 04:28
Generic combinator for injectivity proofs.
open import Relation.Binary.PropositionalEquality
open import Relation.Binary.HeterogeneousEquality
open import Data.Maybe
open import Function
cong⁻¹ : ∀ {A B : Set} {a a'} (f : A → Maybe B) →
(eq : a ≡ a') →
from-just (f a) ≅ from-just (f a')
cong⁻¹ {a = a} f refl = refl
module bins where
open import Size
open import Codata.Stream
open import Codata.Thunk
open import Data.List.Base as List using (List; _∷_; [])
open import Data.List.NonEmpty as List⁺ using (List⁺; _∷_; [_])
open import Function
open import Relation.Unary
open import Relation.Binary
module Reasoning {a ℓ₁ ℓ₂ ℓ₃} {A : Set a}
{_≈_ : Rel A ℓ₁} (≈-trans : Transitive _≈_) (≈-sym : Symmetric _≈_) (≈-refl : Reflexive _≈_)
{_≤_ : Rel A ℓ₂} (≤-trans : Transitive _≤_) (≤-respˡ-≈ : _≤_ Respectsˡ _≈_) (≤-respʳ-≈ : _≤_ Respectsʳ _≈_) (≤-refl : Reflexive _≤_)
{_<_ : Rel A ℓ₃} (<-trans : Transitive _<_) (<-respˡ-≈ : _<_ Respectsˡ _≈_) (<-respʳ-≈ : _<_ Respectsʳ _≈_) (<⇒≤ : _<_ ⇒ _≤_)
(<-≤-trans : ∀ {x y z} → x < y → y ≤ z → x < z)
(≤-<-trans : ∀ {x y z} → x ≤ y → y < z → x < z)
where
module Container
%default total
record Container where
constructor MkContainer
shape : Type
position : shape -> Type
container : Container -> Type -> Type
@gallais
gallais / ViewExample.agda
Last active February 13, 2019 14:19
Using a View makes proving easier
open import Relation.Nullary
open import Agda.Builtin.Equality
data X : Set where
a b c : X
firstA : (x y z : X) → X
firstA a y z = a
firstA x a z = a
firstA x y a = a