The official Sage website offers many resources:
1+1
(1 + 2*(3 + 5))*2
2^3
2**3 # Python 3
20/6 # not 3.333333
2^10
2^100
2^1000
20.0 / 14
numerical_approx(20/14)
numerical_approx(2^1000)
N(20/14)
n(20/14) # function f(x, option)
(20/14).n() # method x.f(option)
N(20/14, digits=60)
(20/14).n(digits=60)
20 // 6 # quotient
20 % 6 # remainder
factorial(100)
factor(2^(2^5)+1)
sin(pi)
tan(pi/3)
arctan(1)
exp(2 * I * pi)
e^(2 * i * pi)
arccos(sin(pi/3))
sqrt(2)
exp(I*pi/7)
euler_gamma.n() # Euler-Mascheroni constant gamma
(golden_ratio).simplify() # golden ratio phi = (1 + sqrt(5))/2
catalan.n() # Catalan’s constant
simplify(arccos(sin(pi/3)))
6*arccos(sin(pi/3)).n(digits=60)
sqrt(2).n(digits=60)
sin?
arc<tab>
Possible completions are:
arc arccos arccosh arccot arccoth arccsc arccsch
arcsec arcsech arcsin arcsinh arctan arctan2 arctanh
arc
y = 1 + 2
y
(2 + y) * y
y = 1 + 2; y
y = 3 * y + 1; y
y = 3 * y + 1; y
y = 3 * y + 1; y
1 + 1
_ + 1
__
pi = -I/2
exp(2*I*pi) # pi = -I/2, pi is not 3.1415...
from sage.all import pi
exp(2*I*pi)
restore() # restores to their default value all predefined variables and functions.
reset() # clear ALL default values and user-defined variables.
z = SR.var('z') # SR stands for Symbolic Ring
2*z + 3
y = SR.var('z')
2*y + 3
c = 2 * y + 3
z = 1 # Python variable z is 1.
2*y + 3
c
Except the symbolic variable x, which is predefined in Sage.
x = SR.var('x') # Don't need it
expr = sin(x); expr
expr(x=1) # substitution
u = SR.var('u')
u = u+1
u = u+1
u
x = SR.var('x', 10)
x
(x[0] + x[1])*x[9]
var('a, b, c, x, y') # var is a conventient alternative for SR.var
a * x + b * y + c
plot(sin(2*x), x, -pi, pi)
plot3d( sin(pi*sqrt(x^2 + y^2))/sqrt(x^2+y^2),
(x,-5,5), (y,-5,5) )
for j in [11, 14..79]:
print(j, end = ", ")
for j in [11, 14..79]:
if j % 5 == 0:
print()
print(j, end = ", ")
for j in [11, 14..79]:
if j % 5 == 0:
pass
print(j, end = ", ")
for j in [11, 14..79]:
if j % 5 == 0:
continue
print(j, end = ", ")
for j in [11, 14..79]:
if j % 5 == 0:
break
print(j, end = ", ")
N = 100
C = [i*j for i in [2..N] for j in [2..N]] # composite numbers
P = [p for p in [2..N] if p not in C] # prime numbers
print(P)