def test_join_meet_three_states():
    domain = IntervalDomain(["a", "b", "c"])
    state1 = IntervalAbstractState({
        "a": Interval(-5, 5),
        "b": Interval(4, 6),
        "c": Interval(float("inf"), float("-inf")),
    })
    state2 = IntervalAbstractState({
        "a": Interval(-4, 6),
        "b": Interval(float("-inf"), -2),
        "c": Interval(5, 5),
    })
    state3 = IntervalAbstractState({
        "a": Interval(-5, 5),
        "b": Interval(-4, float("inf")),
        "c": Interval(5, 5),
    })

    joined = domain.join([state1, state2, state3])

    assert joined.interval_of("a") == Interval(-5, 6)
    assert joined.interval_of("b") == Interval(float("-inf"), float("inf"))
    assert joined.interval_of("c") == Interval(5, 5)

    met = domain.meet([state1, state2, state3])

    assert met.interval_of("a") == Interval(-4, 5)
    assert met.interval_of("b") == Interval(float("inf"), float("-inf"))
    assert met.interval_of("c") == Interval(float("inf"), float("-inf"))
def test_solver_constrained_unsatisfiable():
    domain = IntervalDomain(["a", "b", "c"])
    state = IntervalAbstractState({
        "a": Interval(0, 100),
        "b": Interval(float("inf"), float("-inf")),
        "c": Interval(1, 11),
    })
    solution = domain.model(domain.gamma_hat(state))

    assert solution is None
def test_abstract_consequence_low_best():
    domain = IntervalDomain(["a", "b", "c"])
    lower = IntervalAbstractState({
        "a": Interval(0, float("inf")),
        "b": Interval(float("-inf"), float("inf")),
        "c": Interval(float("-inf"), float("inf")),
    })
    upper = lower.copy()

    consequence = domain.abstract_consequence(lower, upper)

    assert consequence == lower
def test_solver_constrained_satisfiable():
    domain = IntervalDomain(["a", "b", "c"])
    state = IntervalAbstractState({
        "a": Interval(0, 100),
        "b": Interval(-50, -50),
        "c": Interval(1, 11),
    })
    solution = domain.model(domain.gamma_hat(state))

    assert solution is not None

    assert 0 <= solution.value_of("a") <= 100
    assert solution.value_of("b") == -50
    assert 1 <= solution.value_of("c") <= 11
def test_solver_one_unconstrained_satisfiable():
    domain = IntervalDomain(["a", "b", "c"])
    state = IntervalAbstractState({
        "a": Interval(0, 100),
        "b": Interval(-50, -50),
        "c": Interval(float("-inf"), float("inf"))
    })
    solution = domain.model(domain.gamma_hat(state))

    assert solution is not None

    assert 0 <= solution.value_of("a") <= 100
    assert solution.value_of("b") == -50
    assert isinstance(solution.value_of("c"), int)
Esempio n. 6
0
def test_reduce_sign_interval():
    domain_A = SignDomain(["x", "y", "z"])
    input_state_A = SignAbstractState({
        "x": Sign.Negative,
        "y": Sign.Positive,
        "z": Sign.Top,
    })
    domain_B = IntervalDomain(["x", "y", "z"])
    input_state_B = IntervalAbstractState({
        "x": Interval(-2, 3),
        "y": Interval(-5, 5),
        "z": Interval(1, 15),
    })

    domain = ReducedProductDomain(["x", "y", "z"], domain_A, domain_B)
    input_state = ReducedProductAbstractState(input_state_A, input_state_B)
    reduced = domain.reduce(input_state)

    assert reduced.state_A.sign_of("x") == Sign.Negative
    assert reduced.state_A.sign_of("y") == Sign.Positive
    assert reduced.state_A.sign_of("z") == Sign.Positive

    assert reduced.state_B.interval_of("x") == Interval(-2, -1)
    assert reduced.state_B.interval_of("y") == Interval(1, 5)
    assert reduced.state_B.interval_of("z") == Interval(1, 15)
Esempio n. 7
0
def test_bilateral_alpha_hat_add_subtract():
    """Attempts to analyze computation of the form:

    x' := x - 5
    x'' := x' + 5
    """
    domain = IntervalDomain(["x", "x'", "x''"])

    x = domain.z3_variable("x")
    xp = domain.z3_variable("x'")
    xpp = domain.z3_variable("x''")

    # Bounds needed to avoid infinite ascending chains (in practice we should
    # use, eg., widening).
    phi = z3.And(xp == x - 5, xpp == xp + 5, x <= 5, x >= -5)

    # Just from the statements themselves, we can't say anything about the sign
    # of x/x'/x''
    alpha_hat = bilateral(domain, phi)
    assert alpha_hat == RSY(domain, phi)
    assert alpha_hat.interval_of("x") == Interval(-5, 5)
    assert alpha_hat.interval_of("x'") == Interval(-10, 0)
    assert alpha_hat.interval_of("x''") == Interval(-5, 5)
def test_join_bottom_top():
    domain = IntervalDomain(["a", "b", "c"])
    joined = domain.join([domain.bottom, domain.top])

    assert joined == domain.top