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

MathSAT does not allow variables of different sorts with the same name #275

Open
phantamanta44 opened this issue Jun 30, 2022 · 4 comments

Comments

@phantamanta44
Copy link

MathSAT throws an exception if two variables with the same name and different sorts are ever declared. For example:

SolverContextFactory.createSolverContext(SolverContextFactory.Solvers.MATHSAT5).use { solverCtx ->
    val ifm = solverCtx.formulaManager.integerFormulaManager
    val bfm = solverCtx.formulaManager.booleanFormulaManager
    solverCtx.newProverEnvironment().use { prover ->
        prover.addConstraint(ifm.equal(ifm.makeVariable("x"), ifm.makeNumber(0)))
        println(prover.isUnsat)
    }
    solverCtx.newProverEnvironment().use { prover ->
        prover.addConstraint(bfm.equivalence(bfm.makeVariable("x"), bfm.makeTrue()))
        println(prover.isUnsat)
    }
}

This snippet causes the exception:

Exception in thread "main" java.lang.IllegalArgumentException: A symbol with name `x' already exists, with type: Int
	at org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5NativeApi.msat_declare_function(Native Method)
	at org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5FormulaCreator.makeVariable(Mathsat5FormulaCreator.java:154)
	at org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5FormulaCreator.makeVariable(Mathsat5FormulaCreator.java:137)
	at org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5BooleanFormulaManager.makeVariableImpl(Mathsat5BooleanFormulaManager.java:37)
	at org.sosy_lab.java_smt.solvers.mathsat5.Mathsat5BooleanFormulaManager.makeVariableImpl(Mathsat5BooleanFormulaManager.java:25)
	at org.sosy_lab.java_smt.basicimpl.AbstractBooleanFormulaManager.makeVariable(AbstractBooleanFormulaManager.java:63)
	...

Whereas it works as expected for, e.g. Princess or Z3. I could imagine a solution where Mathsat5Formula is an intermediate representation of the formula that only gets "baked" into a MathSAT native formula when actually making a call to the prover, but that comes with some overhead, of course.

@kfriedberger
Copy link
Member

kfriedberger commented Jun 30, 2022 via email

@phantamanta44
Copy link
Author

So then the idea is that the JavaSMT user should either generate a new solver context for every SMT call, or otherwise implement some kind of unique renaming thing themselves?

@kfriedberger
Copy link
Member

yes, separate contexts will help here, or using a naming scheme for different types.

@kfriedberger
Copy link
Member

kfriedberger commented Oct 11, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants