def test_solver_constrained_unsatisfiable(): domain = SignDomain(["a", "b", "c"]) state = SignAbstractState({ "a": Sign.Positive, "b": Sign.Negative, "c": Sign.Bottom }) solution = domain.model(domain.gamma_hat(state)) assert solution is None
def test_solver_constrained_satisfiable(): domain = SignDomain(["a", "b", "c"]) state = SignAbstractState({ "a": Sign.Positive, "b": Sign.Negative, "c": Sign.Positive }) solution = domain.model(domain.gamma_hat(state)) assert solution is not None assert solution.value_of("a") > 0 assert solution.value_of("b") < 0 assert solution.value_of("c") > 0
def test_bilateral_alphahat_bottom(): """Attempts to analyze computation where the resulting alpha-hat is bottom phi := y = x*x && y < 0 """ domain = SignDomain(["x", "y"]) x = domain.z3_variable("x") y = domain.z3_variable("y") phi = z3.And(y == x * x, y < 0) alpha_hat = bilateral(domain, phi) assert alpha_hat == domain.bottom
def main(): """Construct and analyze the example program. """ program = Program(""" x += 5 x -= y y += 5 y -= 3 x -= 6 z += 1 """) domain = SignDomain(["x", "y", "z"]) input_state = SignAbstractState({ "x": Sign.Negative, "y": Sign.Positive, "z": Sign.Negative, }) output_state = program.transform(domain, input_state) print(output_state) assert output_state.sign_of("x") == Sign.Negative assert output_state.sign_of("y") == Sign.Positive assert output_state.sign_of("z") == Sign.Top
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)
def test_bilateral_disjunction(): """Attempts to analyze computation of the form: x' := x * x With the assumption that x > 0 or x < 0 """ domain = SignDomain(["x", "x'"]) x = domain.z3_variable("x") xp = domain.z3_variable("x'") phi = z3.And(z3.Or(x > 0, x < 0), xp == x * x) alpha_hat = bilateral(domain, phi) assert alpha_hat.sign_of("x") == Sign.Top assert alpha_hat.sign_of("x'") == Sign.Positive
def test_RSY_alpha_hat_useful(): """Attempts to analyze computation of the form: x' := ((x * x) + 1) * ((x * x) + 1) """ domain = SignDomain(["x", "x'"]) x = domain.z3_variable("x") xp = domain.z3_variable("x'") phi = z3.And(xp == ((x * x) + 1) * ((x * x) + 1)) # Just from the statements themselves, we can say that x' is positive # (regardless of the value of x). alpha_hat = RSY(domain, phi) assert alpha_hat.sign_of("x") == Sign.Top assert alpha_hat.sign_of("x'") == Sign.Positive
def test_RSY_alpha_hat_add_subtract(): """Attempts to analyze computation of the form: x' := x - 5 x'' := x + 5 """ domain = SignDomain(["x", "x'", "x''"]) x = domain.z3_variable("x") xp = domain.z3_variable("x'") xpp = domain.z3_variable("x''") phi = z3.And(xp == x - 5, xpp == xp + 5) # Just from the statements themselves, we can't say anything about the sign # of x/x'/x'' alpha_hat = RSY(domain, phi) assert alpha_hat.sign_of("x") == Sign.Top assert alpha_hat.sign_of("x'") == Sign.Top assert alpha_hat.sign_of("x''") == Sign.Top
def test_RSY_post_hat_add_subtract(): """Here, we add the knowledge of the input state """ domain = SignDomain(["x", "x'", "x''"]) x = domain.z3_variable("x") xp = domain.z3_variable("x'") xpp = domain.z3_variable("x''") phi = z3.And(xp == x - 5, xpp == xp + 5) # This is where we add our supposition about the input state = SignAbstractState({ "x": Sign.Positive, "x'": Sign.Top, "x''": Sign.Top }) phi = z3.And(domain.gamma_hat(state), phi) post_hat = RSY(domain, phi) assert post_hat.sign_of("x") == Sign.Positive assert post_hat.sign_of("x'") == Sign.Top assert post_hat.sign_of("x''") == Sign.Positive