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

M, R = Matrix, Rational

# 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)
#
# 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)



# 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]))

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