1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
|
//
// IntervalInference.cs
//
// Authors:
// Alexander Chebaturkin (chebaturkin@gmail.com)
//
// Copyright (C) 2012 Alexander Chebaturkin
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Collections.Generic;
using Mono.CodeContracts.Static.DataStructures;
using Mono.CodeContracts.Static.Lattices;
namespace Mono.CodeContracts.Static.Analysis.Numerical {
static class IntervalInference {
public static class ConstraintsFor {
public static IDictionary<TVar, Sequence<TInterval>> GreaterEqualThanZero<TEnv, TVar, TExpr, TInterval>
(TExpr expr, IExpressionDecoder<TVar, TExpr> decoder, TEnv env)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
var result = new Dictionary<TVar, Sequence<TInterval>> ();
var variable = decoder.UnderlyingVariable (expr);
AddToResult (result, variable, env.Eval (expr).Meet (env.Context.Positive));
if (!decoder.IsVariable (expr)) {
Polynomial<TVar, TExpr> zeroPoly; // poly(0)
if (!Polynomial<TVar, TExpr>.TryToPolynomial (new[] {Monomial<TVar>.From (Rational.Zero)}, out zeroPoly))
throw new AbstractInterpretationException (
"It can never be the case that the conversion of a list of monomials into a polynomial fails.");
Polynomial<TVar, TExpr> exprPoly; // poly(expr)
Polynomial<TVar, TExpr> fullPoly; // '0 <= poly(expr)' polynome
if (Polynomial<TVar, TExpr>.TryBuildFrom (expr, decoder, out exprPoly) &&
Polynomial<TVar, TExpr>.TryToPolynomial (ExpressionOperator.LessEqualThan, zeroPoly, exprPoly, out fullPoly) &&
fullPoly.IsIntervalForm) {
var k = fullPoly.Left[0].Coeff; // k != 0
TVar x;
fullPoly.Left[0].IsSingleVariable (out x);
Rational constraint;
if (Rational.TryDivide (fullPoly.Right[0].Coeff, k, out constraint)) {
TInterval interval;
if (k > 0L) // +x <= constraint
interval = env.Eval (x).Meet (env.Context.For (Rational.MinusInfinity, constraint));
else // -x <= -constraint ==> x >= constraint
interval = env.Eval (x).Meet (env.Context.For (constraint, Rational.PlusInfinity));
AddToResult (result, x, interval);
}
}
}
return result;
}
public static IDictionary<TVar, Sequence<TInterval>> LessEqualThan<TEnv, TVar, TExpr, TInterval>
(TExpr left, TExpr right, IExpressionDecoder<TVar, TExpr> decoder, TEnv env, out bool isBottom)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
isBottom = false;
var result = new Dictionary<TVar, Sequence<TInterval>> ();
if (IsFloat (left, decoder) || IsFloat (right, decoder))
return result;
var leftIntv = env.Eval (left);
var rightIntv = env.Eval (right);
var leftVar = decoder.UnderlyingVariable (left);
var rightVar = decoder.UnderlyingVariable (right);
TInterval refinedIntv;
if (TryRefineLessEqualThan<TEnv, TVar, TExpr, TInterval> (leftIntv, rightVar, env, out refinedIntv))
AddToResult (result, rightVar, refinedIntv);
if (TryRefineLeftLessEqualThanK<TEnv, TVar, TExpr, TInterval> (leftVar, rightIntv, env, out refinedIntv))
AddToResult (result, leftVar, refinedIntv);
Polynomial<TVar, TExpr> poly;
Polynomial<TVar, TExpr> leftPoly;
Polynomial<TVar, TExpr> rightPoly;
if (Polynomial<TVar, TExpr>.TryBuildFrom (left, decoder, out leftPoly) &&
Polynomial<TVar, TExpr>.TryBuildFrom (right, decoder, out rightPoly) &&
Polynomial<TVar, TExpr>.TryToPolynomial (ExpressionOperator.LessEqualThan, leftPoly, rightPoly, out poly) &&
poly.IsLinear) {
if (poly.Left.Length == 1)
return TestTrueLessEqualThan_AxLeqK (poly, env, result, out isBottom);
if (poly.Left.Length == 2)
return TestTrueLessEqualThan_AxByLeqK (poly, env, result, out isBottom);
}
return result;
}
public static IDictionary<TVar, Sequence<TInterval>> LessThan<TEnv, TVar, TExpr, TInterval>
(TExpr left, TExpr right, IExpressionDecoder<TVar, TExpr> decoder, TEnv env, out bool isBottom)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
isBottom = false;
var result = new Dictionary<TVar, Sequence<TInterval>> ();
var leftIntv = env.Eval (left);
var rightIntv = env.Eval (right);
var rightVar = decoder.UnderlyingVariable (right);
var successor = IsFloat (left, decoder) || IsFloat (right, decoder) ? Rational.Zero : Rational.One;
TInterval refinedIntv;
if (TryRefineKLessThanRight<TEnv, TVar, TExpr, TInterval> (leftIntv, rightVar, successor, env, out refinedIntv) && !refinedIntv.IsSinglePoint)
AddToResult (result, rightVar, refinedIntv);
if (successor.IsZero)
return result;
var leftVar = decoder.UnderlyingVariable (left);
if (TryRefineLessThan<TEnv, TVar, TExpr, TInterval> (leftVar, rightIntv, env, out refinedIntv) && !refinedIntv.IsSinglePoint)
AddToResult (result, leftVar, refinedIntv);
Polynomial<TVar, TExpr> poly;
Polynomial<TVar, TExpr> leftPoly;
Polynomial<TVar, TExpr> rightPoly;
if (Polynomial<TVar, TExpr>.TryBuildFrom (left, decoder, out leftPoly) &&
Polynomial<TVar, TExpr>.TryBuildFrom (right, decoder, out rightPoly) &&
Polynomial<TVar, TExpr>.TryToPolynomial (ExpressionOperator.LessThan, leftPoly, rightPoly, out poly) &&
poly.IsLinear) {
if (poly.Left.Length == 1)
return TestTrueLessEqualThan_AxLtK (poly, env, result, out isBottom);
if (poly.Left.Length == 2)
return TestTrueLessEqualThan_AxByLtK (poly, env, result, out isBottom);
}
return result;
}
/// <summary>
/// Get interval for 'left' in inequation 'left <= k'.
/// </summary>
public static bool TryRefineLeftLessEqualThanK<TEnv, TVar, TExpr, TInterval> (TVar left, TInterval k, TEnv env, out TInterval refined)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TInterval : IntervalBase<TInterval, Rational>
{
if (!k.IsNormal ())
return false.Without (out refined);
var interval = env.Context.For (Rational.MinusInfinity, k.UpperBound);
TInterval leftIntv;
if (env.TryGetValue (left, out leftIntv))
interval = interval.Meet (leftIntv);
return true.With (interval, out refined);
}
/// <summary>
/// Get interval for 'left' in inequation 'left < k'.
/// </summary>
public static bool TryRefineLessThan<TEnv, TVar, TExpr, TInterval> (TVar left, TInterval k, TEnv env, out TInterval refined)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TInterval : IntervalBase<TInterval, Rational>
{
if (!k.IsNormal ())
return false.Without (out refined);
var interval = env.Context.For (Rational.MinusInfinity, k.UpperBound.IsInteger ? k.UpperBound - 1L : k.UpperBound);
TInterval leftIntv;
if (env.TryGetValue (left, out leftIntv))
interval = interval.Meet (leftIntv);
return true.With (interval, out refined);
}
/// <summary>
/// Get interval for 'right' in inequation 'k <= right'.
/// </summary>
public static bool TryRefineLessEqualThan<TEnv, TVar, TExpr, TInterval> (TInterval k, TVar right, TEnv env, out TInterval refined)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TInterval : IntervalBase<TInterval, Rational>
{
if (!k.IsNormal ())
return false.Without (out refined);
var interval = env.Context.RightOpen (k.LowerBound);
TInterval rightIntv;
if (env.TryGetValue (right, out rightIntv))
interval = interval.Meet (rightIntv);
return true.With (interval, out refined);
}
/// <summary>
/// Get interval for 'right' in inequation 'k < right'.
/// </summary>
public static bool TryRefineKLessThanRight<TEnv, TVar, TExpr, TInterval> (TInterval k, TVar right, Rational successor, TEnv env, out TInterval refined)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TInterval : IntervalBase<TInterval, Rational>
{
if (!k.IsNormal ())
return false.Without (out refined);
// [k, +oo] or (k, +oo]
var interval = env.Context.For (k.LowerBound.IsInteger ? k.LowerBound + successor : k.LowerBound, Rational.PlusInfinity);
TInterval rightIntv;
if (env.TryGetValue (right, out rightIntv))
interval = interval.Meet (rightIntv);
return true.With (interval, out refined);
}
public static void NotEqual<TEnv, TVar, TExpr, TInterval>
(TExpr left, TExpr right, IExpressionDecoder<TVar, TExpr> decoder, TEnv env, out InferenceResult<TVar, TInterval> resultLeft,
out InferenceResult<TVar, TInterval> resultRight) where TInterval : IntervalBase<TInterval, Rational>
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
{
resultLeft = InferenceResult<TVar, TInterval>.Empty;
resultRight = InferenceResult<TVar, TInterval>.Empty;
var leftIntv = env.Eval (left);
var rightIntv = env.Eval (right);
var leftVar = decoder.UnderlyingVariable (left);
var rightVar = decoder.UnderlyingVariable (right);
var successor = IsFloat (left, decoder) || IsFloat (right, decoder) ? Rational.Zero : Rational.One;
// l != r <==> l < r && r < l
LessThanRefinement<TEnv, TVar, TExpr, TInterval> (successor, env, leftIntv, rightIntv, leftVar, rightVar, ref resultLeft);
LessThanRefinement<TEnv, TVar, TExpr, TInterval> (successor, env, rightIntv, leftIntv, rightVar, leftVar, ref resultRight);
}
static void LessThanRefinement<TEnv, TVar, TExpr, TInterval>
(Rational successor, TEnv env,
TInterval leftIntv, TInterval rightIntv,
TVar leftVar, TVar rightVar,
ref InferenceResult<TVar, TInterval> result)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TInterval : IntervalBase<TInterval, Rational>
where TVar : IEquatable<TVar>
{
TInterval refined;
if (TryRefineKLessThanRight<TEnv, TVar, TExpr, TInterval> (leftIntv, rightVar, successor, env, out refined))
result = result.AddConstraintFor (rightVar, refined);
if (TryRefineLessThan<TEnv, TVar, TExpr, TInterval> (leftVar, rightIntv, env, out refined))
result = result.AddConstraintFor (leftVar, refined);
}
static IDictionary<TVar, Sequence<TInterval>> TestTrueLessEqualThan_AxByLeqK<TEnv, TVar, TExpr, TInterval>
(Polynomial<TVar, TExpr> poly, TEnv env, IDictionary<TVar, Sequence<TInterval>> result, out bool isBottom)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
// ax + by <= k
var ax = poly.Left[0];
var by = poly.Left[1];
TVar x, y;
ax.IsSingleVariable (out x);
by.IsSingleVariable (out y);
var k = poly.Right[0].Coeff;
var a = ax.Coeff;
var b = by.Coeff;
var aInterval = env.Context.For (a);
var bInterval = env.Context.For (b);
var kInterval = env.Context.For (k);
var xInterval = env.Eval (x);
var yInterval = env.Eval (y);
IntervalContextBase<TInterval, Rational> ctx = env.Context;
// x <= (k - (b * y)) / a;
var boundingInterval = ctx.Div (ctx.Sub (kInterval, ctx.Mul (bInterval, yInterval)), aInterval);
Func<Rational, TInterval> upperBounded = (i) => ctx.For (Rational.MinusInfinity, i);
Func<Rational, TInterval> lowerBounded = (i) => ctx.For (i, Rational.PlusInfinity);
if (BoundVariable (ctx, a, xInterval, boundingInterval, x, result, out isBottom, upperBounded, lowerBounded))
return result;
// y <= (k - (a * x)) / b;
boundingInterval = ctx.Div (ctx.Sub (kInterval, ctx.Mul (aInterval, xInterval)), bInterval);
if (BoundVariable (ctx, b, yInterval, boundingInterval, y, result, out isBottom, upperBounded, lowerBounded))
return result;
return result;
}
static IDictionary<TVar, Sequence<TInterval>> TestTrueLessEqualThan_AxByLtK<TEnv, TVar, TExpr, TInterval>
(Polynomial<TVar, TExpr> poly, TEnv env, IDictionary<TVar, Sequence<TInterval>> result, out bool isBottom)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
// ax + by <= k
var ax = poly.Left[0];
var by = poly.Left[1];
TVar x, y;
ax.IsSingleVariable (out x);
by.IsSingleVariable (out y);
var k = poly.Right[0].Coeff;
var a = ax.Coeff;
var b = by.Coeff;
var aInterval = env.Context.For (a);
var bInterval = env.Context.For (b);
var kInterval = env.Context.For (k);
var xInterval = env.Eval (x);
var yInterval = env.Eval (y);
IntervalContextBase<TInterval, Rational> ctx = env.Context;
Func<Rational, TInterval> upperBounded =
(i) => ctx.For (Rational.MinusInfinity, !i.IsInteger ? i.PreviousInt32 : i - 1L);
Func<Rational, TInterval> lowerBounded =
(i) => ctx.For (!i.IsInteger ? i.NextInt32 : i + 1L, Rational.PlusInfinity);
// x <= (k - (b * y)) / a;
var boundingInterval = ctx.Div (ctx.Sub (kInterval, ctx.Mul (bInterval, yInterval)), aInterval);
if (BoundVariable (ctx, a, xInterval, boundingInterval, x, result, out isBottom, upperBounded, lowerBounded))
return result;
// y <= (k - (a * x)) / b;
boundingInterval = ctx.Div (ctx.Sub (kInterval, ctx.Mul (aInterval, xInterval)), bInterval);
if (BoundVariable (ctx, b, yInterval, boundingInterval, y, result, out isBottom, upperBounded, lowerBounded))
return result;
return result;
}
/// <summary>
/// Get constraints for variables from polynome in form 'a*x <= k'
/// </summary>
/// <param name="poly">Polynome in canonical form. Two monomes involved. </param>
static IDictionary<TVar, Sequence<TInterval>> TestTrueLessEqualThan_AxLeqK<TEnv, TVar, TExpr, TInterval>
(Polynomial<TVar, TExpr> poly, TEnv env, IDictionary<TVar, Sequence<TInterval>> result, out bool isBottom)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
isBottom = false;
var ax = poly.Left[0];
var k = poly.Right[1];
if (ax.IsConstant) {
if (ax.Coeff > k.Coeff) {
isBottom = true;
return result;
}
}
else {
TVar x;
ax.IsSingleVariable (out x);
Rational div;
if (Rational.TryDivide (k.Coeff, ax.Coeff, out div)) {
var intv = env.Eval (x);
var refined = ax.Coeff.Sign < 1
? intv.Meet (env.Context.For (div, Rational.PlusInfinity))
: intv.Meet (env.Context.For (Rational.MinusInfinity, div));
AddToResult (result, x, refined);
}
}
return result;
}
/// <summary>
/// Get constraints for variables from polynome in form 'a*x <= k'
/// </summary>
/// <param name="poly">Polynome in canonical form. Two monomes involved. </param>
static IDictionary<TVar, Sequence<TInterval>> TestTrueLessEqualThan_AxLtK<TEnv, TVar, TExpr, TInterval>
(Polynomial<TVar, TExpr> poly, TEnv env, IDictionary<TVar, Sequence<TInterval>> result, out bool isBottom)
where TEnv : IIntervalEnvironment<TVar, TExpr, TInterval, Rational>
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
isBottom = false;
var ax = poly.Left[0];
var k = poly.Right[1];
if (ax.IsConstant) {
if (ax.Coeff >= k.Coeff) {
isBottom = true;
return result;
}
}
else {
TVar x;
ax.IsSingleVariable (out x);
Rational div;
if (Rational.TryDivide (k.Coeff, ax.Coeff, out div)) {
var intv = env.Eval (x);
var boundByDivPlus = !div.IsInteger
? env.Context.For (div.NextInt32, Rational.PlusInfinity)
: env.Context.For (div + 1L, Rational.PlusInfinity);
var boundByDivMinus = !div.IsInteger
? env.Context.For (Rational.MinusInfinity, div.NextInt32 - 1L)
: env.Context.For (Rational.MinusInfinity, div - 1L);
var refined = intv.Meet (ax.Coeff.Sign < 1 ? boundByDivPlus : boundByDivMinus);
if (refined.IsBottom) {
isBottom = true;
return result;
}
AddToResult (result, x, refined);
}
}
return result;
}
static bool BoundVariable<TVar, TInterval>
(IntervalContextBase<TInterval, Rational> ctx, Rational a, TInterval xIntervalOld, TInterval boundingInterval, TVar x,
IDictionary<TVar, Sequence<TInterval>> result, out bool isBottom,
Func<Rational, TInterval> upperBounded, Func<Rational, TInterval> lowerBounded)
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
isBottom = false;
if (a.IsZero) {
TInterval boundingForVariable;
if (a.Sign > 0L)
boundingForVariable = upperBounded (boundingInterval.UpperBound);
else
boundingForVariable = lowerBounded (boundingInterval.LowerBound);
var refined = xIntervalOld.Meet (boundingForVariable);
if (refined.IsBottom) {
isBottom = true;
return true;
}
AddToResult (result, x, refined);
}
return false;
}
static bool IsFloat<TVar, TExpr> (TExpr expr, IExpressionDecoder<TVar, TExpr> decoder)
{
if (decoder == null)
return false;
var type = decoder.TypeOf (expr);
return type == ExpressionType.Float32 || type == ExpressionType.Float64;
}
static void AddToResult<TVar, TInterval> (IDictionary<TVar, Sequence<TInterval>> result, TVar variable, TInterval intv)
where TVar : IEquatable<TVar>
where TInterval : IntervalBase<TInterval, Rational>
{
Sequence<TInterval> value;
result.TryGetValue (variable, out value);
result[variable] = value.Cons (intv);
}
}
public struct InferenceResult<TVar, TInterval>
where TInterval : IAbstractDomain<TInterval>
where TVar : IEquatable<TVar> {
public static readonly InferenceResult<TVar, TInterval> Empty =
new InferenceResult<TVar, TInterval> (false, ImmutableMap<TVar, Sequence<TInterval>>.Empty);
public readonly bool IsBottom;
public readonly IImmutableMap<TVar, Sequence<TInterval>> Constraints;
InferenceResult (bool isbottom, IImmutableMap<TVar, Sequence<TInterval>> map)
{
Constraints = map;
IsBottom = isbottom;
}
public InferenceResult<TVar, TInterval> AddConstraintFor (TVar rightVar, TInterval refined)
{
Sequence<TInterval> seq;
Constraints.TryGetValue (rightVar, out seq);
return new InferenceResult<TVar, TInterval> (IsBottom, Constraints.Add (rightVar, seq.Cons (refined)));
}
public InferenceResult<TVar, TInterval> Join (InferenceResult<TVar, TInterval> that)
{
if (IsBottom)
return that;
if (that.IsBottom)
return this;
var result = Empty;
foreach (var var in Constraints.Keys) {
var leftContraints = Constraints[var];
if (leftContraints == null)
continue;
// tops are not included
Sequence<TInterval> rightConstraints;
if (that.Constraints.TryGetValue (var, out rightConstraints) && rightConstraints != null) {
var intv = leftContraints.Head.Join (rightConstraints.Head);
if (!intv.IsTop)
result.AddConstraintFor (var, intv);
}
}
return result;
}
}
}
}
|