symbops.py
819 Bytes
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
from unicodedata import numeric
from sympy import *
from sympy.plotting import plot
def variants(expr, with_plot=False):
print(f"Expr: {latex(expr)}")
print(f"Simplify: {latex(simplify(expr))}")
print(f"Expand: {latex(expand(expr))}")
print(f"Factor: {latex(factor(expr))}")
if with_plot:
plot(expr, (d, 0, 1, 10),ylabel="$\\mathrm{P(expr \\mid \\alpha = 0.3)}$")
init_printing(use_unicode=True)
a, d = symbols('a d')
A = 1 - a
D = 1 - d
wab = a * d
wac = a * D
wA = A
wabc = wab * wac
wAb = wA
wa = wab + wac
wb = wab
wc = wac
wE = wab + wab + wA
z = wabc + 9 * wA + wab + wac + wa + wb +wc + wE
pabc = wabc/z
z_03 = z.subs(a, 0.3)
wabc_03 = wabc.subs(a, 0.3)
pabc_03 = pabc.subs(a, 0.3)
variants(z_03)
variants(wabc_03)
variants(pabc_03)
print(solve(wabc_03 - 0.0015 * z_03, d))