Skip to content

Instantly share code, notes, and snippets.

@smichr
Created January 13, 2011 06:13
Show Gist options
  • Save smichr/777479 to your computer and use it in GitHub Desktop.
Save smichr/777479 to your computer and use it in GitHub Desktop.
"""Return a sympy object representing the absolute value of the argument.
This is an extension of the built-in function abs() to accept symbolic
values. If you pass a SymPy expression to the built-in abs(), it will
pass it automatically to Abs().
Examples::
>>> from sympy import Abs, Symbol, S
>>> x = Symbol('x', real=True)
>>> Abs(-x)
Abs(x)
>>> Abs(x**2)
x**2
>>> Abs(-1)
1
>>> type(_)
<class 'sympy.core.numbers.One'>
The Python built-in will return either an Expr or int depending
on the type of argument::
>>> type(abs(1)) # arg is int
<type 'int'>
>>> abs(-x) # arg is a sympy exprssion
Abs(x)
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment