Problem set 7

Apr 20, 2013 - Problem 1 (easy). Consider the graphs in Problem 3 of Problem. Set 6 (reproduced here in Figure 1). Use Sage to check, for some of them (two ...
155KB taille 7 téléchargements 319 vues
Problem set 7 April 20, 2013 Instructions: upload the file ProblemSet7.sws and look at the examples of useful Sage commands provided there. Next, solve the following problems. Hand in an account of your work at the end of the two hours. Solve the remaining problems for Monday 27 and hand in your work.

Emmanuel Briand. Universidad de Sevilla. 2014–2015. Discrete Mathematics. Grado Ingeniería Informática.

Planar Graphs Problem 1 (easy). Consider the graphs in Problem 3 of Problem Set 6 (reproduced here in Figure 1). Use Sage to check, for some of them (two or three), whether or not they are planar. If so: make sage draw a planar representation. Else: make sage find a Kuratowski subgraph (a subgraph that is a subdivision of K5 or K3,3 ). Make sure to recognize the Kuratowski subgraph (K5 or K3,3 ).

Distances in weighted graphs Problem 2 (less easy). Solve with SAGE’s commands in the Euler projects: 1. Problem 81

Note that a serious solution to these problems should better be implemented from scratch, instead of using Sage’s built-in commands.

https://projecteuler.net/problem=81

and Porblems 82 and 83. You will need to upload the file p081_matrix.txt: how to do this in Sage is explained below. 2. Problems 18 and 67. For Euler-problem 18, copy and paste the triangle in a text file that you will upload as a data file attached to your sage worksheet (as for Problem 81). 3. Problem 107.

Uploading and parsing Data file attached to the Sage worksheet We take as an example the file p081_matrix.txt corresponding to Euler problem 81. You should: • upload the file p081_matrix.txt as a data file for the sage worksheet (Button “Data”, choose “upload or create file” and enter the URL of the file or its address if you saved it on your computer). Come back to the worksheet with the blue button “Worksheet”. • load the file and read and save its content in a variable with:

f = open(DATA + "p081_matrix.txt", 'r') L = f.readlines() f.close()

problem set 7

b u

Figure 1: Which of these graphs are planar? (Problem 1)

a u uc a u ' u

f

f

b u $ u

c

u e & e

u % d

a u

b u

u

ud

G1

f

ud

u ue

a u uc

e u

g u

b u

e u u d

u c

G2

a u

b u

h u

c u

u g

u d u f

u e

G3

2

problem set 7

The list L contains the lines of the file, as character strings, for instance the first term L[0] is

'4445,2697,5115,718,2209,2212,654,4348,3079,6821,7668,3276,8874,4190,378\ 5,2752,9473,7817,9137,496,7338,3434,7152,4355,4552,7917,7827,2460,2350,6\ 91,3514,5880,3145,7633,7199,3783,5066,7487,3285,1084,8985,760,872,8609,8\ 051,1134,9536,5750,9716,9371,7619,5617,275,9721,2997,2698,1887,8825,6372\ ,3014,2113,7122,7050,6775,5948,2758,1219,3539,348,7989,2735,9862,1263,80\ 89,6401,9462,3168,2758,3748,5870\n' • You can get the matrix represented in the file typing:

M = matrix( [ [ int(t) for t in s.split(',')] for s in L ])

Additional explanations on parsing in Python/Sage, for if you need it somewhere else. With the command split you split your string into a list of strings, around some special character, here the comma (“,”).

L[0].split(',') The command int changes a string that represents an integer into this integer, for instance int('4445') is 4445.

Hamiltonian and Eulerian graphs Problem 3 (not difficult). Build in Sage a Hamiltonian graph with 20 vertices and 100 edges. Problem 4 (less easy). What if you want a Hamiltonian path (not cycle) and the only function available is for computing Hamiltonian cycles ? Find a trick that allow you to use the method hamiltonian_cycle. Problem 5 (may be challenging). Solve Euler problem 79: https://projecteuler.net/problem=79

modeling the problem as a problem in Graph Theory, and solving it using Sage’s commands.

3