Equivalent of FullForm form Mathematica

61 views
Skip to first unread message

Christophe Bal

unread,
Mar 3, 2014, 10:30:30 AM3/3/14
to sympy-list
Hello.

Is there an equivalent of FullForm that produces simple treeview of a formula ? Here is basic example seen in a video.

FullForm[x**2+x**3] = Plus[Power[x, 2], Power[y, 3]]

Best regards.
Christophe BAL

Ondřej Čertík

unread,
Mar 4, 2014, 2:09:39 PM3/4/14
to sympy
Hi Christophe,

On Mon, Mar 3, 2014 at 8:30 AM, Christophe Bal <proj...@gmail.com> wrote:
> Hello.
>
> Is there an equivalent of FullForm that produces simple treeview of a
> formula ? Here is basic example seen in a video.
>
> FullForm[x**2+x**3] = Plus[Power[x, 2], Power[y, 3]]

We have this:

In [1]: print_tree(x**2+x**3)
Add: x**3 + x**2
+-Pow: x**3
| +-Symbol: x
| | commutative: True
| +-Integer: 3
| real: True
| nonzero: True
| infinitesimal: False
| commutative: True
| zero: False
| nonpositive: False
| positive: True
| noninteger: False
| negative: False
| nonnegative: True
| hermitian: True
| complex: True
| bounded: True
| rational: True
| unbounded: False
| integer: True
| imaginary: False
| finite: True
| irrational: False
+-Pow: x**2
+-Symbol: x
| commutative: True
+-Integer: 2
real: True
nonzero: True
finite: True
commutative: True
infinitesimal: False
nonpositive: False
positive: True
noninteger: False
zero: False
negative: False
hermitian: True
complex: True
bounded: True
rational: True
unbounded: False
integer: True
imaginary: False
nonnegative: True
irrational: False


and also this:

In [9]: print_python(x**2+x**3)
x = Symbol('x')
e = x**3 + x**2


Ondrej

Mateusz Paprocki

unread,
Mar 4, 2014, 2:25:37 PM3/4/14
to sympy
Hi,

On 3 March 2014 16:30, Christophe Bal <proj...@gmail.com> wrote:
> Hello.
>
> Is there an equivalent of FullForm that produces simple treeview of a
> formula ? Here is basic example seen in a video.
>
> FullForm[x**2+x**3] = Plus[Power[x, 2], Power[y, 3]]
>

In [1]: srepr(x**2 + x**3)
Out[1]: "Add(Pow(Symbol('x'), Integer(3)), Pow(Symbol('x'), Integer(2)))"

Note that `repr()` won't work due to bugs in Python (it's wired to str()):

In [2]: repr(x**2 + x**3)
Out[2]: 'x**3 + x**2'

Mateusz

> Best regards.
> Christophe BAL
>
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sympy/CAAb4jGnmdpAEwhGRYEfdQUv_J1z2Oc60A1QWZbKiLSvHZVxd3A%40mail.gmail.com.
> For more options, visit https://groups.google.com/groups/opt_out.

Christophe Bal

unread,
Mar 4, 2014, 2:55:26 PM3/4/14
to sympy-list
Thanks for this two answers.

Christophe


Ondřej Čertík

unread,
Mar 4, 2014, 3:09:12 PM3/4/14
to sympy
On Tue, Mar 4, 2014 at 12:25 PM, Mateusz Paprocki <mat...@gmail.com> wrote:
> Hi,
>
> On 3 March 2014 16:30, Christophe Bal <proj...@gmail.com> wrote:
>> Hello.
>>
>> Is there an equivalent of FullForm that produces simple treeview of a
>> formula ? Here is basic example seen in a video.
>>
>> FullForm[x**2+x**3] = Plus[Power[x, 2], Power[y, 3]]
>>
>
> In [1]: srepr(x**2 + x**3)
> Out[1]: "Add(Pow(Symbol('x'), Integer(3)), Pow(Symbol('x'), Integer(2)))"

Ah yes, this is what I was trying to find. Thanks Mateusz!

>
> Note that `repr()` won't work due to bugs in Python (it's wired to str()):
>
> In [2]: repr(x**2 + x**3)
> Out[2]: 'x**3 + x**2'
>
> Mateusz
>
>> Best regards.
>> Christophe BAL
>>
>> --
>> 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+un...@googlegroups.com.
>> To post to this group, send email to sy...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/sympy.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/sympy/CAAb4jGnmdpAEwhGRYEfdQUv_J1z2Oc60A1QWZbKiLSvHZVxd3A%40mail.gmail.com.
>> For more options, visit https://groups.google.com/groups/opt_out.
>
> --
> 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+un...@googlegroups.com.
> To post to this group, send email to sy...@googlegroups.com.
> Visit this group at http://groups.google.com/group/sympy.
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAGBZUCa3eAaztQ2jQZSd5ETRA9t370qzo7GrbAR1kPU1%3D-USdg%40mail.gmail.com.

Aaron Meurer

unread,
Mar 4, 2014, 3:26:39 PM3/4/14
to sy...@googlegroups.com
There is also dotprint(). That, along with srepr(), is what the
tutorial uses to explain how expressions are implemented as a tree(*)
http://docs.sympy.org/latest/tutorial/manipulation.html. In the SymPy
Live shell, you can change the output format to Repr to always get the
srepr() form of an expression.

(*) actually a DAG. Common subexpressions may be the same object. This
is done for all singletonized objects in S, and also for many other
objects when the cache is enabled.

Aaron Meurer
> To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CADDwiVBE4BxUdY_bn%3DkkhAdSK98RYmk9mwHBbXwbKhcKzNg5qw%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages