diff --git a/src/simplify_rules.jl b/src/simplify_rules.jl index 88a1a6482..b12a9f272 100644 --- a/src/simplify_rules.jl +++ b/src/simplify_rules.jl @@ -43,7 +43,6 @@ let MUL_DISTRIBUTE = @ordered_acrule((~x)^(~n) * (~x)^(~m) => (~x)^(~n + ~m)) - CANONICALIZE_POW = [ @rule(^(*(~~x), ~y::_isinteger) => *(map(a->pow(a, ~y), ~~x)...)) @rule((((~x)^(~p::_isinteger))^(~q::_isinteger)) => (~x)^((~p)*(~q))) @@ -91,6 +90,13 @@ let @acrule(cot(~x)^2 + 1 => csc(~x)^2) @acrule(csc(~x)^2 + -1 => cot(~x)^2) + @acrule(cosh(~x)^2 + -1*sinh(~x)^2 => one(~x)) + @acrule(cosh(~x)^2 + -1 => sinh(~x)^2) + @acrule(sinh(~x)^2 + 1 => cosh(~x)^2) + + @acrule(cosh(~x)^2 + sinh(~x)^2 => cosh(2 * ~x)) + @acrule(cosh(~x) * sinh(~x) => sinh(2 * ~x)/2) + @acrule(exp(~x) * exp(~y) => _iszero(~x + ~y) ? 1 : exp(~x + ~y)) @rule(exp(~x)^(~y) => exp(~x * ~y)) ] diff --git a/src/utils.jl b/src/utils.jl index 90e0de5cc..acf9e92d6 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -36,10 +36,10 @@ pow(x::Symbolic,y::Symbolic) = Base.:^(x,y) # Simplification utilities function has_trig_exp(term) !istree(term) && return false - fns = (sin, cos, tan, cot, sec, csc, exp) + fns = (sin, cos, tan, cot, sec, csc, exp, cosh, sinh) op = operation(term) - if Base.@nany 7 i->fns[i] === op + if Base.@nany 9 i->fns[i] === op return true else return any(has_trig_exp, arguments(term)) diff --git a/test/rulesets.jl b/test/rulesets.jl index cd1ada549..4730cc102 100644 --- a/test/rulesets.jl +++ b/test/rulesets.jl @@ -100,13 +100,25 @@ end @eqtest simplify(1 + y + cot(x)^2) == csc(x)^2 + y @eqtest simplify(cos(x)^2 - 1) == -sin(x)^2 @eqtest simplify(sin(x)^2 - 1) == -cos(x)^2 + + @eqtest simplify(cosh(x)^2 + 1 - sinh(x)^2) == 2 + @eqtest simplify(cosh(y)^2 + 1 - sinh(y)^2) == 2 + @eqtest simplify(-sinh(y)^2 + cosh(y)^2 + 1) == 2 + + @eqtest simplify(cosh(x)^2 - 1) == sinh(x)^2 + @eqtest simplify(sinh(x)^2 + 1) == cosh(x)^2 end @testset "Double angle formulas" begin @syms r x + @eqtest simplify(r * cos(x / 2)^2 - r * sin(x / 2)^2) == r * cos(x) @eqtest simplify(r * sin(x / 2)^2 - r * cos(x / 2)^2) == -r * cos(x) @eqtest simplify(2cos(x) * sin(x)) == sin(2x) + + @eqtest simplify(r * cosh(x / 2)^2 + r * sinh(x / 2)^2) == r * cosh(x) + @eqtest simplify(r * sinh(x / 2)^2 + r * cosh(x / 2)^2) == r * cosh(x) + @eqtest simplify(2cosh(x) * sinh(x)) == sinh(2x) end @testset "Exponentials" begin