Ask Your Question

slelievre's profile - activity

2019-01-16 11:46:18 -0600 received badge  Nice Answer (source)
2019-01-16 05:17:44 -0600 answered a question CoCal load and commit to github

Note that Ask Sage is dedicated to questions about SageMath, the mathematics software.

For questions and requests concerning CoCalc, please use one of the following channels:

That said, you can open a CoCalc terminal and push to GitHub, provided your project has an "internet access" upgrade.

2019-01-11 06:27:33 -0600 edited question Plot of linear programming restrictions 2d, 3d

Is there a way automatical plot the restiriction and the solution. I know how to plot them by hand. Is there an automatical graphical solution included?

2019-01-11 06:23:22 -0600 commented answer A way to infer multiplication?

Well done. You can accept your own answer to mark the question as solved.

2019-01-10 13:11:38 -0600 commented question Link to file within worksheet

@ASK: Are you using SageMath with the Jupyter Notebook? Or the SageNB notebook?

2019-01-10 12:58:26 -0600 answered a question can we use BFS and DFS algorithm in sagemath?

In SageMath, if you define a graph G (for example G = Graph()), then G.coloring? gives the documentation of the coloring method for G, and G.coloring?? gives the source code.

Reading the documentation reveals two choices are offered: using the "dancing link algorithm" or using "mixed linear integer programming".

See also SageMath documentation for graph coloring.

2019-01-10 12:50:13 -0600 edited question Error in drawing the complement of CompleteBipartite Graph

The following code generates the wrong Graph graphs.CompleteBipartiteGraph(5,6).complement() Can anyone help to correct it please

2019-01-10 12:49:53 -0600 answered a question Error in drawing the complement of CompleteBipartite Graph

The first comment of

explains that the complement graph looks wrong only because it is plotted with the same layout as the original graph, so its edges are all horizontal, drawn on top of each other, making the drawing misleading (it looks as though many edges are missing).

To see the structure of the complement better, change the layout:

sage: G = graphs.CompleteBipartiteGraph(5, 6)
sage: G.show()

sage: Gc = G.complement()
sage: Gc.show(layout='spring')
2019-01-10 12:28:14 -0600 commented question A way to infer multiplication?
2019-01-09 04:28:29 -0600 edited question Find factors of large integers without fully factoring

I have to find the smallest factor of a big number with SAGE. The problem with the factor command is that it displays the results only when the number is fully factored and so for a big number it could take an eternity to have the result. Has somebody a good program for finding factors of a big number without waiting for a full factorization?

2019-01-08 13:40:35 -0600 received badge  Good Answer (source)
2019-01-07 22:43:32 -0600 commented answer How to display a complex number with its real part comes before its imaginary part?

Good exploration of this pretty-printing exercise.

In my experience, pretty-printing always takes a while to get right.

Hints:

  • add the new examples to the function's documentation
  • update the function's documentation to use the new name
  • try more examples and make more changes if needed

For instance, the following examples might suggest some changes:

sage: aa = [0, 1]
sage: bb = [0, 1, -1, 2, -2, 1 - sqrt(3), sqrt(3) - 1, 1 + sqrt(3), -1 - sqrt(3)]
sage: for a in aa:
....:     for b in bb:
....:         print('{:20} {:50}'.format(str(a + b * I), cpx(a + b * I)))
2019-01-07 22:18:08 -0600 commented answer Any way to make Sage display large matrices all in 1 line?

Slight improvement: matrix_plot(A) displays the dots in a frame, as would plot(A, axes=False, frame=True).

2019-01-07 08:06:25 -0600 commented question Generic Symbolic function as input in actual funciton

This function, if used with exact input, will keep everything exact, which might be very slow.

Floating-point will be hugely faster, with the drawback of being not certified.

The best compromise will probably be to use Arb.

2019-01-07 08:01:39 -0600 commented question Generic Symbolic function as input in actual funciton

If using time, add import time as first line of the function or before the function.

2019-01-07 08:00:23 -0600 commented question Generic Symbolic function as input in actual funciton

Body of the def needs indenting.

2019-01-07 07:59:59 -0600 commented question Generic Symbolic function as input in actual funciton

Replacing a = a + b by a += b also increases readability.

2019-01-07 07:48:03 -0600 commented question Generic Symbolic function as input in actual funciton

Side suggestion: semicolons are not needed. Removing them makes code more readable.

2019-01-07 07:34:38 -0600 answered a question Any way to make Sage display large matrices all in 1 line?

Here is a silly answer, along with hopefully less silly ones.

Silly answer: just make the font size small enough so lines fit in the screen's width:

Imgur

Less silly: the visualize_structure method gives a graphical view of the nonzero positions:

sage: A.visualize_structure()

Imgur

Listing nonzero positions in each row is also a sensible (and copy-pasteable) way to visualize the matrix:

sage: dict((i, A.nonzero_positions_in_row(i)) for i in range(A.nrows()))
{0: [0, 7, 14, 67],
 1: [13, 85, 86, 93],
 2: [4, 11, 12, 38],
 3: [8, 16, 40, 75],
 4: [3, 32, 39, 78],
 5: [22, 47, 58, 79],
 6: [5, 26, 57, 68],
 7: [44, 65, 81, 87],
 8: [37, 88, 90, 91],
 9: [6, 46, 52, 84],
 10: [36, 43, 61, 95],
 11: [9, 20, 49, 92],
 12: [33, 34, 45, 71],
 13: [27, 50, 56, 69],
 14: [25, 41, 55, 72],
 15: [1, 19, 23, 30],
 16: [17, 64, 73, 80],
 17: [24, 48, 60, 74],
 18: [54, 70, 76, 83],
 19: [10, 18, 21, 51],
 20: [29, 35, 94, 97],
 21: [31, 42, 62, 96],
 22: [15, 53, 77, 98],
 23: [2, 59, 82, 89],
 24: [3, 28, 63, 66]}

One could also skip the whitespace by custom printing the matrix as follows:

sage: for row in A:
....:     print(''.join([str(a) for a in row]))
....:
100000010000001000000000000000000000000000000000000000000000000000010000000000000000000000000000000
000000000000010000000000000000000000000000000000000000000000000000000000000000000000011000000100000
000010000001100000000000000000000000001000000000000000000000000000000000000000000000000000000000000
000000001000000010000000000000000000000010000000000000000000000000000000000100000000000000000000000
000100000000000000000000000000001000000100000000000000000000000000000000000000100000000000000000000
000000000000000000000010000000000000000000000001000000000010000000000000000000010000000000000000000
000001000000000000000000001000000000000000000000000000000100000000001000000000000000000000000000000
000000000000000000000000000000000000000000001000000000000000000001000000000000000100000100000000000
000000000000000000000000000000000000010000000000000000000000000000000000000000000000000010110000000
000000100000000000000000000000000000000000000010000010000000000000000000000000000000100000000000000
000000000000000000000000000000000000100000010000000000000000010000000000000000000000000000000001000
000000000100000000001000000000000000000000000000010000000000000000000000000000000000000000001000000
000000000000000000000000000000000110000000000100000000000000000000000001000000000000000000000000000
000000000000000000000000000100000000000000000000001000001000000000000100000000000000000000000000000
000000000000000000000000010000000000000001000000000000010000000000000000100000000000000000000000000
010000000000000000010001000000100000000000000000000000000000000000000000000000000000000000000000000
000000000000000001000000000000000000000000000000000000000000000010000000010000001000000000000000000
000000000000000000000000100000000000000000000000100000000000100000000000001000000000000000000000000
000000000000000000000000000000000000000000000000000000100000000000000010000010000001000000000000000
000000000010000000100100000000000000000000000000000100000000000000000000000000000000000000000000000
000000000000000000000000000001000001000000000000000000000000000000000000000000000000000000000010010
000000000000000000000000000000010000000000100000000000000000001000000000000000000000000000000000100
000000000000000100000000000000000000000000000000000001000000000000000000000001000000000000000000001
001000000000000000000000000000000000000000000000000000000001000000000000000000000010000001000000000
000100000000000000000000000010000000000000000000000000000000000100100000000000000000000000000000000

or, replacing zeros by dots:

sage: for row in A:
....:     print(''.join([str(a) if a else '.' for a in row]))
....:
1......1......1....................................................1...............................
.............1.......................................................................11......1.....
....1......11.........................1............................................................
........1.......1.......................1..................................1.......................
...1............................1......1......................................1....................
......................1........................1..........1....................1...................
.....1....................1..............................1..........1..............................
............................................1....................1...............1.....1...........
.....................................1..................................................1.11.......
......1.......................................1.....1...............................1..............
....................................1......1.................1.................................1...
.........1..........1............................1..........................................1......
.................................11..........1.........................1...........................
...........................1......................1.....1............1.............................
.........................1...............1.............1................1..........................
.1.................1...1......1....................................................................
.................1..............................................1........1......1..................
........................1.......................1...........1.............1........................
......................................................1...............1.....1......1...............
..........1.......1..1.............................1...............................................
.............................1.....1..........................................................1..1.
...............................1..........1...................1.................................1..
...............1.....................................1.......................1....................1
..1........................................................1......................1......1.........
...1........................1..................................1..1................................

The above can be obtained in a simpler way, starting from the matrix's str and using replace once:

sage: print(A.str().replace(' ', ''))
[100000010000001000000000000000000000000000000000000000000000000000010000000000000000000000000000000]
[000000000000010000000000000000000000000000000000000000000000000000000000000000000000011000000100000]
[000010000001100000000000000000000000001000000000000000000000000000000000000000000000000000000000000]
[000000001000000010000000000000000000000010000000000000000000000000000000000100000000000000000000000]
[000100000000000000000000000000001000000100000000000000000000000000000000000000100000000000000000000]
[000000000000000000000010000000000000000000000001000000000010000000000000000000010000000000000000000]
[000001000000000000000000001000000000000000000000000000000100000000001000000000000000000000000000000]
[000000000000000000000000000000000000000000001000000000000000000001000000000000000100000100000000000]
[000000000000000000000000000000000000010000000000000000000000000000000000000000000000000010110000000]
[000000100000000000000000000000000000000000000010000010000000000000000000000000000000100000000000000]
[000000000000000000000000000000000000100000010000000000000000010000000000000000000000000000000001000]
[000000000100000000001000000000000000000000000000010000000000000000000000000000000000000000001000000]
[000000000000000000000000000000000110000000000100000000000000000000000001000000000000000000000000000]
[000000000000000000000000000100000000000000000000001000001000000000000100000000000000000000000000000]
[000000000000000000000000010000000000000001000000000000010000000000000000100000000000000000000000000]
[010000000000000000010001000000100000000000000000000000000000000000000000000000000000000000000000000]
[000000000000000001000000000000000000000000000000000000000000000010000000010000001000000000000000000]
[000000000000000000000000100000000000000000000000100000000000100000000000001000000000000000000000000]
[000000000000000000000000000000000000000000000000000000100000000000000010000010000001000000000000000]
[000000000010000000100100000000000000000000000000000100000000000000000000000000000000000000000000000]
[000000000000000000000000000001000001000000000000000000000000000000000000000000000000000000000010010]
[000000000000000000000000000000010000000000100000000000000000001000000000000000000000000000000000100]
[000000000000000100000000000000000000000000000000000001000000000000000000000001000000000000000000001]
[001000000000000000000000000000000000000000000000000000000001000000000000000000000010000001000000000]
[000100000000000000000000000010000000000000000000000000000000000100100000000000000000000000000000000]

or twice:

sage: print(A.str().replace(' ', '').replace('0', '.'))
[1......1......1....................................................1...............................]
[.............1.......................................................................11......1.....]
[....1......11.........................1............................................................]
[........1.......1.......................1..................................1.......................]
[...1............................1......1......................................1....................]
[......................1........................1..........1....................1...................]
[.....1....................1..............................1..........1..............................]
[............................................1....................1...............1.....1...........]
[.....................................1..................................................1.11.......]
[......1.......................................1.....1...............................1..............]
[....................................1......1.................1.................................1...]
[.........1..........1............................1..........................................1......]
[.................................11..........1.........................1...........................]
[...........................1......................1.....1............1.............................]
[.........................1...............1.............1................1..........................]
[.1.................1...1......1....................................................................]
[.................1..............................................1........1......1..................]
[........................1.......................1...........1.............1........................]
[......................................................1...............1.....1......1...............]
[..........1.......1..1.............................1...............................................]
[.............................1.....1..........................................................1..1.]
[...............................1..........1...................1.................................1..]
[...............1.....................................1.......................1....................1]
[..1........................................................1......................1......1.........]
[...1........................1..................................1..1................................]

(one could remove the brackets using .replace('[', '').replace(']', '')).

2019-01-07 07:18:37 -0600 received badge  Nice Answer (source)
2019-01-07 06:55:13 -0600 commented question Any way to make Sage display large matrices all in 1 line?

Are you working in the Sage REPL (read-eval-print loop), also known as the command-line interface (in a terminal), or in the Jupyter Notebook, or in the SageNB notebook, or in SageTeX, or other?

2019-01-07 04:08:51 -0600 answered a question Is there a way to make sage print out all monomials of a Boolean Ring?

Hint: start with the boolean polynomial ring generators.

sage: B = BooleanPolynomialRing(9, 'x', order = 'lex')
sage: print(B.gens())
(x0, x1, x2, x3, x4, x5, x6, x7, x8)
2019-01-05 07:19:52 -0600 received badge  Nice Answer (source)
2019-01-05 04:53:24 -0600 commented question Sage not detecting intergers in Boolean Polynomial Ring?

Note: instead of

for i in range(len(equations)):
    for j in equations[i]:
        if j == 1:
            print 'true'

you could use

for eq in equations:
    for j in eq:
        if j == P.one():
            print 'true'
2019-01-05 04:50:44 -0600 commented answer Sage not detecting intergers in Boolean Polynomial Ring?

Even better: use P.one() instead of P(1).

2019-01-04 13:18:30 -0600 answered a question How to display a complex number with its real part comes before its imaginary part?

One way to obtain \mathbf{i} instead of just i is to use a string replacement.

To also get the real part before the imaginary part, why not use a little helper function.

The following might do what you want.

def latex_of_complex(z):
    r"""
    Return a LaTeX string for this complex number.

    EXAMPLE::

        sage: latex_of_complex(0)
        0
        sage: latex_of_complex(2)
        2
        sage: latex_of_complex(4*i)
        4 \mathbf{i}
        sage: latex_of_complex(7 + 8*i)
        7 + 8 \mathbf{i}
    """
    if z == 0:
        return LatexExpr('0')
    a = z.real()
    b = z.imag()
    if b == 0:
        return latex(a)
    s = (latex(a) + ' + ') if a else ''
    return LatexExpr(s) + latex(b * i).replace('i', r'\mathbf{i}')

Now use latex_of_complex instead of latex to latexify complex numbers with the requested customization.

2019-01-04 12:51:01 -0600 commented answer .coefficients output

Congratulations on solving your problem. Would you share the complete code for a simple example for the benefit of other users?

2018-12-28 13:58:51 -0600 commented question Cannot install SageMath on Ubuntu 16.04: "Maximum recursion depth exceeded"

Please try with Sage 8.5 and report if you get the same error.

Run the following in a terminal and check what output you get:

python --version
2018-12-28 13:25:54 -0600 commented question No Output Given : []
2018-12-28 13:20:09 -0600 answered a question Why doesn't assume(x, 'real') exclude complex values when using plot(x^(1/3)) over a negative domain?

The following workaround can help:

sage: plot(lambda x: sgn(x)*(x*sgn(x))^(1/3), (-5, 5))

One can also use an implicit plot:

sage: implicit_plot(y^3 == x, (x, -5, 5), (y, -2, 2))
2018-12-28 03:27:30 -0600 commented answer Norm in UniversalCyclotomicField

The fix is merged in Sage 8.6.beta0.

2018-12-25 18:10:23 -0600 answered a question Is it possible to remove the latex parentheses from exponential functions?
2018-12-25 08:11:01 -0600 commented question Is it possible to remove the latex parentheses from exponential functions?
2018-12-25 05:21:17 -0600 commented answer generate multiple Vars and vectors with these Vars

@ortolij - i converted @rburing's comment into an answer.

2018-12-24 06:43:09 -0600 commented question Why doesn't f(alpha) act like a function?

To display blocks of code or error messages, skip a line above and below, and do one of the following (all give the same result):

  • indent all code lines with 4 spaces
  • select all code lines and click the "code" button (the icon with '101 010')
  • select all code lines and hit ctrl-K

For instance, typing

If we define `f` by

    def f(x, y, z):
        return x * y * z

then `f(2, 3, 5)` returns `30` but `f(2*3*5)` gives:

    TypeError: f() takes exactly 3 arguments (1 given)

produces:

If we define f by

def f(x, y, z):
    return x * y * z

then f(2, 3, 5) returns 30 but f(2*3*5) gives:

TypeError: f() takes exactly 3 arguments (1 given)

Please edit your question to do that.

2018-12-24 03:19:51 -0600 answered a question LaurentPolynomial can't factor constants
2018-12-19 17:05:54 -0600 answered a question How to import functions to program?

Here is an example:

sage: a = 26 / 7
sage: c = continued_fraction(a)
sage: c
[3; 1, 2, 2]

From there one can explore the convergents:

sage: c.convergent(0)
3
sage: c.convergent(1)
4
sage: c.convergent(2)
11/3
sage: c.convergent(3)
26/7

The numerator and denominator of a convergent can be called using the methods numerator and denominator or p and q.

sage: c.numerator(2)
11
sage: c.denominator(2)
3
sage: c.p(2)
11
sage: c.q(2)
3

One can also start from a list:

sage: c = continued_fraction([3, 1, 2, 2])
sage: c
[3; 1, 2, 2]

etc.

2018-12-13 11:41:23 -0600 answered a question How to make points smaller than size 1 in point3d?

If you're interested in a 2d view in the end, just choose some projection direction, apply the projection to your points, and do a point2d; or see if viewer='tachyon' will give something acceptable.

If you want a 3d view, given that point3d gives you spheres, you might as well plot spheres yourself and choose the radius; hopefully you can choose a smaller radius than the one given by point3d; or you could explore what sage.plot.plot3d.shapes2.Point actually does and try to hack some variation.

2018-12-12 05:39:39 -0600 commented question Integration on a region defined by an inequality
2018-12-12 05:35:08 -0600 answered a question Overloading the binary operation of symmetric groups to reverse the order

As a workaround, instead of multiplying with *, one can explicitly use right multiplication with __rmul__:

sage: S3 = SymmetricGroup(3)
sage: a = S3((1, 2))
sage: b = S3((2, 3))
sage: a * b
(1,3,2)
sage: a.__rmul__(b)
(1,2,3)
2018-12-12 05:25:04 -0600 commented question Find factors of large integers without fully factoring
2018-12-12 05:24:33 -0600 commented question Lower prime divisor