Rewrite an expression
This functionality does not run in MATLAB.
rewrite(f, target) transforms an expression f to a mathematically equivalent form, trying to express f in terms of the specified target function.
The target indicates the function that is to be used in the desired representation. Symbolic function calls in f are replaced by the target function if this is mathematically valid.
With the target arg, the function ln(sign(x)) is rewritten as i arg(x).
With the target exp, all trigonometric and hyperbolic functions are rewritten in terms of exp. Further, the inverse functions as well as arg are rewritten in terms of ln.
With the target sincos, the functions tan, cot, exp, sinh, cosh, tanh, and coth are rewritten in terms of sin and cos.
With the target sin, the same is done as in the case of sincos. Additionally, cos(x)2 is rewritten as 1 - sin(x)2. This holds for the target cos analogously.
With the target sinhcosh, the functions exp, tanh, coth, sin, cos, tan, and cot are rewritten in terms of sinh and cosh. With the targets sinh and cosh, the same is done, and cosh(x)^2 is rewritten in terms of sinh (or sinh(x)^2 in terms of cosh, respectively.)
With the targets arcsin, arccos, arctan, and arccot, the logarithm, all inverse trigonometric functions, and all inverse hyperbolic functions are rewritten in terms of the target function.
With the targets arcsinh, arccosh, arctanh, and arccoth, the logarithm, all inverse hyperbolic functions and all inverse trigonometric functions are rewritten in terms of the target function.
With the target diff, symbolic calls of the differential operator D are rewritten in terms of symbolic calls of the function diff. E.g., D(f)(x) is converted to diff(f(x), x). A univariate expression D(f)(x) is rewritten if x is an identifier or an indexed identifier. A multivariate expression D([n1, n2, ...], f)(x1, x2, ...) is rewritten if x1, x2 are distinct identifiers or indexed identifiers. Trying to rewrite a multivariate call D(f)(x1, x2, ...) of the univariate dervative D(f) raises an error.
With the target D, symbolic diff calls are rewritten in terms of the differential operator D. Derivatives of univariate function calls such as diff(f(x), x) are rewritten as D(f)(x). Derivatives of multivariate function calls are expressed via D([n1, n2, ...], f). E.g., diff(f(x, y), x) is rewritten as D(, f)(x, y).
The targets harmonic and psi serve for rewriting symbolic calls of psi in terms of harmonic and vice versa.
With the target inverf, the function inverfc(x) is rewritten as inverf(1 - x).
With the target inverfc, the function inverf(x) is rewritten as inverfc(1 - x).
This example demonstrates the use of rewrite:
diff(f(x, x), x) = rewrite(diff(f(x, x), x), D)
assume(n, Type::PosInt): rewrite(fact(n), gamma), rewrite(gamma(n), fact); delete n:
rewrite(sign(x), heaviside), rewrite(heaviside(x), sign);
rewrite(tan(x), exp), rewrite(cot(x), sincos), rewrite(sin(x), tan)
Inverse trigonometric functions can be rewritten in terms of each other:
The following result uses the function signIm ("sign of the imaginary part") to make the formula valid throughout the complex plane (apart from the singularities at ):
The target function to be used in the representation: one of andor, arccos, arccosh, arccot, arccoth, arcsin, arcsinh, arctan, arctanh, arg, bernoulli, cos, cosh, cot, coth, diff, D, erf, erfc, erfi, exp, fact, gamma, harmonic, heaviside, inverf, inverfc, lambertW, ln, max, min, piecewise, psi, sign, sin, sincos, sinh, sinhcosh, tan, or tanh