Skip to content

Commit

Permalink
add the Tao example
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Oct 7, 2024
1 parent ca6ad32 commit cc2e013
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions Documentation/SBV/Examples/KnuckleDragger/Tao.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
-----------------------------------------------------------------------------

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

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: Unsupported extension: TypeAbstractions ▫︎ Found: "-----------------------------------------------------------------------------\n-- |\n-- Module : Documentation.SBV.Examples.KnuckleDragger.Tao\n-- Copyright : (c) Levent Erkok\n-- License : BSD3\n-- Maintainer: [email protected]\n-- Stability : experimental\n--\n-- Proves a problem originating in algebra:\n-- https://mathoverflow.net/questions/450890/is-there-an-identity-between-the-commutative-identity-and-the-constant-identity/\n--\n-- Apparently this was posed by Terrence Tao: https://mathstodon.xyz/@tao/110736805384878353\n--\n-- Essentially, for an arbitrary binary operation op, we prove that\n--\n-- @\n-- (x op x) op y == y op x\n-- @\n--\n-- Implies that @op@ must be commutative.\n-----------------------------------------------------------------------------\n\n\n{-# LANGUAGE DeriveAnyClass #-}\n{-# LANGUAGE DeriveDataTypeable #-}\n{-# LANGUAGE DataKinds #-}\n{-# LANGUAGE TypeAbstractions #-}\n{-# LANGUAGE StandaloneDeriving #-}\n{-# LANGUAGE TemplateHaskell #-}\n\n{-# OPTIONS_GHC -Wall -Werror #-}\n\nmodule Documentation.SBV.Examples.KnuckleDragger.Tao where\n\nimport Data.SBV\nimport Data.SBV.Tools.KnuckleDragger\n\n-- | Create an uninterpreted type to do the proofs over.\ndata T\nmkUninterpretedSort ''T\n\n-- | Prove that:\n--\n-- @\n-- (x op x) op y == y op x\n-- @\n--\n-- means that @op@ is commutative.\n--\n-- We have:\n--\n-- >>> tao\n-- Lemma: tao Q.E.D.\n-- [Proven] tao\ntao :: IO Proof\ntao = runKD $ do\n let op :: ST -> ST -> ST\n op = uninterpret \"op\"\n\n lemma \"tao\" ( quantifiedBool (\\(Forall @\"x\" x) (Forall @\"y\" y) -> ((x `op` x) `op` y) .== y `op` x)\n .=> quantifiedBool (\\(Forall @\"x\" x) (Forall @\"y\" y) -> (x `op` y) .== (y `op` x)))\n []\n"
-- |
-- Module : Documentation.SBV.Examples.KnuckleDragger.Tao
-- Copyright : (c) Levent Erkok
-- License : BSD3
-- Maintainer: [email protected]
-- Stability : experimental
--
-- Proves a problem originating in algebra:
-- https://mathoverflow.net/questions/450890/is-there-an-identity-between-the-commutative-identity-and-the-constant-identity/
--
-- Apparently this was posed by Terrence Tao: https://mathstodon.xyz/@tao/110736805384878353
--
-- Essentially, for an arbitrary binary operation op, we prove that
--
-- @
-- (x op x) op y == y op x
-- @
--
-- Implies that @op@ must be commutative.
-----------------------------------------------------------------------------


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

{-# OPTIONS_GHC -Wall -Werror #-}

module Documentation.SBV.Examples.KnuckleDragger.Tao where

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

-- | Create an uninterpreted type to do the proofs over.
data T
mkUninterpretedSort ''T

-- | Prove that:
--
-- @
-- (x op x) op y == y op x
-- @
--
-- means that @op@ is commutative.
--
-- We have:
--
-- >>> tao
-- Lemma: tao Q.E.D.
-- [Proven] tao
tao :: IO Proof
tao = runKD $ do
let op :: ST -> ST -> ST
op = uninterpret "op"

lemma "tao" ( quantifiedBool (\(Forall @"x" x) (Forall @"y" y) -> ((x `op` x) `op` y) .== y `op` x)
.=> quantifiedBool (\(Forall @"x" x) (Forall @"y" y) -> (x `op` y) .== (y `op` x)))
[]
1 change: 1 addition & 0 deletions sbv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Library
, Documentation.SBV.Examples.KnuckleDragger.ListLen
, Documentation.SBV.Examples.KnuckleDragger.RevLen
, Documentation.SBV.Examples.KnuckleDragger.Sqrt2IsIrrational
, Documentation.SBV.Examples.KnuckleDragger.Tao
, Documentation.SBV.Examples.Misc.Definitions
, Documentation.SBV.Examples.Misc.Enumerate
, Documentation.SBV.Examples.Misc.FirstOrderLogic
Expand Down

0 comments on commit cc2e013

Please sign in to comment.