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

Find maximum value? #425

Open
r4dr3fr4d opened this issue May 12, 2022 · 10 comments
Open

Find maximum value? #425

r4dr3fr4d opened this issue May 12, 2022 · 10 comments
Assignees
Milestone

Comments

@r4dr3fr4d
Copy link

Is it possible in STP to find the maximum value of, eg, a bitvector, a la Z3 optimization/maximization?

@TrevorHansen
Copy link
Member

STP doesn't have the functionality to optimise, but it's probably easy for me to implement.

Do you need something like unsigned maximisation of a specified variable in an smt-lib2 format file?

@r4dr3fr4d
Copy link
Author

r4dr3fr4d commented May 13, 2022 via email

@msoos
Copy link
Member

msoos commented May 13, 2022

@TrevorHansen wouldn't that require MUS extraction or correction set generation? Those sound pretty complicated, no?

@aytey
Copy link
Member

aytey commented May 13, 2022

As an FYI: cvc5 implements this with binary search on the optimisation terms

@TrevorHansen
Copy link
Member

I was imaging something straightforward, perhaps like CVC implements.

For example, given the 32-bit variable "maximise" in the problem. We'd encode the whole problem to CNF, send it to Cryptominisat(CMS), then ask CMS to assume that the most-significant bit was 1, and so on. Best case 1 call to CMS, worst case there'd be 32 calls to CMS.

@aytey
Copy link
Member

aytey commented May 13, 2022

Ah, an optimise each term in the order that they're listed in the .smt2 input? So for x + y == 10, if x comes first, you get x=10 and y=0 (I'm purposefully ignoring overflow).

@TrevorHansen
Copy link
Member

I was thinking something even easier to implement. E.g. given the input:

(set-logic QF_BV)

(declare-fun maximise () (_ BitVec 32))
(declare-fun v0 () (_ BitVec 32))

(assert (= maximise (bvsmod v0 (_ bv10 32))))
(check-sat)
(get-model)

It'd try to maximise the variable called "maximise" (considering it's unsigned), just by trying to set each bit to 1 in turn.

Is this going to be good enough?

@aytey
Copy link
Member

aytey commented May 13, 2022

z3 uses (maximize <term>) and (minimize <term>) for this (I think it comes before the check-sat call) -- so calling check-sat does the maximisation/minimisation. afaik, this isn't standard though (e.g., it isn't in SMTLIB or anything like that).

I looked at cvc5 quickly to answer this for myself: I don't think cvc5 supports this via SMTLIB -- looks like it is only via the API.

@aytey
Copy link
Member

aytey commented May 13, 2022

I guess the idea about iteratively flipping bits (from 0 -> 1) for the maximise case seems reasonable, but we'd need to handle the unsigned case (i.e., you don't want to flip the MSB for signed values).

Bad typo there :)

@msoos
Copy link
Member

msoos commented May 13, 2022 via email

@TrevorHansen TrevorHansen self-assigned this Aug 5, 2022
@TrevorHansen TrevorHansen added this to the 2.4 Release milestone Aug 5, 2022
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

No branches or pull requests

4 participants