Created
April 6, 2015 21:24
-
-
Save loguntsov/da467cc9ad5da9f32ff7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module(simplification). | |
-compile([export_all]). | |
zeroA({add,E,{num,0}}) -> E; | |
zeroA({add,{num,0},E}) -> E; | |
zeroA(E) -> E. | |
mulO({mul,E,{num,1}}) -> E; | |
mulO({mul,{num,1},E}) -> E; | |
mulO(E) -> E. | |
mulZ({mul,_,{num,0}}) -> {num,0}; | |
mulZ({mul,{num,0},_}) -> {num,0}; | |
mulZ(E) -> E. | |
compose([])-> fun (E) -> E end; | |
compose([Rule|Rules]) -> | |
fun (E) -> (compose(Rules))(Rule(E)) end. | |
rules() -> [ fun zeroA/1, fun mulO/1, fun mulZ/1]. | |
simp(F,{add,E1,E2}) -> | |
F({add,simp(F,E1),simp(F,E2)}); | |
simp(F,{mul,E1,E2}) -> | |
F({mul,simp(F,E1),simp(F,E2)}); | |
simp(_F,E) -> E. | |
simplify(E) -> simp(compose(rules()),E). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment