Skip to content

Commit bce4c10

Browse files
committed
copilot-theorem: Preserve proposition quantifiers. Refs #254.
Currently, `copilot-language` remembers whether a proposition (i.e., a stream of booleans) is quantified universally (i.e., using `forAll`) or existentially (i.e., using `exists`). When translating from `copilot-language` to `copilot-core`, however, the quantifier is discarded. This means that a `copilot-core` `Property` does not record any quantifier information at all, making it impossible for downstream libraries that use `copilot-core` to handle universal quantification differently from existential quantification. Now that `copilot-core` preserves quantifier information in its API, this commit updates `copilot-theorem` to make use of quantifier information when proving theorems.
1 parent 8e46a13 commit bce4c10

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

copilot-theorem/src/Copilot/Theorem/IL/Translate.hs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,13 @@ translate' b (C.Spec {C.specStreams, C.specProperties}) = runTrans b $ do
6363
localConstraints <- popLocalConstraints
6464
properties <- Map.fromList <$>
6565
forM specProperties
66-
(\(C.Property {C.propertyName, C.propertyExpr}) -> do
67-
e' <- expr propertyExpr
66+
(\(C.Property {C.propertyName, C.propertyProp}) -> do
67+
-- Soundness note: it is OK to call `extractProp` here to drop the
68+
-- quantifier from the proposition `propertyProp`. This is because we
69+
-- IL translation always occurs within the context of a function that
70+
-- returns a `Proof`, and these `Proof` functions are always careful to
71+
-- use `Prover`s that respect the propositions's quantifier.
72+
e' <- expr (C.extractProp propertyProp)
6873
propConds <- popLocalConstraints
6974
return (propertyName, (propConds, e')))
7075

copilot-theorem/src/Copilot/Theorem/TransSys/Translate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ streamOfProp :: C.Property -> C.Stream
139139
streamOfProp prop =
140140
C.Stream { C.streamId = 42
141141
, C.streamBuffer = []
142-
, C.streamExpr = C.propertyExpr prop
142+
, C.streamExpr = C.extractProp (C.propertyProp prop)
143143
, C.streamExprType = C.Bool }
144144

145145
stream :: C.Stream -> Trans Node

copilot-theorem/src/Copilot/Theorem/What4.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,18 @@ proveInternal solver spec k = do
350350
-- This process performs k-induction where we use @k = maxBufLen@.
351351
-- The choice for @k@ is heuristic, but often effective.
352352
let proveProperties = forM (CS.specProperties spec) $ \pr -> do
353+
let prop = CS.extractProp (CS.propertyProp pr)
353354
-- State the base cases for k induction.
354355
base_cases <- forM [0 .. maxBufLen - 1] $ \i -> do
355-
xe <- translateExpr sym mempty (CS.propertyExpr pr) (AbsoluteOffset i)
356+
xe <- translateExpr sym mempty prop (AbsoluteOffset i)
356357
case xe of
357358
XBool p -> return p
358359
_ -> expectedBool "Property" xe
359360

360361
-- Translate the induction hypothesis for all values up to maxBufLen in
361362
-- the past
362363
ind_hyps <- forM [0 .. maxBufLen-1] $ \i -> do
363-
xe <- translateExpr sym mempty (CS.propertyExpr pr) (RelativeOffset i)
364+
xe <- translateExpr sym mempty prop (RelativeOffset i)
364365
case xe of
365366
XBool hyp -> return hyp
366367
_ -> expectedBool "Property" xe
@@ -369,7 +370,7 @@ proveInternal solver spec k = do
369370
ind_goal <- do
370371
xe <- translateExpr sym
371372
mempty
372-
(CS.propertyExpr pr)
373+
prop
373374
(RelativeOffset maxBufLen)
374375
case xe of
375376
XBool p -> return p
@@ -599,7 +600,7 @@ computeAssumptions sym properties spec =
599600
-- user-provided property assumptions.
600601
specPropertyExprs :: [CE.Expr Bool]
601602
specPropertyExprs =
602-
[ CS.propertyExpr p
603+
[ CS.extractProp (CS.propertyProp p)
603604
| p <- CS.specProperties spec
604605
, elem (CS.propertyName p) properties
605606
]

copilot-theorem/tests/Test/Copilot/Theorem/What4.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ checkCounterExample solver propName spec cexPred = do
251251
-- contains the given streams, and is defined by the given boolean expression.
252252
propSpec :: String -> [Stream] -> Expr Bool -> Spec
253253
propSpec propName propStreams propExpr =
254-
Spec propStreams [] [] [Copilot.Property propName propExpr]
254+
Spec propStreams [] [] [Copilot.Property propName (Copilot.Forall propExpr)]
255255

256256
-- | Equality for 'SatResult'.
257257
--

0 commit comments

Comments
 (0)