Skip to content

Commit 07c4f3d

Browse files
Fix and improve kernel2code and asFront methods
1 parent cdd2c12 commit 07c4f3d

File tree

6 files changed

+32
-52
lines changed

6 files changed

+32
-52
lines changed

lisa-examples/src/main/scala/Kernel2Code.scala

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -209,63 +209,48 @@ object Kernel2Code extends lisa.Main {
209209
}
210210
val s_2 = have((x_1, (Q(x_1) ==> Q(f(x_1)))) (Q(f(x)) ==> Q(f(f(x))))) subproof {
211211
val s_2_0 = have((x_1, (Q(x_1) ==> Q(f(x_1)))) (Q(f(x)) ==> Q(f(f(x))))) by InstFunSchema(Map(x -> f(x)))(s_1)
212+
val s_2_1 = have((x_1, (Q(x_1) ==> Q(f(x_1)))) (Q(f(x)) ==> Q(f(f(x))))) by InstFunSchema(Map(x -> f(x)))(s_1)
212213
}
213214
val s_3 = have((x, (Q(x) ==> Q(f(x)))) (Q(x) ==> Q(f(f(x))))) subproof {
214215
val s_3_0 = have(() ((x, (Q(x) ==> Q(f(x)))) ==> (Q(x) ==> Q(f(x))))) by Restate.from(s_1)
215216
val s_3_1 = have(() ((x_1, (Q(x_1) ==> Q(f(x_1)))) ==> (Q(f(x)) ==> Q(f(f(x)))))) by Restate.from(s_2)
216217
val s_3_2 = have(((x, (Q(x) ==> Q(f(x)))), ((x, (Q(x) ==> Q(f(x)))) ==> (Q(x) ==> Q(f(x)))), ((x_1, (Q(x_1) ==> Q(f(x_1)))) ==> (Q(f(x)) ==> Q(f(f(x)))))) (Q(x) ==> Q(f(f(x))))) subproof {
217218
val s_3_2_0 = have(
218-
Q(f(x)) ¬(((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬()))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x))))))
219+
Q(f(x)) ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬())) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
219220
) by Restate
220221
val s_3_2_1 = thenHave(
221-
Q(f(x)) ¬(
222-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
223-
)
224-
) by RightSubstIff(
222+
Q(f(x)) ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
223+
) by RightSubstIff.withParametersSimple(
225224
List(((Q(f(x))), ())),
226225
lambda(
227226
Seq(MaRvIn_1),
228-
¬(
229-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) MaRvIn_1) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(MaRvIn_1)))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(
230-
Q(f(f(x)))
231-
))
232-
)
227+
¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) MaRvIn_1 ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(MaRvIn_1))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
233228
)
234229
)
235230
val s_3_2_2 = have(
236-
¬(Q(f(x))) ¬(
237-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬()))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
238-
)
231+
¬(Q(f(x))) ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬())) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
239232
) by Restate
240233
val s_3_2_3 = thenHave(
241234
¬(Q(f(x))) ¬(
242-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
235+
(¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x)))))
243236
)
244-
) by RightSubstIff(
237+
) by RightSubstIff.withParametersSimple(
245238
List(((Q(f(x))), ())),
246239
lambda(
247240
Seq(MaRvIn_1),
248-
¬(
249-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) MaRvIn_1) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(MaRvIn_1)))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(
250-
Q(f(f(x)))
251-
))
252-
)
241+
¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) MaRvIn_1 ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(MaRvIn_1))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
253242
)
254243
)
255244
val s_3_2_4 = thenHave(
256245
() (Q(f(x)), ¬(
257-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
246+
(¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x)))))
258247
))
259248
) by Restate
260249
val s_3_2_5 = have(
261-
() ¬(
262-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
263-
)
250+
() ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
264251
) by Cut(s_3_2_4, s_3_2_1)
265252
val s_3_2_6 = thenHave(
266-
() ¬(
267-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
268-
)
253+
() ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
269254
) by Restate
270255
val s_3_2_7 =
271256
thenHave(((x, (Q(x) ==> Q(f(x)))), ((x, (Q(x) ==> Q(f(x)))) ==> (Q(x) ==> Q(f(x)))), ((x_1, (Q(x_1) ==> Q(f(x_1)))) ==> (Q(f(x)) ==> Q(f(f(x)))))) (Q(x) ==> Q(f(f(x))))) by Restate
@@ -282,25 +267,21 @@ object Kernel2Code extends lisa.Main {
282267
val s_3 = have(() ((x, (Q(x) ==> Q(f(x)))) ==> (Q(x) ==> Q(f(x))))) by Restate.from(s_1)
283268
val s_4 = have(() ((x_1, (Q(x_1) ==> Q(f(x_1)))) ==> (Q(f(x)) ==> Q(f(f(x)))))) by Restate.from(s_2)
284269
val s_5 = have(
285-
Q(f(x)) ¬(((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬()))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x))))))
270+
Q(f(x)) ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬())) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
286271
) by Restate
287272
val s_6 = thenHave(
288-
Q(f(x)) ¬(
289-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
290-
)
273+
Q(f(x)) ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
291274
) by Restate
292275
val s_7 = have(
293-
¬(Q(f(x))) ¬(((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬()))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x))))))
276+
¬(Q(f(x))) ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬())) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
294277
) by Restate
295278
val s_8 = thenHave(
296279
() (Q(f(x)), ¬(
297-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
280+
(¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x)))))
298281
))
299282
) by Restate
300283
val s_9 = have(
301-
() ¬(
302-
((((¬((((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x))) ¬(Q(f(f(x)))))) ¬((((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x)) ¬(Q(f(x)))))) (x, ¬((Q(x) ¬(Q(f(x))))))) Q(x)) ¬(Q(f(f(x)))))
303-
)
284+
() ¬((¬(((x_1, ¬((Q(x_1) ¬(Q(f(x_1)))))) Q(f(x)) ¬(Q(f(f(x)))))) ¬(((x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(x))))) (x, ¬((Q(x) ¬(Q(f(x)))))) Q(x) ¬(Q(f(f(x))))))
304285
) by Cut(s_8, s_6)
305286
val s_10 = thenHave(((x, (Q(x) ==> Q(f(x)))), ((x, (Q(x) ==> Q(f(x)))) ==> (Q(x) ==> Q(f(x)))), ((x_1, (Q(x_1) ==> Q(f(x_1)))) ==> (Q(f(x)) ==> Q(f(f(x)))))) (Q(x) ==> Q(f(f(x))))) by Restate
306287
val s_11 = have(((x, (Q(x) ==> Q(f(x)))), ((x_1, (Q(x_1) ==> Q(f(x_1)))) ==> (Q(f(x)) ==> Q(f(f(x)))))) (Q(x) ==> Q(f(f(x))))) by Cut(s_3, s_10)

lisa-utils/src/main/scala/lisa/fol/Common.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,11 @@ trait Common {
708708
def rename(newid: Identifier): ConstantConnectorLabel[N] = throw new Error("Can't rename a constant connector label")
709709
def freshRename(taken: Iterable[Identifier]): ConstantConnectorLabel[N] = rename(K.freshId(taken, id))
710710
override def toString(): String = id
711-
def mkString(args: Seq[Formula]): String = if (args.length == 2) (args(0).toString() + " " + toString() + " " + args(1).toString()) else toString() + "(" + args.mkString(", ") + ")"
711+
def mkString(args: Seq[Formula]): String = if (args.length == 1) {
712+
underlyingLabel match
713+
case K.Neg => toString() + "(" + args(0).toString() + ")"
714+
case _ => args(0).toString()
715+
} else "(" + args.mkString(" " + toString() + " ") + ")"
712716
override def mkStringSeparated(args: Seq[Formula]): String = if (args.length == 2) "(" + mkString(args) + ")" else mkString(args)
713717

714718
}

lisa-utils/src/main/scala/lisa/fol/FOLHelpers.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ object FOLHelpers {
118118
def asFront(pf: K.AtomicFormula): Formula =
119119
asFrontLabel(pf.label).applySeq(pf.args.map(asFront))
120120
def asFront(cf: K.ConnectorFormula): Formula =
121-
cf.label match
122-
case K.And | K.Or if cf.args.size == 1 => asFront(cf.args(0))
123-
case K.And | K.Or => cf.args.map(asFront).reduceLeft((a, b) => asFrontLabel(cf.label)(Seq(a, b))) // TODO: handle this more gracefully
124-
case _ => asFrontLabel(cf.label).applyUnsafe(cf.args.map(asFront))
121+
asFrontLabel(cf.label).applyUnsafe(cf.args.map(asFront))
125122
def asFront(bf: K.BinderFormula): BinderFormula =
126123
asFrontLabel(bf.label).apply(asFrontLabel(bf.bound), asFront(bf.inner))
127124

lisa-utils/src/main/scala/lisa/fol/Sequents.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ trait Sequents extends Common with lisa.fol.Lambdas with Predef {
168168
infix def ++?(s1: Sequent): Sequent = this addAllIfNotExists s1
169169

170170
override def toString =
171-
(if left.size == 0 then "" else if left.size == 1 then left.head.toString else "( " + left.mkString(", ") + " )") +
171+
(if left.size == 0 then "" else if left.size == 1 then left.head.toString else "(" + left.mkString(", ") + ")") +
172172
"" +
173-
(if right.size == 0 then "" else if right.size == 1 then right.head.toString else "( " + right.mkString(", ") + " )")
173+
(if right.size == 0 then "" else if right.size == 1 then right.head.toString else "(" + right.mkString(", ") + ")")
174174

175175
}
176176

lisa-utils/src/main/scala/lisa/utils/ProofsConverter.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import lisa.utils.KernelHelpers.lambda
99

1010
object ProofsConverter {
1111

12-
// TODO: fix printing of ∧ and ∨ with > 2 arguments, currently handled as recursive binary operators (see FOLHelpers.scala)
1312
// TODO: remove unnecessary variables "val s_..." in generated proofs -> need to keep track of which steps are used in other steps
1413
// TODO: generate more realistic variable names
1514
// TODO: handle automatic global variable declaration before theorems/proofs
@@ -65,14 +64,14 @@ object ProofsConverter {
6564
case LeftSubstEq(bot, t1, equals, lambdaPhi) => (bot, Seq(t1))
6665
case RightSubstEq(bot, t1, equals, lambdaPhi) => (bot, Seq(t1))
6766
case LeftSubstIff(bot, t1, equals, lambdaPhi) =>
68-
tacticName = s"LeftSubstIff(List(${equals
69-
.map((a, b) => s"((${formula2code(a)}), (${formula2code(b)}))")
70-
.mkString(", ")}), lambda(Seq(${lambdaPhi.vars.map(asFrontLabel).mkString(", ")}), ${formula2code(lambdaPhi.body)}))"
67+
tacticName = s"LeftSubstIff.withParametersSimple(List(${equals
68+
.map((a, b) => s"((${formula2code(a.body)}), (${formula2code(b.body)}))")
69+
.mkString(", ")}), lambda(Seq(${lambdaPhi._1.map(asFrontLabel).mkString(", ")}), ${formula2code(lambdaPhi._2)}))"
7170
(bot, Seq(t1))
7271
case RightSubstIff(bot, t1, equals, lambdaPhi) =>
73-
tacticName = s"RightSubstIff(List(${equals
74-
.map((a, b) => s"((${formula2code(a)}), (${formula2code(b)}))")
75-
.mkString(", ")}), lambda(Seq(${lambdaPhi.vars.map(asFrontLabel).mkString(", ")}), ${formula2code(lambdaPhi.body)}))"
72+
tacticName = s"RightSubstIff.withParametersSimple(List(${equals
73+
.map((a, b) => s"((${formula2code(a.body)}), (${formula2code(b.body)}))")
74+
.mkString(", ")}), lambda(Seq(${lambdaPhi._1.map(asFrontLabel).mkString(", ")}), ${formula2code(lambdaPhi._2)}))"
7675
(bot, Seq(t1))
7776
case InstSchema(bot, t1, mCon, mPred, mTerm) =>
7877
if mCon.isEmpty && mPred.isEmpty then

lisa-utils/src/main/scala/lisa/utils/tptp/ProblemGatherer.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import lisa.utils.tptp.KernelParser.*
44

55
object ProblemGatherer {
66
// Path to the TPTP problems directory
7-
// val path = getClass.getResource("/TPTP/Problems/").getPath
8-
val TPTPProblemPath = "/home/auguste/Documents/EPFL/PhD/Projects/TPTP-v8.2.0/Problems/"
7+
val TPTPProblemPath: String = getClass.getResource("/TPTP/Problems/").getPath
98

109
/**
1110
* @return sequence of tptp problems in the library lib with the tags in spc.

0 commit comments

Comments
 (0)