Sage


SAGE

9.Constructing Small groups: See here.

10.Filter on graph database: Sometimes you need to query something on the database of small graphs. 

from itertools import ifilter

f = lambda g: g."filter1" and not g."filter2"

for g in ifilter(f, graphs(6)):

   print(g)

Or you can use the following command:

import six 

f = lambda g: g."filter1" and not g."filter2"

for g in six.moves.filter(f, graphs(6)):

   print(g)

Or you can use the following command:


from sage.graphs.connectivity import is_connected

Q = GraphQuery(display_cols=['graph6'], num_vertices=9)

for g in Q:

    if is_connected(g) and g.is_vertex_transitive():

        print(diameter(g, algorithm='standard'))

Or you can use the following command:

for g in graphs(6):

        if is_connected(g) and g.is_vertex_transitive():

11.Multiplicities of Eigenvalues

For algebraic multiplicities, you can use the following command:

sage: G.charpoly().roots(AA, multiplicities=True)

sage: A = G.am()

sage: for (l, E) in A.right_eigenspaces():

          print('Eigenvalue', l, 'geometric multiplicity', E.dimension())


12.graph6 <--> sage format

with the following command you can convert your graph in the sage format to graph6 format.

sage: your_graph.graph6_string()

Also for digraphs with digraph6.

sage: your_graph.dig6_string()

Conversely convert graph6 format to sage format

sage: d6 = "C?"

sage: G = Graph(d6, format='graph6')

Also for digraphs with digraph6.

sage: d6 = "C?"

sage: G = DiGraph(d6, format='dig6')

13.Creating .sage file: In Jupyter Notebook, the click on "New" pop-down menu.

Then select "Text File" and name it with the extension .sage .

14.Run your sage program from your command line: Let us call your file "test.sage".

sage:test.sage

15.Time execution: 

from datetime import datetime

start_time = datetime.now()

# your code here

end_time = datetime.now()

print('Duration: {}'.format(end_time - start_time))

16. Launch Sage Notebook from Terminal:

sage: -n jupyter 

17. The group id database:

sage:G.group_id() .all_subgroups()

18. All subgroups of a group:

sage:G.all_subgroups()


sage:G.conjugacy_classes_subgroups()


19. Cayley graphs:

sage:G = SymmetricGroup(4)

sage:G.cayley_graph(generators=[(1,2),(1,3),(1,4),(2,3),(2,4),(3,4)])