Nothing Special   »   [go: up one dir, main page]

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

Add real to int conversions #614

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Conversation

shaobo-he
Copy link

Specifically, three operations are added,
RealToInt -- The SMT to_int function
Ceiling -- Equivalent to the Racket ceiling function
Truncate -- Equivalent to the Racket truncate function

@mikand
Copy link
Contributor
mikand commented Jan 7, 2020

@shaobo-he Thanks for the contribution.

Before accepting this PR, we need to add the new operator also to all other solvers supporting QF_LIRA (mathsat, CVC4 and yices), otherwise the tests will fail.

(note that in your test you specified UFLIRA, instead, you should specify QF_LIRA to target the right fragment and enable all relevant solvers).

Also, other changes are needed, particularly adding examples of RealToInt in tests/examples.py and adding the walk_realtoint to all the walkers (simplifier, rewritings and oracles).

Are you willing to continue the work in this direction? We can of course help you and guide you in this.

Equals(RealToInt(Real(1)), Int(1)))
check = And(check,
Equals(RealToInt(ToReal(b)), b))
for sname in get_env().factory.all_solvers(logic=UFLIRA):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the logic here should be 'QF_LIRA' to enable all the relevant solvers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems QF_LIRA is not defined in pysmt.logics. Should I define it?

@mikand
Copy link
Contributor
mikand commented Jan 7, 2020

Another minor point: RealToInt is a strange name to me, why not calling it Floor?

@shaobo-he
Copy link
Author

Another minor point: RealToInt is a strange name to me, why not calling it Floor?

Floor indeed makes more sense as it reflects the semantics of this operation. However, RealToInt is consistent with the naming of the to_int operation in SMTLIB. So I think it's better to keep the latter.

@shaobo-he
Copy link
Author
shaobo-he commented Jan 7, 2020

@shaobo-he Thanks for the contribution.

Before accepting this PR, we need to add the new operator also to all other solvers supporting QF_LIRA (mathsat, CVC4 and yices), otherwise the tests will fail.

(note that in your test you specified UFLIRA, instead, you should specify QF_LIRA to target the right fragment and enable all relevant solvers).

Also, other changes are needed, particularly adding examples of RealToInt in tests/examples.py and adding the walk_realtoint to all the walkers (simplifier, rewritings and oracles).

Are you willing to continue the work in this direction? We can of course help you and guide you in this.

How about me making as many changes as I can and then you can take over to finish it if necessary? Hopefully you don't have to do a lot.

Specifically, three operations are added,
RealToInt -- The SMT `to_int` function
Ceiling -- Equivalent to the Racket `ceiling` function
Truncate -- Equivalent to the Racket `truncate` function
@shaobo-he
Copy link
Author

Hi, @mikand. I updated this PR. Please take a look at it again and let me know if it needs any changes.

@mikand
Copy link
Contributor
mikand commented Apr 6, 2020

Hi @shaobo-he, thanks for this work and sorry for the latency!

I am unconvinced of the addition of UF_NIRA though: UF_NIRA also contains non-linear terms and mod operators (http://smtlib.cs.uiowa.edu/logics-all.shtml#QF_NIA) that are currently not supported, so I am not comfortable in adding the theory to z3 just for the sake of having the Floor operator implemented.

Also, note that the logic addition code is incomplete: you also need to extend the TheoryOracle in oracles.py to produce non-linearity when it encounters a Floor.

Let me think a bit more on this, but maybe the right way to proceed is to add the mod operator together with the floor to fulfill the requirements of QF_NIA and have a clean implementation of the whole logic?

@marcogario any comment or feedback is welcome.

@shaobo-he
Copy link
Author

Thank you for your feedback.

Also, note that the logic addition code is incomplete: you also need to extend the TheoryOracle in oracles.py to produce non-linearity when it encounters a Floor.

So the changes in https://github.com/pysmt/pysmt/pull/614/files#diff-03f2e786a2b9045a041adfab13dde3a5R244-R249 are not enough? Could you give me some pointers about what should I do here?

@shaobo-he
Copy link
Author

Hello, @mikand. I'm sorry to bother you again. I was wondering if there's any feedback or decision on this PR. I'd like to see this PR merged so that I can start to work on adding operations of floating-point theory otherwise there'll be conflicts.

def walk_realtoint(self, formula, args, **kwargs):
#pylint: disable=unused-argument
"""Extends the Theory with NIRA."""
theory_out = args[0].set_nira() # This makes a copy of args[0]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems problematic. The output should extend the input with nonlinearity as well as integer arithmetic.

@marcogario marcogario added this to the 1.0.0 milestone Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants