diff --git a/Project.toml b/Project.toml index 405677a..ce43845 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TermInterface" uuid = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" authors = ["Shashi Gowda ", "Alessandro Cheli "] -version = "0.1.3" +version = "0.1.4" [compat] julia = "1" diff --git a/src/utils.jl b/src/utils.jl index a51b9cb..bc46b35 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -5,4 +5,11 @@ Returns a single argument anonymous function predicate, that returns `true` if a the argument to the predicate satisfies `isterm` and `gethead(x) == f` """ is_operation(f) = @nospecialize(x) -> isterm(x) && (gethead(x) == f) -export is_operation \ No newline at end of file +export is_operation + + +""" + node_count(t) +Count the nodes in a symbolic expression tree satisfying `isterm` and `getargs`. +""" +node_count(t) = isterm(t) ? reduce(+, node_count(x) for x in getargs(t), init=0) + 1 : 1