Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
LeventErkok committed Sep 16, 2024
1 parent 8eb1c1f commit d40ee8c
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions Documentation/SBV/Examples/Uninterpreted/AUF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-- Maintainer: [email protected]
-- Stability : experimental
--
-- Formalizes and proves the following theorem, about arithmetic,
-- Formalizes and proves the following theorem about arithmetic,
-- uninterpreted functions, and arrays. (For reference, see <http://research.microsoft.com/en-us/um/redmond/projects/z3/fmcad06-slides.pdf>
-- slide number 24):
--
Expand All @@ -27,6 +27,7 @@
-- The function @read@ and @write@ are usual array operations.
-----------------------------------------------------------------------------

{-# LANGUAGE CPP #-}
{-# LANGUAGE ScopedTypeVariables #-}

{-# OPTIONS_GHC -Wall -Werror #-}
Expand All @@ -35,30 +36,22 @@ module Documentation.SBV.Examples.Uninterpreted.AUF where

import Data.SBV

--------------------------------------------------------------
-- * Model using functional arrays
--------------------------------------------------------------
#ifndef HADDOCK
-- $setup
-- >>> -- For doctest purposes only:
-- >>> import Data.SBV
#endif

-- | Uninterpreted function in the theorem
f :: SWord32 -> SWord64
f = uninterpret "f"

-- | Correctness theorem. We state it for all values of @x@, @y@, and
-- the given array @a@. Note that we're being generic in the type of
-- array we're expecting.
-- | Correctness theorem. We state it for all values of @x@, @y@, and the given array @a@. We have:
--
-- >>> prove thm
-- Q.E.D.
thm :: SWord32 -> SWord32 -> SArray Word32 Word32 -> SBool
thm x y a = lhs .=> rhs
where lhs = x + 2 .== y
rhs = f (readArray (writeArray a x 3) (y - 2))
.== f (y - x + 1)

-- | Prove it using SMT-Lib arrays.
--
-- >>> proveSArray
-- Q.E.D.
proveSArray :: IO ThmResult
proveSArray = prove $ do
x <- free "x"
y <- free "y"
a :: SArray Word32 Word32 <- sArray_
return $ thm x y a

0 comments on commit d40ee8c

Please sign in to comment.