-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add KnuckleDragger induction examples
- Loading branch information
1 parent
660b5a2
commit aa2e2ec
Showing
3 changed files
with
62 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
----------------------------------------------------------------------------- | ||
-- | | ||
-- Module : Documentation.SBV.Examples.KnuckleDragger.Induction | ||
-- Copyright : (c) Levent Erkok | ||
-- License : BSD3 | ||
-- Maintainer: [email protected] | ||
-- Stability : experimental | ||
-- | ||
-- Example use of the KnuckleDragger, for some inductive proofs | ||
-- | ||
----------------------------------------------------------------------------- | ||
|
||
{-# OPTIONS_GHC -Wall -Werror #-} | ||
|
||
module Documentation.SBV.Examples.KnuckleDragger.Induction where | ||
|
||
import Prelude hiding (sum) | ||
|
||
import Data.SBV | ||
import Data.SBV.Tools.KnuckleDragger | ||
import Data.SBV.Tools.KnuckleDragger.Induction | ||
|
||
-- | Prove that sum of numbers from @0@ to @n@ is @n*(n-1)/2@. | ||
-- | ||
-- We have: | ||
-- | ||
-- >>> sumProof | ||
-- Axiom: sum_induction Admitted. | ||
-- Lemma: sum_correct Q.E.D. | ||
sumProof :: IO Proven | ||
sumProof = do | ||
let sum :: SInteger -> SInteger | ||
sum = smtFunction "sum" $ \n -> ite (n .== 0) 0 (n + sum (n - 1)) | ||
|
||
spec :: SInteger -> SInteger | ||
spec n = (n * (n+1)) `sDiv` 2 | ||
|
||
(p, induct) <- inductionPrinciple "sum" (\n -> sum n .== spec n) | ||
|
||
lemma "sum_correct" (\(Forall n) -> p n) [induct] | ||
|
||
-- | Prove that sum of square of numbers from @0@ to @n@ is @n*(n+1)*(2n+1)/6@. | ||
-- | ||
-- We have: | ||
-- | ||
-- >>> sumSquareProof | ||
-- Axiom: sumSquare_induction Admitted. | ||
-- Lemma: sumSquare_correct Q.E.D. | ||
sumSquareProof :: IO Proven | ||
sumSquareProof = do | ||
let sumSquare :: SInteger -> SInteger | ||
sumSquare = smtFunction "sumSquare" $ \n -> ite (n .== 0) 0 (n * n + sumSquare (n - 1)) | ||
|
||
spec :: SInteger -> SInteger | ||
spec n = (n * (n+1) * (2*n+1)) `sDiv` 6 | ||
|
||
(p, induct) <- inductionPrinciple "sumSquare" (\n -> sumSquare n .== spec n) | ||
|
||
lemma "sumSquare_correct" (\(Forall n) -> p n) [induct] |
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