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

Sort.sortOf returns the wrong type #16

Closed
daniel-raffler opened this issue Oct 17, 2024 · 6 comments
Closed

Sort.sortOf returns the wrong type #16

daniel-raffler opened this issue Oct 17, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@daniel-raffler
Copy link

Hello,
it seems that Sort.sortOf sometimes returns Integer, even when the term should have type Rational. Here are a few examples I've found:

import ap.SimpleAPI
import ap.parameters.GlobalSettings
import ap.types.Sort
import ap.util.Debug
import org.scalatest.funsuite.AnyFunSuite

class SortOfBug extends AnyFunSuite {
  import ap.parser.IExpression.{Sort => _, _}
  import ap.theories.rationals.Rationals._;

  val withAssertions = false;

  test("plus") {
    Debug.enableAllAssertions(withAssertions)
    SimpleAPI.withProver(enableAssert = withAssertions) { p =>
      import p._

      val a = createConstant("a", dom)
      val b = createConstant("b", dom)
      val f1 = a + b
      printf("%s :: %s\n", f1, Sort.sortOf(f1)) // Says Int, but should be Rational

      assertResult(dom)(Sort.sortOf(f1))
    }
  }

  test("mul") {
    Debug.enableAllAssertions(withAssertions)
    SimpleAPI.withProver(enableAssert = withAssertions) { p =>
      import p._

      val a = createConstant("a", dom)
      val b = int(2) // frac(2,1) works
      val f1 = mul(a, b)
      printf("%s :: %s\n", f1, Sort.sortOf(f1)) // Says Int, but should be Rational

      assertResult(dom)(Sort.sortOf(f1))
    }
  }

  test("nested mul/plus") {
    Debug.enableAllAssertions(withAssertions)
    SimpleAPI.withProver(enableAssert = withAssertions) { p =>
      import p._

      val a = createConstant("a", dom)
      val b = createConstant("b", dom)
      val f1 = a + b

      val c = createBooleanVariable("c")
      val d = frac(2, 1)
      val f2 = ite(c, f1, d)
      printf("%s :: %s\n", f2, Sort.sortOf(f2)) // Says Int, but should be Rational

      assertResult(dom)(Sort.sortOf(f2))
    }
  }
}

There might be other instances like div that just didn't show up in our tests.

Is this something that could be fixed?

@daniel-raffler
Copy link
Author

One more variant of this:

  test("mul") {
    Debug.enableAllAssertions(withAssertions)
    SimpleAPI.withProver(enableAssert = withAssertions) { p =>
      import p._

      val a = createConstant("a", dom)
      val b = int(0)
      val f1 = mul(a, b)
      printf("%s :: %s\n", f1, Sort.sortOf(f1))

      assertResult(dom)(Sort.sortOf(f1))
    }
  }

Here f1 is simplified even further and we get IIntLit 0 instead of just ITimes k a.

@pruemmer
Copy link
Collaborator

This can be fixed, but requires some reorganization of the theory of rationals; I won't have time for doing anything about this problem right away.

@daniel-raffler
Copy link
Author

daniel-raffler commented Nov 1, 2024

This can be fixed, but requires some reorganization of the theory of rationals; I won't have time for doing anything about this problem right away.

Thanks for the updates! We do have a workaround for the issue, so this isn't too pressing.

When you have time, could you maybe release a new version (to Maven) of Princess and Ostrich with the latest bug fixes?

@pruemmer
Copy link
Collaborator

pruemmer commented Nov 12, 2024 via email

@pruemmer
Copy link
Collaborator

@daniel-raffler
Copy link
Author

Yes, it's working now. Thanks for your help!

daniel-raffler added a commit to sosy-lab/java-smt that referenced this issue Jan 14, 2025
The old code was a workaround for a bug in Princess that has since been fixed: uuverifiers/princess#16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants