feat: detect non-polynomial dependence on the variables - #80
Merged
Conversation
Averaging only makes sense for equations that are polynomial in the variables, and nothing here could check for that. `is_harmonic` reasons about time dependence and cannot see `sin(x(t))` at all, because `get_variables(sin(x(t)))` yields `x(t)` and never `t`, so `get_independent` calls the term t-independent. `nonpolynomial_terms` returns every subexpression where a variable sits under something other than `+`, `*` or a non-negative integer power, with `is_polynomial` as the predicate on top and a method for a whole `DifferentialEquation`.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Averaging only makes sense for equations that are polynomial in the variables. Harmonic balance replaces each variable by a truncated Fourier series, and only sums, products and non-negative integer powers keep that series finite. A term like
sin(x)or1/xproduces an infinite spectrum instead, and the Fourier projection then discards every harmonic of it.Nothing here could spot that.
is_harmonicreasons about time dependence, and it cannot seesin(x(t))at all:get_variables(sin(x(t)))yieldsx(t)and nevert, soget_independentcalls the term t-independent and an equation built from it looks free of time dependence.nonpolynomial_terms(x, vars)walks the expression and returns every subexpression where a variable sits under something other than+,*or a non-negative integer power, recursing through derivatives and flagging state-dependent denominators along with negative, fractional and symbolic exponents.is_polynomialis the predicate on top, and aDifferentialEquationmethod checks a whole system at once.