environmentalscience / essm

This package contains helpers to deal with physical variables and units.
https://environmentalscience.github.io/essm/
GNU General Public License v2.0
12 stars 5 forks source link

Make Variables behave as Symbols #35

Closed jirikuncar closed 6 years ago

schymans commented 6 years ago

Apparently, this broke test_units() in test_equations.py.

schymans commented 6 years ago

Note also that the added test is satisfied using the current master, probably due to a change upstream, in sympy:

def test_integral():
    """Test that variables behave as symbols."""
    from sympy import integrate

    assert demo_g in demo_fall.free_symbols
    assert demo_g * demo_fall.definition.t**S(3) / S(6) == integrate(
        demo_fall.rhs, demo_fall.definition.t)
jirikuncar commented 6 years ago

So maybe we can just add the test alone.

schymans commented 6 years ago

The thing is, they probably should not behave as symbols. I finally understood what is meant by the comment that symbols in an expression could balance non-matching units. For example, one could formulate an empirical equation where the units of the proportionality constant are not known a priori. One could use a symbol for the constant, then solve the equation for the symbol, substitute the units of all variables and in this way deduce the appropriate units of the constant. So, all we need to test for is that integrate() works if the integration variable is a quantity. This was the original test. We could add additional tests for other methods, one-by-one. No need to treat a quantity as a free_symbol in general.

schymans commented 6 years ago

OK, variables do not behave as symbols, but this is probably not needed after all. Most importantly, integrate() with variables works now.