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

API for accessing an element of a sequence #1302

Closed
LeventErkok opened this issue Oct 12, 2017 · 10 comments
Closed

API for accessing an element of a sequence #1302

LeventErkok opened this issue Oct 12, 2017 · 10 comments
Labels

Comments

@LeventErkok
Copy link

LeventErkok commented Oct 12, 2017

As discussed here: https://stackoverflow.com/questions/46696982/how-do-you-extract-an-element-as-the-base-type-from-a-seq-type-in-z3

Is there an API (both at SMT-Lib and from other interfaces) to access the element at a given index of a sequence?

I can imagine one issue with this API: What if the index is out-of-bounds. Perhaps that's the reason this function doesn't exist? Maybe the user can be required to provide a default if that is the case.

@NikolajBjorner
Copy link
Contributor

There isn't an API. The API builds on the string proposal for SMT-LIB2 and extends minimally with a unit constructor and allows general sequences. There is a workaround as follows:

Introduce a function nth: (Seq A) Int -> A
Then add the axiom unit(nth(s,j)) = at(s,j) or at(s,j) = empty
for every occurrence of at(s,j), or alternatively add a quantifier with pattern { at(s,j) .

@LeventErkok
Copy link
Author

@NikolajBjorner I was under the impression that users aren't allowed to define polymorphic functions in benchmarks. So, nth has to be declared for each monomorphic sequence instance needed; is that correct?

@NikolajBjorner
Copy link
Contributor

Correct, polymorphic function declarations / definitions are not (yet) available.

@LeventErkok
Copy link
Author

LeventErkok commented Oct 12, 2017

Thanks.. Doesn't seem very effective though, I'm getting unknown for the following rather innocuous query:

(define-sort ISeq () (Seq Int))
(define-const x ISeq (seq.unit 5))
(define-const y ISeq (seq.unit 6))

(declare-fun ISeq.nth (ISeq Int) Int)
(assert (forall ((s ISeq) (i Int))
           (! (or (= (seq.unit (ISeq.nth s i)) (seq.at s i))
                  (= (as seq.empty ISeq)       (seq.at s i)))
           :pattern (seq.at s i)
           :pattern (ISeq.nth s i)
           )))
(assert (<= (ISeq.nth x 0) (ISeq.nth y 0)))
(check-sat)

Should I use a different set of patterns?

@NikolajBjorner
Copy link
Contributor

likely because Z3 doesn't know that the quantifiers are satisfiable.

@LeventErkok
Copy link
Author

LeventErkok commented Oct 12, 2017

OK, I'll close this ticket since at this time it's more of a curiosity.

For reference, I found at least two references where people axiomatized lists with that operation built in:

Would be nice if this was incorporated directly into the sequence theory, which I presume would make it work more friendly with the necessary axiomatization?

@NikolajBjorner
Copy link
Contributor

Granted, it is a valid point

@LeventErkok
Copy link
Author

I'm going to reopen this ticket, as it's popping up quite often. No urgency, but a nice-to-have.

@LeventErkok LeventErkok reopened this Nov 4, 2017
@LeventErkok LeventErkok changed the title API for accessing an element of a spec. API for accessing an element of a sequence Nov 4, 2017
@ghost ghost mentioned this issue Jan 3, 2018
@LeventErkok
Copy link
Author

@NikolajBjorner

Looks like you added support for nth in:

834cf96

I'm closing this ticket. Thanks!

@OrenGitHub
Copy link

Posted an update answer in stack overflow about nth.

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

No branches or pull requests

3 participants