Ask Your Question

j.c.'s profile - activity

2019-02-06 15:33:20 -0600 received badge  Famous Question (source)
2018-11-02 18:52:26 -0600 received badge  Notable Question (source)
2018-06-18 14:53:34 -0600 commented question syllables on symbolic expression

What exactly do you mean by syllable? The definition I'm familiar with is linguistic / phonological and on the face of it has nothing to do with symbolic expressions.

2018-06-16 11:51:28 -0600 commented answer RecursionError when installing SageMath 8.2

Note that this path issue only seems to be a problem when running Sage for the first time. You should be able to reinstall python3 again with homebrew and use Sage without any problem (until you upgrade versions).

2018-06-13 05:00:51 -0600 answered a question Algorithm for finding a defining polynomial for an unramified extension?

The short answer is that this will depend on the way you defined your unramified extension. If, for instance, you defined it using Zq or Qq applied to $p^n$ for small $p,n$ then what is returned is likely to be a Conway polynomial from a database included in SageMath based on the work of Frank Lübeck.

If there's some other specific case you're interested in, perhaps you can edit your question to include the code that constructs that particular extension.


What follows is "the long answer", or how I found this out, starting from knowing essentially nothing about algebraic number theory or any of SageMath's ANT functionality. Hopefully the description of the steps I took in diving into SageMath's source code will be helpful for you in finding the answers to any similar questions you might have in the future.

Suppose we've defined R as follows:

R.<a> = Zq(1024)

Then we can type

?R.defining_polynomial()

to look at the docstring for this particular function.

The resulting output, while somewhat helpful, does not explain what algorithm SageMath is using to compute it. However, it does contain a line pointing to the source code, something like:

File: /Applications/SageMath/local/lib/python2.7/site-packages/sage/rings/padics/padic_extension_generic.py

Now, it's a bit more convenient to look at this file online in e.g. the github mirror of the SageMath source code. I've linked to the specific line where the definition of defining_polynomial() is here.

In this case, it appears that this code simply returns _given_poly, which is defined in the class pAdicExtensionGeneric as one of the parameters to the class constructor. We never called this directly above; instead, we called Zq, so we should look for the code there.

We find that Zq is defined in sage/rings/padics/factory.py, specifically here. In the documentation to Zq, we find that either the polynomial can be specified by hand, or:

By default, the polynomial chosen is the standard lift of the generator chosen for $\mathbb{F}_q$.

In fact, we could have skipped some of the code-diving above as SageMath's reference site has a thematic tutorial on p-adics, see the documentation of Zq on the second page.

However, to find the details of the "generator chosen for $\mathbb{F}_q$", we must return to the code:

The code implementing this can be found here, which uses the modulus() function in the FiniteField class in sage/rings/finite_rings/finite_field_constructor.py.

Looking at the relevant part of that code, we see that modulus() is constructed from R.irreducible_element(n) where R = PolynomialRing(FiniteField(p), 'x') and where $p,n$ are $2,10$ respectively because the order we chose above was 1024.

If we look at the code for the class PolynomialRing, we find that its definition is split into different cases, and the relevant one here is PolynomialRing_dense_mod_p. The function irreducible_element() is defined within and we see that the default polynomial returned in this case comes from sage/rings/finite_rings/conway_polynomials.py (here), which in turn relies on sage/databases/conway.py (here), where we finally find the information that the database comes from Frank Lübeck's tables.

2018-06-13 03:01:54 -0600 received badge  Enthusiast
2018-06-11 15:21:29 -0600 commented answer What is the SAGE command for calculating a Frobenius number

@eric_g Thanks for linking the ticket. I see that it links the same MO question.

2018-06-11 10:59:40 -0600 received badge  Popular Question (source)
2018-06-11 10:58:28 -0600 answered a question What is the SAGE command for calculating a Frobenius number

It appears that this functionality has not been implemented in SageMath. This comment and the associated answer by Stan Wagon at MathOverflow state that the Mathematica function uses the algorithm described here:

A15: Frobenius Numbers by Lattice Point Enumeration by David Einstein, Daniel Lichtblau, Adam Strzebonski, and Stan Wagon.

Here is another paper describing an algorithm by Dale Beihoffer, Jemimah Hendry, Albert Nijenhuis, and Stan Wagon with different properties.

This algorithm of Böcker and Lipták is described in Beihoffer et al as "very elegant and simple", so perhaps that might be something easier to try to code, depending on your needs.

2018-06-11 04:01:37 -0600 commented answer RecursionError when installing SageMath 8.2

Given the path shown in the post /Users/jing/tools/SageMath/sage I don't think that the OP is trying to run sage from within the dmg file.

2018-06-11 03:58:40 -0600 answered a question RecursionError when installing SageMath 8.2

On the off-chance you're using Anaconda, try commenting out the export PATH="/anaconda/bin:$PATH" line in the .bash_profile file (and restarting your terminal) before you run Sage for the first time.

You can uncomment it again after sage successfully runs (until you have to rebuild or upgrade Sage).

2018-06-07 09:58:08 -0600 answered a question pdflatex not available from Jupyter in SageMath-8.1.app

There are some suggestions in this question.

However, the easiest thing to do might be to create a sagerc file per this page (I guess the default location is ~/.sage/sagerc) containing: export PATH = "$PATH:/Library/TeX/texbin/pdflatex"

2018-06-07 09:53:33 -0600 commented answer How to add path on sage startup

The first reference link should now point here http://doc.sagemath.org/html/en/refer...

2018-06-06 19:20:30 -0600 commented answer preparser state for regexs
2018-06-06 13:54:26 -0600 commented answer preparser state for regexs

Thanks, I'll see if I can figure out how to do that later tonight.

2018-06-06 13:09:23 -0600 received badge  Nice Answer (source)
2018-06-06 08:49:46 -0600 received badge  Necromancer (source)
2018-06-06 05:43:46 -0600 answered a question preparser state for regexs

I had a similar issue dealing with the preparser so I wrote an IPython extension which adds a cell magic %%noparse which disables the Sage preparser for the cell its applied to.

Save this code as noparse.py:

from IPython.core.magic import (Magics, magics_class, cell_magic)

import sage.repl.interpreter

@magics_class
class NoParseMagic(Magics):

    @cell_magic
    def noparse(self, line, cell):
        """
        Use this cell magic to disable Sage preparsing in an IPython cell.
        """
        sage.repl.interpreter._do_preparse = False
        self.shell.run_cell(cell)
        sage.repl.interpreter._do_preparse = True

def load_ipython_extension(ipython):
    ipython.register_magics(NoParseMagic)

If you like, you can copy this to .ipython/extensions/. Then in a Sage Jupyter notebook, you can run:

%load_ext noparse

to load the extension. Now the following works:

%%noparse
type(4)

which yields:

<type 'int'>

instead of:

<type 'sage.rings.integer.Integer'>
2018-05-30 22:40:04 -0600 commented answer Starting Sage from precompiled binary

You ought to be able to add back the conda path after first run of sage without trouble. At least, that's always worked for me on my macOS system.

2018-05-24 10:13:53 -0600 answered a question graphs.planar_graphs

To check the type of l, you can type ?l. You will see that l is a generator, not a list object. Thus in order to compute its length (and do other list-specific operations) you must convert it to a list using list.

2018-04-11 04:55:10 -0600 commented question How to plot implicit3d plot with level sets in SageMath?

I agree that it is not clear what level sets you're seeking to plot. However, the answers to these questions could be helpful https://ask.sagemath.org/question/919... https://ask.sagemath.org/question/896...

2018-04-11 04:36:45 -0600 answered a question Map a matrix to a block matrix

Here's another way to do it:

def f(elt):
    return matrix([elt for j in range(3)])

block_matrix([map(f,row) for row in M])

However, from testing with %%timeit on random 3x3 matrices (random_matrix(RDF,3,3)) it seems that this is always very slightly slower than your list constructor approach:

your approach:

1000 loops, best of 3: 932 µs per loop

my above approach:

1000 loops, best of 3: 958 µs per loop

I also tried using M.apply_map(f) but it seems that that function assumes that f returns a scalar element and I couldn't get it to work.

2018-04-10 06:18:05 -0600 received badge  Civic Duty (source)
2018-03-13 16:59:49 -0600 received badge  Nice Answer (source)
2018-03-05 10:12:12 -0600 received badge  Commentator
2018-03-05 10:12:12 -0600 commented answer Can we read local file from Sagecell

This is a way to read local files into a SageMath notebook on your own computer, but it won't work on SageMathCell: https://sagecell.sagemath.org/

2018-03-05 10:09:27 -0600 commented question How to plot similarity of two data sets in Sage?

I suppose your example figure shows expected and simulated on the y-axis with a third table giving the x-values. What do you mean by "the values normally double"? Do you mean that the corresponding values of expected and simulated are quite close to each other? If you plot the difference of expected and simulated against the x-values is that more informative? I also do not understand why points get collected near x=0 and y=0.

2018-03-03 07:05:53 -0600 commented answer Right click options not showing up for jsmol

for completeness, the issue is here https://trac.sagemath.org/ticket/19529

2018-03-03 05:41:59 -0600 answered a question Get variable of polynomial ring

p.variables() returns a tuple which contains the variables of p, so your function could be written:

def f(q):
   return q*q.variables()[0]
2018-03-02 13:28:04 -0600 commented question Sagemath 8.1 windows: Impossible to export jmol figure from Jupyter while it works with former notebook.

Yes, I was mistaken about what your problem was initially.

2018-03-02 12:02:56 -0600 commented question Sagemath 8.1 windows: Impossible to export jmol figure from Jupyter while it works with former notebook.

I now believe you're running into this issue: https://ask.sagemath.org/question/399...

2018-03-02 11:48:19 -0600 commented question Sagemath 8.1 windows: Impossible to export jmol figure from Jupyter while it works with former notebook.

Do you know what kernel you're running in jupyter? There should be a label in the top right of the window.

2018-03-02 10:24:10 -0600 commented answer SageMath and interact / ipywidgets with jupyter

Thanks for the info. I wasn't able to accept my own answer previously since I didn't have 50 points, but now I can.

2018-03-02 10:22:20 -0600 marked best answer SageMath and interact / ipywidgets with jupyter

I got the SageMath kernel working well inside my anaconda distribution's copy of jupyter, following these instructions, so I can open SageMath notebooks using anaconda jupyter and they run perfectly fine -- almost.

I would like to get interact elements / ipywidgets working when I use SageMath as a kernel in anaconda jupyter, but with my current configuration (hopefully described in sufficient detail below), I get the following error message in the console

[IPKernelApp] WARNING | Widget Javascript not detected. It may not be installed or enabled properly.

and the notebook simply outputs the initial value of the function with no interactivity.


I'm running SageMath 8.1 on macOS. I've been able to get interact elements and ipywidgets with SageMath code running in the SageMath jupyter notebook interface (not sure if this was necessary, but I ran

/local/bin/jupyter nbextension enable --py widgetsnbextension

in the SageMath directory.) Everything works as expected, i.e. if I run sagemath -n jupyter and open a notebook containing:

import ipywidgets as widgets

widgets.IntSlider( value=7, min=0, max=10, step=1, description='Test:', disabled=False, continuous_update=False, orientation='horizontal', readout=True, readout_format='d' )

I get a slider widget which works.

Similarly, examples from this interact tutorial on the SageMath wiki run perfectly fine in SageMath jupyter.

I also have an up-to-date anaconda install of jupyter where the ipywidgets nbextension has been enabled; the above ipywidgets code can be run in anaconda jupyter with the ordinary python kernel and works fine.


[The real reason I am asking this question is I would like to figure out how to get interactive widgets working in jupyterlab with the SageMath kernel, but I'm guessing that if the above question can be answered, I can get everything else working as well.]

2018-03-02 10:22:20 -0600 received badge  Scholar (source)
2018-03-02 08:14:14 -0600 received badge  Student (source)
2018-03-02 08:13:59 -0600 received badge  Self-Learner (source)
2018-03-01 22:26:29 -0600 answered a question Sagemath 8.1 windows: Impossible to export jmol figure from Jupyter while it works with former notebook.

I can confirm that there is an issue here with SageMath and jupyter but I don't have any solution, unfortunately.

I just tested jmol in sage -n jupyter on macOS and see the same thing that you do where the submenus are unable to be displayed. I believe we are running into this previous issue.


the following is probably not relevant

You could also try installing the SageMath kernel into jupyter by following the instructions here, with appropriate modifications for Windows. Note that this requires more fiddling and you might find that interact elements don't work by default.