F. B. | 1 Sep 13:28 2014
Picon

Pattern matching and mathematical-awareness

SymPy's default pattern matcher is not a structural one, i.e. it tries to match according to some mathematical rules. A structural pattern matcher would instead just match the structure of the expression-tree.

While it is necessary to have some mathematical awareness such as, give the wild w:
  • associativity awareness (i.e. f(a, b, c) = f(a, f(b, c)) and similar):
    (a+b+c).match(a+w) ==> {w: b+c}
  • commutativity awareness:
    (a+b).match(w+a) ==> {w: b}
  • one-identity awareness (f is one-identical if f(x) = x for any x):
    x.match(Add(w, evaluate=False)) ==> {w: x}

These rules are also available in Wolfram Mathematica.

There are some results which come out as an attempt to apply some kind of equation solving:

In [20]: (x*y).match(x/w)
Out[20]:
  1
w: ─⎬
  y

That is, Mul(x, y) is matched to become Mul(x, Pow(Mul(1, Pow(y, -1)), -1)) which is equivalent mathematically, but not structurally.

I would expect this result by calling:

In [29]: solve(Eq(x*y, x/w), w)
Out[29]:
1
⎢─⎥
y

I was wondering, what are the pattern matching rules for this awareness? This goes beyond the three rules I pointed out hereabove. Technically, mathematical-aware patterns may yield infinite results as long as they are combined with equation solvers.

Wolfram Mathematica seems not to have any solver-awareness, that is, the previous pattern does not match:

In[12]:= (x y) /. x/w_ -> {w}
Out[12]= x y

It would be useful to keep SymPy's pattern matching rules as close as possible to those of Mathematica. I suggest to remove redundant results relying on solvers, or maybe add a parameter to the matcher to turn it off. What do you think?

--
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/10ad1141-ee19-44ad-bd6e-42c982af3da2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Kia Saeedi | 30 Aug 19:14 2014
Picon

ray line problem

hi
i used sympy geometry module and I need to define ray line object with angle
but when I run code , ray line angle change with no reason
is that a bug?
I attached my code with two output example
thank you

--
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/9f7460ad-532f-4f29-b66d-f5675d02be6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Attachment (attachment.zip): application/zip, 41 KiB
Shantanu Singh | 30 Aug 20:41 2014
Picon

How to contribute to sympy

I am new to sympy and OSS community as well but I would like to contribute to this project . Please tell me how to get started 

--
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/d113e8e3-da7d-4181-bad5-5a06a86db5b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
raj454raj | 29 Aug 16:46 2014
Picon

new to sympy

hello guys i just want to start with sympy can you tell me where can i make changes to the code such that it reflects in python shell directly

--
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/277764bf-02d4-4b4d-89ea-4c2add33883d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
James Crist | 28 Aug 05:07 2014
Picon

ufuncify now creates actual ufuncs

I still need to do some cleanups and add tests, but I finally have this working and thought I'd share. I'm really happy with this:

In [1]: from sympy import *

In [2]: a, b, c = symbols('a, b, c')

In [3]: expr = (sin(a) + sqrt(b)*c**2)/2

In [4]: from sympy.utilities.autowrap import ufuncify

In [5]: func = ufuncify((a, b, c), expr)

In [6]: func(1, 2, 3)
Out[6]: 6.7846965230828769

In [7]: func([1, 2, 3, 4, 5], [6, 7, 8, 9, 10], 3)
Out[7]: array([ 11.44343933,  12.36052961,  12.79848207,  13.12159875,  13.75078733])

In [8]: from numpy import arange

In [9]: a = arange(10).reshape((2, 5))

In [10]: c = arange(10, 20).reshape((2, 5))

In [11]: b = 25

In [12]: func(a, b, c)
Out[12]:
array
([[ 250.        ,  302.92073549,  360.45464871,  422.57056   ,
         
489.62159875],
       
[ 562.02053786,  639.86029225,  722.8284933 ,  810.49467912,
         
902.70605924]])

In [13]: type(func)
Out[13]: numpy.ufunc

This now does everything a numpy `ufunc` does normally, as it *is* a ufunc. Codegen is hooked up to numpy api. Type conversion and broadcasting are done automagically.

Caveats: only functions with a single output are accepted (this could be changed to accept multi-output without much effort though). Also, as with all unfuncs, input/outputs must all be scalars (no matrix/Indexed operations allowed).

--
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/76e0fbbe-5ce4-43b7-855b-6ac821f6b8ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Ambar Mehrotra | 27 Aug 21:36 2014
Picon

Use of sympy in Android app

Hi, 

I am working on a proprietary android app that uses sympy for computation purposes.  We are planning to use
sympy in the name of the app. What are the legal implications that I have to take care of to do this? Is it
enough if I mention the sympy BSD licence in the app? 

--

-- 
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@...
To post to this group, send email to sympy@...
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/271c0d7b-2ce4-45cd-9dd1-5db1ab0dacf1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aaron Meurer | 27 Aug 06:10 2014
Picon

SymPy 0.7.6 release

Now that GSoC is over, let's start thinking about doing a 0.7.6 release. Are there any major pull requests from GSoC that are still to be merged?  Any other known changes that should block on the release? 

Aaron Meurer

--
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/CAKgW%3D6LtVFLB3pTqr2G1%3DvHoFnrQnCqqaxACTVjihToO6f0jeg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Alan Bromborsky | 27 Aug 00:57 2014
Picon
Picon

latex notebook printing of lists of custom classes

I am trying to print a list of instances of a custom class. The input is -

print (o3d.grad, o3d.grad)

the output is (custom latex printer)



however  in ipyrhon notebook I input

(o3d.grad, o3d.grad)

I get out
(e_{x} \frac{\partial}{\partial x} + e_{y} \frac{\partial}{\partial y} + e_{z} \frac{\partial}{\partial z}, e_{x} \frac{\partial}{\partial x} + e_{y} \frac{\partial}{\partial y} + e_{z} \frac{\partial}{\partial z}) Also the standard latex tuple and list printer is not using \left ( \right  and \left [ \right ) to enclose
the tuple or list.  How can I write a custom latex tuple and list printer that will also work in ipython notebook.

--
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/53FD10D1.6080309%40verizon.net.
For more options, visit https://groups.google.com/d/optout.

vaibhav kumar | 26 Aug 18:28 2014
Picon

student looking for contribution

hello,
i am a newcomer and i would like to contribute to this project.
Could anybody guide me through the same.


thanks in advance

--
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/db85db60-3401-4f34-9e2e-a186a4bf732d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
vaibhav kumar | 26 Aug 18:15 2014
Picon

starter looking for contribution

Hi,

this is Vaibhav Kumar. I am a student of Computer Science from IIIT Hyderabad. I am keenly instersted to contribute to this project.
Could anyone help me out with the same. 

--
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/b4aa924f-9bb2-4869-96b0-5ab3322082d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Aaron Meurer | 24 Aug 19:46 2014
Picon

A plan for the assumptions

Some of you may have seen Sergey started a pull request to remove uses of the new assumptions in the code, because it's confusing to users who set the old assumptions and it doesn't work.

He asked me there

How the random mix of old and new assumptions can look for you as this transition (or a step in this direction, whatever)? I think - this only can surprise our users. And that's a bad idea to do so, esp. in the core modules (e.g., the sets module).

I wrote up a response there, but then I realized that it would be better to discuss this on the mailing list, so I am posting it here instead. 

You make a good point. However, if you are going to spend time on this, it would be better spent improving the new assumptions (and let's finally merge my branch as a start to this), or merging the two. I still maintain that this pull request is a step backwards. With these changes, the new assumptions aren't used at all, meaning they are tested much less, and more importantly, there is no more motivation to improve them. The old assumptions syntax isn't going away, so why don't we focus on making it so that the new assumptions can read the old assumptions. 

This is what <at> mrocklin and I attempted to do last summer (https://github.com/sympy/sympy/pull/2210). It didn't work, because we tried to do a two-way merge of the assumptions, i.e., so that both `x.is_integer` and `ask(Q.Integer(x))` were always identical (the logic I used was https://github.com/sympy/sympy/pull/2210/files#r5463892, which required both assumptions to be the same). 

Maybe an easier approach would be along the lines of what I have done at #2508. Have ask call a bunch of things, in order, until it gets an answer. In my branch, `ask` calls the current new assumptions, and then my satask. We could make it so that ask first calls the old assumptions, then the new assumptions. Furthermore, the new assumptions should gain trivial handlers for Symbols to so that `ask(Q.real(Symbol('x', real=True)))` is True. 

The first step though will be to go through all the assumptions and make sure they are identical in all systems. This is a good opportunity to clean up some of the contradictory or unexpected assumptions, so it should involve some community input. So I would do it on the mailing list. 

So I what I would recommend doing:

- [ ] Merge my branch #2508. We can maybe wait until after the release to do this so it is minimally disruptive, but this is important, as it will be much easier to add new facts to the new assumptions with satask (and I also want people to start thinking about how to improve the speed of it).
- [ ] Go through all the assumptions facts and make a note of what is different, and also what is confusing. A lot of this is already written down in various places (https://github.com/sympy/sympy/issues/5976, https://github.com/sympy/sympy/pull/2538, probably some of the issues mentioned in https://github.com/sympy/sympy/issues/6730, https://github.com/sympy/sympy/pull/2508/files#diff-e0f95401c86d07d90903363122990de0R172, https://github.com/sympy/sympy/wiki/assumptions_handlers), but we should gather them all down in one place. I think the main thing will be how we handle infinity. 
- [ ] Discuss with the community on the mailing list how we should handle the differences, until we come to a consensus. 
- [ ] Make the new assumptions call the old assumptions first. Also make the handlers access the old assumptions, so that everything sees `Symbol('x', real=True)` as real. This will be the hard part, and lead to lots of test failures. It might be worth trying this first, to really see what facts are different in the two systems.

Note that absent from my plan is making `x.is_real` call the new assumptions. This is what I tried at #2210, and it failed, because it requires everything to work perfectly, and there are so many places that the assumptions are used that it's too much work to get it all in one go. We should get the above working first before we consider this. I don't think there's a big issue with this, because already `ask(Q.real(x))` and `x.is_real` are different. My proposal is to have the first call the second but not the other way around.  

Aaron Meurer

--
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/CAKgW%3D6JGa_hpe8FFNqht2dAG9-YpfO%2BS3Dx6wfoz_-tfF6i9jg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Gmane