Robert | 22 Jul 18:56 2014
Picon

core.py file in 0.7.3 vs 0.7.4.1 diff

I notice that there are multiple lines that now create lists and do not use iteritems:


from:
        sequence = filter(None, sequence)
to: 
        sequence = list(filter(None, sequence))


multiple places where .items() is now used instead of .iteritems().

like:
                    _value = lambda expr, result: (value(**dict([ (
                        str(key)[:-1], val) for key, val in result.iteritems()]))
to:
                    _value = lambda expr, result: (value(**dict([ (
                        str(key)[:-1], val) for key, val in result.items()]))



Generally my understanding is that using iterators is preferred to creating a list especially when iterating. Is there a benefit to using items() over iteritems() for iterations?

Thanks,
Rob

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/e2a09072-2827-42bf-b7b0-34c02a573027%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert | 22 Jul 18:53 2014
Picon

subs with a string, how to make this work with inheritance? Change from 0.7.3 to 0.7.4.1 ?

Hey everyone,

Let's say I defined my own sympy.Symbol called MySymbol2. For some reason subs using a string doesn't always work, but it works for sympy.Symbol.

This is version 0.7.4.1. I have a 0.7.3 example below that works fine. I see that the function fallback in core.py was changed.

from is not test on line 992 in 0.7.3:
if arg is not args[i]
to not equal test on line 1036 in 0.7.4.1:
if arg != args[i]:


    >>> class MySymbol2(sympy.Symbol): pass
    >>> expr = MySymbol2('A') * (MySymbol2('X') > 5)
    >>> print expr.subs({'X':10})
    A*(X > 5)

    >>> expr = sympy.Symbol('A') * (sympy.Symbol('X') > 5)
    >>> print expr.subs({'X':10})
    A*True


Sometimes the subs work fine. Below X and Y are both substituted for my MySymbol
    >>> expr = sympy.sympify('3*X + Y')
    >>> subsDic2 = {'X': MySymbol2('X'), 'Y': MySymbol2('Y')}
    >>> expr2 = expr.subs(subsDic2)
    >>> print [(i, type(i)) for i in expr2.atoms()]
    [(X, <class 'stats.tests.modelSymbolicTest.MySymbol2'>), (3, <class 'sympy.core.numbers.Integer'>), (Y, <class 'stats.tests.modelSymbolicTest.MySymbol2'>)]



I've tried a fix like:

class MySymbolWithNameEq(sympy.Symbol):
    def __eq__(self, other):
        if isinstance(other, sympy.Symbol):
            return self.name.__eq__(other.name)
        else:
            return sympy.Symbol.__eq__(self, other)


but that causes the subs on 3*X+Y to fail and my A*(X>5) still fails. Notice that not all the atoms are replaced. 

    >>> expr = MySymbolWithNameEq('A') * (MySymbolWithNameEq('X') > 5)
    >>> print expr.subs({'X':10})
    A*(X > 5)

    >>> subsDic3 = {'X': MySymbolWithNameEq('X'), 'Y': MySymbolWithNameEq('Y')}
    >>> expr = sympy.sympify('3*X + Y')
    >>> expr2 = expr.subs(subsDic3)
    >>> print [(i, type(i)) for i in expr2.atoms()]
    [(Y, <class 'stats.tests.modelSymbolicTest.MySymbolWithNameEq'>), (X, <class 'sympy.core.symbol.Symbol'>), (3, <class 'sympy.core.numbers.Integer'>)]

#on 0.7.3 the above works correctly
    >>> expr2 = expr.subs(subsDic3)
    >>> print [(i, type(i)) for i in expr2.atoms()]
    [(X, <class 'stats.tests.modelSymbolicTest.MySymbolWithNameEq'>), (3, <class 'sympy.core.numbers.Integer'>), (Y, <class 'stats.tests.modelSymbolicTest.MySymbolWithNameEq'>)]


Any idea how to inherit from sympy.Symbol while still getting string substitution to work reliably?


thanks,
Rob

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/574d5d01-c0ed-4fd5-97f2-ac1ff7156697%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Sudhanshu Mishra | 20 Jul 09:39 2014
Picon

Fwd: Science Showcase

SymPy is now under under science section of GitHub showcases! https://github.com/showcases/science

Regards
Sudhanshu Mishra



---------- Forwarded message ----------
From: Ivan Žužak <support-9UaJU3cA/F/QT0dZR+AlfA@public.gmane.org>
Date: Sun, Jul 20, 2014 at 12:38 PM
Subject: Re: Science Showcase
To: Sudhanshu Mishra <mrsud94-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>


Sure thing -- we just added sympy/sympy to the science showcase. Thanks for the tip!

Cheers,
Ivan

> Hi

I think sympy/sympy makes a strong appeal for the science section of the showcase. If you also think so, please consider adding it.

Thanks!

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/CAFW_KCRqf%3DETg34ejR8vwQRWKDk4iR_XnJp2BJi_-Anmy%2BKMAQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Keaton Burns | 18 Jul 20:52 2014
Picon

Replace method not respecting non-commutativity

Hello,

I'm using the "replace" method to substitute a function symbol with a python lambda function, but this process is failing to respect non-commutativity.  This can be seen with a simple example:

>>> import sympy as sy
>>>
>>> x, y = sy.symbols('x, y', commutative=False)
>>> f = sy.Function('f')
>>> expression = x * f(y)
>>>
>>> # Replace f with trivial lambda function, expect x*y
>>> expression.replace(f, lambda x: x)
y
*x

Using "subs" seems to respect non-commutativity just fine, but I don't know the exact patterns that I'll need to be replacing (i.e. I want to apply the lambda to whatever arguments f happens to have).  

If there isn't a quick fix for replace, is there another way to achieve this sort of function substitution?

Thanks,
Keaton

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/fad5c2d6-7749-4bd4-9fcf-5ba2c813eb0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Madison Stemm | 18 Jul 00:27 2014
Picon

Performance Slowdown with recent SymPy versions?

Hi, I'm not sure if this is well-known in the SymPy community, but my team uses SymPy for a program we're writing, and I've discovered a slowdown that has been accumulating with SymPy versions since 0.7.1. Our program calls solvers.Solve() 10,000 times, and that shows a 25-50 second increase in runtimes with each consecutively newer SymPy version. Obviously, this means that the performance hit is minimal, and only compounds with large amounts of calls, but it's something I wanted to call attention to, so that it can at least be documented (I went through the version histories and didn't see any mention of it.)

If the flag rational=False isn't used in Solve(), which was introduced with SymPy 0.7.2, runtimes increase by about 6000 (!) seconds, so I'm guessing the overall performance hit is caused by similar accuracy improvements even while using floats rather than rationals. For what it's worth, our results are the same between each version, so if there are accuracy improvements, it's not noticeable in our results and I can't confirm that.

Also, to quantify the performance loss, here are the runtimes of our program from SymPy versions 0.7.2 through 0.7.5 -- otherwise, the program and hardware were untouched.
If there's a solution to this problem, I'd love to hear it! But otherwise, I just wanted to inform the community.

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/8268aebc-edd3-47d5-a073-2d339ce52808%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Soumya Biswas | 17 Jul 16:36 2014
Picon

FOL Constants and Unification

Hello Everyone,

I have been working on building the First Order Logic module for SymPy and the (basic) architecture is almost complete. However I have run into a problem that I can't seem to be able to solve.

As many of you would be aware of, FOL uses predicates, functions, variables, constants and quantifiers in its expressions. Instead of reusing the existing Predicates and Functions, I have written new classes for these. However I have used the Symbol class for variables. Now comes the question of constants. As of now I am using non-SymPy objects like strings and integers as constants. However this isn't working out very well. So my initial idea was to add a constants class inside FOL, or if it is of use to other modules, then inside core. However since then it has been pointed out to me, and quite rightly so, that using constants isn't really required. Variables can be used for accomplishing the same thing. In FOL particularly, one can replace a constant with a variable and simply provide it with the appropriate value during interpretation. For e.g. instead of And(a, b, True), one can simply say And(a, b, c) with c = True for the entire scope. It will make a difference where the existence of the constant would have prompted some evaluation (like And(a, False) becomes False), but for most part of FOL such evaluations are not of consequence.

However there seems to be one place where it is necessary to differentiate between variables and constants namely in unification. I am trying to find out if some pre-existing SymPy construct can substitute for constants here. Here mgu stands for the most general unifier.

>>> mgu(P(f(X), g(Z)), P(Y, A))
{Y: f(X), Z: 'a'}

>>> mgu(P(f(X), g(Z)), P(Y, 'A'))
False

Here A is a variable while 'A' is a constant.

To unify two predicates, I am checking if its corresponding arguments can be (recursively) unified. Something can be unified if there exists a variable on one side and any term i.e. function (not containing the same variable), variable or constant on the other side. As can also be seen from the example, we need to be able to distinguish between constants and variables while unification.

Hence I am looking for some way such that the above can be accomplished using some existing SymPy object (without introducing a new constants class),

Thank You

SD

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/d2bbb752-68b4-499e-95b9-c0dfe59a0bea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Robert Boyles | 16 Jul 22:59 2014
Picon

Set precision for sympy multivector coefficients

I am wondering if there is a way to set the precision for sympy objects.

I have two sympy objects (a and q) that when I execute q*a*inv(q), the result is of the form:

ans = 1.0*n_o + x1*e_1 + x2*e_2 + x3*e_3 + x4*n_i + x5*e_1^e_2^n_i

where x5 is on the order of 1E-9.

My problem is that I then want to calculate MV.norm(a), which throws a ValueError that the result is not a scalar, due to the last term. The precision I need to assume something is zero is much less, say 0.001. If that term was assumed to be zero the operation would work as with my other cases. Is there a way to set this at the start of the program and carry throughout all operations?

Thanks,
-Robert

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/1b07ca41-0491-402c-a3c0-491ddf8d710d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Denis Akhiyarov | 16 Jul 16:32 2014
Picon

memory leak from sympy - embedded python

I'm calling iteratively functions from embedded python. The functions share few common sympy expressions from a closure above them on which the function do subs() and solve(). The environment variable SYMPY_USE_CACHE does not work for me. I have to manually clean the cache. Even with that I still get the memory leak which I confirmed on Python side with empty def function(*args): return 0. Investigation with guppy showed that most of the memory consists of:

[Set of 266944 <mixed> objects. Total size = 72143480 bytes.
 Index     Size   %   Cumulative  %   Brief
     0     1684   0.0      1684   0.0 sympy.core.assumptions.StdFactKB: 0x701a750
     1      532   0.0      2216   0.0 sympy.core.assumptions.StdFactKB: 0x701a620
     2      532   0.0      2748   0.0 sympy.core.assumptions.StdFactKB: 0x701a9b0
     3      532   0.0      3280   0.0 sympy.core.assumptions.StdFactKB: 0x701aa48
     4      532   0.0      3812   0.0 sympy.core.assumptions.StdFactKB: 0x701aae0
     5      532   0.0      4344   0.0 sympy.core.assumptions.StdFactKB: 0x701ad40
     6      532   0.0      4876   0.0 sympy.core.assumptions.StdFactKB: 0x7057a48
     7      532   0.0      5408   0.0 sympy.core.assumptions.StdFactKB: 0x7057ca8
     8      532   0.0      5940   0.0 sympy.core.assumptions.StdFactKB: 0x7057d40
     9      532   0.0      6472   0.0 sympy.core.assumptions.StdFactKB: 0x7057dd8


How can I clean these assumptions?

guppy==0.1.10
numpy==1.8.1
sympy==0.7.5


Python 2.7.7 (default, Jun  1 2014, 14:17:13) [MSC v.1500 32 bit (Intel)] on win32

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/96a64348-b343-4fb2-9ecb-3974fce6faec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Chris Smith | 16 Jul 16:12 2014
Picon

intermittent failure in master

Has anybody else seen the following? I've seen it twice now. It happens in 3.4.

File "/home/travis/virtualenv/python3.4.0/lib/python3.4/site-packages/sympy/logic/tests/test_boolalg.py", line 71, in test_Xor

assert Xor(True, False, False, A, B) == ~Xor(A, B)

AssertionError

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/c50858b5-a5b1-4e97-bc69-f59e0f290159%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Justin Vincent | 15 Jul 22:40 2014
Picon

Moments of a normal distribution

Wanted to get the moments of a Normal distribution WRT mu and sigma, a la:

http://en.wikipedia.org/wiki/Normal_distribution#Moments

For starters, this outputs 1 for one for one crazy domains, and then leaves the integral unevaluated on the rest of the domain. But it gets one, so I'm cool with that.

from sympy.statistics import Normal
from sympy import symbols, integrate
f = Normal(mu, sigma).pdf(x)
x, mu, sigma = symbols('x mu sigma')
integrate(f, (x,-oo, oo))

Then when I get the first moment, it really starts to go crazy though, and leaves it all indefinite:
integrate(f * x, (x, -oo, oo))

What approach should I take here if I wanted to get those values cited in wikipedia? Haven't used Sympy much before. Thanks in advance.

Justin

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/2babc41b-0ab4-443c-a75b-d5910ce16c21%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Adam Spontarelli | 15 Jul 16:09 2014
Picon

integration fails with PolynomialDivisionFailed

from sympy import *
x
, ep, D = symbols('x, \epsilon, D')
integrate
(1+5.55*ep**2*exp(-.13*(x/D)), x)

fails and gives the PolynomialDivisionFailed error message. Changing the -0.13 constant to -0.12 succeeds. Is there something about the equation that I'm not understanding or is this a bug in sympy? I'm running sympy version 0.7.5.

Thanks,
Adam

--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
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/0aafc2f9-074c-48ca-8202-782a3cd74d96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gmane