z3 LastIndexOf returns 错误结果?
z3 LastIndexOf returns wrong result?
z3py 的 LastIndexOf
应该 return “字符串中子字符串的最后一个索引”。但是,当子字符串位于字符串的末尾时,似乎 return 是错误的结果,例如:
>>> import z3
>>> def check_lastindexof(s, sub_list):
... for c in sub_list:
... z_index = z3.simplify(z3.LastIndexOf(s, c))
... v_index = s.rindex(c)
... try:
... assert z_index == v_index
... except Exception as e:
... print(f'{c: <6} FAILED expected: {v_index: >2}, got: {z_index}')
...
>>>
>>> s = 'abcdefabcdef'
>>> tests = ['a', 'abc', 'f', 'ef', 'abcdef']
>>> check_lastindexof(s, tests)
f FAILED expected: 11, got: 5
ef FAILED expected: 10, got: 4
abcdef FAILED expected: 6, got: 0
值得注意的是,LastIndexOf
returns -1 如果子字符串在字符串中只存在一次,据我所知这显然是错误的:
>>> s = 'abcdef'
>>> check_lastindexof(s, tests)
f FAILED expected: 5, got: -1
ef FAILED expected: 4, got: -1
abcdef FAILED expected: 0, got: -1
我是不是误解了 z3.LastIndexOf
应该如何工作,或者某处可能存在错误?
z3-solver 版本:4.8.14.0(通过 pip 安装)
这看起来确实是一个错误。请在 https://github.com/Z3Prover/z3/issues
举报
z3py 的 LastIndexOf
应该 return “字符串中子字符串的最后一个索引”。但是,当子字符串位于字符串的末尾时,似乎 return 是错误的结果,例如:
>>> import z3
>>> def check_lastindexof(s, sub_list):
... for c in sub_list:
... z_index = z3.simplify(z3.LastIndexOf(s, c))
... v_index = s.rindex(c)
... try:
... assert z_index == v_index
... except Exception as e:
... print(f'{c: <6} FAILED expected: {v_index: >2}, got: {z_index}')
...
>>>
>>> s = 'abcdefabcdef'
>>> tests = ['a', 'abc', 'f', 'ef', 'abcdef']
>>> check_lastindexof(s, tests)
f FAILED expected: 11, got: 5
ef FAILED expected: 10, got: 4
abcdef FAILED expected: 6, got: 0
值得注意的是,LastIndexOf
returns -1 如果子字符串在字符串中只存在一次,据我所知这显然是错误的:
>>> s = 'abcdef'
>>> check_lastindexof(s, tests)
f FAILED expected: 5, got: -1
ef FAILED expected: 4, got: -1
abcdef FAILED expected: 0, got: -1
我是不是误解了 z3.LastIndexOf
应该如何工作,或者某处可能存在错误?
z3-solver 版本:4.8.14.0(通过 pip 安装)
这看起来确实是一个错误。请在 https://github.com/Z3Prover/z3/issues
举报