allofphysicsgraph / proofofconcept

Physics Derivation Graph: mathematical connections among equations
https://derivationmap.net/
Other
20 stars 6 forks source link

break down the notation of "much greater than" automatically #208

Open bhpayne opened 4 years ago

bhpayne commented 4 years ago

For example, "a + b = c" is replaced by "a = c" under the condition "b << a".

I like the explanation of ">>" provided in this StackOverflow answer, so there is some deeper meaning to the notation.

bhpayne commented 4 years ago

Aaron Meurer provided the following explanation in https://groups.google.com/g/sympy/c/yQ1KAaz7Gus/m/yfN-LaW1BQAJ

You'd want to replace instances of a and b in the expression with b/a, replace that with a single variable like x, then do a series expansion and remove higher order x terms. There isn't anything in SymPy that automates this in one step but you can get a lot of it automatically with subs() and series(). The hard part is that in some of the examples you may have to perform this on subexpressions rather than the whole expression.

For example, one of the examples you linked to is

1/(b*(b + a)) = 1/(b*a) if a >> b.

>>> expr = 1/(b*(a + b))
>>> # Set x = b/a
>>> expr.subs(a, b/x).cancel()
x/(b**2*x + b**2)
>>> # Expand as a series up to O(x**2)
>>> expr.subs(a, b/x).cancel().series(x, n=2)
x/b**2 + O(x**2)
>>> # Remove the O() term and substitute back
>>> expr.subs(a, b/x).cancel().series(x, n=2).removeO().subs(x, b/a)
1/(a*b)