Re: [sympy] Introduction and a question

2019-03-22 Thread Chris Smith
Perhaps the loosely connected components could be identified in some 
canonical way. #16225  

On Wednesday, March 13, 2019 at 2:11:00 PM UTC-5, Aaron Meurer wrote:
>
> If you follow the StackOverflow links at 
> https://github.com/sympy/sympy/issues/11869 you can see some 
> suggestions on how to do this sort of thing. 
>
> Aaron Meurer 
>
> On Sun, Mar 10, 2019 at 12:56 AM Mark Juers  > wrote: 
> > 
> > I'm a 4th-year PhD student in evolutionary biology at Indiana University 
> in Bloomington, IN. I've been using Python for about a year for various 
> biology projects and am working on a package related to my dissertation 
> work.  I am looking to replace Mathematica with SymPy in my workflow. I use 
> Git and Github for my research projects and for personal projects, 
> dotfiles, etc. as well. 
> > 
> > Now for my question. Suppose I have an expression like the following: 
> > 
> > from sympy import * 
> > var('a:d') 
> > w = Wild('w') 
> > test = a * (1 - c) + b * (c - 1) + d 
> > 
> > I'd like to rewrite test as (a - b) * (1 - c) + d 
> > I tried test.replace(a * w - b * w, collect(a * w - b * w, w)), but this 
> does not work. 
> > 
> > Many thanks in advance for your help. 
> > 
> > -- 
> > 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 https://groups.google.com/group/sympy. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/e14dd72b-ddc3-4280-93a3-faa42af092a3%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/b2fddcd9-6982-4e63-b01f-9080fc76d32a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Introduction and a question

2019-03-13 Thread Aaron Meurer
If you follow the StackOverflow links at
https://github.com/sympy/sympy/issues/11869 you can see some
suggestions on how to do this sort of thing.

Aaron Meurer

On Sun, Mar 10, 2019 at 12:56 AM Mark Juers  wrote:
>
> I'm a 4th-year PhD student in evolutionary biology at Indiana University in 
> Bloomington, IN. I've been using Python for about a year for various biology 
> projects and am working on a package related to my dissertation work.  I am 
> looking to replace Mathematica with SymPy in my workflow. I use Git and 
> Github for my research projects and for personal projects, dotfiles, etc. as 
> well.
>
> Now for my question. Suppose I have an expression like the following:
>
> from sympy import *
> var('a:d')
> w = Wild('w')
> test = a * (1 - c) + b * (c - 1) + d
>
> I'd like to rewrite test as (a - b) * (1 - c) + d
> I tried test.replace(a * w - b * w, collect(a * w - b * w, w)), but this does 
> not work.
>
> Many thanks in advance for your help.
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/e14dd72b-ddc3-4280-93a3-faa42af092a3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6L4t_ZJ9a4OP7wDX%2BWqF7SGYbLGjKfFAY95K3LzWZBLwQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Introduction and a question

2019-03-10 Thread Oscar Benjamin
There probably is a better way of doing this in your problem but I
just want to point out a way to "manually" extract parts of an
expression. Let's create an expression with a few parts:

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

In [2]: p = a*x**2 + b*x + c

In [3]: r1, r2 = solve(p, x)

In [4]: r1
Out[4]:
_
   ╱   2
-b + ╲╱  -4⋅a⋅c + b
─
 2⋅a

Okay now suppose I want to get the discriminant out from inside the
square root and do something with it. I can use the .args attribute of
each sympy expression to drill down to the part I want like this:

In [5]: r1.args
Out[5]:
⎛_⎞
⎜ 1 ╱   2 ⎟
⎜1/2, ─, -b + ╲╱  -4⋅a⋅c + b  ⎟
⎝ a   ⎠

In [6]: r1.args[2]
Out[6]:
_
   ╱   2
-b + ╲╱  -4⋅a⋅c + b

In [7]: r1.args[2].args
Out[7]:
⎛   _⎞
⎜  ╱   2 ⎟
⎝╲╱  -4⋅a⋅c + b  , -b⎠

In [8]: r1.args[2].args[0]
Out[8]:
   _
  ╱   2
╲╱  -4⋅a⋅c + b

In [9]: r1.args[2].args[0].args
Out[9]:
⎛  2 ⎞
⎝-4⋅a⋅c + b , 1/2⎠

In [10]: r1.args[2].args[0].args[0]
Out[10]:
  2
-4⋅a⋅c + b


On Sun, 10 Mar 2019 at 16:01, Mark Juers  wrote:
>
> In my real problem, d is an arbitrarily complex expression I'd rather not 
> type out in full, and the factored part is inside a subexpression, so I'm not 
> sure I could get this to work.
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/1b8b1b7e-22ea-4ae9-9338-f0829e2341b2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxQXVeRBKgStk_NcJdKujYRZgV_rXV-t3AC9gnrnJynohg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Introduction and a question

2019-03-10 Thread Mark Juers
In my real problem, d is an arbitrarily complex expression I'd rather not type 
out in full, and the factored part is inside a subexpression, so I'm not sure I 
could get this to work.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/1b8b1b7e-22ea-4ae9-9338-f0829e2341b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Introduction and a question

2019-03-10 Thread Oscar Benjamin
I'm not sure if this would work for your real problem but for this
example you can do:

In [8]: factor(test-d)+d
Out[8]: d - (a - b)⋅(c - 1)

On Sun, 10 Mar 2019 at 07:56, Mark Juers  wrote:
>
> I'm a 4th-year PhD student in evolutionary biology at Indiana University in 
> Bloomington, IN. I've been using Python for about a year for various biology 
> projects and am working on a package related to my dissertation work.  I am 
> looking to replace Mathematica with SymPy in my workflow. I use Git and 
> Github for my research projects and for personal projects, dotfiles, etc. as 
> well.
>
> Now for my question. Suppose I have an expression like the following:
>
> from sympy import *
> var('a:d')
> w = Wild('w')
> test = a * (1 - c) + b * (c - 1) + d
>
> I'd like to rewrite test as (a - b) * (1 - c) + d
> I tried test.replace(a * w - b * w, collect(a * w - b * w, w)), but this does 
> not work.
>
> Many thanks in advance for your help.
>
> --
> 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+unsubscr...@googlegroups.com.
> To post to this group, send email to sympy@googlegroups.com.
> Visit this group at https://groups.google.com/group/sympy.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/e14dd72b-ddc3-4280-93a3-faa42af092a3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxTAHh79YJG-9TF3M-nBARoqoTmtCcSNE7KBA3MwXGn77w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[sympy] Introduction and a question

2019-03-09 Thread Mark Juers
I'm a 4th-year PhD student in evolutionary biology at Indiana University in 
Bloomington, IN. I've been using Python for about a year for various 
biology projects and am working on a package related to my dissertation 
work.  I am looking to replace Mathematica with SymPy in my workflow. I use 
Git and Github for my research projects and for personal projects, 
dotfiles, etc. as well.

Now for my question. Suppose I have an expression like the following:

from sympy import *
var('a:d')
w = Wild('w')
test = a * (1 - c) + b * (c - 1) + d

I'd like to rewrite test as (a - b) * (1 - c) + d
I tried test.replace(a * w - b * w, collect(a * w - b * w, w)), but this 
does not work.

Many thanks in advance for your help.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at https://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/e14dd72b-ddc3-4280-93a3-faa42af092a3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.