@@ -290,12 +290,12 @@ simplifySequent sc ss (UnfocusedSequent hs gs) =
290
290
do (a, hs') <- simplifyProps sc ss hs
291
291
(b, gs') <- simplifyProps sc ss gs
292
292
return (Set. union a b, UnfocusedSequent hs' gs')
293
- simplifySequent sc ss (GoalFocusedSequent hs (gs1,g, gs2)) =
293
+ simplifySequent sc ss (GoalFocusedSequent hs (FB gs1 g gs2)) =
294
294
do (a, g') <- simplifyProp sc ss g
295
- return (a, GoalFocusedSequent hs (gs1, g', gs2))
296
- simplifySequent sc ss (HypFocusedSequent (hs1, h, hs2) gs) =
295
+ return (a, GoalFocusedSequent hs (FB gs1 g' gs2))
296
+ simplifySequent sc ss (HypFocusedSequent (FB hs1 h hs2) gs) =
297
297
do (a, h') <- simplifyProp sc ss h
298
- return (a, HypFocusedSequent (hs1, h', hs2) gs)
298
+ return (a, HypFocusedSequent (FB hs1 h' hs2) gs)
299
299
300
300
301
301
hoistIfsInGoal :: SharedContext -> Prop -> IO Prop
@@ -385,15 +385,17 @@ ppProp opts nenv (Prop tm) = ppTermWithNames opts nenv tm
385
385
-- TODO, I'd like to add metadata here
386
386
type SequentBranch = Prop
387
387
388
+ data FocusedBranch = FB ! [SequentBranch ] ! SequentBranch ! [SequentBranch ]
389
+
388
390
data Sequent
389
- = UnfocusedSequent [SequentBranch ] [SequentBranch ]
390
- | GoalFocusedSequent [SequentBranch ] ([ SequentBranch ], SequentBranch , [ SequentBranch ])
391
- | HypFocusedSequent ([ SequentBranch ], SequentBranch , [ SequentBranch ]) [SequentBranch ]
391
+ = UnfocusedSequent ! [SequentBranch ] ! [SequentBranch ]
392
+ | GoalFocusedSequent ! [SequentBranch ] ! FocusedBranch
393
+ | HypFocusedSequent ! FocusedBranch ! [SequentBranch ]
392
394
393
395
unfocus :: Sequent -> ([SequentBranch ],[SequentBranch ])
394
396
unfocus (UnfocusedSequent hs gs) = (hs,gs)
395
- unfocus (GoalFocusedSequent hs (gs1,g, gs2)) = (hs, gs1 ++ g : gs2)
396
- unfocus (HypFocusedSequent (hs1,h, hs2) gs) = (hs1 ++ h : hs2, gs)
397
+ unfocus (GoalFocusedSequent hs (FB gs1 g gs2)) = (hs, gs1 ++ g : gs2)
398
+ unfocus (HypFocusedSequent (FB hs1 h hs2) gs) = (hs1 ++ h : hs2, gs)
397
399
398
400
unfocusSequent :: Sequent -> Sequent
399
401
unfocusSequent sqt = UnfocusedSequent hs gs
@@ -403,22 +405,22 @@ focusOnGoal :: Integer -> Sequent -> Maybe Sequent
403
405
focusOnGoal i sqt =
404
406
let (hs,gs) = unfocus sqt in
405
407
case genericDrop i gs of
406
- (g: gs2) -> Just (GoalFocusedSequent hs (genericTake i gs, g, gs2))
408
+ (g: gs2) -> Just (GoalFocusedSequent hs (FB ( genericTake i gs) g gs2))
407
409
[] -> Nothing
408
410
409
411
focusOnHyp :: Integer -> Sequent -> Maybe Sequent
410
412
focusOnHyp i sqt =
411
413
let (hs,gs) = unfocus sqt in
412
414
case genericDrop i hs of
413
- (h: hs2) -> Just (HypFocusedSequent (genericTake i hs, h, hs2) gs)
415
+ (h: hs2) -> Just (HypFocusedSequent (FB ( genericTake i hs) h hs2) gs)
414
416
[] -> Nothing
415
417
416
418
sequentToRawSequent :: Sequent -> RawSequent Prop
417
419
sequentToRawSequent sqt =
418
420
case sqt of
419
- UnfocusedSequent hs gs -> RawSequent hs gs
420
- GoalFocusedSequent hs (gs1, g, gs2) -> RawSequent hs (gs1 ++ g : gs2)
421
- HypFocusedSequent (hs1, h, hs2) gs -> RawSequent (hs1 ++ h : hs2) gs
421
+ UnfocusedSequent hs gs -> RawSequent hs gs
422
+ GoalFocusedSequent hs (FB gs1 g gs2) -> RawSequent hs (gs1 ++ g : gs2)
423
+ HypFocusedSequent (FB hs1 h hs2) gs -> RawSequent (hs1 ++ h : hs2) gs
422
424
423
425
424
426
sequentConstantSet :: Sequent -> Map VarIndex (NameInfo , Term , Maybe Term )
@@ -454,21 +456,20 @@ convertibleSequents sc sqt1 sqt2 =
454
456
RawSequent hs2 gs2 = sequentToRawSequent sqt2
455
457
456
458
457
-
458
459
data SequentState
459
460
= Unfocused
460
461
| GoalFocus Prop (Prop -> Sequent )
461
462
| HypFocus Prop (Prop -> Sequent )
462
463
463
464
propToSequent :: Prop -> Sequent
464
- propToSequent p = GoalFocusedSequent [] ([] , p, [] )
465
+ propToSequent p = GoalFocusedSequent [] (FB [] p [] )
465
466
466
467
booleansToSequent :: SharedContext -> [Term ] -> [Term ] -> IO Sequent
467
468
booleansToSequent sc hs gs =
468
469
do hs' <- mapM (boolToProp sc [] ) hs
469
470
gs' <- mapM (boolToProp sc [] ) gs
470
471
case gs' of
471
- [g] -> return (GoalFocusedSequent hs' ([] ,g, [] ))
472
+ [g] -> return (GoalFocusedSequent hs' (FB [] g [] ))
472
473
_ -> return (UnfocusedSequent hs' gs')
473
474
474
475
sequentToProp :: SharedContext -> Sequent -> IO Prop
@@ -508,15 +509,15 @@ ppRawSequent sqt (RawSequent hs gs) =
508
509
turnstile = [ pretty (take 40 (repeat ' =' )) ]
509
510
focused doc = " <<" <> doc <> " >>"
510
511
ppHyp (i, tm)
511
- | HypFocusedSequent (hs1,_h, _hs2) _gs <- sqt
512
+ | HypFocusedSequent (FB hs1 _h _hs2) _gs <- sqt
512
513
, length hs1 == i
513
514
= focused (" H" <> pretty i) <+> tm
514
515
515
516
| otherwise
516
517
= " H" <> pretty i <> " :" <+> tm
517
518
518
519
ppGoal (i, tm)
519
- | GoalFocusedSequent _hs (gs1,_g, _gs2) <- sqt
520
+ | GoalFocusedSequent _hs (FB gs1 _g _gs2) <- sqt
520
521
, length gs1 == i
521
522
= focused (" G" <> pretty i) <+> tm
522
523
@@ -537,10 +538,10 @@ filterPosList pss xs = map snd $ filter f $ zip [0..] xs
537
538
where
538
539
f (i,_) = cofinSetMember i pss
539
540
540
- filterFocusedList :: CofinSet Integer -> ([ a ], a ,[ a ]) -> Either [a ] ([ a ], a ,[ a ])
541
- filterFocusedList pss (xs1,x, xs2) =
541
+ filterFocusedList :: CofinSet Integer -> FocusedBranch -> Either [SequentBranch ] FocusedBranch
542
+ filterFocusedList pss (FB xs1 x xs2) =
542
543
if cofinSetMember idx pss then
543
- Right (xs1',x, xs2')
544
+ Right (FB xs1' x xs2')
544
545
else
545
546
Left (xs1' ++ xs2')
546
547
where
@@ -572,19 +573,19 @@ filterGoals pss (GoalFocusedSequent hs gs) =
572
573
addHypothesis :: Prop -> Sequent -> Sequent
573
574
addHypothesis p (UnfocusedSequent hs gs) = UnfocusedSequent (hs ++ [p]) gs
574
575
addHypothesis p (GoalFocusedSequent hs gs) = GoalFocusedSequent (hs ++ [p]) gs
575
- addHypothesis p (HypFocusedSequent (hs1,h, hs2) gs) = HypFocusedSequent (hs1,h, hs2++ [p]) gs
576
+ addHypothesis p (HypFocusedSequent (FB hs1 h hs2) gs) = HypFocusedSequent (FB hs1 h ( hs2++ [p]) ) gs
576
577
577
578
addNewFocusedGoal :: Prop -> Sequent -> Sequent
578
579
addNewFocusedGoal p sqt =
579
580
let RawSequent hs gs = sequentToRawSequent sqt
580
- in GoalFocusedSequent hs (gs,p, [] )
581
+ in GoalFocusedSequent hs (FB gs p [] )
581
582
582
583
sequentState :: Sequent -> SequentState
583
584
sequentState (UnfocusedSequent _ _) = Unfocused
584
- sequentState (GoalFocusedSequent hs (gs1,g, gs2)) =
585
- GoalFocus g (\ g' -> GoalFocusedSequent hs (gs1,g', gs2))
586
- sequentState (HypFocusedSequent (hs1,h, hs2) gs) =
587
- HypFocus h (\ h' -> HypFocusedSequent (hs1,h', hs2) gs)
585
+ sequentState (GoalFocusedSequent hs (FB gs1 g gs2)) =
586
+ GoalFocus g (\ g' -> GoalFocusedSequent hs (FB gs1 g' gs2))
587
+ sequentState (HypFocusedSequent (FB hs1 h hs2) gs) =
588
+ HypFocus h (\ h' -> HypFocusedSequent (FB hs1 h' hs2) gs)
588
589
589
590
sequentSharedSize :: Sequent -> Integer
590
591
sequentSharedSize sqt = scSharedSizeMany (map unProp (hs ++ gs))
@@ -599,34 +600,34 @@ sequentTreeSize sqt = scTreeSizeMany (map unProp (hs ++ gs))
599
600
traverseSequentWithFocus :: Applicative m => (Prop -> m Prop ) -> Sequent -> m Sequent
600
601
traverseSequentWithFocus f (UnfocusedSequent hs gs) =
601
602
UnfocusedSequent <$> traverse f hs <*> traverse f gs
602
- traverseSequentWithFocus f (GoalFocusedSequent hs (gs1, g, gs2)) =
603
- (\ g' -> GoalFocusedSequent hs (gs1, g', gs2)) <$> f g
604
- traverseSequentWithFocus f (HypFocusedSequent (hs1, h, hs2) gs) =
605
- (\ h' -> HypFocusedSequent (hs1, h', hs2) gs) <$> f h
603
+ traverseSequentWithFocus f (GoalFocusedSequent hs (FB gs1 g gs2)) =
604
+ (\ g' -> GoalFocusedSequent hs (FB gs1 g' gs2)) <$> f g
605
+ traverseSequentWithFocus f (HypFocusedSequent (FB hs1 h hs2) gs) =
606
+ (\ h' -> HypFocusedSequent (FB hs1 h' hs2) gs) <$> f h
606
607
607
608
traverseSequent :: Applicative m => (Prop -> m Prop ) -> Sequent -> m Sequent
608
609
traverseSequent f (UnfocusedSequent hs gs) =
609
610
UnfocusedSequent <$> traverse f hs <*> traverse f gs
610
- traverseSequent f (GoalFocusedSequent hs (gs1, g, gs2)) =
611
+ traverseSequent f (GoalFocusedSequent hs (FB gs1 g gs2)) =
611
612
GoalFocusedSequent <$>
612
613
(traverse f hs) <*>
613
- ( (,,) <$> traverse f gs1 <*> f g <*> traverse f gs2)
614
+ ( FB <$> traverse f gs1 <*> f g <*> traverse f gs2)
614
615
615
- traverseSequent f (HypFocusedSequent (hs1, h, hs2) gs) =
616
+ traverseSequent f (HypFocusedSequent (FB hs1 h hs2) gs) =
616
617
HypFocusedSequent <$>
617
- ( (,,) <$> traverse f hs1 <*> f h <*> traverse f hs2) <*>
618
+ ( FB <$> traverse f hs1 <*> f h <*> traverse f hs2) <*>
618
619
(traverse f gs)
619
620
620
621
checkSequent :: SharedContext -> PPOpts -> Sequent -> IO ()
621
622
checkSequent sc ppOpts (UnfocusedSequent hs gs) =
622
623
do forM_ hs (checkProp sc ppOpts)
623
624
forM_ gs (checkProp sc ppOpts)
624
- checkSequent sc ppOpts (GoalFocusedSequent hs (gs1,g, gs2)) =
625
+ checkSequent sc ppOpts (GoalFocusedSequent hs (FB gs1 g gs2)) =
625
626
do forM_ hs (checkProp sc ppOpts)
626
627
forM_ gs1 (checkProp sc ppOpts)
627
628
checkProp sc ppOpts g
628
629
forM_ gs2 (checkProp sc ppOpts)
629
- checkSequent sc ppOpts (HypFocusedSequent (hs1,h, hs2) gs) =
630
+ checkSequent sc ppOpts (HypFocusedSequent (FB hs1 h hs2) gs) =
630
631
do forM_ hs1 (checkProp sc ppOpts)
631
632
checkProp sc ppOpts h
632
633
forM_ hs2 (checkProp sc ppOpts)
@@ -740,42 +741,42 @@ instance Semigroup TheoremSummary where
740
741
data Evidence
741
742
= -- | The given term provides a direct programs-as-proofs witness
742
743
-- for the truth of its type (qua proposition).
743
- ProofTerm Term
744
+ ProofTerm ! Term
744
745
745
746
-- | This type of evidence refers to a local assumption that
746
747
-- must have been introduced by a surrounding @AssumeEvidence@
747
748
-- constructor.
748
- | LocalAssumptionEvidence Prop TheoremNonce
749
+ | LocalAssumptionEvidence ! Prop ! TheoremNonce
749
750
750
751
-- | This type of evidence is produced when the given proposition
751
752
-- has been dispatched to a solver which has indicated that it
752
753
-- was able to prove the proposition. The included @SolverStats@
753
754
-- give some details about the solver run.
754
- | SolverEvidence SolverStats Sequent
755
+ | SolverEvidence ! SolverStats ! Sequent
755
756
756
757
-- | This type of evidence is produced when the given proposition
757
758
-- has been randomly tested against input vectors in the style
758
759
-- of quickcheck. The included number is the number of successfully
759
760
-- passed test vectors.
760
- | QuickcheckEvidence Integer Sequent
761
+ | QuickcheckEvidence ! Integer ! Sequent
761
762
762
763
-- | This type of evidence is produced when the given proposition
763
764
-- has been explicitly assumed without other evidence at the
764
765
-- user's direction.
765
- | Admitted Text Pos Sequent
766
+ | Admitted ! Text ! Pos ! Sequent
766
767
767
768
-- | This type of evidence is produced when a proposition can be deconstructed
768
769
-- along a conjunction into two subgoals, each of which is supported by
769
770
-- the included evidence.
770
- | SplitEvidence Evidence Evidence
771
+ | SplitEvidence ! Evidence ! Evidence
771
772
772
773
-- | This type of evidence is produced when a previously-proved theorem is
773
774
-- applied via backward reasoning to prove a goal. Pi-quantified variables
774
775
-- of the theorem may be specialized either by giving an explicit @Term@ to
775
776
-- instantiate the variable, or by giving @Evidence@ for @Prop@ hypotheses.
776
777
-- After specializing the given @Theorem@ the result must match the
777
778
-- current goal.
778
- | ApplyEvidence Theorem [Either Term Evidence ]
779
+ | ApplyEvidence ! Theorem ! [Either Term Evidence ]
779
780
780
781
-- | This type of evidence is used to prove an implication. The included
781
782
-- proposition must match the hypothesis of the goal, and the included
@@ -784,53 +785,53 @@ data Evidence
784
785
-- | AssumeEvidence TheoremNonce Prop Evidence
785
786
786
787
-- | This type of evidence is used to prove a universally-quantified statement.
787
- | IntroEvidence (ExtCns Term ) Evidence
788
+ | IntroEvidence ! (ExtCns Term ) ! Evidence
788
789
789
790
-- | This type of evidence is used to apply the "cut rule" of sequent calculus.
790
791
-- The given proposition is added to the hypothesis list in the first
791
792
-- deriviation, and into the conclusion list in the second, where it is focused.
792
- | CutEvidence Prop Evidence Evidence
793
+ | CutEvidence ! Prop ! Evidence ! Evidence
793
794
794
795
-- | This type of evidence is used to modify a goal to prove via rewriting.
795
796
-- The goal to prove is rewritten by the given simpset; then the provided
796
797
-- evidence is used to check the modified goal.
797
- | RewriteEvidence (Simpset TheoremNonce ) Evidence
798
+ | RewriteEvidence ! (Simpset TheoremNonce ) ! Evidence
798
799
799
800
-- | This type of evidence is used to modify a goal to prove via unfolding
800
801
-- constant definitions. The goal to prove is modified by unfolding
801
802
-- constants identified via the given set of @VarIndex@; then the provided
802
803
-- evidence is used to check the modified goal.
803
- | UnfoldEvidence (Set VarIndex ) Evidence
804
+ | UnfoldEvidence ! (Set VarIndex ) ! Evidence
804
805
805
806
-- | This type of evidence is used to modify a goal to prove via evaluation
806
807
-- into the the What4 formula representation. During evaluation, the
807
808
-- constants identified by the given set of @VarIndex@ are held
808
809
-- uninterpreted (i.e., will not be unfolded). Then, the provided
809
810
-- evidence is use to check the modified goal.
810
- | EvalEvidence (Set VarIndex ) Evidence
811
+ | EvalEvidence ! (Set VarIndex ) ! Evidence
811
812
812
813
-- | This type of evidence is used to modify a focused part of the goal.
813
814
-- The modified goal should be equivalent up to conversion.
814
- | ConversionEvidence Sequent Evidence
815
+ | ConversionEvidence ! Sequent ! Evidence
815
816
816
817
-- | This type of evidence is used to modify a goal to prove by applying
817
818
-- 'hoistIfsInGoal'.
818
- | HoistIfsEvidence Evidence
819
+ | HoistIfsEvidence ! Evidence
819
820
820
821
-- | Change the state of the sequent in some "structural" way. This
821
822
-- can involve changing focus, reordering or applying weakening rules.
822
- | StructuralEvidence Sequent Evidence
823
+ | StructuralEvidence ! Sequent ! Evidence
823
824
824
825
-- | Change the state of the sequent in some way that is governed by
825
826
-- the "reversable" L/R rules of the sequent calculus, e.g.,
826
827
-- conjunctions in hypotheses can be split into multiple hypotheses,
827
828
-- negated conclusions become positive hypotheses, etc.
828
- | NormalizeSequentEvidence Sequent Evidence
829
+ | NormalizeSequentEvidence ! Sequent ! Evidence
829
830
830
831
-- | Change the sate of th sequent by invoking the term evaluator
831
832
-- on the focused sequent branch (or all branches, if unfocused).
832
833
-- Treat the given variable indexes as opaque.
833
- | NormalizePropEvidence (Set VarIndex ) Evidence
834
+ | NormalizePropEvidence ! (Set VarIndex ) ! Evidence
834
835
835
836
-- | This type of evidence is used when the current sequent, after
836
837
-- applying structural rules, is an instance of the basic
@@ -1044,7 +1045,7 @@ data ProofGoal =
1044
1045
, goalLoc :: String
1045
1046
, goalDesc :: String
1046
1047
, goalTags :: Set String
1047
- , goalSequent :: Sequent
1048
+ , goalSequent :: ! Sequent
1048
1049
}
1049
1050
1050
1051
@@ -1080,11 +1081,11 @@ predicateToProp sc quant = loop []
1080
1081
Prop <$> toPi argTs t
1081
1082
1082
1083
1083
- -- | A ProofState represents a sequent, where the collection of goals
1084
- -- implies the conclusion.
1084
+ -- | A ProofState consists of a sequents of goals, represented by sequents.
1085
+ -- If each subgoal is provable, that implies the ultimate conclusion.
1085
1086
data ProofState =
1086
1087
ProofState
1087
- { _psGoals :: [ProofGoal ]
1088
+ { _psGoals :: ! [ProofGoal ]
1088
1089
, _psConcl :: (Sequent ,Pos ,Maybe ProgramLoc ,Text )
1089
1090
, _psStats :: SolverStats
1090
1091
, _psTimeout :: Maybe Integer
@@ -1541,7 +1542,8 @@ withFirstGoal (Tactic f) (ProofState goals concl stats timeout evidenceCont star
1541
1542
do let (es1, es2) = splitAt (length gs') es
1542
1543
e <- buildTacticEvidence es1
1543
1544
evidenceCont (e: es2)
1544
- return (Right (x, ProofState (gs' <> gs) concl (stats <> stats') timeout evidenceCont' start))
1545
+ let ps' = ProofState (gs' <> gs) concl (stats <> stats') timeout evidenceCont' start
1546
+ seq ps' (return (Right (x, ps')))
1545
1547
1546
1548
predicateToSATQuery :: SharedContext -> Set VarIndex -> Term -> IO SATQuery
1547
1549
predicateToSATQuery sc unintSet tm0 =
0 commit comments