Skip to content

Commit

Permalink
KD: Add reverse (length xs) = length xs proof.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Sep 10, 2024
1 parent aac926f commit a8e6844
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
by the same name: https://github.com/philzook58/knuckledragger.

* Added several KnuckleDragger proof examples, see Documentation.SBV.Examples.KnuckleDragger modules.
Amongst the proofs are the irrationality of square-root of 2, several list lemmas, and a few
inductive proofs over naturals.

* Add sDivides, which takes a concrete integer and a (possibly symbolic), and returns sTrue
if the first argument divides the second. It is essentially equivalent to @a `sMod` n .== 0`,
Expand Down
42 changes: 42 additions & 0 deletions Documentation/SBV/Examples/KnuckleDragger/RevLen.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-----------------------------------------------------------------------------

Check failure on line 1 in Documentation/SBV/Examples/KnuckleDragger/RevLen.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: Unsupported extension: TypeAbstractions ▫︎ Found: "-----------------------------------------------------------------------------\n-- |\n-- Module : Documentation.SBV.Examples.KnuckleDragger.RevLen\n-- Copyright : (c) Levent Erkok\n-- License : BSD3\n-- Maintainer: [email protected]\n-- Stability : experimental\n--\n-- Proof that reversing a list does not change its length.\n-----------------------------------------------------------------------------\n\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE ScopedTypeVariables #-}\n{-# LANGUAGE TypeAbstractions #-}\n\n{-# OPTIONS_GHC -Wall -Werror #-}\n\nmodule Documentation.SBV.Examples.KnuckleDragger.RevLen where\n\nimport Prelude hiding (length, reverse)\n\nimport Data.SBV\nimport Data.SBV.Tools.KnuckleDragger\n\nimport Data.SBV.List (reverse, length)\n\n-- | @Length xs == length (reverse xs)@\n--\n-- We have:\n--\n-- >>> revLen\n-- Lemma: revLen Q.E.D.\nrevLen :: IO Proven\nrevLen = do\n let p :: SList Integer -> SBool\n p xs = length (reverse xs) .== length xs\n\n induct <- inductionPrinciple p\n\n lemma \"revLen\"\n (\\(Forall @\"xs\" xs) -> p xs)\n [induct]\n"
-- |
-- Module : Documentation.SBV.Examples.KnuckleDragger.RevLen
-- Copyright : (c) Levent Erkok
-- License : BSD3
-- Maintainer: [email protected]
-- Stability : experimental
--
-- Proof that reversing a list does not change its length.
-----------------------------------------------------------------------------

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeAbstractions #-}

{-# OPTIONS_GHC -Wall -Werror #-}

module Documentation.SBV.Examples.KnuckleDragger.RevLen where

import Prelude hiding (length, reverse)

import Data.SBV
import Data.SBV.Tools.KnuckleDragger

import Data.SBV.List (reverse, length)

-- | @length xs == length (reverse xs)@
--
-- We have:
--
-- >>> revLen
-- Lemma: revLen Q.E.D.
revLen :: IO Proven
revLen = do
let p :: SList Integer -> SBool
p xs = length (reverse xs) .== length xs

induct <- inductionPrinciple p

lemma "revLen"
(\(Forall @"xs" xs) -> p xs)
[induct]
1 change: 1 addition & 0 deletions sbv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ Library
, Documentation.SBV.Examples.KnuckleDragger.Kleene
, Documentation.SBV.Examples.KnuckleDragger.Induction
, Documentation.SBV.Examples.KnuckleDragger.ListLen
, Documentation.SBV.Examples.KnuckleDragger.RevLen
, Documentation.SBV.Examples.KnuckleDragger.Sqrt2IsIrrational
, Documentation.SBV.Examples.Misc.Definitions
, Documentation.SBV.Examples.Misc.Enumerate
Expand Down

0 comments on commit a8e6844

Please sign in to comment.