how to define-fun in z3 fixedpoint by using C# API -


i want define functions can used in fixedpoint rule. example:

(declare-var int1 int) (declare-var int2 int) (declare-rel phi( int int)) (define-fun init((a int)(b int)) bool     (and         (= 0)         (= b 0)     ) )  (rule ( =>     (init int1 int2)     (phi int1 int2)) )  (query (and (phi int1 int2) (= int1 0)))    

it said there no api "define-fun", should translated quantifier in api. try use c# api implement it. however, wrong answer. ( result should satisfiable, however, unsatisfiable) code:

using (context ctx = new context()) {     var s = ctx.mkfixedpoint();     solver slover = ctx.mksolver();     intsort b = ctx.intsort;     realsort r = ctx.realsort;     boolsort t = ctx.boolsort;     intexpr int1 = (intexpr) ctx.mkbound(0, b);     intexpr int2 = (intexpr) ctx.mkbound(1, b);     funcdecl phi = ctx.mkfuncdecl("phi", new sort[] {b, b }, t);     funcdecl init = ctx.mkfuncdecl("init", new sort[] {b, b}, t);     s.registerrelation(phi);     s.registerrelation(init);     expr[] initbound = new expr[2];     initbound[0] = ctx.mkconst("init" + 0, init.domain[0]);     initbound[1] = ctx.mkconst("init" + 1, init.domain[1]);     expr initexpr = ctx.mkeq((boolexpr)init[initbound],     ctx.mkand(ctx.mkeq(initbound[0], ctx.mkint(0)), ctx.mkeq(initbound[1], ctx.mkint(0))));     quantifier q = ctx.mkforall(initbound, initexpr, 1);     slover.assert(q);     s.addrule(ctx.mkimplies((boolexpr)init[int1, int2],     (boolexpr)phi[int1, int2]));     status = s.query(ctx.mkand((boolexpr)phi[int1,int2],ctx.mkeq(int1, ctx.mkint(0)))); } 

what's problem?

below follows version macro turned rule.

var s = ctx.mkfixedpoint(); intsort b = ctx.intsort; boolsort t = ctx.boolsort; intexpr int1 = (intexpr) ctx.mkbound(0, b); intexpr int2 = (intexpr) ctx.mkbound(1, b); funcdecl phi = ctx.mkfuncdecl("phi", new sort[] {b, b }, t); funcdecl init = ctx.mkfuncdecl("init", new sort[] {b, b}, t); s.registerrelation(phi); s.registerrelation(init); expr[] initbound = new expr[2]; initbound[0] = ctx.mkconst("init" + 0, init.domain[0]); initbound[1] = ctx.mkconst("init" + 1, init.domain[1]); expr initexpr = ctx.mkimplies(       ctx.mkand(ctx.mkeq(initbound[0], ctx.mkint(0)), ctx.mkeq(initbound[1], ctx.mkint(0))),               (boolexpr)init[initbound]);  quantifier q = ctx.mkforall(initbound, initexpr, 1);  s.addrule(q); s.addrule(ctx.mkimplies((boolexpr)init[int1, int2], (boolexpr)phi[int1, int2]));  status = s.query(ctx.mkand((boolexpr)phi[int1,int2],ctx.mkeq(int1, ctx.mkint(0))));  console.writeline("{0}",a);  console.writeline("{0}", s.getanswer()); 

alternatively 1 can write function

term init(context ctx, term a, term b) {     term 0 = ctx.mkint(0);    return ctx.mkand(ctx.mkeq(a,zero),ctx.mkeq(b,zero)); } 

and use function apply "init".


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -