Besides the pure python options pointed above, if your list is filled by
symbolic expressions, you can also turn it into a vector and do the
substitutions straightforwardly.
Given
x = list(var('x', n=10))
ep = list(var('epsilon', n=10))
a random sublist
my_list = [x[randint(0,8)] for _ in
That's a python question. See for instance,
https://stackoverflow.com/questions/2582138/finding-and-replacing-elements-in-a-list
If you scroll down, there are some suggestions there that deal with
multiple replacements as well
On Tuesday, 28 December 2021 at 06:09:35 UTC-8 cyrille piatecki
On Thursday, May 28, 2009 at 9:31:46 PM UTC+5:30, Jason Grout wrote:
Mike Hansen wrote:
> Hello,
>
> On Thu, May 28, 2009 at 8:38 AM, Paul Sargent wrote:
>> # Subs for lambda (have to use "lambda", but that's a keyword)
lambda is a reserved keyword in Python, which
On Wednesday, September 16, 2015 at 1:54:40 AM UTC-7, Mandeep Singh wrote:
>
> Can we declare lambda as a variable? I want to use it in eigenvalues
> (linear algebra).
> like:
> l = var("lambda");
> It'll give error. So how can I declare it as a variable.
>
This works. I don't know if it will
Hi Bruno,
I am sorry that I (as author of the InfinitePolynomialRing stuff) did
not answer before.
On 2014-04-16, BJ brunojo...@gmail.com wrote:
The output looks something like this:
[-e_8 + e_4^2, -e_10 + e_6*e_4, -1382*e_12 + 2205*e_8*e_4 + 500*e_6^2 -
1323*e_4^3, -10*e_14 + 21*e_10*e_4 +
On Wednesday, April 16, 2014 4:16:30 PM UTC-7, BJ wrote:
I have the following code, which produces a list of polynomials in the
infinite number of variables e_0, e_1, ...
M.e = InfinitePolynomialRing(QQ, implementation=sparse)
However, I've been having a lot of trouble figuring out how
On Thursday, April 17, 2014 9:39:09 AM UTC-7, Nils Bruin wrote:
but it's flawed:
sage: f(e_4=2)
KeyError: 'e_4'
And also flawed in a different way:
sage: f(e_2=e[4])
TypeError: unsupported operand parent(s) for '+': 'Multivariate Polynomial
Ring in e_4, e_2, e_1 over Rational Field' and
On 01/09/2013 09:27 AM, Michael Beeson wrote:
sage: K.d,e,p,g,m,f,u,v,j,N =
FractionField(PolynomialRing(QQ,10,'depgmfuvjN'))
sage: R.s = K[]
sage: w=u
sage: u=0
sage: w
u
Why doesn't Sage answer 0 for the value of w here? More generally, if I
have some complicated expression and I assign a
Your first line defines a function field of several variables and
assigns values to the identifiers d,p,e, etc so that in particular, u
is assigned a value which is the 6th generator of that field. When
you set w=u you have a new identifier called w whose value is a copy
of u's value, so is also
Hi Burcin,
On Jan 25, 4:41 pm, Burcin Erocal bur...@erocal.org wrote:
...
In your example, (k1 + k2) is not a subexpression of f, so there is
nothing to substitute.
In other words, (k1+k2)*2 is automatically turned into 2*k1+2*k2, but
(k1+k2)^2 is not turned into k1^2+2*k1*k2+k2^2 ?
Why?
Thanks. Unfortunately, for my particular example, it didn't work as is
--
| Sage Version 4.2, Release Date: 2009-10-24 |
| Type notebook() for the GUI, and license() for information.|
This simple minded approach seems to work for me:
sage: a(x)=2*x
sage: b(x)=a(x)^2
sage: g(x)=diff(b(x),x)
sage: g(2)
16
-Alasdair
On Jan 21, 2:14 am, Stochastix laurent.decreusef...@gmail.com wrote:
I have the following problem : I have two nested functions
a=lambda x: 2*x
b=lambda x:
Hi,
I think what Minh was trying to say is that these lines:
Stochastix wrote:
sage: a=lambda x: alpha*x-mu1+mu2
sage: f=lambda x: (a(x)*b-c+sqrt((a(x)*b-c)^2+4.0*a(x)*b*r*mu1))/(2*a
(x)*mu1)
sage: g=lambda x: (r+l-mu1*f(x))/mu2
sage: prev=lambda x: f(x)/(f(x)+g(x))
sage: k=lambda x:
Stochastix wrote:
I have the following problem : I have two nested functions
a=lambda x: 2*x
b=lambda x: a(x)^2
Everything goes well as long as I want to compute the derivative of b
but how can I evaluate this derivative at x=2.
I tried
g=lambda x: diff(b(x),x)
g(x) returns 8*x as expected
On Wed, 7 Oct 2009 13:20:30 -0700 (PDT)
ma...@mendelu.cz ma...@mendelu.cz wrote:
BTW: When looked at this problem, the notation D[0](alpha)(r)^2 seems
to be unusual to me.
Is it possible to fix sage so that it prints derivatives of functions
in one variable
as usual: alpha'(r) ?
There is
Sorry I should make my question clearer. I'm not trying to substitute
for sigma^2. What I want to do is replace the various constants
multiplying the terms in sigma with a single constant. For example I
get the following term in sigma^2:
-1/2*(1/R^2 - beta_0/(R^2*beta))*sigma(r)^2
And I want
perhaps, no subst is necessary:
var('r beta beta_0 R a h')
psi=function('psi',r)
sigma=function('sigma',r)
H_0=function('H_0',r)
H_grad = lambda psi : (1/2)*(beta/beta_0)*R^2*(psi.diff(r))^2
H_0(psi) = -(1/2)*(beta/beta_0-1)*psi^2 + beta*a*psi^4 + beta*h*psi
Ranjit a écrit :
I'm trying to figure out how to do a simple substitution. I've the
following code:
var('r beta beta_0 R a h')
psi=function('psi',r)
sigma=function('sigma',r)
H_0=function('H_0',r)
H_grad = lambda psi : (1/2)*(beta/beta_0)*R^2*(psi.diff(r))^2
H_0(psi) =
This works, though it would have been nicer if epsilon actually
equalled what it was replacing. I just tried
(-1/2*(1/R^2 - beta_0/(R^2*beta))*sigma(r)^2).subs((1/R^2 - beta_0/
(R^2*beta))==epsilon)
which works, where
(-1/2*(1/R^2 - beta_0/(R^2*beta))*sigma(r)^2).subs((1/2)*(1/R^2 -
On 8 říj, 19:41, Ranjit rjcha...@gmail.com wrote:
does not. So I guess there's an upper limit to the number of
operations that the expression being replaced can have to work in subs
().
Perhaps true, but IMHO very risky guess which is not true, if pattern
matching in Maxima is behind the
On 7 říj, 16:21, Ranjit rjcha...@gmail.com wrote:
I'm trying to figure out how to do a simple substitution. I've the
following code:
var('r beta beta_0 R a h')
psi=function('psi',r)
sigma=function('sigma',r)
H_0=function('H_0',r)
H_grad = lambda psi :
Mike Hansen wrote:
Hello,
On Thu, May 28, 2009 at 8:38 AM, Paul Sargent psa...@gmail.com wrote:
# Subs for lambda (have to use lambda, but that's a keyword)
sage: e1.subs(lambda = 3)
File ipython console, line 1
Not sure if this is what you are after, but the following would give you
the solution:
sage: solve([e1,e2],c,a)
[[c == (d - b*e)/e, a == d/e]]
You can give n equations to solve and solve for n variables. Solve will
insert one into another automatically.
An equation has a different syntax to a
Hello,
On Fri, May 15, 2009 at 5:06 AM, Paul Sargent psa...@gmail.com wrote:
Lets give ourselves two symbolic equations:
sage: var(a b c d e)
sage: e1 = a == b + c
sage: e2 = d == e * a
Now, lets say I want to know what c is in terms of b, d e. By hand
I'd substitute e1 in e2, and then
On 15 May 2009, at 16:33, Mike Hansen wrote:
In Sage 4.0 which will be released within the week, you'll be able to
do the following:
sage: var(a b c d e)
(a, b, c, d, e)
sage: e1 = a == b + c
sage: e2 = d == e * a
sage: e3 = e2.subs(e1); e3
d == (b + c)*e
Well, that's what I call
On Mar 30, 6:07 pm, Jason Grout jason-s...@creativetrax.com wrote:
V wrote:
Hi,
I'm fairly new to sage with some background in maxima.
My workbook is shared at
http://www.sagenb.org/home/pub/410/
the last three lines show the error I get.
Basically, I derive an equilibrium
V wrote:
On Mar 30, 6:07 pm, Jason Grout jason-s...@creativetrax.com wrote:
V wrote:
Hi,
I'm fairly new to sage with some background in maxima.
My workbook is shared at
http://www.sagenb.org/home/pub/410/
the last three lines show the error I get.
Basically, I derive an equilibrium
This is exactly what I wanted. Thanks for your help! :)
I'll look up the maxima manuals to see if I can force it to think
harder. Thanks anyway!
Have a nice day!
V
On Mar 31, 3:35 pm, Jason Grout jason-s...@creativetrax.com wrote:
V wrote:
On Mar 30, 6:07 pm, Jason Grout
V wrote:
Hi,
I'm fairly new to sage with some background in maxima.
My workbook is shared at
http://www.sagenb.org/home/pub/410/
the last three lines show the error I get.
Basically, I derive an equilibrium condition that I would like to use
in the previous stage of my game
Hi,
On Fri, Mar 13, 2009 at 7:09 PM, hpon peter.norli...@gmail.com wrote:
Hi,
What is the easiest way to make a mathematical substitution in Sage?
For example: We have
eqn1 = F == a + b
I'm not sure I understand what you are trying to do in this line. If you
just want to define F as
Excellent. Thank you Alex!
/hpon
On 13 Mar, 09:16, Alex Ghitza aghi...@gmail.com wrote:
Hi,
On Fri, Mar 13, 2009 at 7:09 PM, hpon peter.norli...@gmail.com wrote:
Hi,
What is the easiest way to make a mathematical substitution in Sage?
For example: We have
eqn1 = F == a + b
One of the issues right now is that sage's piecewise is a completely
separate class then the rest of the calculus library. I think it
should descend from symbolic expression and be on the same level as,
e.g. sin and addition (and probably even have a pynac counterpart).
Letting the operands
On Nov 24, 2008, at 5:04 AM, Ondrej Certik wrote:
On Mon, Nov 24, 2008 at 1:25 PM, David Joyner [EMAIL PROTECTED]
wrote:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED]
wrote:
Hi,
when I use regular expressions, I can use .subs():
sage: e = x+y
sage: e.subs(x=y)
On Tue, Nov 25, 2008 at 3:15 AM, Ondrej Certik [EMAIL PROTECTED] wrote:
One of the issues right now is that sage's piecewise is a completely
separate class then the rest of the calculus library. I think it
Just for the record, this is because Piecewise was implemented long
long ago by David
On Tue, Nov 25, 2008 at 3:13 PM, William Stein [EMAIL PROTECTED] wrote:
On Tue, Nov 25, 2008 at 3:15 AM, Ondrej Certik [EMAIL PROTECTED] wrote:
One of the issues right now is that sage's piecewise is a completely
separate class then the rest of the calculus library. I think it
Just for the
On Tue, 25 Nov 2008 12:15:41 +0100
Ondrej Certik [EMAIL PROTECTED] wrote:
One of the issues right now is that sage's piecewise is a completely
separate class then the rest of the calculus library. I think it
should descend from symbolic expression and be on the same level as,
e.g. sin
On Tue, Nov 25, 2008 at 11:00 PM, Burcin Erocal [EMAIL PROTECTED] wrote:
On Tue, 25 Nov 2008 12:15:41 +0100
Ondrej Certik [EMAIL PROTECTED] wrote:
One of the issues right now is that sage's piecewise is a completely
separate class then the rest of the calculus library. I think it
On Mon, 24 Nov 2008 12:19:55 +0100
Ondrej Certik [EMAIL PROTECTED] wrote:
Hi,
when I use regular expressions, I can use .subs():
sage: e = x+y
sage: e.subs(x=y)
2*y
but not with Piecewise:
sage: var(h H x y)
(h, H, x, y)
sage: u = Piecewise([((0, h), x/h), ((h, H), 1)])
sage:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED] wrote:
Hi,
when I use regular expressions, I can use .subs():
sage: e = x+y
sage: e.subs(x=y)
2*y
but not with Piecewise:
sage: var(h H x y)
(h, H, x, y)
sage: u = Piecewise([((0, h), x/h), ((h, H), 1)])
I don't think
On Mon, Nov 24, 2008 at 7:25 AM, David Joyner [EMAIL PROTECTED] wrote:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED] wrote:
Hi,
when I use regular expressions, I can use .subs():
sage: e = x+y
sage: e.subs(x=y)
2*y
but not with Piecewise:
sage: var(h H x y)
(h, H,
On Mon, Nov 24, 2008 at 1:25 PM, David Joyner [EMAIL PROTECTED] wrote:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED] wrote:
Hi,
when I use regular expressions, I can use .subs():
sage: e = x+y
sage: e.subs(x=y)
2*y
but not with Piecewise:
sage: var(h H x y)
(h, H,
On Mon, Nov 24, 2008 at 2:15 PM, David Joyner [EMAIL PROTECTED] wrote:
On Mon, Nov 24, 2008 at 7:25 AM, David Joyner [EMAIL PROTECTED] wrote:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED] wrote:
Hi,
when I use regular expressions, I can use .subs():
sage: e = x+y
sage:
On Mon, 24 Nov 2008 14:04:53 +0100
Ondrej Certik [EMAIL PROTECTED] wrote:
On Mon, Nov 24, 2008 at 1:25 PM, David Joyner [EMAIL PROTECTED]
wrote:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED]
wrote:
Hi,
when I use regular expressions, I can use .subs():
sage:
On Mon, Nov 24, 2008 at 3:08 PM, Burcin Erocal [EMAIL PROTECTED] wrote:
On Mon, 24 Nov 2008 14:04:53 +0100
Ondrej Certik [EMAIL PROTECTED] wrote:
On Mon, Nov 24, 2008 at 1:25 PM, David Joyner [EMAIL PROTECTED]
wrote:
On Mon, Nov 24, 2008 at 6:19 AM, Ondrej Certik [EMAIL PROTECTED]
William Stein [EMAIL PROTECTED] writes:
On 7/26/07, Roger Mason [EMAIL PROTECTED] wrote:
You should do m.substitute(a=1) just like you're doing -- unfortunately,
nobody implemented that yet, and it's doing some dumb generic behavior.
[...]
Fortunately, I just implemented this for
David William,
David Joyner [EMAIL PROTECTED] writes:
I would use the lambda notation:
sage: m = lambda x: matrix([[x[0],x[1]],[x[2],x[3]]])
sage: m([1,2,3,4])
[1 2]
[3 4]
sage: m([1,2,3,a])
[1 2]
[3 a]
sage: m([a,b,3,4])
[a b]
[3 4]
There might be better ways though.
On 7/26/07, Roger Mason [EMAIL PROTECTED] wrote:
You should do m.substitute(a=1) just like you're doing -- unfortunately,
nobody implemented that yet, and it's doing some dumb generic behavior.
[...]
Fortunately, I just implemented this for SAGE-2.7.1, which I'll release very
very soon.
I would use the lambda notation:
sage: m = lambda x: matrix([[x[0],x[1]],[x[2],x[3]]])
sage: m([1,2,3,4])
[1 2]
[3 4]
sage: m([1,2,3,a])
[1 2]
[3 a]
sage: m([a,b,3,4])
[a b]
[3 4]
There might be better ways though.
On 7/24/07, Roger Mason [EMAIL
48 matches
Mail list logo