从Z3字符串中的字符中提取十进制值

时间:2017-10-02 09:17:10

标签: string z3 smt

令s1为Z3Str中的任意字符串。 我可以检查其中的第三个字符是否为小写字母:

(declare-const s1 String)
(assert (= s1 "74b\x00!!###$$"))
(assert (str.in.re (str.at s1 2) (re.range "a" "z")))
(check-sat)
(get-value (s1))

现在假设确实如此,我想替换第三个字母 大写字母(新字符串s2将包含替换版本)。受标准编程语言的启发, 我可能想做这样的事情:

(declare-const s1 String)
(declare-const s2 String)
(declare-const b1 Bool)
(assert (= s1 "74b\x00!!###$$"))
(assert (= b1 (str.in.re (str.at s1 2) (re.range "a" "z"))))
(assert (= (str.substr s2 0 2) (str.substr s1 0 2)))
(assert (= (str.substr s2 3 8) (str.substr s1 3 8)))
(assert (= (str.len s2) (str.len s1)))
(assert (= (str.at s2 2) (ite b1 (- (str.at s1 2) 32) (str.at s1 2))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 32 = 'a'-'A'
(check-sat)
(get-value (s1 s2 b1))

但是,当然,由于类型的原因,这不起作用:

(error "line 9 column 52: Sort mismatch at argument #1 for function 
(declare-fun - (Int Int) Int) supplied sort is String")

是否有任何直接操纵小数的方法 Z3字符串中字符的值?我的意思是除了所有小写字母上的巨型开关案例......似乎有一些希望,因为API确实支持" \ x61"作为" a"的替代表示。非常感谢任何帮助,谢谢!!

1 个答案:

答案 0 :(得分:2)

以下作品:

tbl_name <- "batting"
DBI::dbGetQuery(sc, paste("DROP TABLE", tbl_name))

如果可以进一步简化这一点确实很好,但我没有看到一种简单的方法,因为API似乎不允许直接从序列访问元素。它允许你得到子序列,但不是元素,这是你真正需要的:注意长度为1的子序列与该位置的基础元素不同,这解释了你得到的合法类型错误。

这是我对此查询的答案:

(declare-const s1 String)
(declare-const s2 String)
(declare-const b1 Bool)
(assert (= s1 "74b\x00!!###$$"))
(assert (= b1 (str.in.re (str.at s1 2) (re.range "a" "z"))))
(assert (= (str.substr s2 0 2) (str.substr s1 0 2)))
(assert (= (str.substr s2 3 8) (str.substr s1 3 8)))
(assert (= (str.len s2) (str.len s1)))

(declare-const subSecElt (_ BitVec 8))
(declare-const eltUpCase (_ BitVec 8))
(assert (= (bvsub subSecElt #x20) eltUpCase))
(assert (= (seq.unit subSecElt) (str.at s1 2)))
(assert (= (str.at s2 2) (ite b1 (seq.unit eltUpCase) (str.at s1 2))))

(check-sat)
(get-value (s1 s2 b1))