```python
from sympy import Symbol, FiniteSet, sympify
from jupyter_math.main import TallBrace, Event, EventSet, SumOverFiniteSet, Probability, Intermediate
from jupyter_math import Def, Pr, EXPAND_OUTER_SUM, SUBSTITUTE_ALL, GET_RESULT
Pr = Probability


d = Def(Symbol('C_A'), FiniteSet('1','2'))
d.display()

TallBrace([d, Symbol('x')]).display()

a = Event('I am happy')
b = Event('not happy')
es = EventSet([a,b])
es.display()

Def(Symbol('X'), es).display()




def lookup_func():
    return None
# 
# s = SumOverFiniteSet(sympify('f(x)'), E_space, 'x')
# s.display()

# 
# gini.display_evaluation(lookup_func, [])
# gini = Def('G', SumOverFiniteSet(Pr(x) , E_space, 'x'))
def lookup(zz):
    lc = {Pr('raining'): 0.6, Pr('sunny'): 0.4, Pr('B', 'sunny'):0.15, Pr('B', 'raining'):0.8, Pr('A', 'raining'): 0.2, Pr('A', 'sunny'): 0.85}
    # if isinstance(zz, Pr):
    #     print(zz._event, print(zz._condition))
    if zz in lc:
        # print('accepted: ', zz)
        return lc[zz]
    
    
    
E_space = Def('E', EventSet(['raining', 'sunny']))
E_space.display()
x = Def('x')
gini = Def('G', SumOverFiniteSet(Pr(x) * (Pr('A', x)**2 + Pr('B', x)**2), E_space, 'x'))
gini.display_evaluation(lookup, [EXPAND_OUTER_SUM, SUBSTITUTE_ALL, GET_RESULT])



pr = Probability('rain', 'humid')
(pr**2).display()

prc = Def('G', SumOverFiniteSet(Pr(x) + Pr(x) , E_space, 'x'))
# prc.display()
prc.display_evaluation(lambda x:1, [Intermediate.EXPAND_OUTER_SUM, Intermediate.SUBSTITUTE_ALL])


pr1 = Probability('rain')
pr1.display()

((pr + pr1)*pr**2).display()

# new_s = SumOverFiniteSet(, E_space, 'x')
```


\[C_{A} = \left\{1, 2\right\}\]



\[\left\{
                \begin{array}{ll}C_{A}\\x
                \end{array}
              \right.\]



\[\{\text{I am happy},\;\text{not happy}\}\]



\[X = \{\text{I am happy},\;\text{not happy}\}\]



\[E = \{\text{raining},\;\text{sunny}\}\]



$\displaystyle \begin{align}

G &= \sum_{x \in E} \Pr(\,x\,) \times ({\Pr(\,\text{A} \mid x\,)}^2 + {\Pr(\,\text{B} \mid x\,)}^2)\\ 
 &= (\Pr(\,\text{raining}\,) \times ({\Pr(\,\text{A} \mid \text{raining}\,)}^2 + {\Pr(\,\text{B} \mid \text{raining}\,)}^2)) + (\Pr(\,\text{sunny}\,) \times ({\Pr(\,\text{A} \mid \text{sunny}\,)}^2 + {\Pr(\,\text{B} \mid \text{sunny}\,)}^2))\\ 
 &= (0.6 \times (0.04 + 0.64)) + (0.4 \times (0.722 + 0.022))\\ 
 &= 0.706
        
\end{align}
        $



\[{\Pr(\,\text{rain} \mid \text{humid}\,)}^2\]



$\displaystyle \begin{align}

G &= \sum_{x \in E} \Pr(\,x\,) + \Pr(\,x\,)\\ 
 &= (\Pr(\,\text{raining}\,) + \Pr(\,\text{raining}\,)) + (\Pr(\,\text{sunny}\,) + \Pr(\,\text{sunny}\,))\\ 
 &= 1
        
\end{align}
        $



\[\Pr(\,\text{rain}\,)\]



\[(\Pr(\,\text{rain} \mid \text{humid}\,) + \Pr(\,\text{rain}\,)) \times {\Pr(\,\text{rain} \mid \text{humid}\,)}^2\]


7e06a4a6972b7ab59cea37db6f59ad89f5ac26be
ipynb
Jupyter Notebook
tests/interactive_test.ipynb
Madoshakalaka/jupyter-math
d01d33ac5a0be413110210a08feef50e6f110bd2
MIT
tests/interactive_test.ipynb
Madoshakalaka/jupyter-math
d01d33ac5a0be413110210a08feef50e6f110bd2
MIT
2020-02-24T19:43:31.000Z
2021-08-23T20:19:18.000Z
tests/interactive_test.ipynb
Madoshakalaka/jupyter-math
d01d33ac5a0be413110210a08feef50e6f110bd2
MIT
Qwen/Qwen-72B
1. YES
2. YES