From 0121d5231da0ac092b5295ed265684fa7c1f53f4 Mon Sep 17 00:00:00 2001 From: Rustan Leino Date: Sun, 13 Apr 2014 11:28:18 -0700 Subject: Fixed abstract interpretation for reals --- Source/AbsInt/IntervalDomain.cs | 161 ++++++++++++++++++++++++++-------------- 1 file changed, 107 insertions(+), 54 deletions(-) (limited to 'Source/AbsInt') diff --git a/Source/AbsInt/IntervalDomain.cs b/Source/AbsInt/IntervalDomain.cs index 640a50fc..6cce0aac 100644 --- a/Source/AbsInt/IntervalDomain.cs +++ b/Source/AbsInt/IntervalDomain.cs @@ -34,7 +34,8 @@ namespace Microsoft.Boogie.AbstractInterpretation public class Node { public readonly Variable V; // variable has type bool or int - // For an integer variable (Lo,Hi) indicates Lo <= V < Hi, where Lo==null means no lower bound and Hi==null means no upper bound + // For an integer variable (Lo,Hi) indicates Lo <= V < Hi, where Lo==null means no lower bound and Hi==null means no upper bound. + // For a real variable (Lo,Hi) indicates Lo <= V <= Hi, where Lo==null means no lower bound and Hi==null means no upper bound. // For a boolean variable, (Lo,Hi) is one of: (null,null) for {false,true}, (null,1) for {false}, and (1,null) for {true}. public readonly BigInteger? Lo; public readonly BigInteger? Hi; @@ -153,7 +154,7 @@ namespace Microsoft.Boogie.AbstractInterpretation if (!V.IsMutable && CommandLineOptions.Clo.InstrumentInfer != CommandLineOptions.InstrumentationPlaces.Everywhere) { // omit invariants about readonly variables return Expr.True; - } else if (V.TypedIdent.Type.IsBool) { + } else if (V.TypedIdent.Type.IsBool) { if (Lo == null && Hi == null) { return Expr.True; } else { @@ -161,7 +162,7 @@ namespace Microsoft.Boogie.AbstractInterpretation var ide = new IdentifierExpr(Token.NoToken, V); return Hi == null ? ide : Expr.Not(ide); } - } else { + } else if (V.TypedIdent.Type.IsInt) { Expr e = Expr.True; if (Lo != null && Hi != null && Lo + 1 == Hi) { // produce an equality @@ -179,6 +180,25 @@ namespace Microsoft.Boogie.AbstractInterpretation } } return e; + } else { + Contract.Assert(V.TypedIdent.Type.IsReal); + Expr e = Expr.True; + if (Lo != null && Hi != null && Lo == Hi) { + // produce an equality + var ide = new IdentifierExpr(Token.NoToken, V); + e = Expr.And(e, BplEq(ide, NumberToExpr((BigInteger)Lo, V.TypedIdent.Type))); + } else { + // produce a (possibly empty) conjunction of inequalities + if (Lo != null) { + var ide = new IdentifierExpr(Token.NoToken, V); + e = Expr.And(e, BplLe(NumberToExpr((BigInteger)Lo, V.TypedIdent.Type), ide)); + } + if (Hi != null) { + var ide = new IdentifierExpr(Token.NoToken, V); + e = Expr.And(e, BplLe(ide, NumberToExpr((BigInteger)Hi, V.TypedIdent.Type))); + } + } + return e; } } } @@ -292,8 +312,8 @@ namespace Microsoft.Boogie.AbstractInterpretation } else { var lo = Node.Max(x.Lo, y.Lo, true); var hi = Node.Min(x.Hi, y.Hi, true); - // if hi<=lo, then we're overconstrained - if (lo != null && hi != null && hi <= lo) { + // if hi<=lo (or hi