Created
October 25, 2022 01:23
-
-
Save donovancrichton/061baeb88d7c73160ff35c3833da7b35 to your computer and use it in GitHub Desktop.
Pigeonhole Principle in Idris
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module PigeonHole | |
import Data.Nat | |
import Data.Vect | |
%default total | |
data Elem : a -> Vect k a -> Type where | |
Here : Elem x (x :: xs) | |
There : Elem x xs -> Elem x (y :: xs) | |
sum' : Vect k Nat -> Nat | |
sum' [] = 0 | |
sum' (x :: xs) = S (sum' xs) | |
pigeonHole : (xs : Vect k Nat) -> (prf : LTE (S k) (PigeonHole.sum' xs)) -> (n : Nat ** (Elem n xs, LTE 2 n)) | |
pigeonHole [] prf = absurd prf | |
pigeonHole (x :: xs) prf = | |
case isLTE 2 x of | |
No contra => | |
let (m ** (prf', prf2')) = pigeonHole xs (fromLteSucc prf) | |
in (m ** (There prf', prf2')) | |
Yes p => (x ** (Here, p)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment