diff --git a/src/simplify_rules.jl b/src/simplify_rules.jl index a612036c..df1cc812 100644 --- a/src/simplify_rules.jl +++ b/src/simplify_rules.jl @@ -101,6 +101,10 @@ let @rule(exp(~x)^(~y) => exp(~x * ~y)) ] + TYPE_RULES = [ + @rule(~x::_isinteger => Int(~x)) + ] + BOOLEAN_RULES = [ @rule((true | (~x)) => true) @rule(((~x) | true) => true) @@ -142,6 +146,7 @@ let If(x -> !ispow(x) && is_operation(^)(x), Chain(CANONICALIZE_POW)), If(is_operation(^), Chain(POW_RULES)), + Chain(TYPE_RULES) ] |> RestartedChain rule_tree diff --git a/test/rulesets.jl b/test/rulesets.jl index cfbc0143..1f115312 100644 --- a/test/rulesets.jl +++ b/test/rulesets.jl @@ -57,6 +57,14 @@ end @test simplify(Term(zero, [x + 2])) == 0 end +@testset "Types" begin + @syms x + + # should convert to int + @test simplify(7.0) === 7 + @test simplify(7.0*x) === 7*x +end + @testset "LiteralReal" begin @syms x1::LiteralReal x2::LiteralReal s = cos(x1 * 3.2) - x2 * 5.8 + x2 * 1.2