Z3解算器用于基于字符串的约束

时间:2015-06-03 08:28:27

标签: c# z3

我正在尝试使用Z3来解决使用Z3 C#API的字符串约束。

到目前为止,我已经研究过示例,但Z3似乎只支持基于数字的代数表达式,例如:

x > 0
y = x + 1 
y < 3

可以使用z3 c#API表示为:

using (Context ctx = new Context())
{
    Expr x = ctx.MkConst("x", ctx.MkIntSort());
    Expr y = ctx.MkConst("y", ctx.MkIntSort());
    Expr zero = ctx.MkNumeral(0, ctx.MkIntSort());
    Expr one = ctx.MkNumeral(1, ctx.MkIntSort());
    Expr three = ctx.MkNumeral(3, ctx.MkIntSort());

    Solver s = ctx.MkSolver();
    s.Assert(ctx.MkAnd(ctx.MkGt((ArithExpr)x, (ArithExpr)zero), ctx.MkEq((ArithExpr)y, 
        ctx.MkAdd((ArithExpr)x, (ArithExpr)one)), ctx.MkLt((ArithExpr)y, (ArithExpr)three)));
    Console.WriteLine(s.Check());

    Model m = s.Model;
    foreach (FuncDecl d in m.Decls)
            Console.WriteLine(d.Name + " -> " + m.ConstInterp(d));

    Console.ReadLine();
}

有没有办法评估基于字符串的表达式,例如:

string S1;
string S2:
string S3;
S3=S1+S2;

任何有关基于字符串的约束的帮助都将受到赞赏。

2 个答案:

答案 0 :(得分:1)

Z3本身不支持字符串作为原始数据类型。 你可以试试z3-str(https://github.com/z3str/Z3-str)。

新加坡国立大学还有S3系统,如ccs 2014所述。

答案 1 :(得分:0)

请注意,Z3 现在支持 String 类型,但有一些限制。此处参考:Z3 solver for string based constraints

相关问题