Comment #9 on issue 636 by mattpap: integrate(1/(x**2+1)) should return
arctan(x)
http://code.google.com/p/sympy/issues/detail?id=636
I've finally made ratint() integrate 1/(1+x^5):
In [1]: from sympy.integrals.rationaltools import *
In [2]: ratint(1/(1+x**1), x)
Out[2]: log(1 + x)
In [3]: simplify(diff(_, x))
Out[3]:
1
─────
1 + x
In [4]: ratint(1/(1+x**2), x)
Out[4]: atan(x)
In [5]: simplify(diff(_, x))
Out[5]:
1
──────
2
1 + x
In [6]: ratint(1/(1+x**3), x)
Out[6]:
⎛ ⎽⎽⎽ ⎽⎽⎽⎞
⎽⎽⎽ ⎜ ╲╱ 3 2⋅x⋅╲╱ 3 ⎟
⎛ 2⎞ ╲╱ 3 ⋅atan⎜- ───── + ─────────⎟
log⎝1 - x + x ⎠ log(1 + x) ⎝ 3 3 ⎠
- ─────────────── + ────────── + ───────────────────────────────
6 3 3
In [7]: simplify(diff(_, x))
Out[7]:
1
──────
3
1 + x
In [8]: ratint(1/(1+x**4), x)
Out[8]:
⎽⎽⎽ ⎛ ⎽⎽⎽⎞ ⎽⎽⎽ ⎛ ⎽⎽⎽ 2⎞ ⎽⎽⎽
⎛ ⎽⎽⎽⎞
⎽⎽⎽ ⎛ ⎽⎽⎽ 2⎞
╲╱ 2 ⋅atan⎝1 - x⋅╲╱ 2 ⎠ ╲╱ 2 ⋅log⎝1 - x⋅╲╱ 2 + x ⎠ ╲╱ 2 ⋅atan⎝1 +
x⋅╲╱ 2 ⎠
╲╱ 2 ⋅log⎝1 + x⋅╲╱ 2 + x ⎠
- ─────────────────────── - ─────────────────────────── +
─────────────────────── +
───────────────────────────
4 8 4
8
In [9]: simplify(diff(_, x))
Out[9]:
1
──────
4
1 + x
In [10]: ratint(1/(1+x**5), x)
Out[10]:
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎛ ⎽⎽⎽⎞ ⎛ ⎛ ⎽⎽⎽⎞ ⎞ ⎛
⎽⎽⎽⎞ ⎛
⎛ ⎽⎽⎽⎞ ⎞ ╱ ⎽
log(1 + x) ⎜ ╲╱ 5 ⎟ ⎜ ⎜ ╲╱ 5 ⎟ 2⎟ ⎜ ╲╱ 5
⎟ ⎜
⎜ ╲╱ 5 ⎟ 2⎟ ╱ ╲╱
────────── - ⎜1/20 - ─────⎟⋅log⎜1 - x⋅⎜1/2 - ─────⎟ + x ⎟ - ⎜1/20 +
─────⎟⋅log⎜1 -
x⋅⎜1/2 + ─────⎟ + x ⎟ + 2⋅ ╱ 1/40 - ───
5 ⎝ 20 ⎠ ⎝ ⎝ 2 ⎠ ⎠ ⎝ 20
⎠ ⎝
⎝ 2 ⎠ ⎠ ╲╱ 20
⎽⎽⎽
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎽⎽ ⎛ ⎽⎽⎽ ⎽⎽⎽ ⎞ ╱
⎽⎽⎽
⎛ ⎽⎽⎽ ⎽⎽⎽
5 ⎜ 800 + 160⋅╲╱ 5 8⋅x⋅╲╱ 5 ⎟ ╱
╲╱ 5
⎜ 800 - 160⋅╲╱ 5 8⋅x⋅╲╱ 5
── ⋅atan⎜- ────────────────────── + ───────────────────⎟ + 2⋅ ╱ 1/40 +
─────
⋅atan⎜────────────────────── + ──────────────
0 ⎜ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎟ ╲╱
200
⎜ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎜ ╱ ⎽⎽⎽ ╱ ⎽⎽⎽ ⎟
⎜ ╱ ⎽⎽⎽ ╱
⎝ 80⋅╲╱ 200 - 40⋅╲╱ 5 ╲╱ 200 - 40⋅╲╱ 5 ⎠
⎝80⋅╲╱ 200 + 40⋅╲╱ 5 ╲╱ 200 + 40⋅╲
⎞
⎟
─────⎟
⎽⎽⎽⎽⎽⎟
⎽⎽⎽ ⎟
╱ 5 ⎠
but here we can't simplify so ... hack, hack, hack:
In [11]: diff(_, x)
Out[11]:
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎛ ⎽⎽⎽⎞ ⎛ ⎽⎽⎽⎞ ⎛ ⎽⎽⎽⎞ ⎛ ⎽⎽⎽⎞
╱ ⎽⎽⎽
⎜ ╲╱ 5 ⎟ ⎜ ╲╱ 5 ⎟ ⎜ ╲╱ 5 ⎟ ⎜ ╲╱ 5 ⎟
⎽⎽⎽ ╱ ╲╱ 5
⎜1/20 + ─────⎟⋅⎜1/2 - 2⋅x + ─────⎟ ⎜1/20 - ─────⎟⋅⎜1/2 - 2⋅x - ─────⎟
16⋅╲╱ 5 ⋅ ╱ 1/40 - ─────
⎝ 20 ⎠ ⎝ 2 ⎠ ⎝ 20 ⎠ ⎝ 2 ⎠
╲╱ 200
────────────────────────────────── + ────────────────────────────────── +
───────────────────────────────────────────────────
⎛ ⎽⎽⎽⎞ ⎛ ⎽⎽⎽⎞ ⎛
⎜ ╲╱ 5 ⎟ 2 ⎜ ╲╱ 5 ⎟ 2
⎜ ⎛
⎽⎽⎽ ⎽⎽⎽
1 - x⋅⎜1/2 + ─────⎟ + x 1 - x⋅⎜1/2 - ─────⎟ + x
⎜ ⎜
800 + 160⋅╲╱ 5 8⋅x⋅╲╱ 5
⎝ 2 ⎠ ⎝ 2 ⎠
⎜1 + ⎜-
────────────────────── + ──────────────────
⎜ ⎜
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎜ ⎜
╱ ⎽⎽⎽ ╱ ⎽⎽⎽
⎝ ⎝
80⋅╲╱ 200 - 40⋅╲╱ 5 ╲╱ 200 - 40⋅╲╱ 5
⎽
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
╱
⎽⎽⎽
⎽⎽⎽ ╱ ╲╱ 5
16⋅╲╱ 5 ⋅ ╱ 1/40 +
─────
╲╱ 200
1
──────────────────────── +
───────────────────────────────────────────────────────────────────────── +
─────────
2⎞
⎛ 2⎞
5⋅(1 + x)
⎞ ⎟ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽ ⎜ ⎛ ⎽⎽⎽
⎽⎽⎽ ⎞ ⎟
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎟ ⎟ ╱ ⎽⎽⎽ ⎜ ⎜ 800 - 160⋅╲╱ 5 8⋅x⋅╲╱
5 ⎟ ⎟ ╱
⎽⎽⎽
─⎟ ⎟⋅╲╱ 200 - 40⋅╲╱ 5 ⎜1 + ⎜────────────────────── +
───────────────────⎟ ⎟⋅╲╱
200 + 40⋅╲╱ 5
⎽⎟ ⎟ ⎜ ⎜ ⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽
⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎽⎟ ⎟
⎟ ⎟ ⎜ ⎜ ╱ ⎽⎽⎽ ╱
⎽⎽⎽ ⎟ ⎟
⎠ ⎠ ⎝ ⎝80⋅╲╱ 200 + 40⋅╲╱ 5 ╲╱ 200 + 40⋅╲╱
5 ⎠ ⎠
In [12]: n,d = _.as_numer_denom()
In [13]: n = n.expand()
In [14]: d = d.expand()
In [15]: N = n.subs(sqrt((200-40*sqrt(5))*(200+40*sqrt(5))), 80*sqrt(5))
In [16]: D = d.subs(sqrt((200-40*sqrt(5))*(200+40*sqrt(5))), 80*sqrt(5))
In [17]: Poly.cancel(N/D)
Out[17]:
⎽⎽⎽
17592186044416000000000000000000⋅╲╱ 5
──────────────────────────────────────────────────────────────────────────────────
⎽⎽⎽
⎽⎽⎽ 5
17592186044416000000000000000000⋅╲╱ 5 +
17592186044416000000000000000000⋅╲╱ 5 ⋅x
In [18]: trim(N/D)
Out[18]:
⎽⎽⎽
17592186044416000000000000000000⋅╲╱ 5
──────────────────────────────────────────────────────────────────────────────────
⎽⎽⎽
⎽⎽⎽ 5
17592186044416000000000000000000⋅╲╱ 5 +
17592186044416000000000000000000⋅╲╱ 5 ⋅x
In [19]: NN = N.subs(sqrt(5), 1)
In [20]: DD = D.subs(sqrt(5), 1)
In [21]: Poly.cancel(NN/DD)
Out[21]:
1
──────
5
1 + x
Implications of the example above are as follows:
1. Improve simplification of algebraic expressions (e.g. expand(power=True))
2. Implement efficient polynomials with coefficients in algebraic number
fields
I will send a series of patches soon, but first I need to polish them a bit.
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en
-~----------~----~----~----~------~----~------~--~---