Closed pjljvandelaar closed 5 years ago
The standard proposal lead by Cesare Tinelli includes a lexicographic string comparison method. it also requires unicode support, so both features would require revisiting the available support.
Unicode would be nice, but is not needed. Only string comparison is required!
@NikolajBjorner This is something I'm interested in as well. Is the commit operational? Because I'm getting a segfault on <=
:
(set-logic ALL)
(declare-fun s0 () String)
(declare-fun s1 () String)
(assert (str.<= s0 s1))
(check-sat)
z3 says:
$ z3 a.smt2
Failed to verify: m_util.str.is_lt(n, e1, e2)
[1] 18261 illegal hardware instruction z3 a.smt2
By the same token adding support for seq.<
and seq.<=
would be nice as well.
The segfault is gone, thanks! But something is still quite fishy:
(set-logic ALL)
(declare-fun x () String)
(declare-fun y () String)
(assert (= x "ab"))
(assert (= y "cd"))
(assert (not (str.<= x y)))
(check-sat)
This correctly returns unsat
:
$ z3 a.smt2
unsat
But if you swap the first two asserts (lines 4 and 5):
(set-logic ALL)
(declare-fun x () String)
(declare-fun y () String)
(assert (= y "cd"))
(assert (= x "ab"))
(assert (not (str.<= x y)))
(check-sat)
z3 says:
$ z3 a.smt2
sat
I believe we can close this now. Support is added for str.< and str.<=.
@NikolajBjorner Would be really nice to have seq.<
and seq.<=
as well; without those two the sequence logic is lacking access to what you must've already implemented for sure.
seq.< and seq.<= are not well defined for all types. Maybe for Int and Real, but what about algebraic data-types, then there should also be <, and <= for ADTs, arrays, user-sorts (and what would that be?).
Great point. I was thinking lexicographic ordering, as given by the order of constructors declared in the data-type itself. (I'm thinking more like deriving Ord
in Haskell; i.e., as long as a
has comparisons, so does List a
; recursively; but perhaps that's a bit too much to ask.)
It all depends on whether there are compelling applications that need this. The type system isn't at the level of Haskell and therefore an implementation would not be principled.
That's a fair point. But perhaps Seq Int
, Seq (_ BV n)
, Seq Real
and Seq (_ FP n m)
are well within reach?
But this is more of a "nice to have" than a "must have" admittedly.
All doable, but it is a use-it-or-lose-it question regarding feature addition.
I don't have a compelling use case for the time being.. If I ever have a need, I'll be sure to ping again!
As a user I would like to reason lexically over strings, like "Monkey" > "Ashtray".
However,
yields
Could support for comparison for strings be added?
At http://cvc4.cs.stanford.edu/wiki/Strings, I read about the str.to.int function: Does this mapping agree with the lexical mapping and should that be used to solve my issue?
See also https://github.com/TorXakis/TorXakis/issues/883