util.py 359 B

123456789101112131415
  1. from sympy.core.basic import Basic
  2. new = Basic.__new__
  3. def assoc(d, k, v):
  4. d = d.copy()
  5. d[k] = v
  6. return d
  7. basic_fns = {'op': type,
  8. 'new': Basic.__new__,
  9. 'leaf': lambda x: not isinstance(x, Basic) or x.is_Atom,
  10. 'children': lambda x: x.args}
  11. expr_fns = assoc(basic_fns, 'new', lambda op, *args: op(*args))