-
Notifications
You must be signed in to change notification settings - Fork 18
/
ResolutionProver.scala
190 lines (157 loc) · 8.69 KB
/
ResolutionProver.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package gapt.provers
import gapt.expr._
import gapt.expr.formula.Atom
import gapt.expr.formula.Formula
import gapt.proofs.expansion.ExpansionProof
import gapt.proofs.expansion.ExpansionProofToLK
import gapt.proofs.expansion.deskolemizeET
import gapt.proofs.lk.LKProof
import gapt.proofs.resolution.Input
import gapt.proofs.resolution.ResolutionProof
import gapt.proofs.resolution.ResolutionToExpansionProof
import gapt.proofs.resolution.ResolutionToLKProof
import gapt.proofs.resolution.eliminateSplitting
import gapt.proofs.resolution.mapInputClauses
import gapt.proofs.resolution.structuralCNF
import gapt.proofs.ContextSection
import gapt.proofs.HOLClause
import gapt.proofs.HOLSequent
import gapt.proofs.Sequent
import gapt.proofs.context.Context
import gapt.proofs.context.mutable.MutableContext
import gapt.proofs.lk.rules.macros.WeakeningContractionMacroRule
import gapt.proofs.withSection
import gapt.utils.Maybe
trait ResolutionProver extends OneShotProver { self =>
override def getLKProof( seq: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[LKProof] = getLKProof( seq, addWeakenings = true )
def getLKProof( seq0: HOLSequent, addWeakenings: Boolean )( implicit ctx0: Maybe[MutableContext] ): Option[LKProof] = {
implicit val ctx: MutableContext = ctx0.getOrElse( MutableContext.guess( seq0 ) )
withSection { section =>
val seq = section.groundSequent( seq0 )
getResolutionProof( seq )( ctx ) map { resolution =>
val lk = ResolutionToLKProof( resolution )
if ( addWeakenings ) WeakeningContractionMacroRule( lk, seq )
else lk
}
}
}
override def isValid( seq: HOLSequent )( implicit ctx: Maybe[Context] ): Boolean =
getResolutionProof( seq )( ctx.map( _.newMutable ) ).isDefined
def getResolutionProof( cnf: Iterable[ResolutionProof] )( implicit ctx: Maybe[MutableContext], dummyImplicit: DummyImplicit ): Option[ResolutionProof] = {
val cnfMap = cnf.view.map( p => p.conclusion -> p ).toMap
getResolutionProof( cnfMap.keySet.map( _.map( _.asInstanceOf[Atom] ) ) ) map { resolution =>
mapInputClauses( resolution )( cnfMap )
}
}
def getResolutionProof( sequentSet: Iterable[HOLSequent] )( implicit ctx0: Maybe[MutableContext], dummyImplicit1: DummyImplicit, dummyImplicit2: DummyImplicit ): Option[ResolutionProof] = {
implicit val ctx = ctx0.getOrElse( MutableContext.guess( sequentSet )( dummyImplicit1 ) )
val cnf = structuralCNF.onProofs(
sequentSet.map( Input ).toSet,
propositional = false,
structural = true,
bidirectionalDefs = false,
cse = false )
getResolutionProof( cnf )( ctx, dummyImplicit1 )
}
def getResolutionProof( formula: Formula )( implicit ctx: Maybe[MutableContext] ): Option[ResolutionProof] = getResolutionProof( Sequent() :+ formula )
def getResolutionProof( seq: HOLSequent )( implicit ctx0: Maybe[MutableContext] ): Option[ResolutionProof] = {
val ctx = ctx0.getOrElse( MutableContext.guess( seq ) )
val section = new ContextSection( ctx )
val ground = section.groundSequent( seq )
val cnf = structuralCNF( ground, propositional = false )( ctx )
getResolutionProof( cnf )( ctx, implicitly )
}
def getResolutionProof( seq: Iterable[HOLClause] )( implicit ctx: Maybe[MutableContext] ): Option[ResolutionProof]
override def getExpansionProof( seq: HOLSequent )( implicit ctx0: Maybe[MutableContext] ): Option[ExpansionProof] = {
implicit val ctx: MutableContext = ctx0.getOrElse( MutableContext.guess( seq ) )
withSection { section =>
getResolutionProof( section.groundSequent( seq ) )( ctx ).map( ResolutionToExpansionProof( _ )( ctx ) )
}
}
def extendToManySortedViaPredicates = new ResolutionProver {
import gapt.proofs.reduction._
override def isValid( sequent: HOLSequent )( implicit ctx: Maybe[Context] ): Boolean = {
val reduction = CNFReductionLKRes |> PredicateReductionCNF |> ErasureReductionCNF
val ( folProblem, _ ) = reduction forward sequent
self.getResolutionProof( folProblem )( ctx.map( _.newMutable ) ).isDefined
}
override def getExpansionProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[ExpansionProof] = {
val reduction = PredicateReductionET |> ErasureReductionET
val ( folProblem, back ) = reduction forward sequent
self.getExpansionProof( folProblem ).map( back )
}
override def getLKProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[LKProof] = {
val reduction = CNFReductionLKRes |> PredicateReductionCNF |> ErasureReductionCNF
val ( folProblem, back ) = reduction forward sequent
self.getResolutionProof( folProblem ).map( proof => back( eliminateSplitting( proof ) ) )
}
override def getResolutionProof( seq: Iterable[HOLClause] )( implicit ctx: Maybe[MutableContext] ): Option[ResolutionProof] = {
val reduction = PredicateReductionCNF |> ErasureReductionCNF
val ( folProblem, back ) = reduction forward seq.toSet
self.getResolutionProof( folProblem ).map( eliminateSplitting( _ ) ).map( back )
}
override def toString = s"$self.extendToManySortedViaPredicates"
}
def extendToManySortedViaErasure = new ResolutionProver {
import gapt.proofs.reduction._
override def isValid( sequent: HOLSequent )( implicit ctx: Maybe[Context] ): Boolean = {
val reduction = CNFReductionLKRes |> ErasureReductionCNF
val ( folProblem, _ ) = reduction forward sequent
self.getResolutionProof( folProblem )( ctx.map( _.newMutable ) ).isDefined
}
override def getExpansionProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[ExpansionProof] = {
val reduction = ErasureReductionET
val ( folProblem, back ) = reduction forward sequent
self.getExpansionProof( folProblem ).map( back )
}
override def getLKProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[LKProof] = {
val reduction = CNFReductionLKRes |> ErasureReductionCNF
val ( folProblem, back ) = reduction forward sequent
self.getResolutionProof( folProblem ).map( proof => back( eliminateSplitting( proof ) ) )
}
override def getResolutionProof( seq: Iterable[HOLClause] )( implicit ctx: Maybe[MutableContext] ): Option[ResolutionProof] = {
val reduction = ErasureReductionCNF
val ( folProblem, back ) = reduction forward seq.toSet
self.getResolutionProof( folProblem ).map( eliminateSplitting( _ ) ).map( back )
}
override def toString = s"$self.extendToManySortedViaErasure"
}
def extendToManySortedViaTagging = new ResolutionProver {
import gapt.proofs.reduction._
override def isValid( sequent: HOLSequent )( implicit ctx: Maybe[Context] ): Boolean = {
val reduction = CNFReductionLKRes |> TagReductionCNF
val ( folProblem, _ ) = reduction forward sequent
self.getResolutionProof( folProblem )( ctx.map( _.newMutable ) ).isDefined
}
override def getExpansionProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[ExpansionProof] = {
val reduction = TagReductionET
val ( folProblem, back ) = reduction forward sequent
self.getExpansionProof( folProblem ).map( back )
}
override def getLKProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[LKProof] = {
val reduction = CNFReductionLKRes |> TagReductionCNF
val ( folProblem, back ) = reduction forward sequent
self.getResolutionProof( folProblem ).map( proof => back( eliminateSplitting( proof ) ) )
}
override def getResolutionProof( seq: Iterable[HOLClause] )( implicit ctx: Maybe[MutableContext] ): Option[ResolutionProof] = {
val reduction = TagReductionCNF
val ( folProblem, back ) = reduction forward seq.toSet
self.getResolutionProof( folProblem ).map( eliminateSplitting( _ ) ).map( back )
}
override def toString = s"$self.extendToManySortedViaTagging"
}
def withDeskolemization = new ResolutionProver {
override def isValid( sequent: HOLSequent )( implicit ctx: Maybe[Context] ): Boolean =
self.isValid( sequent )
override def getExpansionProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[ExpansionProof] =
self.getExpansionProof( sequent ).map( deskolemizeET( _ ) )
override def getLKProof( sequent: HOLSequent )( implicit ctx: Maybe[MutableContext] ): Option[LKProof] =
getExpansionProof( sequent ).flatMap( ep => ExpansionProofToLK( ep ) match {
case Right( lk ) => Some( lk )
case Left( _ ) => None
} )
override def getResolutionProof( seq: Iterable[HOLClause] )( implicit ctx: Maybe[MutableContext] ): Option[ResolutionProof] =
self.getResolutionProof( seq )
override def toString = s"$self.withDeskolemization"
}
}