Skip to content

Commit

Permalink
KD: Start work on sheffer's stroke. WIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Jan 16, 2025
1 parent 07db4a3 commit 7643a15
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
59 changes: 59 additions & 0 deletions Documentation/SBV/Examples/KnuckleDragger/ShefferStroke.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-----------------------------------------------------------------------------

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

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: Unsupported extension: TypeAbstractions ▫︎ Found: "-----------------------------------------------------------------------------\n-- |\n-- Module : Documentation.SBV.Examples.KnuckleDragger.ShefferStroke\n-- Copyright : (c) Levent Erkok\n-- License : BSD3\n-- Maintainer: [email protected]\n-- Stability : experimental\n--\n-- Inspired by https://www.philipzucker.com/cody_sheffer/, proving\n-- that the axioms of sheffer stroke (i.e., nand in traditional boolean\n-- logic), implies it is a boolean algebra.\n-----------------------------------------------------------------------------\n\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE DeriveDataTypeable #-}\n{-# LANGUAGE DeriveAnyClass #-}\n{-# LANGUAGE StandaloneDeriving #-}\n{-# LANGUAGE TemplateHaskell #-}\n{-# LANGUAGE TypeAbstractions #-}\n\n{-# OPTIONS_GHC -Wall -Werror #-}\n\nmodule Documentation.SBV.Examples.KnuckleDragger.ShefferStroke where\n\nimport Data.SBV\nimport Data.SBV.Tools.KnuckleDragger\n\n-- | The abstract type for the domain.\ndata Stroke\nmkUninterpretedSort ''Stroke\n\n-- | The sheffer stroke.\nǀ :: SStroke -> SStroke -> SStroke\nǀ = uninterpret \"∣\"\n\n-- | Negation in terms of ǀ\nﬧ :: SStroke -> SStroke\nﬧ x = x `ǀ` x\n\n-- | Axioms of the sheffer stroke.\nshefferAxioms :: KD [Proof]\nshefferAxioms = do sh1 <- axiom \"sh1\" $ \\(Forall @\"a\" a) -> ﬧ (ﬧ a) .== a\n sh2 <- axiom \"sh2\" $ \\(Forall @\"a\" a) (Forall @\"b\" b) -> a `ǀ` (b `ǀ` ﬧ b) .== ﬧ a\n sh3 <- axiom \"sh3\" $ \\(Forall @\"a\" a) (Forall @\"b\" b) (Forall @\"c\" c) -> ﬧ (a `ǀ` (b `ǀ` c)) .== (ﬧ b `ǀ` a) `ǀ` (ﬧ c `ǀ` a)\n pure [sh1, sh2, sh3]\n\n-- * Commmutativity\n\n-- | Prove that the sheffer stroke is commutative. We have:\n--\n-- >>> commutative\n-- Axiom: sh1 Axiom.\n-- Axiom: sh2 Axiom.\n-- Axiom: sh3 Axiom.\n-- Lemma: commutative Q.E.D.\n-- [Proven] commutative\ncommutative :: IO Proof\ncommutative = runKD $ do\n shefferAxioms >>= lemma \"commutative\" (\\(Forall @\"a\" a) (Forall @\"b\" b) -> a `ǀ` b .== b `ǀ` a)\n"
-- |
-- Module : Documentation.SBV.Examples.KnuckleDragger.ShefferStroke
-- Copyright : (c) Levent Erkok
-- License : BSD3
-- Maintainer: [email protected]
-- Stability : experimental
--
-- Inspired by https://www.philipzucker.com/cody_sheffer/, proving
-- that the axioms of sheffer stroke (i.e., nand in traditional boolean
-- logic), implies it is a boolean algebra.
-----------------------------------------------------------------------------

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeAbstractions #-}

{-# OPTIONS_GHC -Wall -Werror #-}

module Documentation.SBV.Examples.KnuckleDragger.ShefferStroke where

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

-- | The abstract type for the domain.
data Stroke
mkUninterpretedSort ''Stroke

-- | The sheffer stroke.
ǀ :: SStroke -> SStroke -> SStroke
ǀ = uninterpret ""

-- | Negation in terms of ǀ
:: SStroke -> SStroke
ﬧ x = x `ǀ` x

-- | Axioms of the sheffer stroke.
shefferAxioms :: KD [Proof]
shefferAxioms = do sh1 <- axiom "sh1" $ \(Forall @"a" a) -> ﬧ (ﬧ a) .== a
sh2 <- axiom "sh2" $ \(Forall @"a" a) (Forall @"b" b) -> a `ǀ` (b `ǀ` ﬧ b) .== ﬧ a
sh3 <- axiom "sh3" $ \(Forall @"a" a) (Forall @"b" b) (Forall @"c" c) -> ﬧ (a `ǀ` (b `ǀ` c)) .== (ﬧ b `ǀ` a) `ǀ` (ﬧ c `ǀ` a)
pure [sh1, sh2, sh3]

-- * Commmutativity

-- | Prove that the sheffer stroke is commutative. We have:
--
-- >>> commutative
-- Axiom: sh1 Axiom.
-- Axiom: sh2 Axiom.
-- Axiom: sh3 Axiom.
-- Lemma: commutative Q.E.D.
-- [Proven] commutative
commutative :: IO Proof
commutative = runKD $ do
shefferAxioms >>= lemma "commutative" (\(Forall @"a" a) (Forall @"b" b) -> a `ǀ` b .== b `ǀ` a)
1 change: 1 addition & 0 deletions sbv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ Library
, Documentation.SBV.Examples.KnuckleDragger.Kleene
, Documentation.SBV.Examples.KnuckleDragger.Lists
, Documentation.SBV.Examples.KnuckleDragger.Numeric
, Documentation.SBV.Examples.KnuckleDragger.ShefferStroke
, Documentation.SBV.Examples.KnuckleDragger.Sqrt2IsIrrational
, Documentation.SBV.Examples.KnuckleDragger.Tao
, Documentation.SBV.Examples.Misc.Definitions
Expand Down

0 comments on commit 7643a15

Please sign in to comment.