# Revision history [back]

### can you programmatically define a function?

I want to take an array of coefficients and turn that into a function, a math function not a python function. for example take

[2, 0, 2, 7]


and turn this into

$$f(x) = 2x^3 + 2x + 7$$

something like

def createSym(coefficients, degree, x):
symbolicEqn = ''
for i in poly:
symbolicEqn += ' + (x**deg)*i'
deg -= 1
return symbolicEqn
pass


then call my definition in the script like

x = var('x')
coeffArray =  [2, 0, 2, 7]
degree = 3
polynomialEqn = createSym(coeffArray, degree, x)


But symbolicEqn is just a string and not an expression. Is there a sage/python way to do this?

### can you programmatically define a function?

I want to take an array of coefficients and turn that into a function, a math function not a python function. for example take

[2, 0, 2, 7]


and turn this into

$$f(x) = 2x^3 + 2x + 7$$

something like

def createSym(coefficients, degree, x):
symbolicEqn = ''
for i in poly:
symbolicEqn += ' + (x**deg)*i'
deg -= 1
return symbolicEqn
pass


then call my definition in the script like

x = var('x')
coeffArray =  [2, 0, 2, 7]
degree = 3
polynomialEqn = createSym(coeffArray, degree, x)


But symbolicEqn is just a string and not an expression. Is there a sage/python way to do this?

### can you programmatically define a (mathematical) function?

I want to take an array of coefficients and turn that into a function, a math function not a python function. for example take

[2, 0, 2, 7]


and turn this into

$$f(x) = 2x^3 + 2x + 7$$

something like

def createSym(coefficients, degree, x):
symbolicEqn = ''
for i in poly:
symbolicEqn += ' + (x**deg)*i'
deg -= 1
return symbolicEqn
pass


then call my definition in the script like

x = var('x')
coeffArray =  [2, 0, 2, 7]
degree = 3
polynomialEqn = createSym(coeffArray, degree, x)


But symbolicEqn is just a string and not an expression. Is there a sage/python way to do this?

### can you programmatically define a (mathematical) [mathematical] function?

I want to take an array of coefficients and turn that into a function, a math function not a python function. for example take

[2, 0, 2, 7]


and turn this into

$$f(x) = 2x^3 + 2x + 7$$

something like

def createSym(coefficients, degree, x):
symbolicEqn = ''
for i in poly:
symbolicEqn += ' + (x**deg)*i'
', (x**deg)*i
deg -= 1
return symbolicEqn
pass


then call my definition in the script like

x = var('x')
coeffArray =  [2, 0, 2, 7]
degree = 3
polynomialEqn = createSym(coeffArray, degree, x)


But symbolicEqn is just a string and not an expression. Is there a sage/python way to do this?