28 May 21:36 2016

### Render an Expression containing Python variables without symplifying or evaluating it.

Hi all,

Often in Python, I'll punch in an equation based on constants like this:

mass = 10
acceleration = 9.8
print(mass * acceleration)

I'd love to be able to use Sympy to find/replace these variables in an expression and then print the unicode result. For me I'd appreciate being able to see the nicely rendered expression to make sure I typed it in correctly.

vars_dict = {"mass":10,
"acceleration": 9.8}
render_expression("mass * acceleration", vars_dict)

where the output looks like the following:

9.8⋅10
Or.. something more complicated:
constants = {"lbs_per_bucket": 4, "lbs": 2, "lbs_friend": 3}render_expression("(lbs/lbs_per_bucket + lbs_friend)**2", constants)

2 ⎛2 ⎞ ⎜─ + 3⎟ ⎝4 ⎠
Is there a built-in sympy way of rendering an expression that contains python variables without evaluating it?
On the flip-side, is there a way of defining a multi-variable expression, like x + 2y and then inputting the value of y such that sympy just solves for x? In that sense I could include variables from python take take on the defined symbol values.
Cheers--and thanks for taking a look!

--
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.
28 May 19:40 2016

### Convert sympy expressions to use a 3rd party linear programming solver (pulp)

Hi,

First of all, thanks for the fantastic open source library ! It has all I could dream of (export to latex etc...).

I use sympy to generate constraints of a linear programming problem. At the end of it, I want to find the solution for the system with https://github.com/coin-or/pulp, i.e., I want to convert my sympy.core.expr.Expr ( "x+y" etc..) into pulp.LpConstraint variables in order to do as in this tutorial: http://www.coin-or.org/PuLP/CaseStudies/a_blending_problem.html
===
# The five constraints are entered prob += x1 + x2 == 100, "PercentagesSum" prob += 0.100*x1 + 0.200*x2 >= 8.0, "ProteinRequirement" prob += 0.080*x1 + 0.100*x2 >= 6.0, "FatRequirement" prob += 0.001*x1 + 0.005*x2 <= 2.0, "FibreRequirement" prob += 0.002*x1 + 0.005*x2 <= 0.4, "SaltRequirement"===
So for instance in my code, I have a sympy expression 0.100*x1 + 0.200*x2 but I want to substitute x1 and x2 by pulp.LpVariable (similar to sympy symbol) so that the sympy.core.expr.Expr becomes a pulp.LpAffineExpression.
So far, I believe my best option is to use Expr.as_coefficients_dict to rebuild the whole thing.

I wonder if there is a best option (even with another library than pulp, I don't care) to solve this (optimization) problem.

Best regards

--
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.
27 May 10:15 2016

### how to add extra operator for algebra

if i define a new custom multiply operator and would like to add to existing algebra system in python

how can i extend this function?

--
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.
24 May 23:05 2016

### how does solveset handle the assumption system

Hi:

the example

import sympy
energy=sympy.symbols('E',positive=True)
from sympy.assumptions.assume import global_assumptions
position=sympy.symbols('r',real=True)
momentum=energy-1-sympy.exp(position)
interval=sympy.solveset(momentum,position,sympy.S.Reals)
print(interval)

the output is:Intersection((-oo, oo), {log(E - 1)})

the output is true

So it seems that solveset totally ignores the global_assumptions. How to tell solveset the global_assumptions, so it can use them to do more simplification?

I also try sympy.refine and sympy.simplify to simplify the final interval, but none of them can simplify interval to just {log(E-1)};

By the way, I want to ask how does the assumption system interact with other part of sympy. I know I can give assumption when I define variables, like real=True,
positive=True. But I can not give relative assumption, like E+1 is positive or A-B is greater than C. I figure out global_assumptions may consider relative
assumption. But how about the other parts of sympy, like solveset, integrate, integrate.transform, simplify? Do they take global_assumptions into consideration?
I know mathematica, maple and maxima all support relative assumption. And they can use the assumptions to do more simplification. Does the assumption system in
sympy act like the same way?

--
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.
24 May 11:09 2016

### Italics in math equations

I was recently made aware that only variables should be in italics in equations (see e.g. [1], [2], [3]).
I never really reflected over the distinction, but now it seems obvious. Should we make LaTeX output of SymPy follow this?

e.g. change:

>>> x = sympy.Symbol('x')
>>> print(sympy.latex(sympy.Integral(x, x)))
\int x\, dx
to:

>>> x = sympy.Symbol('x')
>>> print(sympy.latex(sympy.Integral(x, x)))
\int x\, \mathrm{d}x

what do you think?

Best regards,
Björn

--
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.
24 May 09:32 2016

### strange behavior with Integral.diff

Hi all,

I've encountered an error when deriving an integral expression which
contains a derivative and has variable bounds. My setup looks like this:

> In [1]: from sympy import *
> In [2]: init_printing()
> In [3]: x, xi = symbols("x, xi"); k = Function("k")
> In [4]: exp = Integral(k(x, xi).diff(x), (xi, 0, x)); exp
> Out[4]:
> x
> ⌠
> ⎮ ∂
> ⎮ ──(k(x, ξ)) dξ     .
> ⎮ ∂x
> ⌡
> 0

For testing purposes I substituted the expression

> In [5]: k_test = x**2*xi + x*xi**2  ,

> In [6]: exp.subs(k(x, xi), k_test).doit()
> Out[6]:
>      3
> 4⋅x
> ────    ,
>  3

which is correct from my point of view.

The problem arises when I differentiate the expression:

> In [9]: exp_dx = exp.diff(x); exp_dx
> Out[9]:
>               x
>               ⌠
>               ⎮   2
> d             ⎮  ∂
> ──(k(x, x)) + ⎮ ───(k(x, ξ)) dξ     .
> dx            ⎮   2
>               ⎮ ∂x
>               ⌡
>               0

According to the Leibniz integral rule
<https://en.wikipedia.org/wiki/Leibniz_integral_rule> I would expect the
first term to be the derivative of k(x, x) in favour of its first
argument instead of the total derivative.
Substituting the text expression thus leads to

> In [9]:  exp_dx.subs([(k(x, xi), k_test), (k(x, x), k_test.subs(xi, x))]).doit()
> Out[9]:
>      2
> 7⋅x ,

which differs from my manual computation that would evaluate to 4x².

Any thoughts on what I could have done wrong, or how to circumvent this
problem?

Stefan (c/o Carsten)

--

--
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@...
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/57440370.7010703%40gmx.de.


24 May 06:59 2016

### any way to get solve with evaluate=False?

>>> solve(x**2,x,evaluate=False)
[0]
>>> sympify('solve(x**2,x,evaluate=False)',evaluate=False)
[0]

Is there any way to have it return solve(x**2,x), like this:

>>> solve(x**2,x,evaluate=False)
solve(x**2,x)

--
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.
24 May 02:37 2016

### polynomials over GF(2)

I would like to perform operations on polynomials over GF(2), i.e., polynomials with binary coefficients.  Is there a way to do this with SymPy?

There is a sympy.polys.galoistools module, but I haven't found any user documentation for it

--
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.
24 May 02:34 2016

### documentation of polynomials module is out-of-date

Documentation at http://docs.sympy.org/0.6.7/modules/polynomials.html gives the following example:

from sympy import * x, y, z = symbols('xyz')

This doesn't work. I believe that the syntax has changed.

--
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.
24 May 01:40 2016

### GSoC coding period has begun

Just a friendly reminder that as of today, the GSoC coding period has
officially begun. Students, remember to blog and meet with your
mentors at least once a week.

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@...
To post to this group, send email to sympy@...


23 May 21:58 2016

### Comparison failure

Hi all,

I am working on a pull request. When writing tests for the PR, I keep encountering false comparisons when the expressions I'm comparing appear to be the exact same. Example shown below:

In[80]: %paste
result
= manualintegrate(x**(3/2) * log(x), x)
desired_result
= 0.4*x**2.5*log(x) - 0.16*x**2.5

print(result)

print(desired_result)

print(result == desired_result)

assert result == desired_result
## -- End pasted text --
0.4*x**2.5*log(x) - 0.16*x**2.5
0.4*x**2.5*log(x) - 0.16*x**2.5
False
Traceback (most recent call last):

File "/home/lindsayad/miniconda2/envs/python3SympyDev/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code

exec(code_obj, self.user_global_ns, self.user_ns)

File "<ipython-input-80-5bc67a132f24>", line 6, in <module>

assert result == desired_result
AssertionError

Any suggestions on how to make these comparisons 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+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.