IexFinder and SymPy Gamma

조회수 45회
읽지 않은 첫 메시지로 건너뛰기

Zoufiné Lauer-Baré

읽지 않음,
2021. 11. 18. 오후 4:28:2121. 11. 18.
받는사람 sympy

Dear SymPy Community,

 the IexFinder: Interactive Symbolic Calculation of Extreme Values


is now listed in the Voila Gallery


As far as I understand is the extreme value analysis in https://gamma.sympy.org/
is restricted to scalar functions (from R to R).

What do you think about an extension of SymPy Gamma to multivariate functions ( at least from R^2 to R) as in the IexFinder project?

The IexFinder project is now indexed in Zenodo and can be referred to as 

Zoufiné Lauer-Baré. (2021). IexFinder: Interactive Symbolic Calculation of Extreme Values (v1.0.1). Zenodo. https://doi.org/10.5281/zenodo.5707406

I think that SymPy Gamma has a great further potential (also compared to commercial CAS's) when going up the dimensions in calculus and in visualization!

What do you think?

Thanks,

regards,

Zoufiné





exFinder_usage_4.png

Peter Stahlecker

읽지 않음,
2021. 11. 19. 오전 4:45:3621. 11. 19.
받는사람 sy...@googlegroups.com
Hi,
I cannot see any use for me personally, but I think it is a great strength of python / sympy that such packages are available.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/sympy/5e711f06-2fbd-4359-856a-2c7f61e6fce6n%40googlegroups.com.

Oscar Gustafsson

읽지 않음,
2021. 11. 19. 오전 8:08:0121. 11. 19.
받는사람 sy...@googlegroups.com
Multi-variate extreme value calculations would indeed be a useful addition to SymPy (and therefore to SymPy Gamma, although I do not know how often SymPy Gamma updates SymPy version).

BR Oscar 


David Bailey

읽지 않음,
2022. 1. 6. 오전 9:41:0622. 1. 6.
받는사람 sy...@googlegroups.com
Dear group,

A substitution like this is easy to make with SymPy:

(a*x**2+b*x+c).subs(x,y)

However, how can I make a conditional substitution, such as:

a) One that would replace even powers of x only.

b) One which would replace even powers of x by y**(n/2) resulting in
a*y**7+b*x+c? I.e. one where parts of the object being replaced would be
available to form part of the result - thus x**14 would contribute '7'
to the resultant expression.

Thanks in anticipation!

David

Oscar Benjamin

읽지 않음,
2022. 1. 6. 오전 11:42:1222. 1. 6.
받는사람 sympy
You can use replace to make arbitrary conditions on substitution.
There are different syntaxes so here's how you do it using wild
pattern-matching:

In [15]: expr = (a*x**14 + b*x + c)

In [16]: expr
Out[16]:
14
a⋅x + b⋅x + c

In [17]: w = Wild('w')

In [18]: expr.replace(x**w, lambda w: y**(w/2) if w.is_even else x**w)
Out[18]:
7
a⋅y + b⋅x + c

Here's how you do it with just functions:

In [19]: query = lambda e: e.is_Pow and e.base == x and e.exp.is_even

In [20]: replacer = lambda e: y**(e.exp/2)

In [21]: expr.replace(query, replacer)
Out[21]:
7
a⋅y + b⋅x + c

Since query and replacer can be completely arbitrary functions any
kind of replacement rule can be implemented in this way.

--
Oscar

David Bailey

읽지 않음,
2022. 1. 6. 오후 4:23:3422. 1. 6.
받는사람 sy...@googlegroups.com
Thanks very much for that Oscar, your solution looks extremely useful
and general. Somehow I hadn't realised the power of Wild(), although I
knew Wild existed. The Wild/replace method looks most useful to me - I
get easily lost in multiple lambda's!.

David

Oscar Benjamin

읽지 않음,
2022. 1. 6. 오후 5:20:0022. 1. 6.
받는사람 sympy
On Thu, 6 Jan 2022 at 21:23, David Bailey <da...@dbailey.co.uk> wrote:
>
> On 06/01/2022 16:41, Oscar Benjamin wrote:
> > You can use replace to make arbitrary conditions on substitution.
> > There are different syntaxes so here's how you do it using wild
> > pattern-matching:
> >
> > In [15]: expr = (a*x**14 + b*x + c)
> >
> > In [16]: expr
> > Out[16]:
> > 14
> > a⋅x + b⋅x + c
> >
> > In [17]: w = Wild('w')
> >
> > In [18]: expr.replace(x**w, lambda w: y**(w/2) if w.is_even else x**w)
> > Out[18]:
> > 7
> > a⋅y + b⋅x + c
> >
> > Here's how you do it with just functions:
> >
> > In [19]: query = lambda e: e.is_Pow and e.base == x and e.exp.is_even
> >
> > In [20]: replacer = lambda e: y**(e.exp/2)
> >
> > In [21]: expr.replace(query, replacer)
> > Out[21]:
> > 7
> > a⋅y + b⋅x + c
> >
> > Since query and replacer can be completely arbitrary functions any
> > kind of replacement rule can be implemented in this way.
> >
> Thanks very much for that Oscar, your solution looks extremely useful
> and general. Somehow I hadn't realised the power of Wild(), although I
> knew Wild existed. The Wild/replace method looks most useful to me - I
> get easily lost in multiple lambda's!.

The lambdas can get confusing. The point to note though is that a
lambda function is just a shorthand for creating a Python function
e.g.

f = lambda e: e.is_Pow

is equivalent to

def f(e):
return e.is_Pow

What that means is that in the functional form of replace you can pass
completely arbitrary functions for the query and the replacer. The
query function is given a subexpression as query(e) and returns True
or False to determine if a replacement should be made. If query(e)
returns True then replacer(e) generates the replacement expression so
if f and g are functions then

expr.replace(f, g)

looks at all subexpressions e in expr and if f(e) is True then e is
replaced by g(e). That's about as general as you can get for
replacements. In the Wild form the query function is replaced by a
pattern so it looks more like pattern-matching. The pattern is easier
to read but pattern matching is strictly less powerful than being able
to use a completely arbitrary query function.

The pattern form is especially nice if you use a pattern for both
query and replacement e.g.:

In [1]: w = Wild('w')

In [2]: (sin(x)**2 + tan(x)).replace(sin(w), exp(w))
Out[2]:
2⋅x
ℯ + tan(x)

--
Oscar

David Bailey

읽지 않음,
2022. 1. 6. 오후 7:05:5522. 1. 6.
받는사람 sy...@googlegroups.com
Thanks again, Oscar for that second helping of insight into how to use Wild!

If only you could be cloned about 6 times, a couple of your copies could
create some SymPy documentation that would sparkle with gems like this.

David

전체답장
작성자에게 답글
전달
새 메시지 0개