egr122

1927 days ago by geneson

a=2+3*5 
       
       
17
17
b = 6*3-4 b 
       
14
14
c = 5/7+1 c 
       
12/7
12/7
c = 1//2 c 
       
0
0
c = 1/2 c 
       
1/2
1/2
a = 1+i print a 
       
I + 1
I + 1
a*a 
       
2*I
2*I
1/a 
       
-1/2*I + 1/2
-1/2*I + 1/2
1//a 
       
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for //: 'Symbolic Ring' and
'Symbolic Ring'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_15.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("MS8vYQ=="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpeuVjxc/___code___.py", line 3, in <module>
    exec compile(u'_sage_const_1 //a
  File "", line 1, in <module>
    
  File "sage/structure/element.pyx", line 1818, in sage.structure.element.Element.__floordiv__ (build/cythonized/sage/structure/element.c:13353)
  File "sage/structure/coerce.pyx", line 1091, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:9657)
  File "sage/structure/coerce.pyx", line 1087, in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:9596)
  File "sage/structure/element.pyx", line 1816, in sage.structure.element.Element.__floordiv__ (build/cythonized/sage/structure/element.c:13318)
  File "sage/structure/element.pyx", line 1851, in sage.structure.element.Element._floordiv_ (build/cythonized/sage/structure/element.c:13639)
TypeError: unsupported operand parent(s) for //: 'Symbolic Ring' and 'Symbolic Ring'
sin(2.3) 
       
0.745705212176720
0.745705212176720
sin(pi) 
       
0
0
e^1 
       
e
e
sin? 
       

File: /home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/functions/trig.py

Type: <class ‘sage.functions.trig.Function_sin’>

Definition: sin(coerce=True, hold=False, dont_call_method_on_arg=False, *args)

Docstring:

The sine function.

EXAMPLES:

sage: sin(0)
0
sage: sin(x).subs(x==0)
0
sage: sin(2).n(100)
0.90929742682568169539601986591
sage: loads(dumps(sin))
sin
sage: sin(x)._sympy_()
sin(x)

We can prevent evaluation using the hold parameter:

sage: sin(0,hold=True)
sin(0)

To then evaluate again, we currently must use Maxima via sage.symbolic.expression.Expression.simplify():

sage: a = sin(0,hold=True); a.simplify()
0

If possible, the argument is also reduced modulo the period length 2\pi, and well-known identities are directly evaluated:

sage: k = var('k', domain='integer')
sage: sin(1 + 2*k*pi)
sin(1)
sage: sin(k*pi)
0

File: /home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/functions/trig.py

Type: <class ‘sage.functions.trig.Function_sin’>

Definition: sin(coerce=True, hold=False, dont_call_method_on_arg=False, *args)

Docstring:

The sine function.

EXAMPLES:

sage: sin(0)
0
sage: sin(x).subs(x==0)
0
sage: sin(2).n(100)
0.90929742682568169539601986591
sage: loads(dumps(sin))
sin
sage: sin(x)._sympy_()
sin(x)

We can prevent evaluation using the hold parameter:

sage: sin(0,hold=True)
sin(0)

To then evaluate again, we currently must use Maxima via sage.symbolic.expression.Expression.simplify():

sage: a = sin(0,hold=True); a.simplify()
0

If possible, the argument is also reduced modulo the period length 2\pi, and well-known identities are directly evaluated:

sage: k = var('k', domain='integer')
sage: sin(1 + 2*k*pi)
sin(1)
sage: sin(k*pi)
0
P = plot(sin, (0,10*pi)) show(P) 
       
c1=circle((1,1),2) c2=circle((1,-1),2) L=line([(0,0), (1,1)]) p=list_plot([1,2,-1+I,3*I],size=20) show(c1+c2+L+p) 
       
m1=matrix([[1,2],[3,4]]) m1 
       
[1 2]
[3 4]
[1 2]
[3 4]
show(m1) 
       

                                
                            

                                
m2=matrix([[7,-3],[0,5]]) show(m2) 
       

                                
                            

                                
m1+m2 
       
[ 8 -1]
[ 3  9]
[ 8 -1]
[ 3  9]
m1*m2 
       
[ 7  7]
[21 11]
[ 7  7]
[21 11]
m2^2 
       
[ 49 -36]
[  0  25]
[ 49 -36]
[  0  25]
m1^-1 
       
[  -2    1]
[ 3/2 -1/2]
[  -2    1]
[ 3/2 -1/2]
m1^(-1) 
       
[  -2    1]
[ 3/2 -1/2]
[  -2    1]
[ 3/2 -1/2]
m1[0][0] 
       
1
1
m1[0,0] 
       
1
1
m1 
       
[1 2]
[3 4]
[1 2]
[3 4]
m1[0,1] 
       
2
2
m1[0][1] 
       
2
2
m2.column(1) 
       
(-3, 5)
(-3, 5)
m2 
       
[ 7 -3]
[ 0  5]
[ 7 -3]
[ 0  5]
mm = copy(m2) mm.set_column(1,[0,0]) mm 
       
[7 0]
[0 0]
[7 0]
[0 0]
mm[1,0] = -1 mm 
       
[ 7  0]
[-1  0]
[ 7  0]
[-1  0]
identity_matrix(3) 
       
[1 0 0]
[0 1 0]
[0 0 1]
[1 0 0]
[0 1 0]
[0 0 1]
rank(m1) 
       
2
2
m1 
       
[1 2]
[3 4]
[1 2]
[3 4]
transpose(m1) 
       
[1 3]
[2 4]
[1 3]
[2 4]
det(m1) 
       
-2
-2
charpoly(m1) 
       
x^2 - 5*x - 2
x^2 - 5*x - 2
m3 = m1 m1 
       
[1 2]
[3 4]
[1 2]
[3 4]
m3 
       
[1 2]
[3 4]
[1 2]
[3 4]
m3[0,0] = 0 m3 
       
[0 2]
[3 4]
[0 2]
[3 4]
m1 
       
[0 2]
[3 4]
[0 2]
[3 4]
m1[0,0] = 1 m1 
       
[1 2]
[3 4]
[1 2]
[3 4]
m = matrix([[0,1,2,3],[2,3,4,5],[0,0,1,0],[2,3,4,5]]) m show(m) print show(m[0][2]) 
       


m3 
       
[1 2]
[3 4]
[1 2]
[3 4]
v = vector([2, 1, -2]) 
       
identity_matrix(3)*v 
       
(2, 1, -2)
(2, 1, -2)
v*identity_matrix(3) 
       
(2, 1, -2)
(2, 1, -2)
transpose(v) 
       
Traceback (click to the left of this block for traceback)
...
AttributeError: 'sage.modules.vector_integer_dense.Vector_integer_dense'
object has no attribute 'transpose'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "_sage_input_62.py", line 10, in <module>
    exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("dHJhbnNwb3NlKHYp"),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
  File "", line 1, in <module>
    
  File "/tmp/tmpV5KD05/___code___.py", line 2, in <module>
    exec compile(u'transpose(v)
  File "", line 1, in <module>
    
  File "/home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/misc/functional.py", line 1645, in transpose
    return x.transpose()
  File "sage/structure/element.pyx", line 484, in sage.structure.element.Element.__getattr__ (build/cythonized/sage/structure/element.c:4377)
  File "sage/structure/element.pyx", line 497, in sage.structure.element.Element.getattr_from_category (build/cythonized/sage/structure/element.c:4486)
  File "sage/cpython/getattr.pyx", line 254, in sage.cpython.getattr.getattr_from_other_class (build/cythonized/sage/cpython/getattr.c:1901)
AttributeError: 'sage.modules.vector_integer_dense.Vector_integer_dense' object has no attribute 'transpose'
w=matrix([v]) show(w) show(transpose(w)) 
       

                                
                            

                                
v = vector([2, 1, -2]) print(v*v) show(v) print(norm(v)) m = matrix([[0,2],[3,4],[5,6]]) print(norm(m)) norm? 
       

File: /home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/misc/functional.py

Type: <type ‘function’>

Definition: norm(x)

Docstring:

Return the norm of x.

For matrices and vectors, this returns the L2-norm. The L2-norm of a vector *v* = (v_1, v_2, \dots, v_n), also called the Euclidean norm, is defined as

|*v*| = \sqrt{\sum_{i=1}^n |v_i|^2}

where |v_i| is the complex modulus of v_i. The Euclidean norm is often used for determining the distance between two points in two- or three-dimensional space.

For complex numbers, the function returns the field norm. If c = a + bi is a complex number, then the norm of c is defined as the product of c and its complex conjugate

norm(c) = norm(a + bi) = c \cdot \overline{c} = a^2 + b^2.

The norm of a complex number is different from its absolute value. The absolute value of a complex number is defined to be the square root of its norm. A typical use of the complex norm is in the integral domain \ZZ[i] of Gaussian integers, where the norm of each Gaussian integer c = a + bi is defined as its complex norm.

See also

  • sage.matrix.matrix2.Matrix.norm()
  • sage.modules.free_module_element.FreeModuleElement.norm()
  • sage.rings.complex_double.ComplexDoubleElement.norm()
  • sage.rings.complex_number.ComplexNumber.norm()
  • sage.symbolic.expression.Expression.norm()

EXAMPLES:

The norm of vectors:

sage: z = 1 + 2*I
sage: norm(vector([z]))
sqrt(5)
sage: v = vector([-1,2,3])
sage: norm(v)
sqrt(14)
sage: _ = var("a b c d", domain='real')
sage: v = vector([a, b, c, d])
sage: norm(v)
sqrt(a^2 + b^2 + c^2 + d^2)

The norm of matrices:

sage: z = 1 + 2*I
sage: norm(matrix([[z]]))
2.23606797749979
sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]])
sage: norm(M)  # abs tol 1e-14
10.690331129154467
sage: norm(CDF(z))
5.0
sage: norm(CC(z))
5.00000000000000

The norm of complex numbers:

sage: z = 2 - 3*I
sage: norm(z)
13
sage: a = randint(-10^10, 100^10)
sage: b = randint(-10^10, 100^10)
sage: z = a + b*I
sage: bool(norm(z) == a^2 + b^2)
True

The complex norm of symbolic expressions:

sage: a, b, c = var("a, b, c")
sage: assume((a, 'real'), (b, 'real'), (c, 'real'))
sage: z = a + b*I
sage: bool(norm(z).simplify() == a^2 + b^2)
True
sage: norm(a + b).simplify()
a^2 + 2*a*b + b^2
sage: v = vector([a, b, c])
sage: bool(norm(v).simplify() == sqrt(a^2 + b^2 + c^2))
True
sage: forget()

File: /home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/misc/functional.py

Type: <type ‘function’>

Definition: norm(x)

Docstring:

Return the norm of x.

For matrices and vectors, this returns the L2-norm. The L2-norm of a vector *v* = (v_1, v_2, \dots, v_n), also called the Euclidean norm, is defined as

|*v*| = \sqrt{\sum_{i=1}^n |v_i|^2}

where |v_i| is the complex modulus of v_i. The Euclidean norm is often used for determining the distance between two points in two- or three-dimensional space.

For complex numbers, the function returns the field norm. If c = a + bi is a complex number, then the norm of c is defined as the product of c and its complex conjugate

norm(c) = norm(a + bi) = c \cdot \overline{c} = a^2 + b^2.

The norm of a complex number is different from its absolute value. The absolute value of a complex number is defined to be the square root of its norm. A typical use of the complex norm is in the integral domain \ZZ[i] of Gaussian integers, where the norm of each Gaussian integer c = a + bi is defined as its complex norm.

See also

  • sage.matrix.matrix2.Matrix.norm()
  • sage.modules.free_module_element.FreeModuleElement.norm()
  • sage.rings.complex_double.ComplexDoubleElement.norm()
  • sage.rings.complex_number.ComplexNumber.norm()
  • sage.symbolic.expression.Expression.norm()

EXAMPLES:

The norm of vectors:

sage: z = 1 + 2*I
sage: norm(vector([z]))
sqrt(5)
sage: v = vector([-1,2,3])
sage: norm(v)
sqrt(14)
sage: _ = var("a b c d", domain='real')
sage: v = vector([a, b, c, d])
sage: norm(v)
sqrt(a^2 + b^2 + c^2 + d^2)

The norm of matrices:

sage: z = 1 + 2*I
sage: norm(matrix([[z]]))
2.23606797749979
sage: M = matrix(ZZ, [[1,2,4,3], [-1,0,3,-10]])
sage: norm(M)  # abs tol 1e-14
10.690331129154467
sage: norm(CDF(z))
5.0
sage: norm(CC(z))
5.00000000000000

The norm of complex numbers:

sage: z = 2 - 3*I
sage: norm(z)
13
sage: a = randint(-10^10, 100^10)
sage: b = randint(-10^10, 100^10)
sage: z = a + b*I
sage: bool(norm(z) == a^2 + b^2)
True

The complex norm of symbolic expressions:

sage: a, b, c = var("a, b, c")
sage: assume((a, 'real'), (b, 'real'), (c, 'real'))
sage: z = a + b*I
sage: bool(norm(z).simplify() == a^2 + b^2)
True
sage: norm(a + b).simplify()
a^2 + 2*a*b + b^2
sage: v = vector([a, b, c])
sage: bool(norm(v).simplify() == sqrt(a^2 + b^2 + c^2))
True
sage: forget()
mQ = matrix([[1,2,3],[4,5,6],[7,8,9]]) print mQ print refm=mQ.echelon_form() refm 
       
[1 2 3]
[4 5 6]
[7 8 9]

[1 2 3]
[0 3 6]
[0 0 0]
[1 2 3]
[4 5 6]
[7 8 9]

[1 2 3]
[0 3 6]
[0 0 0]
mQ = matrix([[1,2,3],[4,5,6],[7,8,9]]) print mQ refm=mQ.echelon_form() refm 
       
[1 2 3]
[4 5 6]
[7 8 9]
[1 2 3]
[0 3 6]
[0 0 0]
[1 2 3]
[4 5 6]
[7 8 9]
[1 2 3]
[0 3 6]
[0 0 0]
print m1 print m1.eigenvalues() 
       
[1 2]
[3 4]

[-0.3722813232690144?, 5.372281323269015?]
[1 2]
[3 4]

[-0.3722813232690144?, 5.372281323269015?]
print m1 m1.eigenvalues() 
       
[1 2]
[3 4]
[-0.3722813232690144?, 5.372281323269015?]
[1 2]
[3 4]
[-0.3722813232690144?, 5.372281323269015?]
print m2 print m2.eigenvalues() 
       
[ 7 -3]
[ 0  5]

[7, 5]
[ 7 -3]
[ 0  5]

[7, 5]
m2.eigenmatrix_right() 
       
(
[7 0]  [  1   1]
[0 5], [  0 2/3]
)
(
[7 0]  [  1   1]
[0 5], [  0 2/3]
)
m2.eigenvectors_right() 
       
[(7, [
  (1, 0)
  ], 1), (5, [
  (1, 2/3)
  ], 1)]
[(7, [
  (1, 0)
  ], 1), (5, [
  (1, 2/3)
  ], 1)]
m2.eigenvectors_left() 
       
[(7, [
  (1, -3/2)
  ], 1), (5, [
  (0, 1)
  ], 1)]
[(7, [
  (1, -3/2)
  ], 1), (5, [
  (0, 1)
  ], 1)]
m1.det() 
       
-2
-2
c=matrix(GF(2),[[0,1,1],[1,0,1],[1,1,0]]) c 
       
[0 1 1]
[1 0 1]
[1 1 0]
[0 1 1]
[1 0 1]
[1 1 0]
c.rank() 
       
2
2
c2=c.change_ring(QQ) c2 
       
[0 1 1]
[1 0 1]
[1 1 0]
[0 1 1]
[1 0 1]
[1 1 0]
c2.rank() 
       
3
3
m1 = matrix([[1,2],[3,4]]) m2 = matrix([[0,1],[1,0]]) n = [] print n print for i in [2,5,7,9,11,3]: n.append(m1-i*identity_matrix(2)) print m1-i*identity_matrix(2) print print n 
       
[]

[-1  2]
[ 3  2]

[-4  2]
[ 3 -1]

[-6  2]
[ 3 -3]

[-8  2]
[ 3 -5]

[-10   2]
[  3  -7]

[-2  2]
[ 3  1]

[[-1  2]
[ 3  2], [-4  2]
[ 3 -1], [-6  2]
[ 3 -3], [-8  2]
[ 3 -5], [-10   2]
[  3  -7], [-2  2]
[ 3  1]]
[]

[-1  2]
[ 3  2]

[-4  2]
[ 3 -1]

[-6  2]
[ 3 -3]

[-8  2]
[ 3 -5]

[-10   2]
[  3  -7]

[-2  2]
[ 3  1]

[[-1  2]
[ 3  2], [-4  2]
[ 3 -1], [-6  2]
[ 3 -3], [-8  2]
[ 3 -5], [-10   2]
[  3  -7], [-2  2]
[ 3  1]]
s=5 t=0 while t < s: print t if 2*(t//2)==t: for j in [0..t]: print '&' t=t+1 
       
0
&
1
2
&
&
&
3
4
&
&
&
&
&
0
&
1
2
&
&
&
3
4
&
&
&
&
&
s=5 t=0 while t < s: print t if 2*floor(t/2)==t: for j in [0..t]: print '&' elif 3*(t//3) == t: print 8 else: print '@' print t=t+1 
       
0
&

1
@

2
&
&
&

3
8

4
&
&
&
&
&
0
&

1
@

2
&
&
&

3
8

4
&
&
&
&
&
def f(x): return x+3 
       
f(4) 
       
7
7
def adj(m): return conjugate(m.transpose()) 
       
m1 = matrix([[1+i, 2],[3-i,4+2*i]]) 
       
adj(m1) 
       
[  -I + 1    I + 3]
[       2 -2*I + 4]
[  -I + 1    I + 3]
[       2 -2*I + 4]
m1.adjoint() 
       
[ 4 -2]
[-3  1]
[ 4 -2]
[-3  1]
def isPrime(n): if n < 2: return 'No' for i in range(2, n): if n % i == 0: return 'No' return 'Yes' 
       
for i in range(20): print str(i)+' '+isPrime(i) 
       
0 No
1 No
2 Yes
3 Yes
4 No
5 Yes
6 No
7 Yes
8 No
9 No
10 No
11 Yes
12 No
13 Yes
14 No
15 No
16 No
17 Yes
18 No
19 Yes
0 No
1 No
2 Yes
3 Yes
4 No
5 Yes
6 No
7 Yes
8 No
9 No
10 No
11 Yes
12 No
13 Yes
14 No
15 No
16 No
17 Yes
18 No
19 Yes
sudoku? 
       

File: /home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/games/sudoku.py

Type: <type ‘function’>

Definition: sudoku(m)

Docstring:

Solves Sudoku puzzles described by matrices.

INPUT:

  • m - a square Sage matrix over \ZZ, where zeros are blank entries

OUTPUT:

A Sage matrix over \ZZ containing the first solution found, otherwise None.

This function matches the behavior of the prior Sudoku solver and is included only to replicate that behavior. It could be safely deprecated, since all of its functionality is included in the Sudoku class.

EXAMPLES:

An example that was used in previous doctests.

sage: A = matrix(ZZ,9,[5,0,0, 0,8,0, 0,4,9, 0,0,0, 5,0,0, 0,3,0, 0,6,7, 3,0,0, 0,0,1, 1,5,0, 0,0,0, 0,0,0,  0,0,0, 2,0,8, 0,0,0, 0,0,0, 0,0,0, 0,1,8, 7,0,0, 0,0,4, 1,5,0, 0,3,0, 0,0,2, 0,0,0, 4,9,0, 0,5,0, 0,0,3])
sage: A
[5 0 0 0 8 0 0 4 9]
[0 0 0 5 0 0 0 3 0]
[0 6 7 3 0 0 0 0 1]
[1 5 0 0 0 0 0 0 0]
[0 0 0 2 0 8 0 0 0]
[0 0 0 0 0 0 0 1 8]
[7 0 0 0 0 4 1 5 0]
[0 3 0 0 0 2 0 0 0]
[4 9 0 0 5 0 0 0 3]
sage: sudoku(A)
[5 1 3 6 8 7 2 4 9]
[8 4 9 5 2 1 6 3 7]
[2 6 7 3 4 9 5 8 1]
[1 5 8 4 6 3 9 7 2]
[9 7 4 2 1 8 3 6 5]
[3 2 6 7 9 5 4 1 8]
[7 8 2 9 3 4 1 5 6]
[6 3 5 1 7 2 8 9 4]
[4 9 1 8 5 6 7 2 3]

Using inputs that are possible with the Sudoku class, other than a matrix, will cause an error.

sage: sudoku('.4..32....14..3.')
Traceback (click to the left of this block for traceback)
...

                                
                            

File: /home/sage/build/sage-8.1/local/lib/python2.7/site-packages/sage/games/sudoku.py

Type: <type ‘function’>

Definition: sudoku(m)

Docstring:

Solves Sudoku puzzles described by matrices.

INPUT:

  • m - a square Sage matrix over \ZZ, where zeros are blank entries

OUTPUT:

A Sage matrix over \ZZ containing the first solution found, otherwise None.

This function matches the behavior of the prior Sudoku solver and is included only to replicate that behavior. It could be safely deprecated, since all of its functionality is included in the Sudoku class.

EXAMPLES:

An example that was used in previous doctests.

sage: A = matrix(ZZ,9,[5,0,0, 0,8,0, 0,4,9, 0,0,0, 5,0,0, 0,3,0, 0,6,7, 3,0,0, 0,0,1, 1,5,0, 0,0,0, 0,0,0,  0,0,0, 2,0,8, 0,0,0, 0,0,0, 0,0,0, 0,1,8, 7,0,0, 0,0,4, 1,5,0, 0,3,0, 0,0,2, 0,0,0, 4,9,0, 0,5,0, 0,0,3])
sage: A
[5 0 0 0 8 0 0 4 9]
[0 0 0 5 0 0 0 3 0]
[0 6 7 3 0 0 0 0 1]
[1 5 0 0 0 0 0 0 0]
[0 0 0 2 0 8 0 0 0]
[0 0 0 0 0 0 0 1 8]
[7 0 0 0 0 4 1 5 0]
[0 3 0 0 0 2 0 0 0]
[4 9 0 0 5 0 0 0 3]
sage: sudoku(A)
[5 1 3 6 8 7 2 4 9]
[8 4 9 5 2 1 6 3 7]
[2 6 7 3 4 9 5 8 1]
[1 5 8 4 6 3 9 7 2]
[9 7 4 2 1 8 3 6 5]
[3 2 6 7 9 5 4 1 8]
[7 8 2 9 3 4 1 5 6]
[6 3 5 1 7 2 8 9 4]
[4 9 1 8 5 6 7 2 3]

Using inputs that are possible with the Sudoku class, other than a matrix, will cause an error.

sage: sudoku('.4..32....14..3.')
Traceback (most recent call last):
...
ValueError: sudoku function expects puzzle to be a matrix, perhaps use the Sudoku class
a = matrix([[0,1,0,0,0,0,0,0,0],[0,0,0,0,0,0,8,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,9,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,1]]) print a print print sudoku(a) print print sudoku(a) 
       
[0 1 0 0 0 0 0 0 0]
[0 0 0 0 0 0 8 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 9 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 1]

[8 1 2 3 4 5 9 6 7]
[5 3 6 9 2 7 8 1 4]
[9 4 7 1 8 6 2 5 3]
[6 2 8 4 5 3 1 7 9]
[1 5 4 7 9 2 6 3 8]
[7 9 3 6 1 8 4 2 5]
[3 8 1 5 6 4 7 9 2]
[4 7 9 2 3 1 5 8 6]
[2 6 5 8 7 9 3 4 1]

[8 1 2 3 4 5 9 6 7]
[5 3 6 9 2 7 8 1 4]
[9 4 7 1 8 6 2 5 3]
[6 2 8 4 5 3 1 7 9]
[1 5 4 7 9 2 6 3 8]
[7 9 3 6 1 8 4 2 5]
[3 8 1 5 6 4 7 9 2]
[4 7 9 2 3 1 5 8 6]
[2 6 5 8 7 9 3 4 1]
[0 1 0 0 0 0 0 0 0]
[0 0 0 0 0 0 8 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 9 0]
[0 0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0 1]

[8 1 2 3 4 5 9 6 7]
[5 3 6 9 2 7 8 1 4]
[9 4 7 1 8 6 2 5 3]
[6 2 8 4 5 3 1 7 9]
[1 5 4 7 9 2 6 3 8]
[7 9 3 6 1 8 4 2 5]
[3 8 1 5 6 4 7 9 2]
[4 7 9 2 3 1 5 8 6]
[2 6 5 8 7 9 3 4 1]

[8 1 2 3 4 5 9 6 7]
[5 3 6 9 2 7 8 1 4]
[9 4 7 1 8 6 2 5 3]
[6 2 8 4 5 3 1 7 9]
[1 5 4 7 9 2 6 3 8]
[7 9 3 6 1 8 4 2 5]
[3 8 1 5 6 4 7 9 2]
[4 7 9 2 3 1 5 8 6]
[2 6 5 8 7 9 3 4 1]
g=Graph({'a':[3,4,5,6],2:[8,10,12],6:[7,8],8:[9],10:[11]}) show(g) 
       
m = g.adjacency_matrix() m 
       
[0 0 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 0 0 0 1 0 1 0 1]
[1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 1 1 0 0 0 0]
[0 0 0 0 0 1 0 0 0 0 0 0]
[0 1 0 0 0 1 0 0 1 0 0 0]
[0 0 0 0 0 0 0 1 0 0 0 0]
[0 1 0 0 0 0 0 0 0 0 1 0]
[0 0 0 0 0 0 0 0 0 1 0 0]
[0 1 0 0 0 0 0 0 0 0 0 0]
[0 0 1 1 1 1 0 0 0 0 0 0]
[0 0 0 0 0 0 0 1 0 1 0 1]
[1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 0 0 0 0 0 0]
[1 0 0 0 0 0 1 1 0 0 0 0]
[0 0 0 0 0 1 0 0 0 0 0 0]
[0 1 0 0 0 1 0 0 1 0 0 0]
[0 0 0 0 0 0 0 1 0 0 0 0]
[0 1 0 0 0 0 0 0 0 0 1 0]
[0 0 0 0 0 0 0 0 0 1 0 0]
[0 1 0 0 0 0 0 0 0 0 0 0]
gg=Graph(m) show(gg) 
       
g=graphs.PathGraph(100) show(g) 
       
C5=graphs.CycleGraph(5) show(C5) 
       
C5.is_planar() 
       
True
True
Pet=graphs.PetersenGraph() show(Pet) Pet.is_isomorphic(C5) 
       
False
False
Pet.is_planar() 
       
False
False
C5.order() 
       
5
5
g=C5.complement() show(g) 
       
Pet.is_connected() 
       
True
True
h=Pet.copy() h.delete_vertex(5) show(h) 
       
h=Pet.copy() h.delete_edge([0,5]) show(h) 
       
g=graphs.CirculantGraph(7,[1,3]) show(g) 
       
from sage.graphs.independent_sets import IndependentSets IS = IndependentSets(g) for s in IS: print s 
       
[0]
[0, 3]
[0, 4]
[1]
[1, 4]
[1, 5]
[2]
[2, 5]
[2, 6]
[3]
[3, 6]
[4]
[5]
[6]
[]
[0]
[0, 3]
[0, 4]
[1]
[1, 4]
[1, 5]
[2]
[2, 5]
[2, 6]
[3]
[3, 6]
[4]
[5]
[6]
[]
from sage.graphs.independent_sets import IndependentSets Im = IndependentSets(g, maximal = true) for s in Im: print s 
       
[0, 3]
[0, 4]
[1, 4]
[1, 5]
[2, 5]
[2, 6]
[3, 6]
[0, 3]
[0, 4]
[1, 4]
[1, 5]
[2, 5]
[2, 6]
[3, 6]
Im.cardinality() 
       
7
7
from sage.graphs.graph_coloring import number_of_n_colorings G = Graph({0: [1, 2, 3], 1: [2]}) show(G) print number_of_n_colorings(G, 2) print number_of_n_colorings(G, 3) print number_of_n_colorings(G, 4) 
       
0
12
72
0
12
72
g=graphs.CirculantGraph(7,[1,2]) show(g) 
       
print number_of_n_colorings(g, 2) print number_of_n_colorings(g, 3) print number_of_n_colorings(g, 4) 
       
0
0
168
0
0
168
p = Permutations(3) print p print for i in p: print i 
       
Standard permutations of 3

[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]
Standard permutations of 3

[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]
p = Permutations(5,3) print p print list(p) 
       
Permutations of {1,...,5} of length 3

[[1, 2, 3],
 [1, 2, 4],
 [1, 2, 5],
 [1, 3, 2],
 [1, 3, 4],
 [1, 3, 5],
 [1, 4, 2],
 [1, 4, 3],
 [1, 4, 5],
 [1, 5, 2],
 [1, 5, 3],
 [1, 5, 4],
 [2, 1, 3],
 [2, 1, 4],
 [2, 1, 5],
 [2, 3, 1],
 [2, 3, 4],
 [2, 3, 5],
 [2, 4, 1],
 [2, 4, 3],
 [2, 4, 5],
 [2, 5, 1],
 [2, 5, 3],
 [2, 5, 4],
 [3, 1, 2],
 [3, 1, 4],
 [3, 1, 5],
 [3, 2, 1],
 [3, 2, 4],
 [3, 2, 5],
 [3, 4, 1],
 [3, 4, 2],
 [3, 4, 5],
 [3, 5, 1],
 [3, 5, 2],
 [3, 5, 4],
 [4, 1, 2],
 [4, 1, 3],
 [4, 1, 5],
 [4, 2, 1],
 [4, 2, 3],
 [4, 2, 5],
 [4, 3, 1],
 [4, 3, 2],
 [4, 3, 5],
 [4, 5, 1],
 [4, 5, 2],
 [4, 5, 3],
 [5, 1, 2],
 [5, 1, 3],
 [5, 1, 4],
 [5, 2, 1],
 [5, 2, 3],
 [5, 2, 4],
 [5, 3, 1],
 [5, 3, 2],
 [5, 3, 4],
 [5, 4, 1],
 [5, 4, 2],
 [5, 4, 3]]
Permutations of {1,...,5} of length 3

[[1, 2, 3],
 [1, 2, 4],
 [1, 2, 5],
 [1, 3, 2],
 [1, 3, 4],
 [1, 3, 5],
 [1, 4, 2],
 [1, 4, 3],
 [1, 4, 5],
 [1, 5, 2],
 [1, 5, 3],
 [1, 5, 4],
 [2, 1, 3],
 [2, 1, 4],
 [2, 1, 5],
 [2, 3, 1],
 [2, 3, 4],
 [2, 3, 5],
 [2, 4, 1],
 [2, 4, 3],
 [2, 4, 5],
 [2, 5, 1],
 [2, 5, 3],
 [2, 5, 4],
 [3, 1, 2],
 [3, 1, 4],
 [3, 1, 5],
 [3, 2, 1],
 [3, 2, 4],
 [3, 2, 5],
 [3, 4, 1],
 [3, 4, 2],
 [3, 4, 5],
 [3, 5, 1],
 [3, 5, 2],
 [3, 5, 4],
 [4, 1, 2],
 [4, 1, 3],
 [4, 1, 5],
 [4, 2, 1],
 [4, 2, 3],
 [4, 2, 5],
 [4, 3, 1],
 [4, 3, 2],
 [4, 3, 5],
 [4, 5, 1],
 [4, 5, 2],
 [4, 5, 3],
 [5, 1, 2],
 [5, 1, 3],
 [5, 1, 4],
 [5, 2, 1],
 [5, 2, 3],
 [5, 2, 4],
 [5, 3, 1],
 [5, 3, 2],
 [5, 3, 4],
 [5, 4, 1],
 [5, 4, 2],
 [5, 4, 3]]
p = Permutations(['a','b','c']) print p print list(p) p1 = p[0] p2 = p[1] print p1 print p2 print p1*p2 
       
Permutations of the set ['a', 'b', 'c']

['a', 'b', 'c']
['a', 'c', 'b']
Traceback (click to the left of this block for traceback)
...
TypeError: unsupported operand parent(s) for *: 'Permutations of the set
['a', 'b', 'c']' and 'Permutations of the set ['a', 'b', 'c']'
Permutations of the set ['a', 'b', 'c']

['a', 'b', 'c']
['a', 'c', 'b']
Traceback (most recent call last):    print p1
  File "", line 1, in <module>
    
  File "/tmp/tmpftUXT9/___code___.py", line 11, in <module>
    exec compile(u'print p1*p2
  File "", line 1, in <module>
    
  File "sage/structure/element.pyx", line 1519, in sage.structure.element.Element.__mul__ (build/cythonized/sage/structure/element.c:12077)
  File "sage/structure/element.pyx", line 1558, in sage.structure.element.Element._mul_ (build/cythonized/sage/structure/element.c:12466)
TypeError: unsupported operand parent(s) for *: 'Permutations of the set ['a', 'b', 'c']' and 'Permutations of the set ['a', 'b', 'c']'
p = Permutations([0,0,1]) print p print list(p) 
       
Permutations of the multi-set [0, 0, 1]

[[0, 0, 1], [0, 1, 0], [1, 0, 0]]
Permutations of the multi-set [0, 0, 1]

[[0, 0, 1], [0, 1, 0], [1, 0, 0]]
p = Permutations(4, avoiding=[1,3,2]) print p print list(p) 
       
Standard permutations of 4 avoiding [1, 3, 2]

[[4, 1, 2, 3],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1],
 [3, 4, 1, 2],
 [3, 4, 2, 1],
 [2, 3, 4, 1],
 [3, 2, 4, 1],
 [1, 2, 3, 4],
 [2, 1, 3, 4],
 [2, 3, 1, 4],
 [3, 1, 2, 4],
 [3, 2, 1, 4]]
Standard permutations of 4 avoiding [1, 3, 2]

[[4, 1, 2, 3],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [4, 3, 1, 2],
 [4, 3, 2, 1],
 [3, 4, 1, 2],
 [3, 4, 2, 1],
 [2, 3, 4, 1],
 [3, 2, 4, 1],
 [1, 2, 3, 4],
 [2, 1, 3, 4],
 [2, 3, 1, 4],
 [3, 1, 2, 4],
 [3, 2, 1, 4]]
p = Permutations(4, avoiding=[[1,3,2],[1,2,3]]) print p print list(p) 
       
Standard permutations of 4 avoiding [[1, 3, 2], [1, 2, 3]]

[[3, 4, 1, 2],
 [4, 3, 1, 2],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [3, 2, 1, 4],
 [3, 2, 4, 1],
 [3, 4, 2, 1],
 [4, 3, 2, 1]]
Standard permutations of 4 avoiding [[1, 3, 2], [1, 2, 3]]

[[3, 4, 1, 2],
 [4, 3, 1, 2],
 [4, 2, 1, 3],
 [4, 2, 3, 1],
 [3, 2, 1, 4],
 [3, 2, 4, 1],
 [3, 4, 2, 1],
 [4, 3, 2, 1]]
W = Words(alphabet='01', length=5) print W print for i in W: print i 
       
Words of length 5 over {'0', '1'}

00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
01010
01011
01100
01101
01110
01111
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111
Words of length 5 over {'0', '1'}

00000
00001
00010
00011
00100
00101
00110
00111
01000
01001
01010
01011
01100
01101
01110
01111
10000
10001
10010
10011
10100
10101
10110
10111
11000
11001
11010
11011
11100
11101
11110
11111