Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#######
#
# E-scripts on sympy.
#
# Note 1: use the eev command (defined in eev.el) and the
# ee alias (in my .zshrc) to execute parts of this file.
# Executing this file as a whole makes no sense.
# An introduction to eev can be found here:
#
#   (find-eev-quick-intro)
#   http://angg.twu.net/eev-intros/find-eev-quick-intro.html
#
# Note 2: be VERY careful and make sure you understand what
# you're doing.
#
# Note 3: If you use a shell other than zsh things like |&
# and the for loops may not work.
#
# Note 4: I always run as root.
#
# Note 5: some parts are too old and don't work anymore. Some
# never worked.
#
# Note 6: the definitions for the find-xxxfile commands are on my
# .emacs.
#
# Note 7: if you see a strange command check my .zshrc -- it may
# be defined there as a function or an alias.
#
# Note 8: the sections without dates are always older than the
# sections with dates.
#
# This file is at <http://angg.twu.net/e/sympy.e>
#           or at <http://angg.twu.net/e/sympy.e.html>.
#        See also <http://angg.twu.net/emacs.html>,
#                 <http://angg.twu.net/.emacs[.html]>,
#                 <http://angg.twu.net/.zshrc[.html]>,
#                 <http://angg.twu.net/escripts.html>,
#             and <http://angg.twu.net/>.
#
#######




# «.irc»			(to "irc")
# «.gitter»			(to "gitter")
# «.debian»			(to "debian")
# «.sympydoc»			(to "sympydoc")
# «.tutorial»			(to "tutorial")
# «.tut-rational»		(to "tut-rational")
# «.tut-symbols»		(to "tut-symbols")
# «.tut-subs»			(to "tut-subs")
# «.tut-apart»			(to "tut-apart")
# «.tut-together»		(to "tut-together")
# «.tut-limit»			(to "tut-limit")
# «.tut-integrate»		(to "tut-integrate")
# «.tut-trig»			(to "tut-trig")
# «.tut-dsolve»			(to "tut-dsolve")
# «.tut-solve»			(to "tut-solve")
# «.tut-linear-alg»		(to "tut-linear-alg")
# «.luatree»			(to "luatree")
# «.func-and-args»		(to "func-and-args")
# «.atoms»			(to "atoms")
# «.polys»			(to "polys")
# «.plotting»			(to "plotting")
# «.plot-parametric»		(to "plot-parametric")
# «.plotting-old»		(to "plotting-old")
# «.vector-fields»		(to "vector-fields")
# «.numerical-integration»	(to "numerical-integration")
# «.integration»		(to "integration")
# «.Eq»				(to "Eq")
# «.Eq»				(to "Eq")
# «.solve»			(to "solve")
# «.dsolve»			(to "dsolve")
# «.Function»			(to "Function")
# «.Symbol»			(to "Symbol")
# «.expand»			(to "expand")
# «.trigonometric»		(to "trigonometric")
# «.mpf»			(to "mpf")
# «.sympy-src»			(to "sympy-src")
# «.sympy-git»			(to "sympy-git")
# «.support»			(to "support")
# «.P2»				(to "P2")
# «.matrices»			(to "matrices")
# «.GA-2013.2-P2B»		(to "GA-2013.2-P2B")
# «.conics»			(to "conics")
# «.conics-2»			(to "conics-2")
# «.inter_plane_line»		(to "inter_plane_line")
# «.printing»			(to "printing")
# «.subs»			(to "subs")
# «.sympy-colors»		(to "sympy-colors")
# «.trig-subst-questions»	(to "trig-subst-questions")
# «.trigonometric-identities»	(to "trigonometric-identities")
# «.lagrange-multipliers»	(to "lagrange-multipliers")
# «.exactify»			(to "exactify")
# «.linear-order2-real»		(to "linear-order2-real")
# «.linear-order2-complex»	(to "linear-order2-complex")
# «.separable-variables»	(to "separable-variables")
# «.inspect-re-and-regex»	(to "inspect-re-and-regex")
# «.re-regex-gitter-question»	(to "re-regex-gitter-question")
# «.ee_dofile-bug»		(to "ee_dofile-bug")
# «.quote»			(to "quote")
# «.equality»			(to "equality")

# (find-angg ".emacs" "sympy")




#####
#
# irc channel
# 2014jun16
#
#####

# «irc» (to ".irc")
# (find-efunction 'find-freenode-3a)
# https://gitter.im/sympy/sympy

*** TOPIC Welcome to the SymPy channel.  See http://sympy.org/.  We
          have moved to Gitter for chat
          (https://gitter.im/sympy/sympy). This channel is logged.
          Logs are at



#####
#
# gitter
# 2020nov01
#
#####

# «gitter»  (to ".gitter")
# https://gitter.im/sympy/sympy#
# (find-sympygitfile "")
# (find-sympygitfile "README.md" "Join the chat at https://gitter.im/sympy/sympy")



#####
#
# debian
# 2022aug10
#
#####

# «debian»  (to ".debian")
# (find-zsh "availabledebs | sort | grep sympy")
apti isympy-common isympy3 python-sympy-doc python3-sympy

# (find-status   "isympy-common")
# (find-vldifile "isympy-common.list")
# (find-udfile   "isympy-common/")
# (find-status   "isympy3")
# (find-vldifile "isympy3.list")
# (find-udfile   "isympy3/")
# (find-status   "python-sympy-doc")
# (find-vldifile "python-sympy-doc.list")
# (find-udfile   "python-sympy-doc/")
# (find-status   "python3-sympy")
# (find-vldifile "python3-sympy.list")
# (find-udfile   "python3-sympy/")
# (find-udfile "python-sympy-doc/examples/README")
# (find-udfile "python-sympy-doc/")
# (find-sympydoc  "index")
# (find-sympydoc  "tutorial/index")
# (find-sympydoc  "tutorial/basic_operations#substitution")
# (find-sympydoc  "tutorial/basic_operations#converting-strings-to-sympy-expressions")
# (find-sympydoc  "tutorial/manipulation#understanding-expression-trees")
# (find-sympydocr "tutorial/manipulation#understanding-expression-trees")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
w isympy


#####
#
# sympydoc
# 2022aug12
#
#####

# «sympydoc»  (to ".sympydoc")
# (find-angg ".emacs" "sympydoc")




#####
#
# sympy tutorial
# 2016jan10
#
#####

# «tutorial» (to ".tutorial")
# (find-es "python" "sympy")
# (find-sympydoc  "tutorial/index")
# (find-sympydocr "tutorial/index")
# (find-sympydoc  "tutorial/printing")
# (find-sympydoc  "tutorial/printing")
# (find-sympydoc  "tutorial/basic_operations")
# (find-sympydoc  "tutorial/basic_operations#substitution")
# (find-sympydocr "tutorial/basic_operations")
# (find-sympydoc "modules/core")
# (find-sympydoc "modules/polys/reference")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
(x + y) * (x - y)
`(1/cos(x)).series(x, 0, 10)`
(1/cos(x)).series(x, 0, 10)

# «tut-rational» (to ".tut-rational")
# (find-sympydoc "tutorial/gotchas#two-final-notes-and")

from sympy import Rational
a = Rational(1,2)
a
a*2
Rational(2)**50/Rational(10)**50

R = Rational
R(1, 2)
R(1)/2   # R(1) is a SymPy Integer and Integer/int gives a Rational

from sympy import pi, E
pi**2
pi.evalf()
(pi + E).evalf()
from sympy import oo
oo > 99999
oo + 1

# «tut-symbols» (to ".tut-symbols")
# (find-sympydoc  "tutorial/gotchas#symbols")
# (find-sympydocr "tutorial/gotchas#symbols")
# (find-sympydoc  "tutorial/gotchas#equals-signs")

from sympy import Symbol
x = Symbol('x')
y = Symbol('y')

from sympy.abc import x, theta

from sympy import symbols, var
a, b, c = symbols('a,b,c')
d, e, f = symbols('d:f')
var('g:h')
var('g:2')

# «tut-subs» (to ".tut-subs")
# (to "subs")
x+y+x-y
(x+y)**2
((x+y)**2).expand()
((x+y)**2).subs(x, 1)
((x+y)**2).subs(x, y)
((x+y)**2).subs(x, 1-y)

from sympy import init_printing
init_printing(use_unicode=False, wrap_line=False, no_global=True)

# «tut-apart» (to ".tut-apart")
from sympy import apart
from sympy.abc import x, y, z
1/( (x+2)*(x+1) )
apart(1/( (x+2)*(x+1) ), x)
(x+1)/(x-1)
apart((x+1)/(x-1), x)

# «tut-together» (to ".tut-together")
from sympy import together
together(1/x + 1/y + 1/z)
together(apart((x+1)/(x-1), x), x)
together(apart(1/( (x+2)*(x+1) ), x), x)


# «tut-limit» (to ".tut-limit")
# (find-sympydocsrcfile "tutorial.txt" ".. index:: calculus")
#
from sympy import limit, Symbol, sin, oo
x = Symbol("x")
limit(sin(x)/x, x, 0)

limit(x, x, oo)
limit(1/x, x, oo)
limit(x**x, x, 0)

from sympy import diff, Symbol, sin, tan
x = Symbol('x')
diff(sin(x), x)
diff(sin(2*x), x)
diff(tan(x), x)

from sympy import limit
from sympy.abc import delta
limit((tan(x + delta) - tan(x))/delta, delta, 0)

diff(sin(2*x), x, 1)
diff(sin(2*x), x, 2)
diff(sin(2*x), x, 3)

from sympy import Symbol, cos
x = Symbol('x')
cos(x).series(x, 0, 10)
(1/cos(x)).series(x, 0, 10)

from sympy import Integral, pprint
y = Symbol("y")
e = 1/(x + y)
s = e.series(x, 0, 5)
print(s)
pprint(s)

from sympy import summation, oo, symbols, log
i, n, m = symbols('i n m', integer=True)
summation(2*i - 1, (i, 1, n))
summation(1/2**i, (i, 0, oo))
summation(1/log(n)**n, (n, 2, oo))
summation(i, (i, 0, n), (n, 0, m))
from sympy.abc import x
from sympy import factorial
summation(x**n/factorial(n), (n, 0, oo))

# «tut-integrate» (to ".tut-integrate")
# (to "integration")
from sympy import integrate, erf, exp, sin, log, oo, pi, sinh, symbols
x, y = symbols('x,y')
integrate(6*x**5, x)
integrate(sin(x), x)
integrate(log(x), x)
integrate(2*x + sinh(x), x)

integrate(x**3, (x, -1, 1))
integrate(sin(x), (x, 0, pi/2))
integrate(cos(x), (x, -pi/2, pi/2))
integrate(exp(-x), (x, 0, oo))
integrate(log(x), (x, 0, 1))

from sympy import Symbol, exp, I
x = Symbol("x")    # a plain x with no attributes
exp(I*x).expand()
exp(I*x).expand(complex=True)
x = Symbol("x", real=True)
exp(I*x).expand(complex=True)

# «tut-trig» (to ".tut-trig")
# (to "trigonometric")
# (find-sympydoc "tutorial/simplification#trigonometric-simplification")
from sympy import asin, asinh, cos, sin, sinh, symbols, I
x, y = symbols('x,y')
sin(x+y).expand(trig=True)
cos(x+y).expand(trig=True)
sin(I*x)
sinh(I*x)
asinh(I)
asinh(I*x)
sin(x).series(x, 0, 10)
sinh(x).series(x, 0, 10)
asin(x).series(x, 0, 10)
asinh(x).series(x, 0, 10)

from sympy import Ylm
from sympy.abc import theta, phi
Ylm(1, 0, theta, phi)
Ylm(1, 1, theta, phi)
Ylm(2, 1, theta, phi)

from sympy import factorial, gamma, Symbol
x = Symbol("x")
n = Symbol("n", integer=True)
factorial(x)
factorial(n)
gamma(x + 1).series(x, 0, 3) # i.e. factorial(x)

from sympy import zeta
zeta(4, x)
zeta(4, 1)
zeta(4, 2)
zeta(4, 3)

from sympy import assoc_legendre, chebyshevt, legendre, hermite
chebyshevt(2, x)
chebyshevt(4, x)
legendre(2, x)
legendre(8, x)
assoc_legendre(2, 1, x)
assoc_legendre(2, 2, x)
hermite(3, x)

# «tut-dsolve» (to ".tut-dsolve")
# (to "dsolve")
# (to "Function")
# (find-sympydoc "tutorial/solvers#solving-differential-equations")
# (find-sympydoc "modules/core#sympy.core.function.Function")
# (find-sympydoc "modules/functions/index")
# (find-sympydoc "modules/solvers/ode#dsolve")
# (find-sympydoc "modules/solvers/ode#ode")

from sympy import Function, Symbol, dsolve
f = Function('f')
x = Symbol('x')
f(x).diff(x, x) + f(x)
dsolve(f(x).diff(x, x) + f(x), f(x))

# «tut-solve» (to ".tut-solve")
# (to "solve")
from sympy import solve, symbols
x, y = symbols('x,y')
solve(x**4 - 1, x)
solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])

# «tut-linear-alg» (to ".tut-linear-alg")
# (find-sympydoc  "index")
# (find-sympydoc  "tutorial/matrices")
# (find-sympydocr "tutorial/matrices")
# (find-sympydoc  "modules/matrices/matrices")
#
from sympy import Matrix, Symbol
Matrix([[1,0], [0,1]])
x = Symbol('x')
y = Symbol('y')
A = Matrix([[1,x], [y,1]])
A
A**2

# (find-sympydoc "tutorial/index")
# (find-sympydoc "modules/core#sympy.core.symbol.Wild")
#
from sympy import Symbol, Wild
x = Symbol('x')
p = Wild('p')
(5*x**2).match(p*x**2)
q = Wild('q')
(x**2).match(p*x**q)
print (x+1).match(p**x)
p = Wild('p', exclude=[1,x])
print((x+1).match(x+p))   # 1 is excluded
print((x+1).match(p+1))   # x is excluded
print((x+1).match(x+2+p)) # -1 is not excluded

# (find-sympydoc  "tutorial/printing")
# (find-sympydocr "tutorial/printing")
#
from sympy import Integral
from sympy.abc import x
print(x**2)
print(1/x)
print(Integral(x**2, x))

from sympy import Integral, pprint
from sympy.abc import x
pprint(x**2)
pprint(1/x)
pprint(Integral(x**2, x))

from sympy import init_printing, var, Integral
init_printing(use_unicode=False, wrap_line=False, no_global=True)
var("x")
x**3/3
Integral(x**2, x) #doctest: +NORMALIZE_WHITESPACE

from sympy.printing.python import python
from sympy import Integral
from sympy.abc import x
print(python(x**2))
print(python(1/x))
print(python(Integral(x**2, x)))

from sympy import Integral, latex
from sympy.abc import x
latex(x**2)
latex(x**2, mode='inline')
latex(x**2, mode='equation')
latex(x**2, mode='equation*')
latex(1/x)
latex(Integral(x**2, x))

from sympy.printing.mathml import mathml
from sympy import Integral, latex
from sympy.abc import x
print(mathml(x**2))
print(mathml(1/x))

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
isympy
from sympy import Integral, preview
from sympy.abc import x
preview(Integral(x**2, x)) #doctest:+SKIP





#####
#
# luatree
# 2022aug23
#
#####

# «luatree»  (to ".luatree")
# (find-angg "luatree/luatree.py")
# (find-sympydocr "")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
import sys
sys.path[1:1] = ["/home/edrx/luatree"]
from luatree import *

from sympy import Function, Symbol
f   = Function('f')
g   = Function('g')
x,u,a,b = symbols('x,u,a,b')
foo = diff(f(g(x)), x)
bar = Eq(foo, 42)
foo
bar
luatree(bar)

od  = f(x).diff(x, x) + f(x)

x, y = symbols('x,y')
integrate(6*x**5, x)
integrate(sin(x), x)
integrate(log(x), x)
integrate(2*x + sinh(x), x)

integrate(x**3, (x, -1, 1))
integrate(sin(x), (x, 0, pi/2))





#####
#
# func-and-args
# 2022aug07
#
#####

# «func-and-args»  (to ".func-and-args")
# (find-angg "luatree/luatree.py")
# (find-es "python" "type")
# (defun a () (interactive) (find-es "sympy" "func-and-args"))

Hi all, I need some help to port this way of drawing objects as trees
- http://angg.twu.net/eev-maxima.html#luatree - from Maxima to
SymPy... in Maxima if o is an object that is not an atom then op(o)
returns its "operator" and args(o) returns its list of arguments -
see:
https://maxima.sourceforge.io/docs/manual/maxima_33.html#index-args

How do I do something similar to "op" and "args" in SymPy? Thanks in advance...

Kalevi Suominen @jksuom 12:38
@edrx Maybe https://docs.sympy.org/latest/tutorial/manipulation.html#recursing-through-an-expression-tree would help.

Eduardo Ochs @edrx 13:30
@jksuom, that's exactly what I needed! Thanks! =)

# (find-sh "locate manipulation")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
foo = x + y * z
foo
foo.func
foo.is_Atom
x.is_Atom
(5).is_Atom     # err
foo.func
foo.func.__str__
foo.func.__str__(foo.func)
foo.func.__repr__(foo.func)
type(foo.func)
type(55)
str(type(55))
repr(type(55))
type(type(55))
type(55.0)
type("55")
import re as stdlib_re






#####
#
# atoms
# 2022aug19
#
#####

# «atoms»  (to ".atoms")
# (find-pydoc "library/functions#type")
# (find-sympydoc "index")
# (find-sympydoc  "modules/core#sympy.core.basic.Basic.atoms")
# (find-sympydoc  "modules/core#sympy.core.expr.AtomicExpr")
# (find-sympydocw "modules/core#sympy.core.expr.AtomicExpr")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import Function, Symbol, dsolve
f  = Function('f')
x  = Symbol('x')
od = f(x).diff(x, x) + f(x)



isinstance(f, AtomicExpr)
isinstance(f, UndefinedFunction)
isinstance(x, AtomicExpr)
isinstance(5, AtomicExpr)
f
type(f)
UndefinedFunction



#####
#
# polynomials
# 2016jan25
#
#####

# «polys» (to ".polys")
# http://docs.sympy.org/0.7.2/modules/polys/reference.html

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import pdiv
from sympy.abc import x
pdiv(x**4, (x-2)*(x+3))
prem(x**4, (x-2)*(x+3))
pquo(x**4, (x-2)*(x+3))

((x**2 - x + 7) * (x-2)*(x+3)               ).expand()
((x**2 - x + 7) * (x-2)*(x+3) + (-13*x + 42)).expand()
apart((-13*x + 42)/((x-2) * (x+3)))
together((-81/5) / (x+3) + (16/5) / (x-2))

apa = apart((-13*x + 42)/((x-2) * (x+3)))
tog = together((-81/5) / (x+3) + (16/5) / (x-2))
apa
tog




#####
#
# Plotting
# 2016jul10 / 2021feb10
#
#####

# «plotting» (to ".plotting")
# (find-sympydocsrcfile "modules/plotting.txt")
# (find-sympytutgrep "grep --color -niH -e plot *.rst")
# https://docs.sympy.org/latest/modules/plotting.html
# https://docs.sympy.org/latest/modules/plotting.html#sympy.plotting.plot.plot_parametric

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import symbols
from sympy.plotting import plot
x = symbols('x')
plot(x**2, (x, -5, 5))
plot(x, x**2, x**3, (x, -5, 5))
plot((x**2, (x, -6, 6)), (x, (x, -5, 5)))
plot(x**2, adaptive=False, nb_of_points=400)




#####
#
# plot-parametric
# 2021feb10
#
#####

# «plot-parametric»  (to ".plot-parametric")
# https://docs.sympy.org/latest/modules/plotting.html#sympy.plotting.plot.plot_parametric

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

from sympy import symbols, cos, sin
from sympy.plotting import plot_parametric
u = symbols('u')
plot_parametric((cos(u), sin(u)), (u, -5, 5))

from sympy import symbols, cos, sin
from sympy.plotting import plot_parametric
t = symbols('t')
plot_parametric((cos(t), sin(t)), (t, 0, 6))
plot_parametric((cos(t*2), sin(t)), (t, 0, 6))
plot_parametric((cos(t) + t, sin(t)), (t, 0, 6))

plot_parametric((cos(u), sin(u)), (u, cos(u)), (u, -10, 10))



#####
#
# plotting-old
# 2013aug09
#
#####

# «plotting-old»  (to ".plotting-old")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import var, Plot
var('x y z')
Plot(x*y**3-y*x**3)
Plot((x**2 + y**2) / (x - 1))
help(Plot)

plot(x*y**3-y*x**3)
plot((x**2 + y**2) / (x - 1))
help(plot)






#####
#
# vector fields
# 2016aug01
#
#####

# «vector-fields» (to ".vector-fields")
# https://www.getdatajoy.com/examples/python-plots/vector-fields
# http://stackoverflow.com/questions/25342072/computing-and-drawing-vector-fields
# http://www.scipy-lectures.org/intro/matplotlib/auto_examples/plot_quiver_ex.html

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# http://www.scipy-lectures.org/intro/matplotlib/auto_examples/plot_quiver_ex.html
import numpy as np
import matplotlib.pyplot as plt

n = 8
X, Y = np.mgrid[0:n, 0:n]
T = np.arctan2(Y - n / 2., X - n/2.)
R = 10 + np.sqrt((Y - n / 2.0) ** 2 + (X - n / 2.0) ** 2)
U, V = R * np.cos(T), R * np.sin(T)

plt.axes([0.025, 0.025, 0.95, 0.95])
plt.quiver(X, Y, U, V, R, alpha=.5)
plt.quiver(X, Y, U, V, edgecolor='k', facecolor='None', linewidth=.5)

plt.xlim(-1, n)
plt.xticks(())
plt.ylim(-1, n)
plt.yticks(())

plt.show()





#####
#
# numerical integration
# 2016mar21
#
#####

# «numerical-integration» (to ".numerical-integration")
# http://docs.sympy.org/0.7.2/modules/mpmath/calculus/integration.html
# http://docs.sympy.org/0.7.6/modules/mpmath/calculus/integration.html
# http://docs.sympy.org/latest/modules/integrals/integrals.html#numeric-integrals
# https://en.wikipedia.org/wiki/Tanh-sinh_quadrature
# (find-sympydfile "")
# (find-sympydfile "integrals/")
# (find-sympydfile "integrals/quadrature.py" "Gauss-Legendre quadrature")
# (find-sympydfile "mpmath/calculus/quadrature.py")
# (find-sympydfile "mpmath/calculus/quadrature.py" "def quad(")
# (find-sympydsh "find * | sort")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy.mpmath import *
mp.dps = 15; mp.pretty = True
quad(sin, [0, pi])

f = lambda x, y: cos(x+y/2)
quad(f, [-pi/2, pi/2], [0, pi])

mp.dps = 15
quad(lambda x: 2/(x**2+1), [0, inf])
quad(lambda x: exp(-x**2), [-inf, inf])**2

mp.dps = 50
2*quad(lambda x: sqrt(1-x**2), [-1, 1])

mp.dps = 1000
2*quad(lambda x: sqrt(1-x**2), [-1, 1])  

mp.dps = 15
chop(quad(lambda z: 1/z, [1,j,-1,-j,1]))

mp.dps = 30
f = lambda x, y: (x-1)/((1-x*y)*log(x*y))
quad(f, [0, 1], [0, 1])
+euler

f = lambda x, y: 1/sqrt(1+x**2+y**2)
quad(f, [-1, 1], [-1, 1])
4*log(2+sqrt(3))-2*pi/3

f = lambda x, y: 1/(1-x**2 * y**2)
quad(f, [0, 1], [0, 1])
pi**2 / 8
quad(lambda x, y: 1/(1-x*y), [0, 1], [0, 1])
pi**2 / 6

mp.dps = 15
print(quad(lambda x,y: exp(-x-y), [0, inf], [1, inf]))
print(1/e)

f = lambda x: quad(lambda y: 1, [-sqrt(1-x**2), sqrt(1-x**2)])
quad(f, [-1, 1])

mp.dps = 15
f = lambda x,y,z: x*y/(1+z)
quad(f, [0,1], [0,1], [1,2], method='gauss-legendre')
(log(3)-log(2))/4

mp.dps = 15
quad(lambda x: abs(sin(x)), [0, 2*pi])      # Bad
quad(lambda x: abs(sin(x)), [0, pi, 2*pi])  # Good

mp.dps = 15
quad(log, [0, 1], method='tanh-sinh')       # Good
quad(log, [0, 1], method='gauss-legendre')  # Bad

quad(lambda x: 1/sqrt(x), [0, 1], method='tanh-sinh')

mp.dps = 30
a = quad(lambda x: 1/sqrt(x), [0, 1], method='tanh-sinh')
mp.dps = 15
+a

quad(sin, [0, 100]); 1-cos(100)             # Good
quad(sin, [0, 1000]); 1-cos(1000)           # Bad

quad(sin, linspace(0, 1000, 10))            # Good

quad(sin, [0, 1000], maxdegree=10)          # Also good

f = lambda x: 1/(1+x**2)
quad(f, [-100, 100])                        # Bad
quad(f, [-100, 100], maxdegree=10)          # Good
quad(f, [-100, 0, 100])                     # Also good

from sympy.mpmath import *
mp.dps = 15; mp.pretty = True
f = lambda x: sin(3*x)/(x**2+1)
quadosc(f, [0,inf], omega=3)
quadosc(f, [0,inf], period=2*pi/3)
quadosc(f, [0,inf], zeros=lambda n: pi*n/3)
(ei(3)*exp(-3)-exp(3)*ei(-3))/2             # Computed by Mathematica

quadosc(lambda x: cos(x)/(1+x**2), [-inf, inf], omega=1)
pi/e
quadosc(lambda x: cos(x)/x**2, [-inf, -1], period=2*pi)
cos(1)+si(1)-pi/2

quadosc(lambda x: exp(3*j*x)/(1+x**2), [-inf,inf], omega=3)
pi/e**3
quadosc(lambda x: exp(3*j*x)/(2+x+x**2), [-inf,inf], omega=3)
2*pi/sqrt(7)/exp(3*(j+sqrt(7))/2)

quadosc(j0, [0, inf], period=2*pi)
quadosc(j1, [0, inf], period=2*pi)
j0zero = lambda n: findroot(j0, pi*(n-0.25))
quadosc(j0, [0, inf], zeros=j0zero)

mp.dps = 30
f = lambda x: cos(x**2)
quadosc(f, [0,inf], zeros=lambda n:sqrt(pi*n))
f = lambda x: sin(x**2)
quadosc(f, [0,inf], zeros=lambda n:sqrt(pi*n))
sqrt(pi/8)

mp.dps = 15
f = lambda x: sin(exp(x))
quadosc(f, [1,inf], zeros=lambda n: log(n))
pi/2-si(e)

f = lambda x: 1/x**2+sin(x)/x**4
quadosc(f, [1,inf], omega=1)  # Bad
quadosc(f, [1,inf], omega=0.5)  # Perfect
1+(cos(1)+ci(1)+sin(1))/6

quadosc(lambda x: cos(x)/exp(x), [0, inf], omega=1)
quad(lambda x: cos(x)/exp(x), [0, inf])




#####
#
# integration
# 2016jul19
#
#####

# «integration» (to ".integration")
# (to "tut-integrate")
# https://github.com/sympy/sympy/issues/9045 BUG/DOC: Trig Functions "cannot create mpf from..." depending on namespace
# (find-es "sympy" "tut-integrate")
# (find-sympydgrep "grep --color -nRH -e integrate *")
# (find-sympydgrep "grep --color -nRH -e manualintegrate *")
# (find-sympydgrep "grep --color -nRH -e 'def quad' *")
# (find-sympydfile "integrals/integrals.py" "def integrate")
# (find-sympydfile "integrals/integrals.py" "def integrate" "manual=True")
# (find-sympydfile "integrals/integrals.py" "def integrate" "Examples\n")
# (find-sympydfile "integrals/integrals.py" "def integrate" "if isinstance")
# (find-sympydfile "integrals/manualintegrate.py" "def manualintegrate")
# (find-sympydfile "mpmath/calculus/quadrature.py" "def quad")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
Integral(cos(x**2), (x, 2, 3))
body = cos(x**2)
f = lambda x: cos(x**2)
body
f(x)
Integral(f(x), (x, 2, 3))

from sympy.mpmath import quad
quad(f, [0, 3])

from sympy.mpmath import *
mp.dps = 15; mp.pretty = True
quad(sin, [0, pi])
body = cos(x**2)
f = lambda x: cos(x**2)
f
f(1)
f(x)
quad(f, [0, 3])
? integral
? Integral

# (find-fline "/usr/lib/python2.7/dist-packages/sympy/integrals/integrals.py")

i = Integral(x, x)
i
at = Integral(x, (x, x))
at = Integral(x, (x, 2, 3))
at
i.as_dummy()
at.as_dummy()

Integral(x, (x, 2, 3))
f = lambda x: cos(x**2)
f(x)
f(0)
Integral(f(x), (x, 2, 3))




#####
#
# Eq
# 2016dec04
#
#####

# «Eq» (to ".Eq")
# (find-sympytutfile "gotchas.rst" "Eq(x + 1, 4)")
# (find-sympydfile "sympy/core/relational.py" "class Relational")
# (find-sympydfile "core/relational.py" "class Relational")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
from sympy import *
t,u = symbols('t u')

rt = M([1,2]) + t*M([3,4])              # [3*t+1, 4*t+2]
rt
eq_xyt = Eq(M([x,y]), rt)
eq_xyt
eq_xt = Eq(x, rt[0])
eq_xt
eq_tx = Eq(t, solve(eq_xt, t)[0])
eq_tx
eq_tx.rhs
rx = rt.subs(t, eq_tx.rhs)
rx
eq_yx = Eq(y, rx[1])
eq_yx




#####
#
# Eq
# 2016aug01
#
#####

# «Eq» (to ".Eq")
# (find-sympydfile "core/relational.py" "def Eq")
# (find-sympydfile "core/relational.py" "class Relational")

# (find-sympydfile "core/add.py" "class Add")
# http://docs.sympy.org/0.7.2/gotchas.html#getting-help-from-within-sympy
# http://docs.sympy.org/0.7.2/guide.html#sympy-s-architecture
# (find-sympytutfile "gotchas.rst")
# (find-sympydocsrcfile "guide.rst")
# (find-sympydocsrcfile "guide.rst" "SymPy's Architecture")
# (find-sympyfile "doc/src/guide.rst")




#####
#
# solve
# 2016jul31
#
#####

# «solve» (to ".solve")
# (find-sympytutfile "")
# (find-sympytutfile "solvers.rst")
# (find-sympytutfile "solvers.rst" "solveset(Eq(x**2, 1), x)")
# (find-es "sympy" "tut-solve")
# (find-es "ipython" "2016.1-GA-P2")
# (find-es "python" "dict")
# (to "tut-solve")
# (find-sympydgrep "grep --color -niH -e solve *")
# (find-sympydgrep "grep --color -niRH -e solve_lin *")
# (find-sympydfile "solvers/solvers.py" "def solve_linear")
# (find-sympydfile "solvers/solvers.py" "def minsolve_linear_system")
# (find-sympydfile "solvers/solvers.py" "def solve_linear_system")
# http://docs.sympy.org/0.7.2/tutorial.html#algebraic-equations
# (find-LATEX "2016-2-GA-algebra.tex" "parametrizadas")
# (gaap 14)

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
from sympy import *
t,u = symbols('t u')
rt = M([3,3]) + t*M([2,-1])
su = M([4,1]) + u*M([-1,1])
rt
su
rt-su
solve(rt - su, t, u)
solve(rt - su, [t, u])
sol = solve(rt - su, [t, u])
sol
sol.keys()
sol.keys()[1]
sol[t]
sol[u]
rt.subs(t, sol[t])
su.subs(u, sol[u])

rt
sol = solve(rt[0]-x, t)[0]
rt.subs(t, sol)
y - rt.subs(t, sol)[1]

sol = solve(rt[0]-x, t)[0]
ryx = y - rt.subs(t, sol)[1]
sol = solve(su[0]-x, u)[0]
syx = y - su.subs(u, sol)[1]
ryx
syx
sol = solve(ryx - syx, x)[0]
ryx.subs(x, sol)
syx.subs(x, sol)

rt = M([3,3]) + t*M([2,-1])
su = M([4,1]) + u*M([-1,1])
sol = solve(rt - su, t, u)
solt, solu = sol[t], sol[u]
solt, solu
rt.subs(t, solt)
su.subs(u, solu)
solx = rt.subs(t, solt)[0]
soly = rt.subs(t, solt)[1]
solx, soly




#####
#
# dsolve
# 2016aug01
#
#####

# «dsolve» (to ".dsolve")
# (to "tut-dsolve")
# (find-sympytutgrep "grep --color -nH -e dsolve *")
# (find-sympytutfile "solvers.rst" "dsolve(diffeq, f(x))")
# http://docs.sympy.org/0.7.2/tutorial.html#differential-equations
# https://github.com/sympy/sympy/wiki/Quick-examples#solve-an-ordinary-differential-equation
# (find-sympytutfile "calculus.rst" "``diff`` can take multiple derivatives at once")
# (find-sympytutfile "intro.rst" "dsolve")
# (find-sympydfile "solvers/ode.py")
# (find-sympydfile "solvers/ode.py" "def dsolve")
# (find-sympydfile "solvers/ode.py" "def dsolve" "  Examples\n")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
f = Function('f')
eq = f(x).diff(x,x) + 9*f(x) - 1
dsolve(eq, f(x))

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# (find-sympydfile "solvers/ode.py" "def dsolve" "  Examples\n")
from sympy import Function, dsolve, Eq, Derivative, sin, cos
from sympy.abc import x
f = Function('f')
dsolve(Derivative(f(x), x, x) + 9*f(x), f(x))
eq = sin(x)*cos(f(x)) + cos(x)*sin(f(x))*f(x).diff(x)
dsolve(eq, hint='separable_reduced')
dsolve(eq, hint='1st_exact')
dsolve(eq, hint='almost_linear')




#####
#
# Function
# 2016aug01
#
#####

# «Function» (to ".Function")
# (to "tut-dsolve")
# (find-sympydoc "tutorial/index#symbols")
# (find-sympydoc "tutorial/solvers#solving-differential-equations")
# (find-sympydoc "modules/core#functionclass")
# (find-sympydoc "modules/core#id22")
# (find-sympydoc "modules/core#lambda")
# (find-sympydoc "modules/core#module-sympy.core.function")
# (find-sympydoc "modules/core#module-sympy.core.symbol")
# (find-sympydoc "modules/core#symbols")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import Function, Symbol, dsolve
f  = Function('f')
x  = Symbol('x')
od = f(x).diff(x, x) + f(x)
od.func
od.args
od.args[1]
od.args[1].func
od.args[1].args
od.args[1].args[0]
type(f)
type(f).__name__


# (find-sympydfile "")
# (find-sympydgrep "grep -nRwH -e subs *")
# (find-sympydfile "core/tests/test_function.py" "Subs(f(x), x, 0).subs(x, 1)")
# (find-sympydfile "core/tests/test_subs.py" "eq.subs(f(x), 4)")
# (find-sympydfile "core/tests/test_subs.py" "(f(x)**2).subs(f, sin)")
# (find-sympydfile "core/basic.py" "def subs")
# (find-sympydfile "core/function.py")
# (find-sympydfile "core/function.py" "Think of 2*cos(x) as f(c).subs(c, cos(x))")
# (find-sympydfile "core/function.py" "diff(f(x), x).diff(f(x))")
# (find-sympydfile "core/function.py" "e.subs(f, sin).doit()")
# (find-sympydfile "core/function.py" "class Lambda(Expr):")

# (find-sympydgrep "grep -nRwH -e expand *")



#####
#
# Symbol
# 2017jul18
#
#####

# «Symbol» (to ".Symbol")
# (find-sympydfile "core/symbol.py" "def symbols")
# (find-sympydfile "core/symbol.py" "symbols('f,g,h', cls=Function)")



#####
#
# expand
# 2017jul18
#
#####

# «expand» (to ".expand")
# (find-sympydfile "core/function.py" "def expand")



#####
#
# Trigonometric functions and their inverses
# 2016aug08
#
#####

# «trigonometric» (to ".trigonometric")
# (to "tut-trig")
# http://docs.sympy.org/latest/modules/functions/elementary.html#trigonometric-inverses
# http://docs.sympy.org/latest/modules/functions/elementary.html#asec
# http://docs.sympy.org/0.7.2/modules/functions/index.html#contents
# (find-sympydfile "functions/elementary/trigonometric.py" "class sec")
# (find-sympydfile "functions/elementary/tests/test_trigonometric.py" "def test_csc")
# (find-sympydgrep "grep --color -nRH -e asin *")
# (find-sympydgrep "grep --color -nRH -e csc *")
# (find-sympyfile "sympy/functions/elementary/tests/test_trigonometric.py" "def test_asec")
# (find-sympyfile "sympy/functions/elementary/trigonometric.py" "class asec")




#####
#
# mpf
# 2016jul23
#
#####

# «mpf» (to ".mpf")
# (find-sympydgrep "grep --color -nRH -e 'def mpf' *")
# (find-sympydgrep "grep --color -nRH -e 'mpf_normalize' *")
# (find-sympydfile "core/numbers.py" "def mpf_norm")
# (find-sympydfile "mpmath/libmp/libmpf.py")
# (find-sympydfile "mpmath/libmp/libmpf.py" "def _normalize")
# http://docs.sympy.org/0.6.7/modules/mpmath/basics.html
# http://docs.sympy.org/0.7.2/modules/mpmath/index.html
# http://mpmath.org/
# http://mpmath.org/doc/0.19/




#####
#
# sympy src
# 2016jul19
#
#####

# «sympy-src» (to ".sympy-src")
# (find-angg ".emacs" "sympy")
# (find-fline "/usr/lib/python2.7/dist-packages/sympy/integrals/integrals.py")
# (find-zsh "dmissing sympy")
# (find-status   "python-sympy")
# (find-vldifile "python-sympy.list")
# (find-udfile   "python-sympy/")
# (find-fline "/usr/lib/python2.7/dist-packages/sympy/")

# (find-sympydfile "integrals/integrals.py" "Create an unevaluated integral")
# (find-sympydfile "mpmath/functions/functions.py" "def asec")




#####
#
# SymPy from git
# 2013aug09 / 2020nov01
#
#####

# «sympy-git» (to ".sympy-git")
# (find-angg ".emacs" "sympy")
# https://github.com/sympy/sympy
# (find-git-links "https://github.com/sympy/sympy" "sympygit")

* (eepitch-shell2)
* (eepitch-kill)
* (eepitch-shell2)
mkdir -p ~/bigsrc/
cd       ~/bigsrc/
git clone git://github.com/sympy/sympy.git
cd       ~/bigsrc/sympy/
git pull

# (code-c-d "sympygit" "~/bigsrc/sympy/")
# (find-sympygitfile "")
# (find-sympygitsh "find * | sort | grep /re")
# (find-sympygrep "grep --color -nRH --null -e 'Returns real part of expression.' *")

# (find-sympygitsh "find * | sort | grep -i parametric")
# (find-sympygitsh "find * | sort | grep -i plot")
# (find-sympygitfile "examples/beginner/")




* (eepitch-shell2)
* (eepitch-kill)
* (eepitch-shell2)
# (find-fline "~/bigsrc/")
cd ~/bigsrc/
git clone git://github.com/sympy/sympy.git

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
# rm -Rfv ~/bigsrc/sympy/
cd      ~/bigsrc/
git clone git://github.com/sympy/sympy.git
cd      ~/bigsrc/sympy/

git branch --list -a
git for-each-ref
PAGER=cat git log --oneline --graph --all -20

# (find-fline "~/bigsrc/")
# (find-fline "~/bigsrc/sympy/")
# (find-gitk  "~/bigsrc/sympy/")

# (code-c-d "sympy" "~/bigsrc/sympy/")
# (find-sympyfile "")

# git pull --depth 1
# git pull
# git reset
# git clean -dfx
# git reset --hard


# http://code.google.com/p/sympy/
# http://sympy.org/en/index.html
# http://docs.sympy.org/0.7.2/index.html
# http://docs.sympy.org/0.7.2/tutorial.html
# http://docs.sympy.org/0.7.2/modules/plotting.html
# http://docs.sympy.org/0.7.2/_sources/tutorial.txt

(code-c-d "sympyex" "/usr/share/doc/python-sympy/examples/")
(code-c-d "sympy" "~/bigsrc/sympy/")
# (find-sympyfile "")
# (find-sympyfile "README.rst")
# (find-sympyfile "README.rst" "cd doc" "make html")
# (find-sympyfile "doc/")
# (find-sympyfile "doc/Makefile")
# (find-sympyfile "doc/Makefile" "help:")
# (find-sympysh "find * | sort")
# (find-sympysh "find * | sort" "tutorial")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd ~/bigsrc/sympy/
git reset
cd ~/bigsrc/sympy/doc/
make html

apti librsvg

# (find-es "gnome" "librsvg")
# (find-es "autoconf" "autoconf-git")
# (find-es "gettext")


# (find-sympyfile "examples/")
# (find-sympyexfile "")
# (find-sympyfile "doc/src/tutorial/tutorial.en.rst")

# (find-sympyfile "setup.py")
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
cd ~/bigsrc/sympy/
python setup.py --help install
python setup.py --help-commands

python setup.py install --user |& tee ospui

# (find-fline "~/.local/bin/isympy")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
~/.local/bin/isympy
# (find-fline "/home/edrx/bigsrc/sympy/doc/src/tutorial/tutorial.en.rst")
# http://docs.sympy.org/0.7.2/tutorial.html





#####
#
# support
# 2019oct14
#
#####

# «support» (to ".support")
# https://www.sympy.org/en/support.html





#####
#
# P2
# 2013aug13
#
#####

# «P2» (to ".P2")
# (find-sympygrep "grep -nH -e all_coeffs *.py")
# (find-sympygrep "grep -nH -e all_coeffs sympy/polys/*.py")
# (find-sympyfile "sympy/polys/polytools.py" "def all_coeffs(f):")
# (find-sympyfile "sympy/polys/polyclasses.py" "def all_coeffs(f):")
# (find-sympyfile "sympy/matrices/matrices.py")
# (find-sympyfile "doc/src/tutorial/matrices.rst")



# http://docs.sympy.org/0.7.2/modules/polys/reference.html#sympy.polys.polytools.Poly.all_coeffs

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import Poly
w = symbols('w')
a, b, c, d, e, f = symbols('a b c d e f')

# Questao 2b:
poly   = x*y - 1
poly_x = -1 + 2*z + w
poly_y = -2 + w
poly_zw = poly.subs(x, poly_x).subs(y, poly_y)
poly_zw
poly_zw.expand()
poly_zw.expand().subs(z, x).subs(w, y)

# Questao 2c:
poly   = x*y - 1
poly_x = e + a*z + b*w
poly_y = f + c*z + d*w
poly_zw  = poly.subs(x, poly_x).subs(y, poly_y)
poly_zwe = poly_zw.expand().subs(z, x).subs(w, y)
Poly(poly_zwe, x)
Poly(poly_zwe, x).all_coeffs()
Poly(poly_zwe, x).all_coeffs()[1]

def coe(p, x, i):
    return Poly(p, x).all_coeffs()[i]

def coexy(p, i, j):
    return coe(coe(p, x, i), y, j)

coe(x**3*y**4, y, 1)
coe(x**3*y**4, y, 4)
poly_zwe
coexy(poly_zwe, 0, 2)
coexy(poly_zwe, 0, 1)
coexy(poly_zwe, 0, 0)

coexy(poly_zwe, 1, 1)
coexy(poly_zwe, 1, 0)

coexy(poly_zwe, 2, 0)

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
# Questão 3a:
M = Matrix([[2, 1], [0, 1]])
M
(M**-1) * Matrix([x+1, y+2])

# Questão 3b:
((M**-1) * Matrix([x+1, y+2])).subs(x,  1).subs(y,  1)
((M**-1) * Matrix([x+1, y+2])).subs(x, -1).subs(y, -1)
((M**-1) * Matrix([x+1, y+2])).subs(y, 1/x)
((M**-1) * Matrix([x+1, y+2])).subs(y, 1/x).subs(x,  1)
((M**-1) * Matrix([x+1, y+2])).subs(y, 1/x).subs(x, -1)
((M**-1) * Matrix([x+1, y+2])).subs(y, 1/x).subs(x, 1/2)





#####
#
# Matrices
# 2013dec02
#
#####

# «matrices» (to ".matrices")
# (find-sympytutfile "matrices.rst")
# (find-sympyfile "sympy/matrices/matrices.py")
# (find-sympyfile "sympy/matrices/matrices.py" "def dot(self, b):")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
v = Matrix([10, 20, 30])
w = Matrix([5, 5, 0])
v
w
w.T
v.T * w
v.dot(w)
v - w

def V(a, b):
  return Matrix([a, b])
def D5(v):
  w = V(0, 5) - v
  return w.dot(w)
def d5(a, b):
  w = V(0, 5) - V(a, b)
  return w.dot(w)
def lambdao(v, w):
  return v.dot(w) / v.dot(v)
def projo(v, w):
  return (v.dot(w) / v.dot(v)) * v
def C(v):
  return projo(v, V(0, 10))
def DC(v):
  return D5(C(v))

C(V(1, 1)).T
C(V(2, 1)).T
C(V(3, 1)).T
C(V(30, 10)).T
C(V(10, 30)).T
C(V(x, y)).T
C(V(7, 1)).T
DC(V(x, y))
DC(V(7, y))
DC(V(1, 1))
DC(V(10, 1))
DC(V(-11, 7))




* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
def V(a, b):
  return Matrix([a, b])
def norm2(v):
  return v.dot(v)
def norm(v):
  return sqrt(norm2(v))
def un(v):
  return v / norm(v)
def Ecirc(C0, R, P):
  return norm2(P - C0) - R**2
def ecirc(C0x, C0y, R, x, y):
  return Ecirc(V(C0x, C0y), R, V(x, y))

R = Rational

def getx(v):
  return v.dot(V(1, 0))
def gety(v):
  return v.dot(V(0, 1))
def inr(a, b, x, y):
  return y - (a*x + b)
def Inr(a, b, P):
  return inr(a, b, getx(P), gety(P))

def lambdao(v, w):
  return v.dot(w) / v.dot(v)
def projo(v, w):
  return (v.dot(w) / v.dot(v)) * v
def C(v):
  return projo(v, V(0, 10))
def DC(v):
  return D5(C(v))

C(V(4, 1))
C(V(5, 1))
C(V(6, 1))
C(V(8, 1))

inr(R(2)/3, -4, 0, -4)
inr(R(2)/3, -4, 6, 0)
inr(R(2)/3, -4, 0, 0)

Inr(R(2)/3, -4, V(0, -4))
Inr(R(2)/3, -4, V(6, 0))
Inr(R(2)/3, -4, V(0, 0))

ecirc(0, 0, 5, x, y)

A = V(3, -2)
w = V(3, 2)
wu = un(w)
P = A + 5*wu
Q = A - 5*wu

P
Q
Inr(R(2)/3, -4, P)
Inr(R(2)/3, -4, Q)
norm(P - A)
norm(Q - A)

B = projo(V(3, 2), V(0, 4)) + V(0, -4)
B.T
Inr(R(2)/3, -4, B)

5 * un(V(2, 1))

w = V(3, 2)
(V(3, -2) + 5*un(w)).T

norm(V(30,40))

R(4).sqrt
sqrt(6)

P = V((48 + sqrt(6516))/26, R(2)/3 * (48 + sqrt(6516))/26 - 4)
Q = V((48 - sqrt(6516))/26, R(2)/3 * (48 - sqrt(6516))/26 - 4)
P
Q
A = V(3, -2)
norm(A - P)
norm2(A - P)
expand(norm(A - P))


def bdelta(a, b, c):
  return b*b - 4*a*c
def bdeltar(a, b, c):
  return sqrt(bdelta(a, b, c))
# def broot1(a, b, c):
#   return 

def ry(x):
  return 2/3 * x - 4
x1 = (24 + 3 * sqrt(181)) / 13
x2 = (24 - 3 * sqrt(181)) / 13

y1 = ry(x1)
x1 = x1.evalf(15)
y1 = y1.evalf(15)

V(x1, y1)
norm(V(x1, y1))

y(x1)))

# (find-sympytutfile "basic_operations.rst")




#####
#
# GA 2013.2 P2B
# 2014jan15
#
#####

# «GA-2013.2-P2B» (to ".GA-2013.2-P2B")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
def V(a, b):
  return Matrix([a, b])
def norm2(v):
  return v.dot(v)
def norm(v):
  return sqrt(norm2(v))
def un(v):
  return v / norm(v)
def vl(v):
  return Matrix([[0, -1],[1, 0]]) * v

# Demo: M=(2,4), I=(4,8)
R = 5
RR = 10

# I=(72/25, 96/25)
R = 3
RR = 4

# I=(40/29, 100/29)
R = 2
RR = 5

C0  = V(0, R)
C00 = V(RR, 0)
v = C00 - C0
dd = norm(v)
aa = (R*R - RR*RR + dd*dd) / (2*dd)
ap = dd - aa
bb = sqrt(R*R - aa*aa)
aa
bb
vu = un(v)
wu = vl(vu)
M = C0 + aa*vu
I  = M + bb*wu
II = M - bb*wu
M
I
II
norm(C0 - I)
norm(C00 - I)
M.evalf(4)
I.evalf(4)




#####
#
# conics
# 2014may14
#
#####

# «conics» (to ".conics")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import Poly
a, b, c, d, e, f, u, v = symbols('a b c d e f u v')
# U, V = symbols('U V', cls=Function)

P = y - x**2;
H = x*y - 1;
E = x*x + y*y - 1;

PP = v - u**2;
HH = u*v - 1;
EE = u*u + v*v - 1;

PP
HH.subs(u, 2*x).subs(v, y/2)
PP.subs(v, 2)

PPP = A + t*uu + t*t*vv
HHH = A + t*uu + (1/t)*vv

\par P = { (x,y)Ý\R^2 }{ y=x² }
\par H = { (x,y)Ý\R^2 }{ xy=1 }
\par E = { (x,y)Ý\R^2 }{ x²+y²=1 }
\ssk
\par P' = { (x,y)Ý\R^2 }{ V(x,y)=U(x,y)² }
\par H' = { (x,y)Ý\R^2 }{ U(x,y)V(x,y)=1 }
\par E' = { (x,y)Ý\R^2 }{ U(x,y)²+V(x,y)²=1 }
\ssk
\par P'' = { A + t\uu + t²\vv }{ tÝ\R }
\par H'' = { A + t\uu + \frac 1t \vv }{ tÝ\R, t \neq 0 }
\par E'' = { A + (\cos \th)\uu + (\sen \th)\vv }{ tÝ\R }





#####
#
# conics 2
# 2014jun04
#
#####

# «conics-2» (to ".conics-2")
# (to "matrices")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

def pyrtopoly(a, b, c, d, e, f, x, y):
  return a*y*y + b*y + c*x*y + d + e*x + f*x*x
def V(a, b):
  return Matrix([a, b])
def M(a, b, c, d):
  return Matrix([[a, b], [c, d]])

def pyrintersec(a, b, c, d, e, f):
  return M(a, c, d, f)**-1 * V(-b, -e)
def pyrcenter(a, b, c, d, e, f):
  return pyrintersec(2*a, b, c, c, e, 2*f)

((x-2)**2 + (y-3)**2)
((x-2)**2 + (y-3)**2).expand()

pyrcenter(1, -6, 0, 13, -4, 1)

M(10, 20, 30, 40)
M(10, 20, 30, 40)**-1


* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
from sympy import Poly

U = x/4 + y/2 - 1
V = -x/4 + y/2 - 1
expand(U*U)
expand(V*V)
expand(U*V)

def coefyx(p, cy, cx):
  return Poly(Poly(p, y).nth(cy), x).nth(cx)
def asmat(p):
  return Matrix([[coefyx(p, 2, 0),              0,               0 ],
                 [coefyx(p, 1, 0), coefyx(p, 1, 1),              0 ],
                 [coefyx(p, 0, 0), coefyx(p, 0, 1), coefyx(p, 0, 2)]])
def aspoly0(m, x, y):
  return (m * Matrix([1, x, x*x])).dot(Matrix([y*y, y, 1]))
def aspoly(m):
  return (m * Matrix([1, x, x*x])).dot(Matrix([y*y, y, 1]))
def conicpoly(a, b, c, d, e, f):
  return a*y*y + b*y + c*x*y + d + e*x + f*x*x
def linepoly(a, b, c):
  return a*y + b + c*x
def hompoly(a, b, c):
  return a*y*y + b*x*y + c*x*x

asmat(hompoly(2, 3, 4))
asmat(conicpoly(2, 3, 4, 5, 6, 7))

aspoly(Matrix([[2, 0, 0], [3, 4, 0], [5, 6, 7]]))
aspoly(Matrix([[2, 0, 0], [3, 4, 0], [5, 6, 7]])).expand()
asmat(aspoly(Matrix([[2, 0, 0], [3, 4, 0], [5, 6, 7]])))

asmat(aspoly0(asmat(conicpoly(2, 3, 4, 5, 6, 7)), x, y+10))




#####
#
# intersection of plane and line
# 2017jul19
#
#####

# «inter_plane_line» (to ".inter_plane_line")
# file:///usr/share/doc/python2.7/html/tutorial/controlflow.html#defining-functions

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

plane    = lambda P: sprod3(P, V3(2,2,1)) - 4
line     = lambda t: V3(1,2,3) + t*V3(2,1,0)

plane(V3(2,0,0))    # 0
plane(V3(0,0,0))    # -4
line(0)
line(1)
plane(line(0))

plane_line_to_t_ = lambda plane,line:      solve(plane(line(t)), t)
plane_line_to_t  = lambda plane,line:      solve(plane(line(t)), t)[0]
plane_line_to_P  = lambda plane,line: line(solve(plane(line(t)), t)[0])
inter_plane_line = lambda plane,line: line(solve(plane(line(t)), t)[0])

plane_line_to_t_(plane, line)
plane_line_to_t (plane, line)
plane_line_to_P (plane, line)
P = plane_line_to_P (plane, line)
plane(P)

plane_line_to_t(plane, line)
plane_line_to_P(plane, line)






piaa     = lambda aa: lambda P: sprod3(P, V3(2,2,1)) - aa
s        = lambda t: t*nn
H = plane_line_to_P(piaa(4), s)
H
piaa(4)(H)
H
sprod3(H, H)

piaa(aa)(V3(x,y,z))

V3(1,2,3)
line(4)
plane(line(4))

plane(line(t))
solve(plane(line(t)), t)[0]

closest_plane_P = lambda nn,A,P: plane_line_to_P(plane_from_nn_A(nn, A), 




#####
#
# printing
# 2019jul09
#
#####

# «printing» (to ".printing")
# (find-sympytutfile "printing.rst" "str(expr)")
# (find-sympytutfile "printing.rst" "print(latex(Integral(sqrt(1/x), x)))")




#####
#
# subs
# 2019jul09
#
#####

# «subs» (to ".subs")
# (to "tut-subs")
# (find-sympytutgrep "grep --color -nH -e subs *")
# (find-sympytutfile "basic_operations.rst" "expr.subs(x, y)")
# https://docs.sympy.org/latest/tutorial/basic_operations.html#substitution



#####
#
# sympy-colors
# 2019sep25
#
#####

# «sympy-colors» (to ".sympy-colors")
# (find-fline "~/LOGS/2019sep25.emacs")
# (find-fline "~/LOGS/2019sep25.emacs" "prompt with too many colors")

# (find-man "1 isympy")
# (find-man "1 isympy" "-- --colors=NoColor")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
isympy

y
isympy -- --colors=NoColor

y

w isympy
aptrm isympy isympy3 isympy-common
rehash
w isympy





#####
#
# Assessing the difficulty of trigonometic substitution questions
# 2019oct29
#
#####

# «trig-subst-questions» (to ".trig-subst-questions")
# (find-es "ipython" "2019.1-C2-P1")
# (find-es "ipython" "2019.1-C2-P1" "trig-subst-questions")
# (find-TH "2019.1-C2" "provas-antigas")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

S = sqrt(1 - x**2)
T = sqrt(x**2 + 1)
Z = sqrt(x**2 - 1)

integrate(x**3 * S**-3, x)
integrate(x**3 * S**-2, x)
integrate(x**3 * S**-1, x)
integrate(x**3 * S** 1, x)
integrate(x**3 * S** 2, x)
integrate(x**3 * S** 3, x)

integrate(x**2 * S**-3, x)
integrate(x**2 * S**-2, x)
integrate(x**2 * S**-1, x)    # bom
integrate(x**2 * S** 1, x)
integrate(x**2 * S** 2, x)
integrate(x**2 * S** 3, x)

integrate(x**3 * T**3, x)
integrate(x**2 * T**-7, x)

integrate(sin(x)**2 * cos(x)**3, x)




#####
#
# My way of generating trigonometric identities via Fourier
# 2019nov25
#
#####

# «trigonometric-identities» (to ".trigonometric-identities")
# (find-angg ".sympyrc.py" "C2-trig-ids")
# (find-esgrep "grep --color -nH -e 'E\\*\\*' ipython.e")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
s,u,z  = symbols("s,u,z")
t,th   = symbols("t,th")
E,Einv = symbols("E,Einv")

EE  = lambda n: E**n
Cos = lambda n: (EE(n) + EE(-n)) /  2
Sin = lambda n: (EE(n) - EE(-n)) / (2*I)
expify  = lambda f: f.expand().subs(E, exp(I*th))
int02pi = lambda f: integrate(f, (th, 0, 2*pi)) / (2 * pi)
getcoef = lambda f,n: int02pi(expify(f * EE(-n)))
getcoefcos = lambda f,n: (getcoef(f, n) + getcoef(f, -n))
getcoefsin = lambda f,n: (getcoef(f, n) - getcoef(f, -n)) * I
getcos     = lambda f,n: getcoefcos(f, n) * cos(n*th)
getsin     = lambda f,n: getcoefsin(f, n) * sin(n*th)
getconst   = lambda f: getcoef(f, 0)

f = 3 + 4*Sin(5) + 6*Cos(7)
f
expify(f)
getconst(f)
getsin(f, 5)
getcos(f, 7)
getconst(f) + getsin(f, 5) + getcos(f, 7)

f = Sin(1)**3
f
expify(f)
getsin(f, 1) + getsin(f, 3)

f = Cos(1)**2
f
expify(f)
getconst(f) + getcos(f, 2)

f = Sin(1)**4 * Cos(1)**2
f
expify(f)
getconst(f) + getcos(f, 2) + getcos(f, 4) + getcos(f, 6)




#####
#
# Lagrange multipliers
# 2019dec03
#
#####

# «lagrange-multipliers» (to ".lagrange-multipliers")
# (find-books "__analysis/__analysis.el" "bortolossi")
# (find-books "__analysis/__analysis.el" "bortolossi" "multiplicadores de Lagrange")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
# (find-bortolossi12page (+ -456 463)     "Lagrangeano")

la = symbols('la')
F = x*y
H = x + 2*y - 6

L = F - la*H
grad_F = M([F.diff(x), F.diff(y)])
grad_H = M([H.diff(x), H.diff(y)])
L_xyla = M([L.diff(x), L.diff(y), L.diff(la)])
sol = solve(L_xyla)
sol
grad_F.subs(sol)
grad_H.subs(sol)




#####
#
# Exact EDOs: test exactness, find integrating factors
# 2019dec04
#
#####

# «exactify» (to ".exactify")
# (find-angg ".sympyrc.py" "exactify")
# (find-books "__analysis/__analysis.el" "trench")
# (find-trenchpage (+ 10  83) "2.6 Integrating Factors")
# (find-trenchpage (+ 10  84)   "Theorem 2.6.1")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

exactness    = lambda M,N:  M.diff(y) - N.diff(x)
exactify_x   = lambda M,N: (M.diff(y) - N.diff(x)) / N
exactify_y   = lambda M,N: (N.diff(x) - M.diff(y)) / M
exactify_xi  = lambda M,N: integrate(exactify_x(M, N), x)
exactify_yi  = lambda M,N: integrate(exactify_y(M, N), y)
exactify_xie = lambda M,N: exp(exactify_xi(M, N))
exactify_yie = lambda M,N: exp(exactify_yi(M, N))

F = x**2 * y**3
M0 = F.diff(x)
N0 = F.diff(y)
exactness(M0, N0)
M0, N0
`M0, N0`

H = x
M1,N1 = H*M0,H*N0
M1,N1
exactness(M1, N1)
exactify_x  (M1, N1)
exactify_xi (M1, N1)
exactify_xie(M1, N1)
exactify_y  (M1, N1)
exactify_yi (M1, N1)
exactify_yie(M1, N1)

mux = exactify_xie(M1, N1)
muy = exactify_yie(M1, N1)
M2,N2 = mux*M1,mux*N1
M3,N3 = muy*M1,muy*N1
M2,N2
M3,N3
exactness(M2,N2)
exactness(M3,N3)






#####
#
# ODEs of the form f''+af'+bf = 0 with real solutions
# 2019dec11
#
#####

# «linear-order2-real» (to ".linear-order2-real")
# (find-es "ipython" "2019.2-C2-P2" "Questao 1")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
f = Function('f')
a, b = symbols('a b')

eq    = f(x).diff(x, x) - f(x).diff(x) - 6*f(x)
g     = a*exp(-2*x) + b*exp(3*x)                 # generic solution
cond1 = g.subs(x, 0)         - 4
cond2 = g.diff(x).subs(x, 0) - 5

eq
dsolve(eq)
`dsolve(eq)`
g
sol = solve((cond1, cond2), [a, b])
sol
g.subs(sol)






#####
#
# ODEs of the form f''+af'+bf = 0 with complex solutions
# 2019dec11
#
#####

# «linear-order2-complex»  (to ".linear-order2-complex")
# (find-es "ipython" "2019.1-C2-P2" "Questao 2")
# (find-es "ipython" "2019.2-C2-P2" "Questao 2")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
f,f1,f2,f3,f4 = symbols('f,f1,f2,f3,f4', cls=Function)
y = symbols('y', cls=Function)
D = symbols("D")

a, b = symbols('a b')
a, b =  -4, 3
eq = f(x).diff(x,x) + 8*f(x).diff(x) + 25*f(x)
eq

((D - (a+b*I)) * (D - (a-b*I)))
((D - (a+b*I)) * (D - (a-b*I))).expand()
eq
dsolve(eq, f(x))

f1 = exp((a+b*I)*x)
f2 = exp((a-b*I)*x)
f3 = cos(b*x) * exp(a*x)
f4 = sin(b*x) * exp(a*x)
f1
f2
f3
f4

# Doesn't work:
eq.subs(f(x), f1(x))
eq.subs(f, f1)
eq.subs(f, f2)
eq.subs(f, f3)
eq.subs(f, f4)
f1
f2
dsolve(eq, f(x))




#####
#
# ODEs with separable variables
# 2019dec11
#
#####

# «separable-variables» (to ".separable-variables")
# (find-books "__analysis/__analysis.el" "trench")
# (find-books "__analysis/__analysis.el" "trench" "Separable")
# (find-angg ".emacs" "c2q192")
# (find-angg ".emacs" "c2q192" "separ")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)
execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")
y = symbols('y')
y,c3 = symbols('y,c3')

g = x**3
h = exp(2*y)
g
h
G = integrate(g, x)
H = integrate(h, y)
G
H
G - H - c3
sols = solve(G - H - c3, y)
sols[0]
sols[1]

f,f1,f2,f3,f4 = symbols('f,f1,f2,f3,f4', cls=Function)
y = symbols('y', cls=Function)
D = symbols("D")




#####
#
# inspect-re-and-regex (thx Bruno Macedo)
# 2020nov01
#
#####

# «inspect-re-and-regex»  (to ".inspect-re-and-regex")
# (find-es "sympy" "sympy-git")
# (find-sympyfile "sympy/functions/elementary/complexes.py" "class re(Function):")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
export PYTHONSTARTUP=$HOME/.pythonrc.py
export PAGER=cat
isympy3

import inspect
from pprint import pprint
pprint(inspect.getdoc(re))
pprint(inspect.getfile(re))
import re as regex
pprint(inspect.getdoc(regex))





#####
#
# My question about re and regex at gitter
# 2020nov01
#
#####

# «re-regex-gitter-question»  (to ".re-regex-gitter-question")
# (find-angg ".pythonrc.py" "imports")

file:///usr/share/doc/python3.7/html/howto/regex.html
file:///usr/share/doc/python3.7/html/library/re.html
https://docs.python.org/3.7/howto/regex.html

https://gitter.im/sympy/sympy#

Hi, I just discovered that when I run a recent sympy on python3 "re"
becomes the class "re" in functions/elementary/complexes.py... so if I
run an old Python script that I have that uses re.sub - see:
https://docs.python.org/3.7/howto/regex.html - it fails. Is there a
stadard way to handle this?

From Aaron Meurer @asmeurer Nov 02 21:28:
@eduardoochs_twitter avoid using import * in scripts. Only import the
names from sympy that you use If you are using sympy.re, you can
either import sympy as sym and use sym. everywhere, like
sym.Symbol('x'), or you can import re as stdlib_re and use
stdlib_re.sub and so on.




#####
#
# ee_dofile-bug
# 2020nov01
#
#####

# «ee_dofile-bug»  (to ".ee_dofile-bug")

* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
sudo apt-get install isympy3
# (find-sh       "which isympy3")
# (find-fline "/usr/bin/isympy3")
# (find-fline "~/.pythonrc.py")
# (find-fline "~/.sympyrc.py")
cd
rm -v .pythonrc.py
rm -v .sympyrc.py
wget http://angg.twu.net/.pythonrc.py
wget http://angg.twu.net/.sympyrc.py


* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
export PYTHONSTARTUP=$HOME/.pythonrc.py
export PAGER=cat
isympy3

import inspect
from pprint import pprint
pprint(inspect.getdoc(re))
import re as regex
pprint(inspect.getdoc(regex))


ee_dofile("~/.sympyrc.py")   # (find-angg ".sympyrc.py")
# ^ AttributeError: type object 're' has no attribute 'sub'
f0 = x**2 / (x**2 + 3*x - 10)
f0
f0.apart()




#####
#
# quote
# 2022aug23
#
#####

# «quote»  (to ".quote")
# (find-sympydocrfile "")
# (find-sympydocrgrep "grep --color=auto -niRH --null -e quot *")

Hi all, another basic question related to my attempt to port some code
from Maxima to SymPy... Maxima has an overwhelming amount of ways to
control how expressions should be simplified, and we can "quote" some
subexpressions of bigger expressions to indicate that they should not
be simplified. Is it possible to do something like that in SymPy? I've
just grepped all the .rst docs of SymPy for words like "quote", and I
only got some results related to quoting in strings... What are the
keywords that I should search for?



#####
#
# equality
# 2021jun10
#
#####

# «equality»  (to ".equality")

* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

* (eepitch-vterm)
* (eepitch-kill)
* (eepitch-vterm)
isympy3
f = x**2 + 4*x + 3
g = exp(y)
f
g
Eq(f, g)

f.subs(x, y+z)




In [1]: f = x**2 + 4*x + 3
In [2]: g = exp(y)
In [3]: f
Out[3]: 
 2          
x  + 4*x + 3

In [4]: g
Out[4]: 
 y
e 

In [5]: Eq(f, g)
Out[5]: 
 2              y
x  + 4*x + 3 = e 

In [6]: f.subs(x, y+z)
Out[6]: 
       2
(y + z)  + 4*(y + z) + 3




https://docs.sympy.org/latest/modules/polys/reference.html

Poly(U, x)
Poly(U, x).all_coeffs()
Poly(U, x).all_coeffs()[0]
Poly(U, x).all_coeffs()[1]
# Poly(U, x).all_coeffs()[2]
Poly(U, x).nth(0)
Poly(U, x).nth(1)
Poly(U, x).nth(2)
Poly(U, x).nth(3)
Poly(U, x).coeff(1)

Matrix([[2, 3, 4], [5, 6, 7], [8, 9, 10]])





* (eepitch-isympy)
* (eepitch-kill)
* (eepitch-isympy)

# (find-sh "which isympy")
# (find-fline "/usr/bin/isympy")
# (find-fline "/usr/bin/isympy3")

from sympy import symbols
from sympy.plotting import plot
from sympy import Piecewise
x = symbols('x')
s = Piecewise((1, (x >= 0) & (x <= 1)), (-1, (x >= 1) & (x <= 2)), (0, True))
plot(s,(x,-1,3))





#  Local Variables:
#  coding:               utf-8-unix
#  End: