Ask Your Question

Nathann's profile - activity

2020-12-11 20:06:58 +0200 received badge  Nice Answer (source)
2018-11-27 11:55:39 +0200 received badge  Nice Answer (source)
2017-10-19 18:51:21 +0200 received badge  Nice Answer (source)
2016-11-21 15:16:14 +0200 received badge  Nice Answer (source)
2016-07-20 09:35:13 +0200 received badge  Good Answer (source)
2016-07-20 09:34:54 +0200 received badge  Nice Answer (source)
2016-03-09 21:12:29 +0200 received badge  Nice Answer (source)
2016-02-02 12:14:14 +0200 answered a question Can I import M2 matrices into sage?

I don't know anything about macaulay and don't have it installed, but I suggest you try to make the content of your command be a string, or you will keep hitting this syntax error. What about

 sage: A = macaulay2('value get "~/matrices/foo/001-matrix"')

Does it give what you want ?


2015-11-23 09:26:56 +0200 commented answer Suggestions for improving speed

Here is a tutorial on profiling in Sage, in case you want to figure out what exactly is going too slow:

2015-11-06 09:27:49 +0200 answered a question Execution time vs. Computation time in MILP


Whatever you define through solver_parameter only forwards the parameter to the lp solver. If you want a precise definition of what exactly they do, you should refer to the documentation of those solvers. I don't know more than you do on this point.

For GLPK, we copy/pasted the documentation from their manual in the doc of this function:

You can go check out their official doc to see if more precisions were given.


2015-11-03 16:08:50 +0200 answered a question solver_parameter('timelimit') doesnt work

Could you show us a minimal working example of what you do? If you tell me that you set the time limit and that the time limit is not respect, then it is a bug.

2015-10-11 19:25:25 +0200 answered a question Multiplicative group of integers mod n?

The integers modulo n are not a group with respect to multiplication. 1 is a unit element, but 0 has no inverse.

2015-10-01 18:43:26 +0200 answered a question Error when computing Automorphism Group

The error is that D is a tuple, and not a group. Read the documentation of direct_product, by typing

sage: G.direct_product?
2015-09-28 20:20:24 +0200 commented answer Binary variable in mixed integer linear program
2015-09-28 20:20:06 +0200 commented answer Binary variable in mixed integer linear program

I do not know, but you should ask on sage-support. Other will know better than I, and they may not read this thread.

2015-09-28 09:18:03 +0200 answered a question Binary variable in mixed integer linear program

No sorry, I do not think that any of the solvers we use support that.

Did you think of modelling your problem as a SAT problem instead? Could it help? Obviously it may not be possible depending on what you want to solve, but it may also be easier with this other formalism.

2015-09-26 16:29:21 +0200 received badge  Nice Answer (source)
2015-09-25 11:42:22 +0200 answered a question Adding relations to a poset

It seems that you want to add relations to a poset until... it is not a poset anymore?

Unfortunately (for you and I), posets have been made to be immutable (i.e. you can't modify one once it is built). Fortunately (for you and I) you do not need to use posets. You can use directed graphs instead. And you can add/remove edges from a given DiGraph, and then I expect that what you want to ensure is that my_digraph.is_directed_acyclic returns True.

2015-09-16 22:00:52 +0200 answered a question load a graph from a dot file

This should work:

sage: import networkx
sage: g = Graph(networkx.read_dot(''))

Currently you can write .dot files with Graph.export_to_file but not read them yet. We have "been about to write it" several times now, gut given that none of us apparently needs it, it still isn't actual code.

If you want to start contributing to Sage, that's a good starting point: useful contribution, and not technically complicated.


2015-09-16 21:19:18 +0200 commented answer Transform a list of coefficients to polynomial (in GF(2^8))

No prob, I agree with you ;-)

2015-09-16 16:01:29 +0200 answered a question Transform a list of coefficients to polynomial (in GF(2^8))

Here is a first solution

sage: sum(c*x**i for i,c in enumerate(reversed(coeff)))
x^6 + x^4 + x^3 + x^2 + 1

And another, with "Horner's method":

sage: p = 0
sage: for i in coeff:
....:      p = p*x+i
sage: p
x^6 + x^4 + x^3 + x^2 + 1
2015-09-08 12:28:30 +0200 commented answer How to use linear algebra inside of MixedIntegerLinearPrograms?

It is true that the "matrix shortcut" that is used in the add_constraint method is not available in set_objective. That should be rather straightforward to implement, though. If any of you feels like contributing to Sage, that is a good occasion.

2015-08-27 12:42:14 +0200 commented answer How do I generate list of connected graphs with given number of vertices?

By "document" are you refering to the documentation of nauty_geng? If so, know that you can get the doc of any Sage function with a question mark. In the present case, just type


In Sage.

2015-08-25 09:20:31 +0200 answered a question How do I generate list of connected graphs with given number of vertices?

If you read the documentation of nauty_geng, you will see that it has a '-c' flag to do exactly what you want.

2015-08-13 09:43:20 +0200 commented answer Isomorphisms of 2-skeletons of polytopes

It could make sense to have a .skeleton() method, by the way...

2015-08-13 09:41:44 +0200 answered a question Isomorphisms of 2-skeletons of polytopes

Couldn't you solve your problem by building the vertex graph of your polytope, and testing isomorphism between graphs?

2015-08-07 23:56:11 +0200 answered a question delete_edge() Won't Delete Edges from Graph

H = G does not make a copy of the graph. G and H are the very same object in memory, and if you modify one the other also contains the modification. It is the very same memory address. If you want to copy your graph, use H = copy(G).

This is a behaviour that you should expect in any object-oriented language.

2015-07-27 10:57:31 +0200 answered a question imports in sage/combinat/

For such questions, please write to sage-devel!for...

2015-07-21 17:49:21 +0200 answered a question Integer types and log()

Could you please report this bug by sending a message to sage-devel [1]? You only need say that the following looks weird:

sage: log(int(8),2)
sage: log(8,2)

About your problem: you can easily solve it by explicitly turning len(A) into a Sage integer:

sage: e=[None]*8
sage: log(len(e),2)
sage: log(Integer(len(e)),2)


2015-07-19 19:36:37 +0200 commented answer How to call GAPs SmallGroup from sage? (I am getting an error, though the correct library is installed.)

Err sorry, there is something that you can do (though you really should use the latest version of Sage): download this file into /Applications/ You can then run 'sage -i database_gap' again.

2015-07-19 19:34:15 +0200 commented answer How to call GAPs SmallGroup from sage? (I am getting an error, though the correct library is installed.)

This is due to a recent change in our hosting. Not your fault, but the only thing you can do is download a more recent version of Sage. If you have further questions and need to post long logs, please write to sage-support instead: this forum is " okayish" for simple questions, but it's hard to read long logs and you have no way to insert them in your 'comments'.

2015-07-19 07:39:56 +0200 answered a question How to call GAPs SmallGroup from sage? (I am getting an error, though the correct library is installed.)

Run 'sage -i database_gap`, that solved it for me. I am going to check why the wrong message is apparently returned.


2015-07-18 08:49:10 +0200 answered a question bug in the pq-trees library ?

I get the following trace, in which 0,2 and 4 are contiguous.

sage: from sage.graphs.pq_trees import P
sage: pqtree=P([[3, 5, 7],[4, 7], [1, 7], [3], [6],[0, 1, 3, 4],[0, 6], [0, 2, 5],[2], [2, 6]])
sage: pqtree
('P', [{3, 5, 7}, {4, 7}, {1, 7}, {3}, {6}, {0, 1, 3, 4}, {0, 6}, {0, 2, 5}, {2}, {2, 6}])
sage: pqtree.set_contiguous(0)
(1, True)
sage: pqtree.set_contiguous(2)
(1, True)
sage: pqtree.set_contiguous(4)
(1, True)
sage: pqtree
('P', [{3, 5, 7}, {1, 7}, {3}, {6}, ('Q', [('P', [{2}, {2, 6}]), {0, 2, 5}, {0, 6}, {0, 1, 3, 4}, {4, 7}])])

Perhaps your problem can be solved by using the latest version?

2015-07-16 10:58:05 +0200 commented answer Multiprocessing Maximal Cliques Enumeration

If you say that you have "some massive graphs", then to me your problem is of the second kind. And it would be much easier for you to parallelize it by solving several graphs at once. As per your pbitMCE algorithm, there are many ways to implement it in Sage, be it directly in Python code or in anything that can be compiled to a C library. You can then call it from Sage with

2015-07-15 17:02:06 +0200 answered a question Multiprocessing Maximal Cliques Enumeration

If networkx's implementation did not change since last I read it, then yes both are mono-core indeed, and those two are the only ones available in Sage.

What is your reason for wanting a mutithreaded version? Do you have one big graph in which you want to know all cliques? Or do you have many graphs in which you want to compute all cliques? In the latter case, you can much more easily parallelize the computations by running the same mono-threaded implementation on several instances at once.


2015-07-13 13:14:52 +0200 answered a question Seeking an efficient filter for partitions.

Would this work?

sage: Partitions(4, max_part=2,inner=[2]).list()
[[2, 2], [2, 1, 1]]
2015-07-08 16:38:46 +0200 received badge  Nice Answer (source)
2015-07-08 13:46:09 +0200 answered a question add matrix as a contraint

What about this?

sage: m = Matrix([[1,2,3],[4,5,6],[7,8,9]])
sage: p = MixedIntegerLinearProgram()
sage: x = p.new_variable(real=True, nonnegative=True)
sage: p.add_constraint(m*x <= 1)

  x_0 + 2.0 x_1 + 3.0 x_2 <= 1.0
  4.0 x_0 + 5.0 x_1 + 6.0 x_2 <= 1.0
  7.0 x_0 + 8.0 x_1 + 9.0 x_2 <= 1.0
  x_0 is a continuous variable (min=0.0, max=+oo)
  x_1 is a continuous variable (min=0.0, max=+oo)
  x_2 is a continuous variable (min=0.0, max=+oo)
2015-05-30 13:44:16 +0200 answered a question Enumerating solutions to a system of linear relations

Hello !

It seems that you are looking for that:

Note that it is a bit slow currently, but it should be improved in a couple of months if I get to do what I plan to.

Also, in case you want to solve such a system of equations and would be looking for one solution (not all of them), know that you can use Mixed Integer Linear Programming in Sage quite easily:

Good luck,


2015-05-03 11:54:48 +0200 answered a question How can I get Sage to go over all possible maps between two sets?

To list all functions from A to B you must iterate on all points of B^|A|. This can be achieved with itertools' 'product' function:

def all_functions(A,B):
    from itertools import product
    B_to_the_A = product(B,repeat=len(A))
    for p in B_to_the_A:
        yield dict(zip(A,p))

sage: for f in all_functions("abc",[0,1]):
....:     print f
{'a': 0, 'c': 0, 'b': 0}
{'a': 0, 'c': 1, 'b': 0}
{'a': 0, 'c': 0, 'b': 1}
{'a': 0, 'c': 1, 'b': 1}
{'a': 1, 'c': 0, 'b': 0}
{'a': 1, 'c': 1, 'b': 0}
{'a': 1, 'c': 0, 'b': 1}
{'a': 1, 'c': 1, 'b': 1}


2015-04-25 22:32:38 +0200 answered a question Hierholzer's algorithm


Your explanation is far from clear, but it seems that Hierholzer's algorithm is meant to give you a eulerian circuit in a eulerian graph. Isn't your problem solved by calling Graph.eulerian_circuit ?


2015-04-24 11:39:25 +0200 answered a question How can I search and count all induced subgraphs in a directed graph with edge labels?
2015-04-15 15:22:15 +0200 received badge  Nice Answer (source)
2015-04-14 18:12:28 +0200 answered a question A confusing syntax error when using elif

The 'elif' should not be inside of the 'if'

2015-04-14 15:27:19 +0200 received badge  Great Answer (source)
2015-04-14 07:52:52 +0200 received badge  Good Answer (source)
2015-04-13 21:47:39 +0200 received badge  Nice Answer (source)
2015-04-13 20:58:33 +0200 answered a question I want to review a ticket with positively reviewed dependencies. How do I use git to see the new changes?

If a branch A depends on branches A1 A2 .. Ai, then in order to see the modifications that A makes without seeing those already made in A1, ..., Ai you can type:

git diff A ^A1 ^A2 ... ^Ai

Of course the A and Ai must be names of branches or identifiers of commits.


2015-04-03 17:09:05 +0200 commented question bug in the pq-trees library ?

Could you please provide the commands to build your pq-tree?