sage: # This worksheet was developed in the first lecture of Spring 2016. sage: # It is modified to prepare for Spring 2017. The most important change sage: # is the introduction of pi.n(digits=20) which is the quickest way to sage: # evaluate the decimal expansion of a symbolic constant such as pi. sage: # Sage knows the symbol pi sage: pi sage: sin(pi) 0 sage: # we can ask to see an approximation of pi sage: print float(pi) 3.14159265359 sage: # as in Python, every symbol has a type sage: type(pi) sage: # We are not limited by the hardware machine arithmetic. sage: pi20 = pi.n(digits=20) sage: print pi20 sage: print sin(pi20) sage: print type(pi20) 3.1415926535897932385 6.5640070857470010853e-22 sage: # we can make a plot of a sine function sage: plot(sin,(-pi,+pi)) sage: # let us make a more interesting plot sage: var('x') sage: plot(exp(-x^2)*sin(8*x),(-pi,pi)) sage: # Sage consists of many systems, in the command below we save the command as a string sage: # and then execute the command with the eval. sage: # The argument to RealField is the number of bits. sage: # For the number of decimal places (in our decimal number system), sage: # we multiply with the logarithm of 10. sage: # Suppose we wish to see pi with 30 decimal places sage: cmd = 'RealField(30*log(10))(pi)' sage: print eval(cmd) 3.1415926535897932385 sage: # to see which system executed the command sage: from sage.misc.citation import get_systems sage: get_systems(cmd) ['MPFI', 'MPFR', 'ginac'] sage: # to see the dictionary of systems Sage recognizes: sage: print sage.misc.citation.systems.keys() ['Mathematica', 'M4RI', 'PARI', 'Frobby', 'MuPAD', 'mwrank', 'Axiom', 'LiE', 'Macaulay2', 'MPFI', 'Singular', 'ECM', 'Linbox', 'GAP', 'FLINT', 'matlab', 'Octave', 'povray', 'numpy', 'MPFR', 'qsieve', 'ginac', 'gfan', 'scipy', 'KASH', 'GMP', 'Maxima', 'Symmetrica', 'PolyBoRi', 'Tachyon', 'Magma', 'R', 'NTL', 'Givaro', 'Maple'] sage: # to prepare for the last exercise: sage: from sage.misc.citation import get_systems sage: get_systems('pi.n(digits=20)') ['MPFR', 'ginac']