Ask Your Question

Revision history [back]

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