def test_parse_12(): # 2*sqrt(|x|) - 3 > 10 expr = 2*Sqrt(Abs(X)) - 3 expr_prime = Poly(Sqrt(Abs(Y)), [-3, 2]) assert expr == expr_prime event = EventInterval(expr, Interval.open(10, oo)) assert (expr > 10) == event
def test_solver_10(): # Sympy hangs on this test. # exp(sqrt(log(x))) > -5 solution = Interval(1, oo) event = Exp(Sqrt(Log(Y))) > -5 answer = event.solve() assert answer == solution
def test_solver_13(): # 2*sqrt(|x|**2) - 3 > 10 solution = Union( Interval.open(-oo, -Rat(13, 2)), Interval.open(Rat(13, 2), oo)) event = (2*Sqrt(abs(Y)**2) - 3) > 10 answer = event.solve() assert answer == solution
def test_dnf_factor(): E00 = Exp(X0) > 0 E01 = X0 < 10 E10 = X1 < 10 E20 = (X2**2 - X2 * 3) < 0 E30 = X3 > 10 E31 = (Sqrt(2 * X3)) < 0 E40 = X4 > 0 E41 = X4 << [1, 5] E50 = 10 * Log(X5) + 9 > 5 event = (E00) event_dnf = event.to_dnf() dnf = dnf_factor(event_dnf) assert len(dnf) == 1 assert dnf[0][X0] == E00 event = E00 & E01 event_dnf = event.to_dnf() dnf = dnf_factor(event_dnf) assert len(dnf) == 1 assert dnf[0][X0] == E00 & E01 event = E00 | E01 event_dnf = event.to_dnf() dnf = dnf_factor(event_dnf) assert len(dnf) == 2 assert dnf[0][X0] == E00 assert dnf[1][X0] == E01 event = E00 | (E01 & E10) event_dnf = event.to_dnf() dnf = dnf_factor(event_dnf, {X0: 0, X1: 0}) assert len(dnf) == 2 assert dnf[0][0] == E00 assert dnf[1][0] == E01 & E10 event = (E00 & E01 & E10 & E30 & E40) | (E20 & E50 & E31 & ~E41) # For the second clause we have: # ~E41 = (-oo, 1) U (1, 5) U (5, oo) # so the second clause becomes # = (E20 & E50 & E31 & ((-oo, 1) U (1, 5) U (5, oo))) # = (E20 & E50 & E31 & (-oo, 1)) # or (E20 & E50 & E31 & (1, 5)) # or (E20 & E50 & E31 & (5, oo)) event_dnf = event.to_dnf() event_factor = dnf_factor(event_dnf) assert len(event_factor) == 4 # clause 0 assert len(event_factor[0]) == 4 assert event_factor[0][X0] == E00 & E01 assert event_factor[0][X1] == E10 assert event_factor[0][X3] == E30 assert event_factor[0][X4] == E40 # clause 1 assert len(event_factor[1]) == 4 assert event_factor[1][X3] == E31 assert event_factor[1][X2] == E20 assert event_factor[1][X4] == (X4 < 1) assert event_factor[1][X5] == E50 # clause 2 assert len(event_factor[2]) == 4 assert event_factor[2][X3] == E31 assert event_factor[2][X2] == E20 assert event_factor[2][X4] == (1 < (X4 < 5)) assert event_factor[2][X5] == E50 # clause 3 assert len(event_factor[3]) == 4 assert event_factor[3][X3] == E31 assert event_factor[3][X2] == E20 assert event_factor[3][X4] == (5 < X4) assert event_factor[3][X5] == E50
def test_solver_11_closed(): # exp(sqrt(log(x))) >= 6 solution = Interval(sympy.exp(sympy.log(6)**2), oo) event = Exp(Sqrt(Log(Y))) >= 6 answer = event.solve() assert answer == solution
def test_parse_13(): # 2*sqrt(|x|**2) - 3 > 10 expr = 2*Sqrt(Abs(X)**2) - 3 expr_prime = Poly(Sqrt(Pow(Abs(Y), 2)), [-3, 2]) assert expr == expr_prime
def test_parse_10(): # exp(sqrt(log(x))) > -5 expr = Exp(Sqrt(Log(Y))) event = EventInterval(expr, Interval.open(-5, oo)) assert (expr > -5) == event