2^{38} \cdot 3^{18} \cdot 5^{9} \cdot 7^{5} \cdot 11^{3} \cdot 13^{3} \cdot 17^{2} \cdot 19^{2} \cdot 23 \cdot 29 \cdot 31 \cdot 37
r U# Worksheet 'talk' (2007-01-16 at 03:53)
sage: %sagex
sage: def is2pow(unsigned int n):
... while n != 0 and n%2 == 0:
... n = n >> 1
... return n == 1
r U# Worksheet 'talk' (2007-01-16 at 03:53)
sage: time v = [n for n in range(10^5) if is2pow(n)]
CPU time: 0.04 s, Wall time: 0.07 sr U# Worksheet 'talk' (2007-01-16 at 03:54)
sage: def is2pow(n):
... while n != 0 and n%2 == 0:
... n = n >> 1
... return n == 1
r U# Worksheet 'talk' (2007-01-16 at 03:54)
sage: %sagex
sage: def is2pow_compiled(unsigned int n):
... while n != 0 and n%2 == 0:
... n = n >> 1
... return n == 1
r U# Worksheet 'talk' (2007-01-16 at 03:54)
sage: time v = [n for n in range(10^5) if is2pow(n)]
CPU time: 3.39 s, Wall time: 4.54 sr U# Worksheet 'talk' (2007-01-16 at 03:54)
sage: time v = [n for n in range(10^5) if is2pow_compiled(n)]
CPU time: 0.04 s, Wall time: 0.04 sr U# Worksheet 'talk' (2007-01-16 at 03:55)
sage: v
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]r U# Worksheet 'talk' (2007-01-16 at 03:55)
sage: time v = [n for n in range(10^5) if is2pow_compiled(n)]; v
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
CPU time: 0.04 s, Wall time: 0.05 sr U# Worksheet 'talk' (2007-01-16 at 03:55)
sage: time v = [n for n in range(10^5) if is2pow(n)]; v
[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536]
CPU time: 3.29 s, Wall time: 3.39 sr UA# Worksheet 'talk' (2007-01-16 at 03:56)
sage: a = gp('2+3'); a
5r UA# Worksheet 'talk' (2007-01-16 at 03:56)
sage: a = gp('2+3'); a
5r U6# Worksheet 'talk' (2007-01-16 at 03:57)
sage: a^3
125r U]# Worksheet 'talk' (2007-01-16 at 03:57)
sage: type(a)
r U6# Worksheet 'talk' (2007-01-16 at 04:03)
sage: 2 + 2
4r U[# Worksheet 'talk' (2007-01-16 at 04:03)
sage: prime_range(20)
[2, 3, 5, 7, 11, 13, 17, 19]r U6# Worksheet 'talk' (2007-01-16 at 04:03)
sage: 2 ^ 3
8r UD# Worksheet 'talk' (2007-01-16 at 04:03)
sage: %python
sage: 2 ^ 3
1r UP# Worksheet 'talk' (2007-01-16 at 04:03)
sage: factorial(20)
2432902008176640000r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: show(factor( factorial(40) ))
2^{38} \cdot 3^{18} \cdot 5^{9} \cdot 7^{5} \cdot 11^{3} \cdot 13^{3} \cdot 17^{2} \cdot 19^{2} \cdot 23 \cdot 29 \cdot 31 \cdot 37
r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: m = matrix(5,5, range(25)); m
[ 0 1 2 3 4]
[ 5 6 7 8 9]
[10 11 12 13 14]
[15 16 17 18 19]
[20 21 22 23 24]r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: f = m.charpoly(); show(f)
x^{5} - 60x^{4} - 250x^{3}
r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: show(factor(f))
(x^{2} - 60x - 250) \cdot x^{3}
r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: m = matrix(5,5, range(25)); show(m)
\left(\begin{array}{rrrrr}
0&1&2&3&4\\
5&6&7&8&9\\
10&11&12&13&14\\
15&16&17&18&19\\
20&21&22&23&24
\end{array}\right)
r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: f = m.charpoly('T'); show(f)
T^{5} - 60T^{4} - 250T^{3}
r U# Worksheet 'talk' (2007-01-16 at 04:03)
sage: show(factor(f))
(T^{2} - 60T - 250) \cdot T^{3}
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: m = matrix(5,5,[randint(10) for _ in range(25)]); show(m)
Traceback (most recent call last):
...
TypeError: randint() takes exactly 3 arguments (2 given)r T # Worksheet 'talk' (2007-01-16 at 04:04)
sage: m = matrix(5,5,[randint(-10,10) for _ in range(25)]); show(m)
\left(\begin{array}{rrrrr}
0&-7&-8&-6&7\\
-8&-8&0&-2&1\\
-2&-4&7&0&-6\\
5&8&-4&0&5\\
3&-3&2&0&7
\end{array}\right)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: f = m.charpoly('T'); show(f)
T^{5} - 6T^{4} - 95T^{3} + 497T^{2} + 589T - 12256
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: show(factor(f))
(T^{5} - 6T^{4} - 95T^{3} + 497T^{2} + 589T - 12256)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)
\left(\begin{array}{rrrrr}
0&1&1&1&1\\
1&1&0&0&1\\
0&0&0&0&1\\
0&0&0&0&0\\
0&0&1&1&0
\end{array}\right)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: f = m.charpoly('T'); show(f)
T^{5} - T^{4} - 2T^{3} + T^{2} + T
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: show(factor(f))
(T - 1) \cdot T \cdot (T + 1) \cdot (T^{2} - T - 1)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)
\left(\begin{array}{rrrrr}
1&0&0&1&0\\
0&1&0&0&1\\
1&0&0&0&1\\
1&1&1&0&0\\
0&1&1&1&0
\end{array}\right)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: f = m.charpoly('T'); show(f)
T^{5} - 2T^{4} - 2T^{3} + T^{2} + 5T - 2
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: show(factor(f))
(T^{5} - 2T^{4} - 2T^{3} + T^{2} + 5T - 2)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)
\left(\begin{array}{rrrrr}
0&0&1&0&0\\
1&0&0&1&1\\
0&1&1&1&1\\
0&0&0&1&1\\
0&1&1&0&0
\end{array}\right)
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: f = m.charpoly('T'); show(f)
T^{5} - 2T^{4} - T^{3} - T^{2}
r U# Worksheet 'talk' (2007-01-16 at 04:04)
sage: show(factor(f))
T^{2} \cdot (T^{3} - 2T^{2} - T - 1)
r U# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(a)
Traceback (most recent call last):
...
NameError: name 'a' is not definedr U# Worksheet 'interface' (2007-01-16 at 04:06)
sage: 5 + a
Traceback (most recent call last):
...
NameError: name 'a' is not definedr UF# Worksheet 'interface' (2007-01-16 at 04:06)
sage: a = gp('2+3'); a
5r U;# Worksheet 'interface' (2007-01-16 at 04:06)
sage: a^3
125r Ub# Worksheet 'interface' (2007-01-16 at 04:06)
sage: type(a)
r UQ# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(a)
GP/PARI interpreterr U<# Worksheet 'interface' (2007-01-16 at 04:06)
sage: 5 + a
10r US# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(5+a)
GP/PARI interpreterr UF# Worksheet 'interface' (2007-01-16 at 04:06)
sage: pari(5) + gp(5)
10r Uk# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(pari(5) + gp(5))
Interface to the PARI C libraryr US# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(5+a)
GP/PARI interpreterr UE# Worksheet 'interface' (2007-01-16 at 04:06)
sage: gap(5) + gp(5)
10r UN# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(gap(5) + gp(5))
Gapr U^# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(gp(5) + gap(5))
GP/PARI interpreterr UN# Worksheet 'interface' (2007-01-16 at 04:06)
sage: parent(gap(5) + gp(5))
Gapr UT# Worksheet 'interface' (2007-01-16 at 04:07)
sage: a = gp('x^3 - y^3'); a
x^3 - y^3r UY# Worksheet 'interface' (2007-01-16 at 04:07)
sage: a^3
x^9 - 3*y^3*x^6 + 3*y^6*x^3 - y^9r Ub# Worksheet 'interface' (2007-01-16 at 04:07)
sage: type(a)
r UQ# Worksheet 'interface' (2007-01-16 at 04:07)
sage: parent(a)
GP/PARI interpreterr T # Worksheet 'interface' (2007-01-16 at 04:07)
sage: a.factor()
Traceback (most recent call last):
...
TypeError: Error executing code in GP/PARI:
CODE:
sage[22]=factor(sage[20]);
GP/PARI ERROR:
*** factor: sorry, factor for general polynomials is not yet implemented.r U# Worksheet 'interface' (2007-01-16 at 04:07)
sage: sage_eval(a)
Traceback (most recent call last):
...
TypeError: source must be a string.r U# Worksheet 'interface' (2007-01-16 at 04:07)
sage: b = sage_eval(str(a)); b
Traceback (most recent call last):
...
NameError: name 'y' is not definedr U# Worksheet 'interface' (2007-01-16 at 04:07)
sage: R. = QQ[x,y]
sage: b = R(a)
Traceback (most recent call last):
...
TypeError: unable to convert x^3 - y^3 to a rationalr UZ# Worksheet 'interface' (2007-01-16 at 04:07)
sage: R. = QQ[x,y]
sage: b = R(str(a))
r U]# Worksheet 'interface' (2007-01-16 at 04:07)
sage: b.factor()
(-1*y + x) * (y^2 + x*y + x^2)r UH# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: show(sieve_step(1,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: show(sieve_step(2,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: show(sieve_step(3,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: show(sieve_step(5,100))
r
UH# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: show(sieve_step(7,100))
r UI# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: show(sieve_step(11,100))
r U# Worksheet 'sieve' (2007-01-16 at 04:09)
sage: s = [sieve_step(p,100) for p in [2,3,5,7]]
sage: G = graphics_array(s, 2,2)
sage: G.show(axes=False)
r
T # Worksheet 'sieve' (2007-01-16 at 04:10)
sage: %hideall
sage: #auto
sage:
sage: def number_grid(c, box_args={}, font_args={},offset=0):
... """
... INPUT:
... c -- list of length n^2, where n is an integer.
... The entries of c are RGB colors.
... box_args -- additional arguments passed to box.
... font_args -- all additional arguments are passed
... to the text function, e.g., fontsize.
... offset -- use to fine tune text placement in the squares
...
... OUTPUT:
... Graphics -- a plot of a grid that illustrates
... those n^2 numbers colored according to c.
... """
... try:
... n = square_root(ZZ(len(c)))
... except ArithmeticError:
... raise ArithmeticError, "c must have square length"
... G = Graphics()
... k = 0
... for j in reversed(range(n)):
... for i in range(n):
... col = c[int(k)]
... R = line([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], thickness=.2, **box_args)
... P = polygon([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], rgbcolor=col, **box_args)
... G += P + R
... if col != (1,1,1):
... G += text(str(k+1), (i+.5+offset,j+.5), **font_args)
... k += 1
... G.axes(False)
... G.range(0,n,0,n)
... return G
CPU time: 0.00 s, Wall time: 0.00 sr T # Worksheet 'sieve' (2007-01-16 at 04:10)
sage: %hideall
sage: #auto
sage:
sage: def number_grid(c, box_args={}, font_args={},offset=0):
... """
... INPUT:
... c -- list of length n^2, where n is an integer.
... The entries of c are RGB colors.
... box_args -- additional arguments passed to box.
... font_args -- all additional arguments are passed
... to the text function, e.g., fontsize.
... offset -- use to fine tune text placement in the squares
...
... OUTPUT:
... Graphics -- a plot of a grid that illustrates
... those n^2 numbers colored according to c.
... """
... try:
... n = square_root(ZZ(len(c)))
... except ArithmeticError:
... raise ArithmeticError, "c must have square length"
... G = Graphics()
... k = 0
... for j in reversed(range(n)):
... for i in range(n):
... col = c[int(k)]
... R = line([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], thickness=.2, **box_args)
... P = polygon([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], rgbcolor=col, **box_args)
... G += P + R
... if col != (1,1,1):
... G += text(str(k+1), (i+.5+offset,j+.5), **font_args)
... k += 1
... G.axes(False)
... G.range(0,n,0,n)
... return G
CPU time: 0.00 s, Wall time: 0.00 sr U# Worksheet 'sieve' (2007-01-16 at 04:10)
sage: show(sieve_step(1,100))
Traceback (most recent call last):
...
NameError: name 'sieve_step' is not definedr U# Worksheet 'sieve' (2007-01-16 at 04:10)
sage: show(sieve_step(2,100))
Traceback (most recent call last):
...
NameError: name 'sieve_step' is not definedr T # Worksheet 'sieve' (2007-01-16 at 04:11)
sage: %hideall
sage: #auto
sage:
sage: def number_grid(c, box_args={}, font_args={},offset=0):
... """
... INPUT:
... c -- list of length n^2, where n is an integer.
... The entries of c are RGB colors.
... box_args -- additional arguments passed to box.
... font_args -- all additional arguments are passed
... to the text function, e.g., fontsize.
... offset -- use to fine tune text placement in the squares
...
... OUTPUT:
... Graphics -- a plot of a grid that illustrates
... those n^2 numbers colored according to c.
... """
... try:
... n = square_root(ZZ(len(c)))
... except ArithmeticError:
... raise ArithmeticError, "c must have square length"
... G = Graphics()
... k = 0
... for j in reversed(range(n)):
... for i in range(n):
... col = c[int(k)]
... R = line([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], thickness=.2, **box_args)
... P = polygon([(i,j),(i+1,j),(i+1,j+1),(i,j+1),(i,j)], rgbcolor=col, **box_args)
... G += P + R
... if col != (1,1,1):
... G += text(str(k+1), (i+.5+offset,j+.5), **font_args)
... k += 1
... G.axes(False)
... G.range(0,n,0,n)
... return G
CPU time: 0.00 s, Wall time: 0.00 sr T # Worksheet 'sieve' (2007-01-16 at 04:11)
sage: %hideall
sage: #auto
sage:
sage: def sieve_step(p, n, gone=(1,1,1), prime=(1,0,0), \
... multiple=(.6,.6,.6), remaining=(.9,.9,.9),
... fontsize=11,offset=0):
... """
... Return graphics that illustrates sieving out
... multiples of p. Numbers that are a nontrivial
... multiple of primes < p are shown in the gone color.
... Numbers that are a multiple of p are shown in
... a different color. The number p is shown in
... yet a third color.
...
... INPUT:
... p -- a prime (or 1, in which case all points are colored "remaining")
... n -- a SQUARE integer
... gone -- rgb color for integers that have been sieved out
... prime -- rgb color for p
... multiple -- rgb color for multiples of p
... remaining -- rgb color for integers that have not been sieved out yet
... and are not multiples of p.
... """
... if p == 1:
... c = [remaining]*n
... else:
... exclude = prod(prime_range(p)) # exclude multiples of primes < p
... c = []
... for k in range(1,n+1):
... if k <= p and is_prime(k):
... c.append(prime)
... elif k == 1 or (gcd(k,exclude) != 1 and not is_prime(k)):
... c.append(gone)
... elif k%p == 0:
... c.append(multiple)
... else:
... c.append(remaining)
... # end for
... # end if
... return number_grid(c,{},{'fontsize':fontsize},offset=offset)
CPU time: 0.00 s, Wall time: 0.00 sr UH# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(1,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(2,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(3,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(5,100))
r UH# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(7,100))
r UI# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(11,100))
r U# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: s = [sieve_step(p,100) for p in [2,3,5,7]]
sage: G = graphics_array(s, 2,2)
sage: G.show(axes=False)
r US# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(2,400,fontsize=6))
r UT# Worksheet 'sieve' (2007-01-16 at 04:11)
sage: show(sieve_step(13,400,fontsize=6))
r U6# Worksheet 'talk' (2007-01-16 at 04:49)
sage: 2 + 2
4r U[# Worksheet 'talk' (2007-01-16 at 04:49)
sage: prime_range(20)
[2, 3, 5, 7, 11, 13, 17, 19]r U6# Worksheet 'talk' (2007-01-16 at 04:49)
sage: 2 ^ 3
8r UD# Worksheet 'talk' (2007-01-16 at 04:49)
sage: %python
sage: 2 ^ 3
1r UP# Worksheet 'talk' (2007-01-16 at 04:49)
sage: factorial(20)
2432902008176640000r! U# Worksheet 'talk' (2007-01-16 at 04:49)
sage: show(factor( factorial(40) ))
2^{38} \cdot 3^{18} \cdot 5^{9} \cdot 7^{5} \cdot 11^{3} \cdot 13^{3} \cdot 17^{2} \cdot 19^{2} \cdot 23 \cdot 29 \cdot 31 \cdot 37
r" U# Worksheet 'talk' (2007-01-16 at 04:49)
sage: m = matrix(5,5,[randint(0,1) for _ in range(25)]); show(m)
\left(\begin{array}{rrrrr}
1&0&1&0&0\\
1&0&1&0&1\\
0&0&0&1&0\\
1&0&1&0&0\\
1&0&1&1&1
\end{array}\right)
r# U# Worksheet 'talk' (2007-01-16 at 04:49)
sage: f = m.charpoly('T'); show(f)
T^{5} - 2T^{4} + T^{2}
r$ U# Worksheet 'talk' (2007-01-16 at 04:49)
sage: show(factor(f))
(T - 1) \cdot T^{2} \cdot (T^{2} - T - 1)
r% Ur# Worksheet 'features' (2007-01-16 at 04:49)
sage: show(plot(sin(x),-pi,6*pi,rgbcolor=(0.5,0,0.5)),figsize=[8,3])
r& T # Worksheet 'features' (2007-01-16 at 04:49)
sage: %hide
sage: t = Tachyon(xres=700, yres=500, camera_center=(2,7,4), look_at=(2,0,0), raydepth=4)
sage: t.light((10,3,2), 1, (1,1,1))
sage: t.light((10,-3,2), 1, (1,1,1))
sage: t.texture('black', color=(0,0,0))
sage: t.texture('red', color=(1,0,0))
sage: t.texture('grey', color=(.9,.9,.9))
sage: t.plane((0,0,0),(0,0,1),'grey')
sage: t.cylinder((0,0,0),(1,0,0),.01,'black')
sage: t.cylinder((0,0,0),(0,1,0),.01,'black')
sage: E = EllipticCurve('37a'); show(E)
sage: P = E([0,0])
sage: Q = P
sage: n = 60
sage: for i in range(n):
... Q = Q + P
... c = i/n + .1
... t.texture('r%s'%i,color=(float(i/n),0,0))
... t.sphere((Q[0], -Q[1], .01), .04, 'r%s'%i)
...
sage: show(t)
y^2 + y = x^3 - x
r' U# Worksheet 'riemann' (2007-01-16 at 04:51)
sage: #auto
sage: def f(x):
... return x / log(x)
...
sage: def p(x):
... return prime_pi(x)
r( T # Worksheet 'riemann' (2007-01-16 at 04:51)
sage: xmax = 20
sage: G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') + \
... plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') + \
... plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
...
sage: G.show(xmax=xmax)
r) T # Worksheet 'riemann' (2007-01-16 at 04:51)
sage: xmax = 500
sage: G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') + \
... plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') + \
... plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
...
sage: G.show(xmax=xmax)
r* T # Worksheet 'riemann' (2007-01-16 at 04:51)
sage: xmax = 20000
sage: G = plot(f, 2,xmax, linestyle='--', label='x/log(x)') + \
... plot(Li,2,xmax, plot_points=30, plot_division=0, label='Li(x)') + \
... plot(p, 2,xmax, label='P(X)', rgbcolor=(1,0,0))
...
sage: G.show(xmax=xmax)
r+ eU_Notebook__defaultsr, }r- (Ucell_output_colorr. U#0000EEr/ Umax_history_lengthr0 MUcell_input_colorr1 U#0000000r2 Uword_wrap_colsr3 KPuU_Notebook__worksheet_dirr4 Usage_notebook/worksheetsr5 U_Notebook__history_countr6 K U_Notebook__log_serverr7 U_Notebook__filenamer8 Usage_notebook/nb.sobjr9 U_Notebook__default_worksheetr: j, U_Notebook__server_logr; ]r< U_Notebook__next_worksheet_idr= KU_Notebook__kill_idler> K U_Notebook__systemr? NU_Notebook__show_debugr@ U_Notebook__dirrA U
sage_notebookrB U_Notebook__authrC U:U_Notebook__colorrD NU_Notebook__object_dirrE Usage_notebook/objectsrF U_default_filenamerG U:/Users/was/talks/2007-01-15-sage-cse/sage_notebook/nb.sobjrH U_Notebook__splashpagerI ub.