@@ -13,6 +13,11 @@ julia>drop_powers((x+y)^2 + (x+y)^3, [x,y], 3)
1313x^2 + y^2 + 2*x*y
1414```
1515"""
16+ function drop_powers (expr:: BasicSymbolic , vars:: Vector{<:BasicSymbolic} , deg:: Int )
17+ return unwrap (drop_powers (Num (expr), Num .(vars), deg))
18+ end
19+
20+ # Num fallback: the actual implementation
1621function drop_powers (expr:: Num , vars:: Vector{Num} , deg:: Int )
1722 Symbolics. @variables ϵ
1823 subs_expr = deepcopy (expr)
@@ -43,17 +48,19 @@ function drop_powers(eqs::Vector{Equation}, var::Vector{Num}, deg::Int)
4348 Equation (drop_powers (eq. lhs, var, deg), drop_powers (eq. rhs, var, deg)) for eq in eqs
4449 ]
4550end
51+ drop_powers (expr:: BasicSymbolic , var:: BasicSymbolic , deg:: Int ) = drop_powers (expr, [var], deg)
4652drop_powers (expr, var:: Num , deg:: Int ) = drop_powers (expr, [var], deg)
47- drop_powers (x, vars, deg:: Int ) = drop_powers (wrap (x), vars, deg)
48- # ^ TODO : in principle `drop_powers` should get in BasicSymbolic and have a fallback for Num
53+ drop_powers (x, vars, deg:: Int ) = drop_powers (Num (x), Num .(vars), deg)
4954
5055" Return the highest power of `y` occurring in the term `x`."
51- function max_power (x:: Num , y:: Num )
56+ function max_power (x:: BasicSymbolic , y:: BasicSymbolic )
5257 terms = get_all_terms (x)
5358 powers = power_of .(terms, y)
5459 return maximum (powers)
5560end
5661
62+ # Num fallback: unwrap to BasicSymbolic
63+ max_power (x:: Num , y:: Num ) = max_power (unwrap (x), unwrap (y))
5764max_power (x:: Vector{Num} , y:: Num ) = maximum (max_power .(x, y))
5865max_power (x:: Complex , y:: Num ) = maximum (max_power .([x. re, x. im], y))
5966max_power (x, t) = max_power (wrap (x), wrap (t))
0 commit comments