Skip to content

Commit dcabb30

Browse files
committed
Try to simplify numbers with integer values to integers
1 parent f9b0ade commit dcabb30

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/simplify_rules.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ let
101101
@rule(exp(~x)^(~y) => exp(~x * ~y))
102102
]
103103

104+
TYPE_RULES = [
105+
@rule(~x::_isinteger => Int(~x))
106+
]
107+
104108
BOOLEAN_RULES = [
105109
@rule((true | (~x)) => true)
106110
@rule(((~x) | true) => true)
@@ -142,6 +146,7 @@ let
142146
If(x -> !ispow(x) && is_operation(^)(x),
143147
Chain(CANONICALIZE_POW)),
144148
If(is_operation(^), Chain(POW_RULES)),
149+
Chain(TYPE_RULES)
145150
] |> RestartedChain
146151

147152
rule_tree

test/rulesets.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ end
5757
@test simplify(Term(zero, [x + 2])) == 0
5858
end
5959

60+
@testset "Types" begin
61+
@syms x
62+
63+
# should convert to int
64+
@test simplify(7.0) === 7
65+
@test simplify(7.0*x) === 7*x
66+
end
67+
6068
@testset "LiteralReal" begin
6169
@syms x1::LiteralReal x2::LiteralReal
6270
s = cos(x1 * 3.2) - x2 * 5.8 + x2 * 1.2

0 commit comments

Comments
 (0)