Add IEEE-754 Floating Point to Bitvector Conversion Fallback#512
Add IEEE-754 Floating Point to Bitvector Conversion Fallback#512baierd wants to merge 92 commits into
Conversation
…traint is not handed to the user
…gestion + add helper to get mantissa and exponent sizes for FPs (not finished for all solvers)
…n of user defined results for special FP numbers
…ll BV capable solvers
…ings and add it to JavaDoc
…BV transformation and width comparison
…umber mapping) and a test for FP size/mantissa/exponent in relation to BV width for toIeeeBitvector()
…ulaManager (based on solver return)
…d text for native toIeeeBitvector() in AbstractFloatingPointFormulaManager
|
@kfriedberger the SMTLIB2 standard defines the size of an FP as mantissa + exponent with the mantissa including the sign bit. Our current implementation excludes it, and we do not document this properly in all cases, especially the FP type constructor. This is problematic, as the standard defines the size of a BV representation of a FP as My proposal (already WIP):
I don't want to change the current FP-Type constructor, as users expect this to not change behavior. What do you think? I am happy about thoughts/ideas. Edit: it would probably be a good idea to also update the API for |
…tMantissaSizeWithSignBit() +
…he type/mantissa with/without sign bit and add sign bit to toString and toSMTLIBString representations
…a with/without sign bit and use those as far as possible to make the code unambiguous for mantissas
…IEEE BV method availability
…n bit and add some assertions for mantissa/exponent
…guous about the sign bit
…h new mantissa API
…resentation using fromIeeeBitvector() (BV -> FP)
…rsion-not-supported-in-all-solvers
…and +-Inf as bitvectors
…ither FP 0.0 or -0.0
…rsion-not-supported-in-all-solvers # Conflicts: # src/org/sosy_lab/java_smt/basicimpl/AbstractFormulaManager.java
| + " operation by utilizing the 'to_fp' operation."; | ||
| throw new IllegalArgumentException( | ||
| illegalArgumentException.getMessage() + additionalMessage, illegalArgumentException); | ||
| } |
There was a problem hiding this comment.
4x getMessage --> maybe use a variable for that.
There was a problem hiding this comment.
Done! Thanks for noticing!
I also extracted it into a method and moved the call due to how parsing was changed in parseAll().
| * only used to verify the exponent and mantissa sizes of pTerm. | ||
| * @return input term pTerm in a {@link FloatingPointFormula}. | ||
| */ | ||
| protected FloatingPointFormula wrapFloatingPointAndAssertType( |
There was a problem hiding this comment.
Why not just keep the name wrap and make it so complex?
There was a problem hiding this comment.
The more detailed assertions were helpful when developing the BV-FP conversion, as the solvers handle things distinctly.
There was a problem hiding this comment.
The check(s) are now assertions
| return getFormulaCreator().encapsulateFloatingPoint(pTerm); | ||
| } | ||
|
|
||
| protected FloatingPointFormula wrapFloatingPoint(TFormulaInfo pTerm) { |
There was a problem hiding this comment.
Is this second method really needed? Why not just name it wrap in this context?
There was a problem hiding this comment.
I renamed both and simplified/combined them. This can of course also be done in a distinct way, but this implementation guarantees that we will always check the correct assertion.
There was a problem hiding this comment.
Is this second method really needed?
It makes it easier to understand. The assertions were helpful when developing the BV-FP conversion, but are not strictly necessary. We can also use a single method that uses wrap(term, null) or so if you want.
| termManager.mk_term(Kind.FP_TO_FP_FROM_BV, bvVar, sizeExp, sizeSig), | ||
| pNumber)); | ||
|
|
||
| bitwuzlaCreator.addConstraintForVariable(newVariable, equal); |
There was a problem hiding this comment.
Removing this piece of code will remove the reason for BitwuzlaFormulaCreator::constraintsForVariables. Please clean up the unused code there.
There was a problem hiding this comment.
Good spot, thanks! I removed it.
|
The idea of this PR is quite similar to the implementation of Some request from my side:
Overall, the idea is good. If it works for special cases like NaN, Inf, Subnormal, etc, then fine for me. |
…rsion-not-supported-in-all-solvers # Conflicts: # src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaFloatingPointManager.java # src/org/sosy_lab/java_smt/solvers/cvc4/CVC4FloatingPointFormulaManager.java # src/org/sosy_lab/java_smt/solvers/cvc5/CVC5FloatingPointFormulaManager.java
…for old bv to fp workaround impl
…in Bitwuzla needed for old bv to fp workaround impl
…ith better error msg
…or messages to a method and the invocation into parseAllImpl() as this is called for all parsing operations
…pected to throw, as if requireParser() fails, the test would fail with a weird error
…rsion-not-supported-in-all-solvers # Conflicts: # src/org/sosy_lab/java_smt/basicimpl/AbstractFloatingPointFormulaManager.java # src/org/sosy_lab/java_smt/basicimpl/AbstractFormulaManager.java # src/org/sosy_lab/java_smt/solvers/bitwuzla/BitwuzlaFormulaCreator.java # src/org/sosy_lab/java_smt/solvers/cvc4/CVC4FormulaCreator.java # src/org/sosy_lab/java_smt/solvers/cvc5/CVC5FormulaCreator.java
…rsion-not-supported-in-all-solvers # Conflicts: # src/org/sosy_lab/java_smt/basicimpl/AbstractFormulaManager.java
…nsive check and make the cheap checks message lazy
I chose Note: It returns a
It works due to SMTLIB(2) only defining each special FP number only once. Hence "all" bitvector NaN representations return the "same" NaN (as defined by SMTLIB2). If translated back, the original bitvector is returned. I added tests for all special FP numbers that check this. |
…rsion-not-supported-in-all-solvers
This PR adds a fallback method for
FloatingPointManager.toIeeeBitvector(FloatingPointFormula):FloatingPointManager.toIeeeBitvector(FloatingPointFormula, BitvectorFormula), returns a BooleanFormula that is the result of the equality of the FP input with the BV input (BV is equal to the floating-points bit representation according to the IEEE 754-2008 floating-point format). Special FP numbers are returned as the solver sees fit.Tests for this method have been added. This includes the SMTLIB2 output of it, and the native
toIeeeBitvector()method, showing us what solver can parse what output.Furthermore, i added common FP type checks in the wrapping function of
AbstractFloatingPointFormulaManager