Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
# See:
#   (find-es "python" "execfile")
#   (find-angg ".pythonrc.py")
#   (find-angg ".pythonrc.py" "ee_dofile")
# Usage:
#   execfile(os.getenv("HOME")+"/.sympyrc.py")   # (find-angg ".sympyrc.py")

# <<.GA-vectors>>		(to "GA-vectors")
# <<.GA-intersections-R3>>	(to "GA-intersections-R3")
# <<.C2-trig-ids>>		(to "C2-trig-ids")
# <<.exactify>>			(to "exactify")



M, R = Matrix, Rational



# <<GA-vectors>>  (to ".GA-vectors")
# Analytic Geometry:
#   kprod2(k, v), kprod3(k, v)
#   sprod2(u, v), sprod3(u, v)
#   norm2(u),     norm3(u)
#   norm22(u),    norm32(u)
#   proj2(u, v),  proj3(u, v)
#                 vprod(u, v)
#
V2 = lambda x,y:   M([x,y])
V3 = lambda x,y,z: M([x,y,z])
V  = V2
#
kprod2 = lambda k,u: (k*u[0], k*u[1])
kprod3 = lambda k,u: (k*u[0], k*u[1], k*u[2])
sprod2 = lambda u,v: u[0]*v[0] + u[1]*v[1]
sprod3 = lambda u,v: u[0]*v[0] + u[1]*v[1] + u[2]*v[2]
norm22 = lambda u:      sprod2(u, u)
norm32 = lambda u:      sprod3(u, u)
norm2  = lambda u: sqrt(sprod2(u, u))
norm3  = lambda u: sqrt(sprod3(u, u))
proj2  = lambda u,v: kprod2(sprod2(u, v)/sprod2(u, u), u)
proj3  = lambda u,v: kprod3(sprod3(u, v)/sprod3(u, u), u)
vprod_ = lambda u1,u2,u3,v1,v2,v3: (u2*v3-u3*v2, u3*v1-u1*v3, u1*v2-u2*v1)
vprod  = lambda u,v: M(vprod_(u[0], u[1], u[2], v[0], v[1], v[2]))
#
drPdenom = lambda m: sqrt(1 + m**2)

# <<GA-intersections-R3>>  (to ".GA-intersections-R3")
# Intersections in R^3
#   Experimental. See: (find-es "ipython" "2017.1-GA-VR")
#   Example:
#     plane = lambda P: sprod3(P, V3(2,2,1)) + 4
#     line  = lambda t: V3(1,2,3) + t*V3(2,1,0)
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])
dist_plane_P     = lambda nn,A,B: sprod3(nn,(B-A)) / norm3(nn)
plane_from_nn_A  = lambda nn,A: lambda P: sprod3((P-A), nn)
line_from_A_vv   = lambda A,vv: lambda t: A+t*vv
#
def closest_plane_P(nn,A,P):
  plane = plane_from_nn_A(nn, A)
  line  = line_from_A_V(P, nn)
  return plane_line_to_P(plane, line)
#
# 2018jan19:
Proj2  = lambda u,v: (sprod2(u, v)/sprod2(u, u)) * u
Proj3  = lambda u,v: (sprod3(u, v)/sprod3(u, u)) * u
closest_line_P2 = lambda line,P: line(0) + Proj2(line(1)-line(0), P-line(0))
closest_line_P3 = lambda line,P: line(0) + Proj3(line(1)-line(0), P-line(0))



# Calculus 2:
# (find-es "ipython" "2016.1-C2-P1")
def differenc(body, xab):
  return body.subs(xab[0], xab[2]) - body.subs(xab[0], xab[1])
def differen2(body, xab):
  return (body.subs(xab[0], xab[2]), body.subs(xab[0], xab[1]))



# <<C2-trig-ids>>  (to ".C2-trig-ids")
# (find-es "sympy" "trigonometric-identities")
# Trigonometric identities using Fourier to obtain the coefficients
#
th,E = symbols("th,E")
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)


# <<exactify>>  (to ".exactify")
# (find-es "sympy" "exactify")
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))



# Not yet:
# (find-es "ipython" "trig-subst")

 # Local Variables:
 # ee-anchor-format: "<<%s>>"
 # End: