Ask Your Question

Why is math.exp or math.sin used?

asked 2017-05-18 23:03:34 -0500

cybervigilante gravatar image

I saw a small function that used math.

def f(x,y): return math.exp(x/5)*math.sin(y)

I removed math. from the terms and it worked just the same. What is the purpose of math. ?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-05-19 01:52:11 -0500

tmonteil gravatar image

updated 2017-05-19 01:52:40 -0500

When you write:

sage: math.exp(2)

you rely on the exp function provided by Python math numerical library.

When you write:

sage: exp(2)

you rely on the Sage exp function, which by default returns a symbolic expressions. Tou can get its numerical value (with arbitrary precision) as:

sage: exp(2).n()
sage: exp(2).n(digits=100)
edit flag offensive delete link more


I assume the Python library is faster for basic numerical work? But emphasis on the arbitrary precision!!!

kcrisman gravatar imagekcrisman ( 2017-05-19 06:05:42 -0500 )edit

yes, and for performance aspects there are technical remarks and neat comparisons in this thread.

mforets gravatar imagemforets ( 2017-05-20 13:49:11 -0500 )edit

Your Answer

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

Add Answer

Question Tools

1 follower


Asked: 2017-05-18 23:03:34 -0500

Seen: 29 times

Last updated: May 19