[sympy] Hanging search function of docs.sympy.org (firefox, chromium)

2017-07-13 Thread Carsten Knoll
Hi all,


a colleague just indicated to me that they are not able to perform a
search on  with firefox on Windows 8. IE works.

I can reproduce this on Debian with FF (52.2.0 (64-Bit)) and Chromium
(59.0.3071.86).

Example:
http://docs.sympy.org/latest/search.html?q=diff

The "animation"

Searching
Searching.
Searching..
Searching...

keeps running with change.


Not sure whether this is a sympy issue but at least it seems
sympy-PR-related.


Best regards,

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+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/2ddfb8a8-e872-b2dc-ef00-5bfaaaf6b335%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] strange behavior with Integral.diff

2016-05-24 Thread Carsten Knoll
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  ,

leading to

> 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
 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?

Thanks in advance,
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+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/57440370.7010703%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Can sympy solve this equation?

2016-02-23 Thread Carsten Knoll
On 02/23/2016 05:46 PM, Carl Sandrock wrote:

> ...
> This matches your method. So this has saved me some tedious algebra,
> but not the effort of finding the order in which to evaluate the
> equations. I wish that sympy could do this automatically. 

I agree.

Maybe this could be added to 

https://github.com/sympy/sympy/wiki/gsoc-2016-ideas#solvers

Casually, there is a parallel thread on this list on that topic.


On 02/23/2016 03:26 PM, Kshitij Saraogi wrote:
> Hello,
> 
> I am Kshitij Saraogi and I will be a GSoC applicant this year under SymPy.
> 
> I wanted to discuss about the Solvers project.[1] <
> https://github.com/sympy/sympy/wiki/gsoc-2016-ideas#solvers>
> 
> After going through the discussions mentioned on the Ideas page, I would
> like to get inputs on a few ideas for this project:
> 

>  ...
>3. Implementing more equation solvers: [3]
> 
> 
>   * System of  multivariate linear equations.
> 
>   * Nonlinear multivariate equation solver.
> 
>   * Equations solvable by LamberW function (Transcendental equation solver)
> 
>   * Nested trignometric expressions.
>  ...


@ Kshitij: Do you think our problem/feature request is already covered by issue 
10006?

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+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/56CC9779.7010909%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Can sympy solve this equation?

2016-02-23 Thread Carsten Knoll
Hi,

I already had similar problems. The system of equation is of order 3
which might be too hard. But there is a linear part and if this is
solved first and then plugged into the remaining 2 equations, sympy can
manage it.

I documented my attempt here:

https://gist.github.com/cknoll/c03dcf8443c0409d37da


(Generally, I think sympy.solve could sometimes be a little bit smarter,
to use such structural properties.)



On 02/23/2016 06:43 AM, Carl Sandrock wrote:
> I am attempting to work a problem from a textbook in sympy, but sympy
> fails to find a solution which appears valid. For interest, it is the
> design of a PID controller using direct synthesis with a second order
> plus dead time model.
> 
> The whole problem can be reduced to finding K_C, tau_I and tau_D which
> will make
> 
> K_C*(s**2*tau_D*tau_I + s*tau_I + 1)/(s*tau_I) = (s**2*tau_1*tau_2 +
> s*tau_1 + s*tau_2 + 1)/(K*s*(-phi + tau_c))
> 
> 
> for given tau_1, tau_2, K and phi.
> 
> 
> I have tried to solve this by matching coefficients:
> 
> 
> import sympy
> 
> 
> s, tau_c, tau_1, tau_2, phi, K = sympy.symbols('s, tau_c, tau_1, tau_2,
> phi, K')
> 
> target = (s**2*tau_1*tau_2 + s*tau_1 + s*tau_2 + 1)/(K*s*(-phi + tau_c))
> 
> K_C, tau_I, tau_D = sympy.symbols('K_C, tau_I, tau_D', real=True)
> PID = K_C*(1 + 1/(tau_I*s) + tau_D*s)
> 
> eq = (target - PID).together()
> eq *= sympy.denom(eq).simplify()
> eq = sympy.poly(eq, s)
> 
> sympy.solve(eq.coeffs(), [K_C, tau_I, tau_D])
> 
> This returns an empty matrix. However, the textbook provides the
> following solution:
> 
> booksolution = {K_C: 1/K*(tau_1 + tau_2)/(tau_c - phi),
> tau_I: tau_1 + tau_2,a
> tau_D: tau_1*tau_2/(tau_1 + tau_2)}
> 
> Which appears to satisfy the equations I'm trying to solve: 
> 
> [c.subs(booksolution).simplify() for c in eq.coeffs()]
> 
> returns
> 
> [0, 0, 0]
> 
> Can I massage this into a form which sympy can solve? What am I doing wong?
> 
> -- 
> 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/4d922cfe-9f54-4196-b7d8-15abb053e091%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/56CC8A6B.4080107%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] integrate tan(x) for real argument

2016-02-22 Thread Carsten Knoll
Thanks. Both variants are helpful!

Carsten

On 02/19/2016 08:23 PM, Aaron Meurer wrote:
> It looks like the meijerg algorithm gives the better form:
> 
> In [33]: integrate(tan(x), x, meijerg=True)
> Out[33]: -log(cos(x))
> 
> Aaron Meurer
> 
> On Fri, Feb 19, 2016 at 2:21 PM, Ondřej Čertík  
> wrote:
>> On Fri, Feb 19, 2016 at 8:45 AM, Aaron Meurer  wrote:
>>> trigsimp() will convert the sin to cos. To remove the negative and
>>> square, you'll have to use expand_log(force=True), which gives a
>>> complex constant (which can be ignored, since this is an integral).
>>>
>>> It would definitely be better if integrate at least gave log(1 -
>>> sin(x)**2) so that the result is real.
>>
>> Here is a code that does this:
>>
>> In [1]: expand_log(integrate(tan(x), x).trigsimp(), force=True)
>> Out[1]: -log(cos(x)) - I*pi/2
>>
>> Ondrej



-- 
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/56CB103F.3060509%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] integrate tan(x) for real argument

2016-02-19 Thread Carsten Knoll
I want to calculate the antiderivative for tan(x)

In [4]: x = sp.Symbol('x', real=True)

In [5]: sp.integrate(sp.tan(x), x)
Out[5]: -log(sin(x)**2 - 1)/2


This result is technically correct, but I would (for didactic purposes)
prefer something like

-log(cos(x)).

How can I achieve this?

Thanks.
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+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/56C71381.4090204%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] matrix rank, svd and mpmath

2015-09-09 Thread Carsten Knoll
On 09/08/2015 10:45 PM, Aaron Meurer wrote:
> On Mon, Sep 7, 2015 at 5:37 PM, Carsten Knoll <carstenkn...@gmx.de> wrote:
>> Hi,
>>
>> I want to write a routine to determine the rank of a symbolic matrix and
>> it seems to be a quite tricky task.
>>
>> The routine is required to be applicable for matrices whose entries are
>> "big expressions", hence calling simplify is not an option.
>>
>>
>> My strategy: extracting all occurring symbols and replacing them by
>> random numbers. This way, I arrive at a numeric matrix, which might
>> contain very small numbers which are nevertheless different from zero.
>> Then, I call evalf with different precisions and look at the singular
>> values. My assumption was, that the singular values which are
>> "practically 0" must become smaller with rising precision while singular
>> values whose true value is small but greater zero wont change much.
> 
> I don't know if that is going to be true. I believe what you are
> dealing with is related the so-called table-maker's dilemma
> https://en.wikipedia.org/wiki/Rounding#Table-maker.27s_dilemma.
> There's no way to tell how many digits you need to get a "zero" value
> below a certain epsilon.
> 
> That isn't to say that there aren't good heuristics for doing this,
> some of which are implemented in SymPy (see equal() for instance).
> 


Thanks for that hint.
I now use a heuristic basing on Matrix.rank combined with an "adaptive"
iszerofunc. Just in case someone has a related problem the code is here:

https://github.com/cknoll/rst_symbtools/blob/7a2a4dc9eec617d41f9db3591931615272a80af9/symb_tools.py#L2636

(For curiosity, I still would be interested if there is a possibility to
calculate singular values with arbitrary precision with mpmath.)


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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/55F00210.3030902%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] matrix rank, svd and mpmath

2015-09-07 Thread Carsten Knoll
Hi,

I want to write a routine to determine the rank of a symbolic matrix and
it seems to be a quite tricky task.

The routine is required to be applicable for matrices whose entries are
"big expressions", hence calling simplify is not an option.


My strategy: extracting all occurring symbols and replacing them by
random numbers. This way, I arrive at a numeric matrix, which might
contain very small numbers which are nevertheless different from zero.
Then, I call evalf with different precisions and look at the singular
values. My assumption was, that the singular values which are
"practically 0" must become smaller with rising precision while singular
values whose true value is small but greater zero wont change much.

I tried three ways to calculate the singular values, all of which lead
to problems:

1. mpmath: I could not figure out how to increase precision


2. numpy: precision is limited by data type (np.float64)


3. direct calculation by (M.T*M).eigenvals()
This often works as expected but fails for the following expample:


M = Matrix([
[1,   0, 0],
[1, sin(3)**50, 1],
[0,   0, 0]])

due to the 0-row, one singular value should be exactly zero.

But I get the following:

In [14]:  Matrix((M.T*M).evalf(prec=20).eigenvals().keys()).evalf(20)
Out[14]:
Matrix([
[  2.6180339887498948482 - 0.e-27*I],
[  0.3819660112501051518 - 0.e-28*I],
[2.4515092575814173921e-102 + 0.e-125*I]])

In [15]:  Matrix((M.T*M).evalf(prec=50).eigenvals().keys()).evalf(50)
Out[15]:
Matrix([
[  2.6180339887498948482045868343656381177203091798058 - 0.e-56*I],
[ 0.38196601125010515179541316563436188227969082019424 - 0.e-58*I],
[2.4515092575814173921301544696749858514095930873163e-102 + 0.e-156*I]])


This contradicts my assumption that with increasing precision the last
singular value should get smaller (i.e. closer to 0).

Interestingly, if I swap M and M.T (which leaves the singular values of
a quadratic matrix invariant by definition ) I get the expected result:


In [16]:  sp.Matrix((M*M.T).evalf(prec=20).eigenvals().keys()).evalf(20)
Out[16]:
Matrix([
[0],
[2.6180339887498948482],
[0.3819660112501051518]])


Questions:

1. Is this a viable strategy for rank calculation? Are there preferable
alternatives?

2. Is it possible to use mpmath to calculate arbitrary precise singular
values?

3. If not, how could I alternatively calculate the eigenvalues of
(M.T*M) with arbitrary precision?


4. Is the non-convergence to zero for the last singular value in the
above example a bug or is my expection wrong?


Thanks in advance and best regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/55EE11C6.8090309%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] simplification of exp(x*log(y))

2015-07-18 Thread Carsten Knoll
Hi,

due to various substitutions I have a bulky expression of the following
structure

A + exp(B*log(C) + D)

I want sympy to simplify this to

A + C**B*exp(D)

I think it boils down to the simplification of

exp(B*log(C))


which I also can't perform:

from sympy import exp, log, expand_power_exp
from sympy.abc import B, C

term = exp(B*log(C))

print term.simplify()
print term.expand()
print expand_power_exp(term)


# results
exp(B*log(C))
exp(B*log(C))
exp(B*log(C))

I think a possible way would be the following:

exp(B*log(C) + D) =  exp(B*log(C))*exp(D) =  exp(log(C))**B*exp(D)
= C**B*exp(D)


But how can I tell sympy to see that?

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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/55AA3498.9010108%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread Carsten Knoll
On 05/19/2015 07:48 AM, Joachim Durchholz wrote:
 
 An external dictionary isn't ideal but better than this, at least from
 the maintainer's perspective.
 
 Maybe we can give you better help if you describe your use case in some
 more detail.

 At some point I create symbols from which I know, that they are
 derivatives and I want to store their order. Using the classes Function
 and Derivative is no real option because I want the symbols to behave as
 symbols on most occasions.
 
 Ah. This sounds like a design problem in Derivative to me that we should
 fix.
 Can you post what you did, what you'd have needed to get out, and what
 SymPy gave you?

I think strongest argument for me was that the string representation of
the expressions gets too long for Functions and Derivatives. This
reduces my chance to see any structure.

Second argument is that I have a (own) library for modeling differential
forms which internally uses Symbol and does not straight forwardly work
with Function instances.

E.g.

x.name - 'x'
x(t).name - AttributeError

However, this discussions make me think, if using Functions would not be
the better alternative

 
 In general, I think there are situations, where it might be useful to
 store some algorithm-specific extra information to some symbols.
 
 For algorithms of SymPy itself, I think the algorithms should be fixed :-)
 
 It would be useful for coding external algorithms, but it does come with
 ramifications (most importantly the potential for namespace conflicts);
 from a maintenance perpective, it's far better if such an algorithm does
 its own data management.

OK. I can perfectly live with this.




-- 
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 http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/555B0556.2040908%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-19 Thread Carsten Knoll
On 05/19/2015 02:39 AM, Aaron Meurer wrote:
 On Mon, May 18, 2015 at 12:29 PM, Joachim Durchholz j...@durchholz.org 
 wrote:
 Am 18.05.2015 um 15:56 schrieb Carsten Knoll:

 I want to equip an Symbol with an additional attribute to store some
 specific information right in place.

 For 'normal' Python classes it is no problem to dynamically create an
 additional attribute for an already existing instance.

 However, for sympy Symbols if I try

 x = Symbol('x')
 x.k = 0

 I get the error

 AttributeError: 'Symbol' object has no attribute 'k'


 That happens because we use __slots__ for performance reasons.
 However, storing attributes in that way is a bad idea in general, because
 you risk name conflicts with future versions of SymPy. (That's also the
 reason why using subclasses to extend a library tends to break over time.)
 
 I'm not so sure about this.
 
 The real reason that storing an attribute on x is a bad idea is that
 SymPy implicitly assumes that it can replace one expression with the
 same expression if the two are equal, so, e.g., if you had
 
 x1 = Symbol('x')
 x2 = Symbol('x')
 x1.k = 0
 
 and supposing it worked, along with x1 == x2 giving True, then SymPy
 would assume that it has the freedom at any point to swap x1 with x2
 and visa versa (and indeed, it does do this quite a bit with the
 cache).

Thanks for pointing that out. I will add it to my tests.

 
 I think what you really want to do is create a subclass of Symbol that
 stores the attributes in .args, so that they become part of the
 equality of the object.  Joachim's alternative 1 (store the
 information separately) also sounds like a good one (and probably much
 simpler to implement).


Subclassing and adding attributes in .args indeed seems more complicated.

I will stick with the external dict solution.


Regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/555B0666.3060405%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-18 Thread Carsten Knoll
On 05/18/2015 04:12 PM, Amit Saha wrote:
 On Mon, May 18, 2015 at 11:56 PM, Carsten Knoll carstenkn...@gmx.de wrote:
 I want to equip an Symbol with an additional attribute to store some
 specific information right in place.

 For 'normal' Python classes it is no problem to dynamically create an
 additional attribute for an already existing instance.

 However, for sympy Symbols if I try

 x = Symbol('x')
 x.k = 0

 I get the error

 AttributeError: 'Symbol' object has no attribute 'k'

 Is there any possibility to equip the Symbol x with this attribute?

 I already tried this workarround:

 class ExtendedSymbol(sp.Symbol):
 pass


 x = ExtendendSymbol('x')

 x.k = 0 # no problem here


 However then I have the following unwanted behavior:

 x2 = sp.Symbol('x')
 x2 == x # - False
 
 Not sure if it is possible for your situation, but may be you could
 overrride the __eq__ method in your ExtendedSymbol class to call the
 base class's method?
 

I also thought in that direction, but how would that look like? I mean
overriding a method just to call the respective method of the base class
should be the same as not overiding the method at all, or not?

I then thought on mirroring the Symbol inside and piping all external
calls (including calls to '__eq__') to the wrapped Symbol instance and
fetching only AttributeErrors outside. But this seems to complicated.

The cleanest way would be to somehow dynamically highjack the
SymbolClass itself.

Equipping that class with new methods or class variables is no problem
but adding instance attributes is not possible. Not sure where this
behavior is implemented.

-- 
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 http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/5559FBBD.302%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] How to equip a Symbol with an additional attribute?

2015-05-18 Thread Carsten Knoll
I want to equip an Symbol with an additional attribute to store some
specific information right in place.

For 'normal' Python classes it is no problem to dynamically create an
additional attribute for an already existing instance.

However, for sympy Symbols if I try

x = Symbol('x')
x.k = 0

I get the error

AttributeError: 'Symbol' object has no attribute 'k'

Is there any possibility to equip the Symbol x with this attribute?

I already tried this workarround:

class ExtendedSymbol(sp.Symbol):
pass


x = ExtendendSymbol('x')

x.k = 0 # no problem here


However then I have the following unwanted behavior:

x2 = sp.Symbol('x')
x2 == x # - False

Any ideas?

Best regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/5559EF9B.3090106%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-18 Thread Carsten Knoll
On 05/18/2015 04:48 PM, Carsten Knoll wrote:
 On 05/18/2015 04:12 PM, Amit Saha wrote:
 On Mon, May 18, 2015 at 11:56 PM, Carsten Knoll carstenkn...@gmx.de wrote:
 I want to equip an Symbol with an additional attribute to store some
 specific information right in place.

 
 Equipping that class with new methods or class variables is no problem
 but adding instance attributes is not possible. Not sure where this
 behavior is implemented.
 


If someone is interested: I found an (ugly) workaround:


# because sympy does not allow to dynamically attach attributes
# to symbols we set up our own infrastructure for storing them


import sympy as sp
sp._attribute_store = {}


def new_setattr(self, name, value):
try:
self.__orig_setattr__(name, value)
except AttributeError:
sp._attribute_store[(self, name)] = value


def new_getattr(self, name):
try:
res = self.__getattribute__(name)
except AttributeError, AE:
try:
res = sp._attribute_store[(self, name)]
except KeyError:
# raise the original AttributeError
raise AE
return res


sp.Symbol.__orig_setattr__ = sp.Symbol.__setattr__
sp.Symbol.__setattr__ = new_setattr

sp.Symbol.__getattr__ = new_getattr



Still, I would prefer to store the attribute directly 'inside'  the
symbol instance but at least in the rest of my code this solution feel
like it were like that.

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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/555A1D0B.2090905%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] How to equip a Symbol with an additional attribute?

2015-05-18 Thread Carsten Knoll

 
 That happens because we use __slots__ for performance reasons.

I was not aware of the __slots__ mechanism. Now I know.

 However, storing attributes in that way is a bad idea in general,
 because you risk name conflicts with future versions of SymPy. (That's
 also the reason why using subclasses to extend a library tends to break
 over time.)

OK.

On the other hand syntax looks much cleaner

 
 Alternative 1: You could set up a dict with a Symbol-to-attributes
 mapping: Symbols are hashable (that's a guaranteed property).

Thats what I meanwhile did (see my other message on this thread). In
addition I redefine __setattr__ and __getatrr__ of the Symbol class to
hide the dictionary access behind the scene.

This feels somehow strange but it works. Lets see how long.

 
 Alternative 2: We could add a `userdict` attribute in Symbol, so that
 SymPy users can store additional attributes there.

This would be nice from my point of view. But wouldnt this cause
performance issues? As I understand, __slots__ is used to prevent every
Symbol instance from having a dict. But introducing a `userdict` would
negate this effort.



 I'm not too happy with either alternative.
 Maybe we can give you better help if you describe your use case in some
 more detail.


At some point I create symbols from which I know, that they are
derivatives and I want to store their order. Using the classes Function
and Derivative is no real option because I want the symbols to behave as
symbols on most occasions.

In general, I think there are situations, where it might be useful to
store some algorithm-specific extra information to some symbols.

Thanks and Regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/555A6B5B.9010808%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] Matrices with noncommutative symbols

2015-05-11 Thread Carsten Knoll
Hello,

I wonder about the following behavior


In [1]: import sympy as sp

In [2]: x, y = sp.symbols('x, y', commutative = False)

In [3]: M1 = x*sp.eye(2)

In [4]: M2 = y*x*sp.eye(2)

In [5]: y*M1-M2
Out[5]:
Matrix([
[x*y - y*x, 0],
[0, x*y - y*x]])



I would have expected that the two matrices are equal.

However, multiplying y from the right to M1 results in products where y
is on the left side:

In [6]: y*M1
Out[6]:
Matrix([
[x*y,   0],
[  0, x*y]])


For reference two other results:

In [7]: M2
Out[7]:
Matrix([
[y*x,   0],
[  0, y*x]])

In [8]: M1*y
Out[8]:
Matrix([
[x*y,   0],
[  0, x*y]])


Questions:

1. Is this behavior intended?
2. Is there any (easy) way to achieve my intended behavior, i.e.
respecting multiplication order when using matrix multiplication.


Thanks,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/55510F66.4060900%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] dsolve - strange boundaries of Integral object

2015-04-13 Thread Carsten Knoll
Thanks for the clarifications,

On 04/13/2015 06:28 PM, Aaron Meurer wrote:
 On Fri, Apr 10, 2015 at 3:54 AM, Carsten Knoll carstenkn...@gmx.de wrote:

 1. What does an object like

 Integral(F(t), (t, 0))

 mean?
 
 It means the integral of F(t), evaluated at t = 0. It's the same as
 Integral(F(t), (t, a, 0)) except we don't want to create a new
 arbitrary symbol a.
 
 Normally this is not a well-defined concept, but for solutions from
 dsolve, it is, because there is always a + C arbitrary constant factor
 in the solution that absorbs the term with a.

OK. But anyway: wouldn't it be simpler for dsolve (from user point of
view) to return a Integral object with two boundary values the lower
being zero and the upper being t. If I see it right, this formulation of
the solution has the same level of generality but the advantage that it
is possible to perform useful calculation with the result. E.g. I want
to determine C1 in terms of the intial value x(0).

 

 2. Is the behavior described below intended or is it kind of a bug?
 
 If you mean Integral(F(t), t).subs(t, 0) returning Integral(F(t), (t,
 0)) instead of vanishing, that is intended. SymPy can't know that
 Integral(F(t), (t, 0)) is supposed to be 0. The only way to get
 constants to absorb into C1 is to use constantsimp.

Here I do not understand how I could use constantship? If evaluate
Integral(F(t), (t, 0)) (i.e. I choose t=0) than the integral should be
constant.

In Fact I get

In [22]: sp.Integral(F(t), (t, 0)).is_constant()
Out[22]: True

But this Term is not absorbed into C1. (Should it be?)

 

 3. What would be a (generic) workaround? (I was thinking in replacing
 all Integrals occurring in the rhs-result of dsolve and replacing them
 by new definite integrals like Integral(F(tau), (tau, 0, t)). But maybe
 this should happen in dsolve itself.)
 
 If you want to do this, it shouldn't be hard to use replace() to do it.

Thanks for the tip. I was thinking in using subs, but replace seems much
more elegant.

I interpret your suggestion to use replace in my private code (not
altering the behavior of sympy.dsolve), right?


Thanks,
Carsten.

 
 Aaron Meurer
 

 Tanks and best regards,
 Carsten.


 On 04/08/2015 06:18 PM, Carsten Knoll wrote:
 I have the following problem


 In [1]: from sympy import *

 In [3]: x, F, t = symbols('x, F, t')

 In [4]: ode = x(t).diff(t) - F(t)

 In [5]: sol = dsolve(ode).rhs

 In [7]: sol
 Out[7]: C1 + Integral(F(t), t)

 In [8]: sol.subs(t, 0)
 Out[8]: C1 + Integral(F(t), (t, 0))


 I want the last expression to evaluate to C1, i.e.

 Integral(F(t), t).subs(t, 0)

 should vanish instead of returning a strange object with one bound
 specified.

 The application of .doit() does not help either.


 BTW: IMHO dsolve should return something like

 C1 + Integral(F(tau), (tau, 0, t))

 where tau is a dummy variable


 Thanks in advance,

 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+unsubscr...@googlegroups.com.
 To post to this group, send email to sympy@googlegroups.com.
 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/55278FCE.8020101%40gmx.de.
 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 http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/552C5735.4080109%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] dsolve - strange boundaries of integrate

2015-04-08 Thread Carsten Knoll
I have the following problem


In [1]: from sympy import *

In [3]: x, F, t = symbols('x, F, t')

In [4]: ode = x(t).diff(t) - F(t)

In [5]: sol = dsolve(ode).rhs

In [7]: sol
Out[7]: C1 + Integral(F(t), t)

In [8]: sol.subs(t, 0)
Out[8]: C1 + Integral(F(t), (t, 0))


I want the last expression to evaluate to C1, i.e.

Integral(F(t), t).subs(t, 0)

should vanish instead of returning a strange object with one bound
specified.

The application of .doit() does not help either.


BTW: IMHO dsolve should return something like

C1 + Integral(F(tau), (tau, 0, t))

where tau is a dummy variable


Thanks in advance,

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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/552554E4.1050702%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] return types of solve?

2015-01-21 Thread Carsten Knoll
I try to include sympy in teaching material.

When doing this, the focus is not on programming nor implementation
details. The CAS should be as transparent as possible. The CAS-using
code should read like the math done in a textbook.

I think sympy is very close to this. However, there are some annoying
obstacles to transparency.

One of it is the return behavior of solve. There are at least three
cases (if a solution can be found):

* a dict
* a list of tuples
* a list of dicts

for me it is hard to predict, when which case will occur. The behavior
can be influenced by keyword args but this would require additional
(off-topic) explanation to the students..

So, I am thinking in implementing my own wrapper for solve to overcome
this. However, I from my point of view it would be a lot cleaner if the
default return type (in the case of a unique solution) is always one
dict. Because then the solution can immediatly passed to subs(...).

Question: Is there any chance to change the solve behavior like that? (I
would try to work on it.)


See an example of what I mean (copied from an IP notebook):


In [1]:

import sympy as sp

print sp.__version__

0.7.5

In [2]:

x1, x2 = xx = sp.Matrix( sp.symbols(x1:3) )

z1, z2 = zz = sp.Matrix( sp.symbols(z1:3) )

In [3]:

q = sp.Matrix([x1, -x2 + x1*(1-x1**2)])

q

Out[3]:

Matrix([
[  x1],
[x1*(-x1**2 + 1) - x2]])

Say z:=q(x). We want to calculate x=q^{−1}(z). We use 0=z−q(x) as
expression to solve.
In [4]:

sp.solve(q-zz, xx)  # returns a list (len=1) of tuples (len=2) of
expressions

Out[4]:

[(z1, -z1**3 + z1 - z2)]

In [5]:

# This is what I finally want to do:

# q_inv = xx.subs(x_sol)



# but this requires some overhead

sp.solve(q-zz, xx, dict=True)  # returns a list (len=1) of dicts

Out[5]:

[{x1: z1, x2: -z1**3 + z1 - z2}]

In [6]:

x_sol = sp.solve(q-zz, xx, dict=True)[0]

q_inv = xx.subs(x_sol)

q_inv  # this is the result I want (but with less 'magic' overhead)

Out[6]:

Matrix([
[  z1],
[-z1**3 + z1 - z2]])

In [7]:

# on the other hand, solve can behave like 'expected' (by me):


sp.solve(q-zz, zz)  # returns one dict (good)

Out[7]:

{z2: -x1**3 + x1 - x2, z1: x1}


Best regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/54C01EE2.3040206%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


[sympy] solve() for unsolveable system returns a nonempty dict

2014-03-08 Thread Carsten Knoll
Until today I thought, if solve returns a nonempty dict, then there is a
(complete) solution to the provided system.


However this is apparently not the case:

 solve([y, x], x)
{x:0}


Moreover, this behavior seems not to be consistent


 solve([x, y], y)
[]


(results from SymPy 0.7.4.1 on live.sympy.org)


Am I on a wrong track or is that a bug?

Best regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
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/531B53E9.600%40gmx.de.
For more options, visit https://groups.google.com/d/optout.


Re: [sympy] Re: sympify(MutableMatrix) - ImmutableMatrix

2013-11-08 Thread Carsten Knoll
I see.

Thank you both for the information.

On 11/08/2013 12:47 AM, Aaron Meurer wrote:
 Yes, sympify() always returns an instance of Basic if it can.
 Basic instances have to be immutable, so MutableMatrix is not Basic
 whereas ImmutableMatrix is. This is done so that classes that
 include matrices in their args automatically get the immutable one.
 Immutability is important because of hashing.
 
 Historically, Matrix was only one class, the mutable version. 
 ImmutableMatrix was created to handle instances where we needed to 
 include in in the args of an expression. Matrix remains mutable by 
 default for backwards compatibility purposes, though this may
 change in the future.
 
 Aaron Meurer
 
 On Thu, Nov 7, 2013 at 12:55 PM, F. B. franz.bona...@gmail.com
 wrote:
 Sympy objects are usually immutable once created, mutable
 matrices are an exceptions.
 
 I guess that sympify simply avoids creating a mutable object.
 
 
 On Thursday, November 7, 2013 7:44:37 PM UTC+1, Carsten Knoll
 wrote:
 
 Hi all,
 
 
 I just stumbled on the following behavior:
 
 
 type(eye(2))
 
 class′sympy.matrices.dense.MutableDenseMatrix′
 
 type(sympify(eye(2)))
 
 class′sympy.matrices.immutable.ImmutableMatrix′
 
 
 Is this supposed to work that way or is it a (minor) Bug?
 
 
 Best regards, 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+unsubscr...@googlegroups.com. To post to this group, send
 email to sympy@googlegroups.com. 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 sympy+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy.
For more options, visit https://groups.google.com/groups/opt_out.


[sympy] diffgeom: wedgeproduct

2013-04-17 Thread Carsten Knoll
Hi everyone,

I just realized that sympy is able to deal with 1-forms and wedge
products and such stuff. Thats really great!

I have a tow questions:



In [3]: from sympy.diffgeom import WedgeProduct

In [4]: from  sympy.diffgeom.rn import R3_r as R3

In [5]: WedgeProduct(R3.dx, R3.dx)
Out[5]: WedgeProduct(dx, dx)

#1 Is it possible for sympy to see that this is the Zero-2-form?


In [9]: WedgeProduct(R3.dx, R3.dx+2*R3.dy)
Out[9]: WedgeProduct(dx, dx + 2*dy)


#2 Is it possible to (pretty)print a wedge product in a
basis-representation? (In this case this IMHO would be 2*dx^dy).

I was thinking about evaluating the Wedgeproducts with base vectors to
get the Information, but I guess there must be a intern way..


Best regards,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [sympy] diffgeom: wedgeproduct

2013-04-17 Thread Carsten Knoll
Thank you for your comments and hints.

 
 I was thinking about evaluating the Wedgeproducts with base vectors to
 get the Information, but I guess there must be a intern way..
 
 There is actually no intern way. This design decision was based on
 the requirement to be able to write stuff like
 WedgeProduct(stuff_in_one_basis, stuff_in_other_basis). Nonetheless
 having helpers that do what you want automatically would be a nice
 addition.

I just wrote a simple function that does what I need (at least for the
moment).

In case anybody is interested:


# -*- coding: utf-8 -*-

A function for printing (nested) wedge products in human readable form



import sympy.diffgeom as d
import sympy as sp


wp = d.WedgeProduct


def simple_print_nform(nform, Mf, n):

nform  the n-form to be simplified
Mf the Manifold
n  the grade of the nform # TODO: get it automatically

bv = Mf.base_vectors()
bonf = Rn.base_oneforms()
combs1 = it.combinations(bv, n)
combs2 = it.combinations(bonf, n) # just for printing

res = 0
for c1, c2 in zip(combs1, combs2):
# c2 looks like this [(dx1, dx2), (dx1, dx3), ...]
txt = ^.join([str(bf) for bf in c2])
symb = sp.Symbol(txt)
coeff = nform(*c1).expand()

res+= coeff*symb

return res

 # just for convenice (inspired by diffgeo.rn.R2 and R3)
def Rnr(n):
assert isinstance(n, int)
Rn =  d.Manifold('R%i' %n, n)
orgn = d.Patch('origin', Rn)

Rnr = d.CoordSystem('rectangular', orgn, sp.symbols('x1:%i'%(n+1)))


cf = Rnr.coord_functions()
bv = Rnr.base_vectors()
bonf = Rnr.base_oneforms()

for elt in cf+bv+bonf:
setattr(Rnr, str(elt), elt)

return Rnr

if __name__ == __main__:
# calculation in R4:
n = 4
Rn = Rnr(n)


dxi = Rn.base_oneforms()
import itertools as it
combs = list(it.combinations(dxi, 2))

ai = sp.symbols('a1:%i' % (len(combs)+1))
bi = sp.symbols('b1:%i' % (n+1))

w = sum([b*d for b,d in zip(bi, dxi)])
dw = sum([a*wp(c[0],c[1]) for a,c in zip(ai, combs)])


q = wp(dw, w) # 2-form ^ 1-form  = 3-form

print simple_print_nform(q, Rn, 3)




from IPython import embed
embed()


-- 
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 http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.




[sympy] Bug in trigsimp(matrix, method=fu)?

2013-03-29 Thread Carsten Knoll

Hi,

in current master (python 2.7) this works for me:


trigsimp(Matrix([sin(x), cos(x)]))

It is equivalent to the call:

trigsimp(Matrix([sin(x), cos(x)]), method = matching)


however the following do not:

trigsimp(Matrix([sin(x), cos(x)]), method = fu)
trigsimp(Matrix([sin(x), cos(x)]), method = groebner)
trigsimp(Matrix([sin(x), cos(x)]), method = combined)

They produce the following Error:


AttributeError: ImmutableMatrix has no attribute normal.


I dont think that this should be this way.

Anyway:
A workaround is to use Matrix.applyfunc(...)


Best,
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+unsubscr...@googlegroups.com.
To post to this group, send email to sympy@googlegroups.com.
Visit this group at http://groups.google.com/group/sympy?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.




[sympy] trigsimp - cos(x+y)

2012-12-05 Thread Carsten Knoll
Hi there,


today I stumbled on a trigsimp problem:

In [4]: trigsimp(cos(x+y).expand(trig=True))
Out[4]: -sin(x)*sin(y) + cos(x)*cos(y)

In [5]: simplify(cos(x+y).expand(trig=True))
Out[5]: -sin(x)*sin(y) + cos(x)*cos(y)


In other words: the identity

-sin(x)*sin(y) + cos(x)*cos(y) == cos(x+y)

is not recognized.


There was a discussion on this in June 2012 (subject:  trigsimp applied
to a matrix; see below).

Is there any chance to get this feature into the master branch?

Best,
Carsten





On 06/12/2012 12:08 AM, Kjetil brinchmann Halvorsen wrote: see inline:

 On Mon, Jun 11, 2012 at 5:55 PM, Chris Smith smi...@gmail.com wrote:
 On Tue, Jun 12, 2012 at 3:20 AM, Kjetil brinchmann Halvorsen
 kjetil1...@gmail.com wrote:
 This MUST be a bug:

 In [29]: ( sin(s)*sin(t)-cos(s)*cos(t)).trigsimp()
 Out[29]: sin(s)⋅sin(t) - cos(s)⋅cos(t)

 It works in my trigsimp branch
 (https://github.comsee inline:/sympy/sympy/pull/772 which I closed
for lack of
 interest):

Then you should maybe consider reopening it?   That seems
 a quitet basic functionality!

 Kjetil


 cos(x+y).expand(trig=1)
 -sin(x)*sin(y) + cos(x)*cos(y)
 simplify(_)
 cos(x + y)

 /c


-- 
You received this message because you are subscribed to the Google Groups 
sympy group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.



Re: [sympy] Experiences with sympy in teaching?

2012-08-01 Thread Carsten Knoll
We gave a python course for engineering students this semester (and in
Spring 2011). It was quite mechanical-oriented (3D Visualization,
Multibody-Systems, ...) but included one lecture about sympy (Lagrangian
equations).

This maybe might serve as a application example.

see  http://www1.inf.tu-dresden.de/~pykurs/

and in particular

http://www1.inf.tu-dresden.de/~pykurs/material/alt/pykurs03.zip

(The material is in German)

Maybe, the sage-community (which seems to be connected to sympy) might
have some material for you.

Best,
Carsten




On 08/01/2012 10:08 AM, Ingolf Schäfer wrote:
 Dear all,
 
 I am a lecturer for mathematics and considering to use Sympy in a
 supplemental calculus course for future math teachers. Does anyone have
 experiences with sympy in this context and is willing to share them?
 
 Yours,
 
 Ingolf
 
 -- 
 You received this message because you are subscribed to the Google
 Groups sympy group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/sympy/-/qsQD7bFufrgJ.
 To post to this group, send email to sympy@googlegroups.com.
 To unsubscribe from this group, send email to
 sympy+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/sympy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
sympy group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.



Re: [sympy] latex expressions as symbol strings?

2012-02-21 Thread Carsten Knoll

Hi Aaron,


On 02/20/2012 09:25 PM, Aaron Meurer wrote:

The easiest way to do this is to use the symbol_names flag that was
recently added to latex().  I think this may have been added since
0.7.1, so you'll need to use a development version to get it (see
https://github.com/sympy/sympy/wiki/getting-the-bleeding-edge).  With
that, you can get:

In [462]: latex(phidd**2, symbol_names={phidd:r'\ddot{\varphi}'})
Out[462]: \ddot{\varphi}^{2}


that is the solution I was looking for. Thank you.

However, as far as I see, there is no possibility to pass the 
symbol_names argument to preview.


https://github.com/ness01/sympy/blob/master/sympy/printing/preview.py#L114


I think it should not be hard to modify the preview signature from

def preview(expr, output='png', viewer=None, euler=True):

to

def preview(expr, output='png', viewer=None, euler=True, **latex_settings):


pass these settix to the latex function.

Would that make sense?

Carsten.




If you don't want to type that each time, you can define the dict
before hand and do latex(expr, symbol_names=translation_dict), or if
you just want to make things fast for an interactive demo, you can
redefine latex at the beginning as

def latex(*args, **kwargs): # or def my_latex if you don't want to override it
 kwargs['symbol_names'] = {phidd:r'\ddot{\varphi}'}
 return sympy.latex(*args, **kwargs)

which will make things a little more confusing, but will allow for
faster typing (so it depends on what your goal is).

If you're using automatic latex in the IPython notebook or qtconsole,
you'll have to modify the sympy profile.

Aaron Meurer

On Mon, Feb 20, 2012 at 7:30 AM, Carsten Knollcarstenkn...@gmx.de  wrote:

Hi,

I am writing a script in which I generate the an expression. This expression
I want to use 1) with preview and 2) with lambdify.


Lets say

expr = phidd**2

And I want preview to use the latex code '\ddot{\varphi}' for rendering of
phidd. Therfore I defined:

phidd = sp.Symbol(r'\ddot{\varphi}').


However, this causes problems when I call

sp.lambdify(phidd, expr)


File string, line 1
 lambda \ddot{\varphi}: (\ddot{\varphi}**2)
  ^
SyntaxError: unexpected character after line continuation character

A manual workarround would be to substitute the critical symbol with some
uncritical one.

However Im wondering if there is another (cleaner) way.

I would like to use the code in a tutorial session, therefore I would like
minimize the ballast.


Best regards,
Carsten

--
You received this message because you are subscribed to the Google Groups
sympy group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.





--
You received this message because you are subscribed to the Google Groups 
sympy group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.



Re: [sympy] latex expressions as symbol strings?

2012-02-21 Thread Carsten Knoll

On 02/21/2012 11:27 AM, Aaron Meurer wrote:

Yes, that's a great idea.  Can you submit a pull request implementing it?

Aaron Meurer


I'll try it in the next days.

in printing/tests there is no file covering the preview module. So I 
think it will not be necessary to implement a test.



Carsten.

--
You received this message because you are subscribed to the Google Groups 
sympy group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.



[sympy] latex expressions as symbol stings?

2012-02-20 Thread Carsten Knoll

Hi,

I am writing a script in which I generate the an expression. This 
expression I want to use 1) with preview and 2) with lambdify.



Lets say

expr = phidd**2

And I want preview to use the latex code '\ddot{\varphi}' for rendering 
of phidd. Therfore I defined:


phidd = sp.Symbol(r'\ddot{\varphi}').


However, this causes problems when I call

sp.lambdify(phidd, expr)


File string, line 1
 lambda \ddot{\varphi}: (\ddot{\varphi}**2)
  ^
SyntaxError: unexpected character after line continuation character

A manual workarround would be to substitute the critical symbol with 
some uncritical one.


However Im wondering if there is another (cleaner) way.

I would like to use the code in a tutorial session, therefore I would 
like minimize the ballast.



Best regards,
Carsten

--
You received this message because you are subscribed to the Google Groups 
sympy group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.