Ask Your Question

# Prevent sage from calculating a function?

So I have some code where I would like to formally plug in a number value into a symbolic function without having sage calculate it.

For example, if I have;

var(x)
f(x) = x^2
c = 2


And then I put in f(c), I'd like it to return 2^2 and not 4. I imagine there must be a way to do this, but I can't seem to find it with googling. Any suggestions would be appreciated.

edit retag close merge delete

## 1 Answer

Sort by ยป oldest newest most voted

In Sage, what you want is called "holding" the operation.

Find more about it by searching the word "hold" on this page:

http://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/expression.html


For example, compare the abs operation, without holding or with holding:

sage: SR(-5).abs()
5
sage: SR(-5).abs(hold=True)
abs(-5)


However, the hold context is not implemented for all operations.

In your case, I would use the string representation for f(x) and replace x by 2:

sage: f(x) = x^2
sage: print str(f(x)).replace('x', '2')
2^2

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2015-12-23 19:15:59 +0200

Seen: 186 times

Last updated: Dec 28 '15