atoms() works at the expression tree level, meaning it will only
return something if it exactly appears in the expression. In the
example x - 1, the expression is Add(x, -1), which doesn't contain 1.
It instead contains -1. Note that SymPy doesn't have a subtraction
class. Subtraction is represented as addition of a negative, where the
negative is represented as multiplication by -1 (or in the case of
number, just the negative number).

Aaron Meurer

On Fri, Apr 29, 2022 at 12:15 PM Audrius-St <[email protected]> wrote:
>
> Hello,
>
> import sympy as sp
>
> In the following example code, it is not clear to me why the first expression 
> returns
> expr.atoms(sp.S(1)) {1}
>
> whereas the second expression returns
> expr.atoms(sp.S(1)) set()
>
> def main():
>
>     x = sp.symbols('x')
>
>     expr = x + 1
>     print(f'expr.atoms(sp.S(1)) {expr.atoms(sp.S(1))}')
>
>     expr = x - 1
>     print(f'expr.atoms(sp.S(1)) {expr.atoms(sp.S(1))}')
>
>
> if __name__ == "__main__":
>     main()
>
>
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/bcd40bf3-44aa-4297-a218-2c71aadd3682n%40googlegroups.com.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6L3CkYjKUpbj11gGwHohGMB-FFkRMZ8sOt7_esLDKmZkA%40mail.gmail.com.

Reply via email to