Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Types #166

Merged
merged 75 commits into from
Oct 5, 2023
Merged

Types #166

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
dbe7796
Starting a layer of abstraction.
SimonGuilloud Apr 14, 2023
6c042fa
swrdgv
SimonGuilloud Apr 24, 2023
d520029
sedgf
SimonGuilloud Apr 24, 2023
c65fb35
ONgoing work. FOL structure mostly implemented, substitutions ongoing.
SimonGuilloud Apr 25, 2023
0ce9761
continued
SimonGuilloud Apr 25, 2023
9ccb586
further changes
SimonGuilloud Apr 26, 2023
68736bd
LisaObject has a self type being self
SimonGuilloud Apr 26, 2023
ddae31e
More improvements on substitution
SimonGuilloud Apr 27, 2023
5c845e5
More work
SimonGuilloud Apr 28, 2023
a836795
multivar substitution
SimonGuilloud Apr 30, 2023
bb6c1eb
improvements to MapProofTest
SimonGuilloud May 2, 2023
c4d7e94
finished fol, need to do prooflib
SimonGuilloud May 7, 2023
080d045
started work on prooflib, cut plenty unused code in Library.scala
SimonGuilloud May 7, 2023
0900263
Merge branch 'cmain' into types
SimonGuilloud May 7, 2023
f55a856
more work on substitutions
SimonGuilloud May 8, 2023
1103c1c
updated WithTheorems
SimonGuilloud May 8, 2023
a52e24d
finished BasicSteptactics and substitutions
SimonGuilloud May 9, 2023
c317eca
more corrections of tactics using unifier
SimonGuilloud May 9, 2023
5603e26
fixed F and K imports
SimonGuilloud May 12, 2023
dddaf6b
finished PrrofHelpers and definitions. Definitions possibly not final
SimonGuilloud May 14, 2023
99286a1
Done most of the simpleDeducedSteps
SimonGuilloud May 25, 2023
f1f977e
Merge branch 'cmain' into types
SimonGuilloud May 25, 2023
88ff893
ongoing work on types
SimonGuilloud Jul 26, 2023
0a1a296
Merge branch 'main' into types
SimonGuilloud Aug 9, 2023
fd65fc7
added doc in Common.scala
SimonGuilloud Aug 9, 2023
1b5cc63
more doc, some simplification
SimonGuilloud Aug 10, 2023
6f8c234
Merge branch 'main' into types
SimonGuilloud Aug 10, 2023
746915b
more doc and simplification of unneeded parts
SimonGuilloud Aug 10, 2023
1981033
fixed some export issues. Commented some tests. translation left for …
SimonGuilloud Aug 10, 2023
7533316
remove some debug code
SimonGuilloud Aug 10, 2023
4c1c261
add missing files
SimonGuilloud Aug 10, 2023
02c1a3e
continue F integration. FInished with Set theory library files, now d…
SimonGuilloud Aug 11, 2023
666009a
simplifier remaining
SimonGuilloud Aug 14, 2023
8403076
renaming and mroe compatibility
SimonGuilloud Aug 15, 2023
955819d
Merge branch 'main' into types
SimonGuilloud Aug 15, 2023
6a45376
more adaptations
SimonGuilloud Aug 15, 2023
be7137e
Merge branch 'main' into types
SimonGuilloud Sep 11, 2023
8fd8d72
merge build.sbt
SimonGuilloud Sep 11, 2023
8a3a004
fixing
SimonGuilloud Sep 11, 2023
dd475e2
transforming unification to Front
SimonGuilloud Sep 11, 2023
a8af5a7
weird issues with match types and dotty
SimonGuilloud Sep 12, 2023
c4c5d62
Compiles..? Need to simplify use of Arity in formula labels now. Fing…
SimonGuilloud Sep 12, 2023
c0cdbee
add missing files
SimonGuilloud Sep 13, 2023
da9147f
still compiles
SimonGuilloud Sep 13, 2023
2462f04
Term**0 |-> Term
SimonGuilloud Sep 13, 2023
af5b029
Does not compile (dotty crash). Possibly due to covariant schematic l…
SimonGuilloud Sep 13, 2023
bc2c143
Labels are contravariant
SimonGuilloud Sep 13, 2023
f561156
Merge branch 'types' into types2
SimonGuilloud Sep 13, 2023
a32bc3b
Weird "inherits conflicting instances of non-variant base trait LisaO…
SimonGuilloud Sep 14, 2023
45bd1af
structure seems to work; Constant extends ConstantFunctionSymbol[0], …
SimonGuilloud Sep 14, 2023
061e768
back to the "common super type with case classes" structure
SimonGuilloud Sep 14, 2023
70b812e
finished predicates, compiles. Connector left
SimonGuilloud Sep 14, 2023
bb7ab9a
Finished datastructure. TODO: Underlyings, Arity, uncomment asFront
SimonGuilloud Sep 14, 2023
93804f0
Compiles, checked arity and underlyings (mostly)
SimonGuilloud Sep 14, 2023
c604056
Rehabilited asFront. Next stop, Substitution.
SimonGuilloud Sep 14, 2023
e4a38c4
Merge branch 'main' into types2
SimonGuilloud Sep 15, 2023
3965dff
porting unificationUtils
SimonGuilloud Sep 15, 2023
fb98f77
half of unificationUtils done. Need to make Common even closer struct…
SimonGuilloud Sep 15, 2023
f1789ff
progress through unification
SimonGuilloud Sep 15, 2023
ea8c761
compiles, progressing
SimonGuilloud Sep 15, 2023
4c30a17
safe for reset
SimonGuilloud Sep 15, 2023
51be8a9
only applySubst remaining.
SimonGuilloud Sep 15, 2023
5637954
Substitution done, everything compiles.
SimonGuilloud Sep 16, 2023
1eaf18a
rehabilited commented function
SimonGuilloud Sep 17, 2023
70e66a2
utils tests compiles and pass.
SimonGuilloud Sep 17, 2023
c6deaa2
Finished setTheorzLibrary, close to finish OLPropositionalSolver
SimonGuilloud Sep 17, 2023
1d416e3
Quantifiers.scala work, completed BasicProofTactic, implemented print…
SimonGuilloud Sep 17, 2023
e37e263
progress on compilation and run of SetTheory.scala
SimonGuilloud Sep 19, 2023
acc0aeb
ordinals1 works
SimonGuilloud Sep 19, 2023
f7851cd
Everything works, even example package. Some tests are still commenta…
SimonGuilloud Sep 20, 2023
f4fd66f
Small improvements
SimonGuilloud Sep 20, 2023
656bec8
Ready for demo
SimonGuilloud Sep 21, 2023
ae8c694
scalafix, scalafmt
SimonGuilloud Sep 22, 2023
06c5fe9
git add
SimonGuilloud Sep 22, 2023
40d6e65
Removed unused option in build.sbt, run scalafixAll and scalafmtAll o…
SimonGuilloud Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ target
*.scala.semanticdb

*.iml

# silex and scallion

silex/*
scallion/*
19 changes: 14 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ inThisBuild(
)
)


val commonSettings = Seq(
version := "0.9",
crossScalaVersions := Seq("2.12.13", "2.13.4", "3.0.1", "3.2.0"),
organization := "ch.epfl.lara",
scalacOptions ++= Seq("-Ximport-suggestion-timeout", "0")
)


val scala2 = "2.13.8"
val scala3 = "3.2.2"

Expand Down Expand Up @@ -49,9 +58,9 @@ lazy val scallion = githubProject("https://github.com/sankalpgambhir/scallion.gi
lazy val silex = githubProject("https://github.com/epfl-lara/silex.git", "fc07a8670a5fa8ea2dd5649a00424710274a5d18")

lazy val root = Project(
id = "lisa",
base = file(".")
)
id = "lisa",
base = file(".")
)
.settings(commonSettings3)
.settings(
version := "0.1"
Expand Down Expand Up @@ -86,6 +95,6 @@ lazy val examples = Project(
id = "lisa-examples",
base = file("lisa-examples")
)
.settings(commonSettings)
.settings(commonSettings3)
.dependsOn(root)

.dependsOn(root)
202 changes: 88 additions & 114 deletions lisa-examples/src/main/scala/Example.scala
Original file line number Diff line number Diff line change
@@ -1,86 +1,67 @@
import lisa.automation.kernel.OLPropositionalSolver.*
import lisa.kernel.fol.FOL.*
import lisa.kernel.proof.RunningTheory
import lisa.kernel.proof.SCProofChecker.*
import lisa.kernel.proof.SequentCalculus.*
import lisa.mathematics.settheory.SetTheory.*
import lisa.prooflib.BasicStepTactic.*
import lisa.prooflib.ProofTacticLib.*
import lisa.prooflib.Substitution
import lisa.prooflib.Substitution.ApplyRules
import lisa.utils.FOLPrinter.*
import lisa.utils.KernelHelpers.checkProof
import lisa.utils.unification.UnificationUtils.*

/**
* Discover some of the elements of LISA to get started.
*/
object Example {

import lisa.kernel.proof.SequentCalculus.*

def main(args: Array[String]): Unit = {
val phi = formulaVariable()
val psi = formulaVariable()
val PierceLaw = SCProof(
Hypothesis(phi |- phi, phi),
Weakening(phi |- (phi, psi), 0),
RightImplies(() |- (phi, phi ==> psi), 1, phi, psi),
LeftImplies((phi ==> psi) ==> phi |- phi, 2, 0, (phi ==> psi), phi),
RightImplies(() |- ((phi ==> psi) ==> phi) ==> phi, 3, (phi ==> psi) ==> phi, phi)
)
val PierceLaw2 = SCProof(
RestateTrue(() |- ((phi ==> psi) ==> phi) ==> phi)
)

checkProof(PierceLaw)
checkProof(PierceLaw2)

val theory = new RunningTheory
val pierceThm: theory.Theorem = theory.makeTheorem("Pierce's Law", () |- ((phi ==> psi) ==> phi) ==> phi, PierceLaw, Seq.empty).get
}

}
import lisa.prooflib.Substitution.{ApplyRules as Substitute}

object ExampleDSL extends lisa.Main {
object Example extends lisa.Main {

// Simple Theorem with LISA's DSL
val x = variable
val P = predicate(1)
val f = function(1)
val y = variable
val P = predicate[1]
val f = function[1]

// Simple proof with LISA's DSL
val fixedPointDoubleApplication = Theorem(∀(x, P(x) ==> P(f(x))) |- P(x) ==> P(f(f(x)))) {
assume(∀(x, P(x) ==> P(f(x))))
assume(P(x))
val step1 = have(P(x) ==> P(f(x))) by InstantiateForall
val step2 = have(P(f(x)) ==> P(f(f(x)))) by InstantiateForall
have(thesis) by Tautology.from(step1, step2)
}
show

// More complicated example of a proof with LISA DSL
val y = variable
val z = variable
val unionOfSingleton = Theorem(union(singleton(x)) === x) {
val X = singleton(x)
val forward = have(in(z, x) ==> in(z, union(X))) subproof {
have(in(z, x) |- in(z, x) /\ in(x, X)) by Tautology.from(pairAxiom of (y -> x, z -> x))
val step2 = thenHave(in(z, x) |- ∃(y, in(z, y) /\ in(y, X))) by RightExists
have(thesis) by Tautology.from(step2, unionAxiom of (x -> X))
}

val backward = have(in(z, union(X)) ==> in(z, x)) subproof {
have(in(z, y) |- in(z, y)) by Restate
val step2 = thenHave((y === x, in(z, y)) |- in(z, x)) by ApplyRules(y === x)
have(in(z, y) /\ in(y, X) |- in(z, x)) by Tautology.from(pairAxiom of (y -> x, z -> y), step2)
val step4 = thenHave(∃(y, in(z, y) /\ in(y, X)) |- in(z, x)) by LeftExists
have(in(z, union(X)) ==> in(z, x)) by Tautology.from(unionAxiom of (x -> X), step4)
}

have(in(z, union(X)) <=> in(z, x)) by RightIff(forward, backward)
thenHave(forall(z, in(z, union(X)) <=> in(z, x))) by RightForall
andThen(Substitution.applySubst(extensionalityAxiom of (x -> union(X), y -> x)))
// Example of set theoretic development

/**
* Theorem --- The empty set is a subset of every set.
*
* `|- ∅ ⊆ x`
*/
val emptySetIsASubset = Theorem(
∅ ⊆ x
) {
have((y ∈ ∅) ==> (y ∈ x)) by Weakening(emptySetAxiom of (x := y))
val rhs = thenHave(∀(y, (y ∈ ∅) ==> (y ∈ x))) by RightForall
have(thesis) by Tautology.from(subsetAxiom of (x := ∅, y := x), rhs)
}
show

/**
* Theorem --- If a set has an element, then it is not the empty set.
*
* `y ∈ x ⊢ ! x = ∅`
*/
val setWithElementNonEmpty = Theorem(
(y ∈ x) |- x =/= ∅
) {
have((x === ∅) |- !(y ∈ x)) by Substitute(x === ∅)(emptySetAxiom of (x := y))
}

/**
* Theorem --- A power set is never empty.
*
* `|- !powerAxiom(x) = ∅`
*/
val powerSetNonEmpty = Theorem(
powerSet(x) =/= ∅
) {
have(thesis) by Tautology.from(
setWithElementNonEmpty of (y := ∅, x := powerSet(x)),
powerAxiom of (x := ∅, y := x),
emptySetIsASubset
)
}

/*

import lisa.mathematics.settheory.SetTheory.*


// Examples of definitions
val succ = DEF(x) --> union(unorderedPair(x, singleton(x)))
Expand All @@ -89,53 +70,46 @@ object ExampleDSL extends lisa.Main {
val inductiveSet = DEF(x) --> in(∅, x) /\ forall(y, in(y, x) ==> in(succ(y), x))
show

val defineNonEmptySet = Lemma(∃!(x, !(x === ∅) /\ (x === unorderedPair(∅, ∅)))) {
val subst = have(False <=> in(∅, ∅)) by Rewrite(emptySetAxiom of (x -> ∅()))
have(in(∅, unorderedPair(∅, ∅)) <=> False |- ()) by Rewrite(pairAxiom of (x -> ∅(), y -> ∅(), z -> ∅()))
andThen(Substitution.applySubst(subst))
thenHave(∀(z, in(z, unorderedPair(∅, ∅)) <=> in(z, ∅)) |- ()) by LeftForall
andThen(Substitution.applySubst(extensionalityAxiom of (x -> unorderedPair(∅(), ∅()), y -> ∅())))
andThen(Substitution.applySubst(x === unorderedPair(∅(), ∅())))
thenHave((!(x === ∅) /\ (x === unorderedPair(∅, ∅))) <=> (x === unorderedPair(∅, ∅))) by Tautology
thenHave(∀(x, (x === unorderedPair(∅, ∅)) <=> (!(x === ∅) /\ (x === unorderedPair(∅, ∅))))) by RightForall
thenHave(∃(y, ∀(x, (x === y) <=> (!(x === ∅) /\ (x === unorderedPair(∅, ∅)))))) by RightExists
}
show

// This definition is underspecified
val nonEmpty = DEF() --> The(x, !(x === ∅))(defineNonEmptySet)
show

// Simple tactic definition for LISA DSL
import lisa.automation.kernel.OLPropositionalSolver.*

// object SimpleTautology extends ProofTactic {
// def solveFormula(using proof: library.Proof)(f: Formula, decisionsPos: List[Formula], decisionsNeg: List[Formula]): proof.ProofTacticJudgement = {
// val redF = reducedForm(f)
// if (redF == ⊤) {
// Restate(decisionsPos |- f :: decisionsNeg)
// } else if (redF == ⊥) {
// proof.InvalidProofTactic("Sequent is not a propositional tautology")
// } else {
// val atom = findBestAtom(redF).get
// def substInRedF(f: Formula) = redF.substituted(atom -> f)
// TacticSubproof {
// have(solveFormula(substInRedF(⊤), atom :: decisionsPos, decisionsNeg))
// val step2 = thenHave(atom :: decisionsPos |- redF :: decisionsNeg) by Substitution2(⊤ <=> atom)
// have(solveFormula(substInRedF(⊥), decisionsPos, atom :: decisionsNeg))
// val step4 = thenHave(decisionsPos |- redF :: atom :: decisionsNeg) by Substitution2(⊥ <=> atom)
// have(decisionsPos |- redF :: decisionsNeg) by Cut(step4, step2)
// thenHave(decisionsPos |- f :: decisionsNeg) by Restate
// }
// }
// }
// def solveSequent(using proof: library.Proof)(bot: Sequent) =
// TacticSubproof { // Since the tactic above works on formulas, we need an extra step to convert an arbitrary sequent to an equivalent formula
// have(solveFormula(sequentToFormula(bot), Nil, Nil))
// thenHave(bot) by Restate.from
// }
// }


*/

/*



// Simple tactic definition for LISA DSL
import lisa.automation.kernel.OLPropositionalSolver.*

// object SimpleTautology extends ProofTactic {
// def solveFormula(using proof: library.Proof)(f: Formula, decisionsPos: List[Formula], decisionsNeg: List[Formula]): proof.ProofTacticJudgement = {
// val redF = reducedForm(f)
// if (redF == ⊤) {
// Restate(decisionsPos |- f :: decisionsNeg)
// } else if (redF == ⊥) {
// proof.InvalidProofTactic("Sequent is not a propositional tautology")
// } else {
// val atom = findBestAtom(redF).get
// def substInRedF(f: Formula) = redF.substituted(atom -> f)
// TacticSubproof {
// have(solveFormula(substInRedF(⊤), atom :: decisionsPos, decisionsNeg))
// val step2 = thenHave(atom :: decisionsPos |- redF :: decisionsNeg) by Substitution2(⊤ <=> atom)
// have(solveFormula(substInRedF(⊥), decisionsPos, atom :: decisionsNeg))
// val step4 = thenHave(decisionsPos |- redF :: atom :: decisionsNeg) by Substitution2(⊥ <=> atom)
// have(decisionsPos |- redF :: decisionsNeg) by Cut(step4, step2)
// thenHave(decisionsPos |- f :: decisionsNeg) by Restate
// }
// }
// }
// def solveSequent(using proof: library.Proof)(bot: Sequent) =
// TacticSubproof { // Since the tactic above works on formulas, we need an extra step to convert an arbitrary sequent to an equivalent formula
// have(solveFormula(sequentToFormula(bot), Nil, Nil))
// thenHave(bot) by Restate.from
// }
// }
*/
// val a = formulaVariable()
// val b = formulaVariable()
// val c = formulaVariable()
Expand Down
33 changes: 33 additions & 0 deletions lisa-examples/src/main/scala/ExampleKernel.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import lisa.utils.K

import K.*

/**
* Discover some of the elements of the logical kernel of LISA.
*/
object ExampleKernel {

import lisa.kernel.proof.SequentCalculus.*

def main(args: Array[String]): Unit = {
val phi = formulaVariable()
val psi = formulaVariable()
val PierceLaw = SCProof(
Hypothesis(phi |- phi, phi),
Weakening(phi |- (phi, psi), 0),
RightImplies(() |- (phi, phi ==> psi), 1, phi, psi),
LeftImplies((phi ==> psi) ==> phi |- phi, 2, 0, (phi ==> psi), phi),
RightImplies(() |- ((phi ==> psi) ==> phi) ==> phi, 3, (phi ==> psi) ==> phi, phi)
)
val PierceLaw2 = SCProof(
RestateTrue(() |- ((phi ==> psi) ==> phi) ==> phi)
)

checkProof(PierceLaw, println)
checkProof(PierceLaw2, println)

val theory = new RunningTheory
val pierceThm: theory.Theorem = theory.makeTheorem("Pierce's Law", () |- ((phi ==> psi) ==> phi) ==> phi, PierceLaw, Seq.empty).get
}

}
Loading
Loading