Think about things that are literally not numbers: In [9]: Interval(1, 2).is_number Out[9]: False
In [10]: ImmutableMatrix([[1, 2], [3, 4]]).is_number Out[10]: False On Mon, 13 Sept 2021 at 13:00, Chris Smith <smi...@gmail.com> wrote: > To confirm, if you mean that it is free from any Symbol (free or bound) > then `not expr.has(Symbol)` will be best. But if you consider `Integral(x, > (x, 1, 2))` as a number then you should use `is_number` or `free_symbols`, > with `expr.is_number` failing sooner than `not expr.free_symbols` if the > expression has a free symbol. (So if you suspect the expression has free > symbols then use `is_number`, else `free_symbols`). > > `f.is_number != (not bool(f.free_symbols))` should be an invariant for > Expr, but SymPy also deals with Booleans, so `S.true.is_number` is False > and `S.true.free_symbols` is empty. > > /c > > On Sunday, September 12, 2021 at 11:56:23 PM UTC-5 distan...@gmail.com > wrote: > >> Are there any cases when f.is_number != (not bool(f.free_symbols))? >> >> If I have an arbitrary expression, what is the correct way to check >> whether it has variables? >> >> Thank you. >> > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to sympy+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/9af46205-ce22-494c-a604-c27b6682fa96n%40googlegroups.com > <https://groups.google.com/d/msgid/sympy/9af46205-ce22-494c-a604-c27b6682fa96n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sympy+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAHVvXxTFGLR%2B0-N%3Drx6iwf9JVQp_3K_d7u%3Dn-1NFbm8egHxERQ%40mail.gmail.com.