def test_functional_diffgeom_ch3(): x0, y0 = symbols('x0, y0', extended_real=True) x, y, t = symbols('x, y, t', extended_real=True) f = Function('f') b1 = Function('b1') b2 = Function('b2') p_r = R2_r.point([x0, y0]) s_field = f(R2.x, R2.y) v_field = b1(R2.x) * R2.e_x + b2(R2.y) * R2.e_y assert v_field.rcall(s_field).rcall(p_r).doit() == b1(x0) * Derivative( f(x0, y0), x0) + b2(y0) * Derivative(f(x0, y0), y0) assert R2.e_x(R2.r**2).rcall(p_r) == 2 * x0 v = R2.e_x + 2 * R2.e_y s = R2.r**2 + 3 * R2.x assert v.rcall(s).rcall(p_r).doit() == 2 * x0 + 4 * y0 + 3 circ = -R2.y * R2.e_x + R2.x * R2.e_y series = intcurve_series(circ, t, R2_r.point([1, 0]), coeffs=True) series_x, series_y = zip(*series) assert all(term == cos(t).taylor_term(i, t) for i, term in enumerate(series_x)) assert all(term == sin(t).taylor_term(i, t) for i, term in enumerate(series_y))
def test_sympyissue_11799(): n = 2 M = Manifold('M', n) P = Patch('P', M) coord = CoordSystem('coord', P, ['x%s' % i for i in range(n)]) x = coord.coord_functions() dx = coord.base_oneforms() f = Function('f') g = [[f(x[0], x[1])**2, 0], [0, f(x[0], x[1])**2]] metric = sum(g[i][j]*TP(dx[i], dx[j]) for i in range(n) for j in range(n)) R = metric_to_Riemann_components(metric) d = Symbol('d') assert (R[0, 1, 0, 1] == -Subs(Derivative(f(d, x[1]), d, d), (d, x[0]))/f(x[0], x[1]) - Subs(Derivative(f(x[0], d), d, d), (d, x[1]))/f(x[0], x[1]) + Subs(Derivative(f(d, x[1]), d), (d, x[0]))**2/f(x[0], x[1])**2 + Subs(Derivative(f(x[0], d), d), (d, x[1]))**2/f(x[0], x[1])**2)
def test_Derivative(): assert mcode(Derivative(f(x), x, x)) == 'Hold[D[f[x], x, x]]' assert mcode(Derivative(sin(x), x)) == "Hold[D[Sin[x], x]]" assert mcode(Derivative(x, x)) == "Hold[D[x, x]]" assert mcode(Derivative(sin(x)*y**4, x, 2)) == "Hold[D[y^4*Sin[x], x, x]]" assert mcode(Derivative(sin(x)*y**4, x, y, x)) == "Hold[D[y^4*Sin[x], x, y, x]]" assert mcode(Derivative(sin(x)*y**4, x, y, 3, x)) == "Hold[D[y^4*Sin[x], x, y, y, y, x]]"
def make_expression(terms): product = [] for term, rat, sym, deriv in terms: if deriv is not None: var, order = deriv while order > 0: term, order = Derivative(term, var), order - 1 if sym is None: if rat is S.One: product.append(term) else: product.append(Pow(term, rat)) else: product.append(Pow(term, rat * sym)) return Mul(*product)
def test_functional_diffgeom_ch4(): x0, y0, theta0 = symbols('x0, y0, theta0', extended_real=True) x, y, r, theta = symbols('x, y, r, theta', extended_real=True) r0 = symbols('r0', positive=True) f = Function('f') b1 = Function('b1') b2 = Function('b2') p_r = R2_r.point([x0, y0]) p_p = R2_p.point([r0, theta0]) f_field = b1(R2.x, R2.y) * R2.dx + b2(R2.x, R2.y) * R2.dy assert f_field.rcall(R2.e_x).rcall(p_r) == b1(x0, y0) assert f_field.rcall(R2.e_y).rcall(p_r) == b2(x0, y0) s_field_r = f(R2.x, R2.y) df = Differential(s_field_r) assert df(R2.e_x).rcall(p_r).doit() == Derivative(f(x0, y0), x0) assert df(R2.e_y).rcall(p_r).doit() == Derivative(f(x0, y0), y0) s_field_p = f(R2.r, R2.theta) df = Differential(s_field_p) assert trigsimp(df(R2.e_x).rcall(p_p).doit()) == ( cos(theta0) * Derivative(f(r0, theta0), r0) - sin(theta0) * Derivative(f(r0, theta0), theta0) / r0) assert trigsimp(df(R2.e_y).rcall(p_p).doit()) == ( sin(theta0) * Derivative(f(r0, theta0), r0) + cos(theta0) * Derivative(f(r0, theta0), theta0) / r0) assert R2.dx(R2.e_x).rcall(p_r) == 1 assert R2.dx(R2.e_x) == 1 assert R2.dx(R2.e_y).rcall(p_r) == 0 assert R2.dx(R2.e_y) == 0 circ = -R2.y * R2.e_x + R2.x * R2.e_y assert R2.dx(circ).rcall(p_r).doit() == -y0 assert R2.dy(circ).rcall(p_r) == x0 assert R2.dr(circ).rcall(p_r) == 0 assert simplify(R2.dtheta(circ).rcall(p_r)) == 1 assert (circ - R2.e_theta).rcall(s_field_r).rcall(p_r) == 0
def test_Derivative(): assert mcode(Derivative(f(x), x, x)) == 'D[f[x], x, x]'