```python
import numpy as np
import sympy
sympy.init_printing(use_unicode=True)
from sympy import *
from sympy.solvers import solve
from IPython.display import display

def simplified(exp):
    simp = simplify(exp)
    display(simp)
    return simp

def firstOrderCondition(exp, var, iSelectedSolution=None):
    diffExp = simplify(diff(exp, var))
    display(diffExp)
    solutions = solve(diffExp, var)
    display(solutions)
    if iSelectedSolution is not None:
        solution = solutions[iSelectedSolution]
        optimum = exp.subs(var, solution)
        return simplified(optimum)
    else:
        return solutions

x = symbols('x')
w,A,B = symbols('w A B', Integer=True, Positive=True)
n,p,q,d = symbols('n p q d', positive=True)
```

### Optimal Channel Initialization


```python
Xn = simplified(n/(2*p-1) - w/(2*p-1)*(1-(p/(1-p))**n)/(1-(p/(1-p))**w) )
```


```python
firstOrderCondition(Xn,n)
```


```python
Xn = simplified(n*(1-q**(-w/B)) - w*(1-q**(-n/B)))
firstOrderCondition(Xn,n)
```


```python
nopt.subs(B,1)
```


```python
nopt.subs(q,1/2)
```


```python
sympy.simplify(Xn.subs(n,nopt))
```


```python
cp = (A * x**(A+1) - (A+1)*x**A + 1)/(x-1)
cp
```


```python
sympy.simplify(cp.subs(A, 3))
```

c69e0b3ecf93f91bd212a530c1decc49f3403b5f
ipynb
Jupyter Notebook
old/sympy-sample-notebook.ipynb
erelsgl/bitcoin-simulations
79bfa0930ab9ad17be59b9cad1ec6e7c3530aa3b
MIT
2018-11-26T02:44:38.000Z
2018-11-26T02:44:38.000Z
old/sympy-sample-notebook.ipynb
erelsgl/bitcoin-simulations
79bfa0930ab9ad17be59b9cad1ec6e7c3530aa3b
MIT
old/sympy-sample-notebook.ipynb
erelsgl/bitcoin-simulations
79bfa0930ab9ad17be59b9cad1ec6e7c3530aa3b
MIT
2018-09-06T00:11:26.000Z
2021-08-29T17:14:59.000Z
Qwen/Qwen-72B
1. YES
2. YES