egison-5.1.0: test/lib/math/analysis.egi
--
-- Originally auto-generated by egison-translator; modernized for the
-- typed CAS (declare symbol; expectations follow the current normal
-- forms: the Pythagorean auto rule rewrites cos^2 to 1 - sin^2,
-- casRewriteExp merges exp products and powers, and function-symbol
-- derivative marks are positional and sorted -- Schwarz canonical
-- form, so the mixed second-order Taylor terms merge into one).
--
declare symbol x, y, z, a
assertEqual "d/d - case 1" (d/d (x ^ 2) x) (2 * x)
assertEqual "d/d - case 2" (d/d (a ^ (x ^ 2)) x) (2 * a ^ (x ^ 2) * log a * x)
assertEqual "d/d - case 3" (d/d (cos x * sin x) x) (1 - 2 * sin x ^ 2)
assertEqual
"d/d - case 4"
(d/d (sigmoid z) z)
(exp (- z) / (1 + 2 * exp (- z) + exp (-2 * z)))
assertEqual "d/d - case 5" (d/d (d/d (log x) x) x) ((-1) / x ^ 2)
assertEqual
"taylor-expansion - case 1"
(take 4 (taylorExpansion (e ^ (i * x)) x 0))
[1, i * x, -1 * x ^ 2 / 2, -1 * i * x ^ 3 / 6]
def f := function (x, y)
assertEqual
"multivariate-tailor-expansion - case 1"
(take 3 (multivariateTaylorExpansion (f x y) [|x, y|] [|0, 0|]))
[ f 0 0
, ((userRefs f [1]) 0 0) * x + ((userRefs f [2]) 0 0) * y
, (1 / 2) * ((userRefs f [1, 1]) 0 0) * x ^ 2
+ ((userRefs f [1, 2]) 0 0) * x * y
+ (1 / 2) * ((userRefs f [2, 2]) 0 0) * y ^ 2 ]
assertEqual
"function expr"
(let g := function (x, y)
in d/d g y)
(let g := function (x, y)
in userRefs g [y])
assertEqual
"analytic derivative keeps FunctionData and registered chain rules"
(∂/∂ (sin (f ^ 2)) x)
(2 * (userRefs f [1]) * f * cos (f ^ 2))
assertEqual
"analytic derivative maps coordinate tensors"
(∂/∂ f [|x, y|])
[|userRefs f [1], userRefs f [2]|]
def derivativeVector := generateTensor (\[i] -> function (x, y)) [2]
def functionDataHead (value: MathValue) : MathValue :=
match value as mathValue with
| func $head _ -> head
| _ -> 0
assertEqual
"symbolIndices preserves component and derivative index kinds"
(symbolIndices
(functionDataHead
(partialDiffMV
(partialDiffMV derivativeVector_2 y) x)))
[SubIndex 2, UserIndex 1, UserIndex 2]