def test_Mul(self): from sympy.abc import a, b, c, x, y m = Symbol ('m', commutative=False) n = Function('n', commutative=False) k = Function('k', commutative=False) assert straighten(Bind(a*m, x, b*Bind(c*n(x), y, k(x,y)))) == a*b*c*Bind(m,x,Bind(n(x),y,k(x,y))) assert straighten(Bind(a*Bind(b*m, x, c*n(x)), y, k(y))) == a*b*c*Bind(m,x,Bind(n(x),y,k(y))) assert straighten(Bind(m, x, Bind(n(x), y, a*exp(b*x+c*y)*k(x,y)))) == a*Bind(m, x, exp(b*x)*Bind(n(x), y, exp(c*y)*k(x,y))) a = Function('a') b = Function('b') c = Function('c') assert straighten(Bind(a(x)*m, x, b(x)*Bind(c(x)*n(x), y, k(x,y)))) == a(x)*Bind(m,x,b(x)*c(x)*Bind(n(x),y,k(x,y))) assert straighten(Bind(a(x)*Bind(b(x)*m, x, c(x)*n(x)), y, k(y))) == a(x)*b(x)*Bind(m,x,c(x)*Bind(n(x),y,k(y)))
def splice(a, b, x0, width, x, dx): from sympy import tanh ax = a(x) bx = b(x) dax = symdiff(a)(x) dbx = symdiff(b)(x) f = ax + (bx-ax) * (1+tanh((x-x0)/width)) / 2 df = (dax + (dbx-dax) * (1+tanh((x-x0)/width)) / 2 + (bx - ax) * (1-tanh((x-x0)/width)**2) / (2*width)) * dx return f, df
def test_bisectors(): r1 = Line3D(Point3D(0, 0, 0), Point3D(1, 0, 0)) r2 = Line3D(Point3D(0, 0, 0), Point3D(0, 1, 0)) bisections = r1.bisectors(r2) assert bisections == [Line3D(Point3D(0, 0, 0), Point3D(1, 1, 0)), Line3D(Point3D(0, 0, 0), Point3D(1, -1, 0))] ans = [Line3D(Point3D(0, 0, 0), Point3D(1, 0, 1)), Line3D(Point3D(0, 0, 0), Point3D(-1, 0, 1))] l1 = (0, 0, 0), (0, 0, 1) l2 = (0, 0), (1, 0) for a, b in cartes((Line, Segment, Ray), repeat=2): assert a(*l1).bisectors(b(*l2)) == ans
def test_linear_system_function(): a = Function('a') assert solve([a(0, 0) + a(0, 1) + a(1, 0) + a(1, 1), -a(1, 0) - a(1, 1)], a(0, 0), a(0, 1), a(1, 0), a(1, 1)) == {a(1, 0): -a(1, 1), a(0, 0): -a(0, 1)}
def test_linear_system(): x, y, z, t, n, a = symbols('x,y,z,t,n,a') assert solve([x - 1, x - y, x - 2*y, y - 1], [x,y]) is None assert solve([x - 1, x - y, x - 2*y, x - 1], [x,y]) is None assert solve([x - 1, x - 1, x - y, x - 2*y], [x,y]) is None assert solve([x + 5*y - 2, -3*x + 6*y - 15], x, y) == {x: -3, y: 1} M = Matrix([[0,0,n*(n+1),(n+1)**2,0], [n+1,n+1,-2*n-1,-(n+1),0], [-1, 0, 1, 0, 0]]) assert solve_linear_system(M, x, y, z, t) == \ {y: 0, z: t*(-n - 1)/n, x: t*(-n - 1)/n} assert solve([x + y + z + t, -z - t], x, y, z, t) == {x: -y, z: -t} assert solve([a(0, 0) + a(0, 1) + a(1, 0) + a(1, 1), -a(1, 0) - a(1, 1)], a(0, 0), a(0, 1), a(1, 0), a(1, 1)) == {a(1, 0): -a(1, 1), a(0, 0): -a(0, 1)}
def test_linear_system_function(): a = Function('a') assert solve([a(0, 0) + a(0, 1) + a(1, 0) + a(1, 1), -a(1, 0) - a(1, 1)], a(0, 0), a(0, 1), a(1, 0), a(1, 1)) == { a(1, 0): -a(1, 1), a(0, 0): -a(0, 1) }
def test_linear_system(): n, t = symbols('n,t') assert solve([x - 1, x - y, x - 2 * y, y - 1], [x, y]) is None assert solve([x - 1, x - y, x - 2 * y, x - 1], [x, y]) is None assert solve([x - 1, x - 1, x - y, x - 2 * y], [x, y]) is None assert solve([x + 5 * y - 2, -3 * x + 6 * y - 15], x, y) == {x: -3, y: 1} M = Matrix([[0, 0, n * (n + 1), (n + 1)**2, 0], [n + 1, n + 1, -2 * n - 1, -(n + 1), 0], [-1, 0, 1, 0, 0]]) assert solve_linear_system(M, x, y, z, t) == \ {y: 0, z: t*(-n - 1)/n, x: t*(-n - 1)/n} assert solve([x + y + z + t, -z - t], x, y, z, t) == {x: -y, z: -t} assert solve([a(0, 0) + a(0, 1) + a(1, 0) + a(1, 1), -a(1, 0) - a(1, 1)], a(0, 0), a(0, 1), a(1, 0), a(1, 1)) == { a(1, 0): -a(1, 1), a(0, 0): -a(0, 1) }