On Wed, Jan 1, 2014 at 4:41 PM, Bulvyf <[email protected]> wrote:
> Happy New Year to all,
>
> I'm a newb with SymPy so may need some hand holding in its appropriate use.
> Warning ego boost forthcoming: Sympy a most impressive addition to Python,
> and deserves many prestigious accolades for what it can accomplish within
> the Python framework.  My hat off to all its developers.
>
> Anyways on to the point of this posting:
>
> Request for additional documentation
> Personal Objective: simplify generated equations using
> Leaf nodes, for example:
> 'X','1.0'
> and unary/binary "functions", for example:
> '+','-','*','%','SIN','COS','EXP','LOG'
> such that the result is a finite real number for equations of one variable
> (x).
> SymPy Issues:
> Its not clear how to:
> 1) enforce that the formula' symbol simplification always result in a
> non-imaginary equation (ie A+B*i is not ideal) and
> 2) whether the result of a variable substitution (eg x=2) can cause the
> formula to equation to a certain type and/or value range (ie it must always
> be a real result, but if its infinite or undefined allow conditional testing
> of the result type).
>
> Example session from SymPy Shell (showing substitution of x with 2, gives an
> imaginary result):
>
>>>>
>>>> ((log(((sin(1.0)-x)+(cos(1.0)%exp(x))))%(((1.0*1.0)%cos(1.0))*log(sin(1.0))))-sin((exp((cos(1.0)+1.0))%(cos(cos(x))-(log(x)*exp(x))))))
> Result (NB: super-text alignment for "power" and mult operators were lost in
> copy/paste):
> −sin(Mod(4.66600061716673,−1.0exlog(x)+1.0cos(cos(x))))+Mod(1.0log(−x+Mod(0.54030230586814,1.0ex)+0.841470984807897),−0.0793455441584221)
>
>>>> x=2.0
>>>>
>>>> ((log(((sin(1.0)-x)+(cos(1.0)%exp(x))))%(((1.0*1.0)%cos(1.0))*log(sin(1.0))))-sin((exp((cos(1.0)+1.0))%(cos(cos(x))-(log(x)*exp(x))))))
> Result: (ditto)
> −1.0Mod(0.00482678027827896−1.0iπ,0.0793455441584221)−0.570000843230427
>
>
> Documentation Issues:
> In some documentation "assume" is used to apparently refine the type or
> range of numbers in equations (on
> http://code.google.com/p/sympy/wiki/SympyResearch This is a well written
> page but apparently has been transferred to another location and may no
> longer be valid by nature of it being "research").

Oh no, don't look at pages on the Google Code wiki. They are ancient.
You should refer to things at docs.sympy.org.

> However, trying this information in "SymPy shell" did not work.
> Refencing http://docs.sympy.org/latest/modules/assumptions/assume.html only
> adds to the confusion.

That's because the Google Code wiki was just some old ideas and the
docs.sympy.org documents their actual implementation.

> That is, the examples there don't work within the popup 'SymPy shell'!
> Ticket #2722 entered (on
> https://github.com/sympy/sympy/issues?page=1&state=open)

Unfortunately the Live shell has some issues of its own. Basically,
the way that the session is stored is using pickling, so it blows up
whenever it hits an object that can't be pickled.

>
> "How to" Questions (request for examples):
> 1) when/if would you use "assume"?

Unfortunately, the assumptions system is a little bit of a mess right
now. I would recommend using the so-called old assumptions for now,
meaning that if you have a symbol that you want to assume is real (for
instance), create it like

x = Symbol('x', real=True)

and if you want to test if an expression is real, use

expr.is_real

The new assumptions don't work as completely yet, and once we merge
them, the old syntax will stick around (that's the current plan
anyway).

There is a new assumptions system (assume(), assuming(), Q), but it's
not as powerful yet. You can play with it if you want, but it might
not work when the other system would.

> 2) Are all the param names still valid in the current release? (from the
> google code research page given above)

I would just forget about that page. It has a lot of ideas, not all of
which were eventually implemented.

> 3) How do we constrain the simplification of formula to use non imaginary
> results?

You can check is_real. If it's False, then the expression is not real.
Note that if it's None, that means that it doesn't know, e.g., it
could go either way, or it isn't smart enough to figure it out.

> 4) More specifically how do we simplify an equation so it stays as real
> only.

Well, if a number is complex, it's complex :)

So you should check your math. In this case,
(sin(1.0)-x)+(cos(1.0)%exp(x)) is negative at x = 2, so the logarithm
of it is not a real number.

> 5) How do we test for SymPy specific types eg Infinity "oo"?

Use the assumptions. is_real will tell you if it is real. is_finite
will exclude -oo and oo (and also 0, due to an oddity in the way the
assumptions are currently defined, so you'll have to do expr.is_real
and (expr.is_zero or expr.is_finite)).

Aaron Meurer

>
> I'm assuming all questions are unrelated, but please re-organize if they are
> indeed related?
>
> Thanks,
>
> Evan
>
>
> --
> 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 post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sympy.
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to