For example, I want to see exactly how the function math.sin(x) is defined.
I have tried inspect.getsource however this does not seem to work for the math module.
Videos
It depends on the implementation. CPython is using math functions from the standard C library. Jython is most likely using Java's math methods. And so on.
In fact, Python has nothing to do with the actual implementation of math functions. Those are more related to IEEE 754 which is used almost exclusively to represent floating point numbers in computers nowadays.
Anyway, speaking in terms of CPython, its math module is just a thin wrapper over C functions (prooflink, at the bottom of the page). The C functions are implemented as part of the standard C library. It is usually included in OS distributions and it is most likely distributed in binary form, without sources. Note also that many microprocessors have specialised instructions for some of these operations, and your compiler may well make use of those rather than jumping to the implementation in the C library.
I can't tell you the exact algorithm which is used in the standard C library on your system. Some of the possible algorithms are explained here.
In the specific case of OS X, the math functions live in libSystem.dylib, which unfortunately is not Open Source (there is only stub code available on Apple's Open Source site). You can however disassemble it if you are interested - on current systems, try e.g.
otool -tvV /usr/lib/system/libsystem_m.dylib
Some modules are written in C and not in python so you wouldn't be able to find the .py files. For a list of these you can use:
import sys
print sys.builtin_module_names
Since it's written in C you will have to find it in the source code. If you have the source already it's in the modules directory.
The math and sys modules are builtins -- for purposes of speed, they're written in C and are directly incorporated into the Python interpreter.
To get a full list of all builtins, you can run:
Copy>>> import sys
>>> sys.builtin_module_names
On my machine, that results in the following list:
Copy__builtin__
__main__
_ast
_bisect
_codecs
_codecs_cn
_codecs_hk
_codecs_iso2022
_codecs_jp
_codecs_kr
_codecs_tw
_collections
_csv
_functools
_heapq
_hotshot
_io
_json
_locale
_lsprof
_md5
_multibytecodec
_random
_sha
_sha256
_sha512
_sre
_struct
_subprocess
_symtable
_warnings
_weakref
_winreg
array
audioop
binascii
cPickle
cStringIO
cmath
datetime
errno
exceptions
future_builtins
gc
imageop
imp
itertools
marshal
math
mmap
msvcrt
nt
operator
parser
signal
strop
sys
thread
time
xxsubtype
zipimport
zlib
These modules are not written in Python but in C.
You can find them (at least on linux) in a subfolder of the lib-folder called lib-dynload.
The math module is then in a file math.cpython-33m.so (on windows probably with .dll instead of .so). The cpython-33m part is my python version (3.3).