# How to Assign value to a symbolic function?

I have the little program:

P = function('P')
x,y = var('x y')
def S(x):
return sum(P(x,y),y,0,1)
S(x)


It returns:

P(x, 1) + P(x, 0)

Now, any idea on how to assign particular values to P(x,y) and return S(x) accordingly?

edit retag close merge delete

Sort by ยป oldest newest most voted

Just an alternative:

sage: P = function('P')
sage: x,y = var('x,y')
sage: S(x) = sum(P(x,y),y,0,1)
sage: S(2)
P(2, 0) + P(2, 1)

more

I want to be able to assign a specific value to P(2,0) and to P(2,1) For instance I would like to be able to set the values: P(2,0)=100 and P(2,1)=100

( 2019-12-13 20:00:44 -0500 )edit

Try:

x.subs?
x.sugstitute_function?


Seasonings to taste...

more

I am not able to use subs. But yes I would like something as:

P=function('P')
x,y=var('x y')

def S(x):
return sum(P(x,y),y,0,1)

P(0,1)=100
P(0,0)=100

S(0)

( 2019-12-13 20:01:36 -0500 )edit

Why can't you use subs? This works:

sage: S(0).subs({P(0,1):100,P(0,0):100})
200

( 2019-12-15 17:22:07 -0500 )edit