Ask Your Question

nbruin's profile - activity

2019-11-09 13:25:57 -0600 answered a question How to create a subgroup with MAGMA inside SAGE of a group created with MAGMA inside SAGE?

As pointed out in a comment, there is a naming issue: you first create an object representing $S_4$ and bind it to the name GGG in sage. The object itself doesn't know about that binding or name, so when you translate it to Magma, that information is not present there. Objects created via sage's magma interface will be stored in the list _sage_, so your group can probably be referred to via something like _sage_[2] or so. Figuring out which place it's stored in is a rather fragile operation, though. It would be better to let the interface do that lookup for you.

The subgroup you want to make could be created via something like

GGG.sub(sigma)

where sigma is the cycle $(1,2)$ represented in magma. This is difficult to obtain, because magma's syntax for creating permutation group elements is finicky: you need a "group context" to create it, and I don't think the standard interface tools allow you to do this. Ideally something like magma(gensGG[2]) would do the trick, but it doesn't.

This works, though:

sigma = magma('Sym(4)!(1,2)')

I think going forward, your chances of success would be a little better by using sage's own wrappers of Gap's permutation groups:

sage: GG=SymmetricGroup(4)
sage: sigma=GG( (1,2))

although that object sigma still doesn't know how to be translated to magma. Implementing that would be fairly straightforward, though (and it would end up doing the analogue of what is done above).

2019-11-05 21:19:36 -0600 received badge  Good Answer (source)
2019-11-05 20:34:37 -0600 commented answer Latex multicolumn is not recognized

(please ignore or delete this comment)

2019-11-05 10:31:37 -0600 commented answer linear algebra derivative expressions

I suspect you have to write things out in explicit variables then. It looks like you basically want to work with a fairly general vector field. I'm not so sure a computer algebra system can help you much with that without you doing some pretty specific preprocessing. The examples you gave are (trivially) resolved. Perhaps a different example closer to what you want to accomplish would help.

2019-11-05 04:29:59 -0600 received badge  Nice Answer (source)
2019-11-03 23:56:34 -0600 answered a question linear algebra derivative expressions

I assume your matrix A has entries that do not depend on the entries of x? Then with $y=Ax$ you already define $y$ to be a linear function in $x$, so the derivative of $y$ with respect to $x$ is simply $x\mapsto A$.

Similarly, assuming that $A$ a symmetric matrix that is independent of $x$ (otherwise your function doesn't deserve the name quadratic form) you have that the total derivative of $\alpha$ with respect to $x$ is simply $x\mapsto x^t A$.

No computation necessary; just a calculus book.

2019-10-31 15:30:57 -0600 answered a question Output of @interact disappears when exporting Jupyter notebook to HTML

This is not really a sage question anymore, since the interact feature is now realized by jupyter widgets, which exists outside of sage as well. That's good, because there is a larger community that may be able to help you.

If you go to "widgets -> embed widgets" you are offered copy-pastable html code that produces exactly the image that you want. So you get html that does what you want.

I haven't been able to find a tool that automatically does the substitutions for you. In fact, this thread (or rather the lack of a satisfying response) suggests this might still be missing functionality.

In general, the ipywidgets documentation is probably the way to go. As mentioned there jupyter-sphinx or nbsphinx may offer the functionality you are looking for.

EDIT: (elevating one of the comments below for better visibility)

The route "File -> Download As -> HTML", after one saves the widgets state, still fails. However, as suggested in the Plotly thread linked above, it can be successfully done through the command line:

$jupyter nbconvert --to html test.ipynb
2019-10-27 11:17:31 -0600 commented answer bus or segmentation fault calling integrate

The error message shown here indicates it's maxima that blows up, and indeed, if you include the right initialization code in maxima, it crashes on this example. So it's a bug in maxima, as the other bugs are, The place to report them to get them worked on is maxima. The ticket referenced above is a dumping ground of (probably) maxima-related integration faults anyway. There's nog guarantee the examples there ae actually listed. So if you want to keep track of this example on trac too, then that ticket is a good one to put the example. The only way for that ticket to make progress is if someone takes the effort of reporting the cases listed there to maxima, in a way that the behaviour shows in maxima directly.

2019-10-26 23:06:42 -0600 answered a question bus or segmentation fault calling integrate

Looks a lot like the reports on https://trac.sagemath.org/ticket/25636 by someone who shares your name.

2019-10-22 16:25:27 -0600 answered a question Can I git pull Sage if I compiled from source?

Updating an already cloned git-repository is normally done with git pull .... See

http://doc.sagemath.org/html/en/devel...

for more basic information to set up git properly with remote repositories to pull updates from. Once you have that set up (and are on, say, master branch), you should be able to do something like git pull origin master to update your branch. Most of the time, the make build step after that should be sufficient to update your build. See the rest of the developer guide for tips on what to do when it's not. You can also look into using the git-trac utility that is explained there. It makes several configuration steps a little easier.

2019-10-17 00:19:33 -0600 answered a question Looking for musical exercises using sage

Producing sound (files) from python is pretty straightforward. Python has standard library support for it and more advanced packages that google can guide you to. This is not a task that sage specifically will be good at, but the python ecosystem should give you the basic tools for reading/writing sound data. Once you have the data you can analyse it and fourier transform it to your heart's content. Or you can produce wave forms and write them to sound files.

For actually playing and recording sound (not just reading and writing sound files) you could look into something like python-sounddevice or some other library, but be aware that if you are using a notebook (remotely!) the sound device on the server may not be the same as the sound device on the computer where your browser runs. In Jupyter, you may be able to use IPython.display.Audio.

2019-10-16 11:16:14 -0600 answered a question Finite field F_16=F_4[y]/(y**2+xy+1) (where F_4=F_2[x]/(x**2+x+1))

To construct GF(16) as a two-step extension, which is what it appears you are interested in, would go as follows.

sage: k=GF(2)
sage: kx.<x>=k[]
sage: kt.<t>=k[]
sage: kx.<x>=k.extension(t^2+t+1)
sage: x^2+x+1
0
sage: kxu.<u>=kx[]
sage: kxy.<y>=kx.extension(u^2+x*u+1)
sage: y^2+x*y+1
0
sage: kxy
Univariate Quotient Polynomial Ring in y over Finite Field in x of size 2^2 with modulus y^2 + x*y + 1

This has a slight problem: the field kxy constructed above is a relatively inefficient version of GF(16): sage just knows it's a quotient of a polynomial ring, whereas for GF(16) sage has a specialized implementation that should be quite fast.

As suggested by dan_fuela one you can just construct GF(16) any way you want and then find the elements x,y with the desired properties in it. You don't have to exhaustively search the whole field for the right minimal polynomials to occur though: you can just ask sage to solve the relevant polynomial equation. In GF(16) it doesn't matter much because it's a tiny field, but enumerating larger fields quickly becomes undoable.

sage: kxy=GF(16)
sage: kxyT.<T>=kxy[]
sage: x=(T^2+T+1).roots()[0][0] # this just selects the first root from the full list of roots with multiplicities
sage: y=(T^2+x*T+1).roots()[0][0]
sage: x^2+x+1
0
sage: y^2+x*y+1
0
2019-09-29 15:08:02 -0600 answered a question I can't show special characters

For show(<string>) the code executed is basically show(latex(<string>)).

If you want to work with non-ascii characters, you should go for unicode. In Python3 that's going to be the default. At the moment we're still on Python2, so you should do something like

S= u'á'

If you do that, then you'll see that show(S) gives you an error. If you define

T='á'

then show(T) basically "silently" fails: the non-ascii character gets inserted into a TeX typesetting routine that is currently not capable of handling non-ascii characters. There are variants of TeX (specifically XeTeX) that are unicode-capable, but that's not what is currently used in sage.

The normal LaTeX way of typesetting a word like "rápido" would be as "r\'apido", but that doesn't seem to be supported in the notebook either.

I think it would be entirely reasonable to open a feature-request to let "show" support non-ascii (and particularly accented) characters.

2019-09-20 01:42:55 -0600 commented answer Determining if two subgroups of a symmetric group are conjugate

The problem is that ConjugacyClass looks like it determines the conjugacy class of elements, not of subgroups.

2019-09-20 01:40:22 -0600 edited answer Determining if two subgroups of a symmetric group are conjugate

This is quite old, but since it is not answered:

One way to do this is do use the (built-in) version of GAP to test the conjugacy.

This has the function RepresentativeAction(g,g1,g2) which takes three arguments, g, g1, g2 and either returns fail if g1 and g2 are not conjugate in g, or returns a conjugating element if they are.

You need to turn everything into a GAP-object in order to do this.

 gap.RepresentativeAction(gap("SymmetricGroup(3)"), gap(G1), gap(G2))

This returns () which is the identity, indicating that the groups are not only conjugate, but identical.

EDIT: if you define

S = SymmetricGroup(3)
gen1 = Permutation('(1,2)(3)')
gen2 = Permutation('(1,3)(2)')
H1=S.subgroup([gen1])
H2=S.subgroup([gen2])

You'll see that you get

sage: gap.RepresentativeAction(gap(S),gap(H1),gap(H2))
(2,3)

so the subgroups are conjugate, but not identical. Useful to know how to get this info, though!

2019-09-20 01:19:39 -0600 commented question Wrong hessian

That is indeed astonishing. It would be much more useful if you would paste in the straight output that you get from print H. Please edit your question so that it does show whatever computation you want to do in executable form. I don't think anyone will understand the character string you are currently displaying.

2019-09-18 11:53:41 -0600 answered a question What is DATA variable analog when running in Jupyter notebook?

When you run code in a jupyter notebook, the code just runs with the current directory set to the location of the ipynb file. So if you execute something like save(...) or load(...), that is where the files would be located. You can change the current directory with os.chdir to another directory, and then you can load and save from/to there. You'd have to make sure to re-execute that change when you restart the kernel. Or you can specify full paths and not depend on the current directory at all.

2019-08-26 13:10:53 -0600 answered a question LLL algorithm extended to linearly dependent vectors

Have you tried the standard ".LLL" method on integer matrices? It seems to work fine on non-maximal rank examples too. You might want to dig into the documentation of the underlying libraries to confirm that the results are intended to be valid.

2019-08-08 10:34:53 -0600 answered a question The shortest string containing all given substrings

The program doesn't use any sage-specific functionality, and it doesn't have to. You can just use any correct python implementation. The routine presented seems like a verbatim copy of the one on https://en.wikipedia.org/wiki/De_Brui... . Note that the definition of a "de bruijn sequence" includes it's a cyclic sequence. So you should be appending the head of the sequence to the tail:

"hccc" in seq+seq[:3]
2019-07-31 11:47:21 -0600 answered a question can't display the inverse of complex matrix

I think the problem is that you compute with symbolic matrices. Computations there can easily blow up horribly and I expect that is what's happening. The line:

FFTc.change_ring(CC)

produces a new matrix with complex-float entries, but since you don't assign it to anything, the resulting matrix just gets lost. You continue working with the symbolic matrix after that, and I think that just grinds to a halt due to explosion of intermediate expressions. Perhaps you meant to compute with a float approximation to the matrix instead?

Note that computing a "kernel" of a float matrix generally doesn't work, because numerically matrices of non-maximal rank aren't really distinguishable from maximal rank ones. Also computing the "inverse" numerically is generally tricky and requires special measures to get a bit of numerical stability. Sage unfortunately doesn't do that by default (in part because you're probably doing something wrong if you're computing an inverse numerically).

2019-07-25 00:55:44 -0600 received badge  Nice Answer (source)
2019-07-24 16:49:20 -0600 answered a question Complex numerical integration: how can it be performed in SageMath?

I think you can use something along the lines of

CC=ComplexBallField(100)
f=fast_callable(e^(I*(x+x^3/3)),vars=[x],domain=CC)
CC.integral(lambda x,_: f(x)  ,CC(0),CC(1))

which gets you a result along the lines of:

[0.7778906934510079480835322919 +/- 3.85e-29] + [0.5105422937539419671472249270 +/- 1.82e-29]*I

Exciting part: these error bounds are meant to be certified! No other computer algebra package will give you certified numerical integrals. This is using ARB, see http://fredrikj.net/blog/2017/11/new-...

Caveat: this is rather new code, so the interface hasn't been tested very much yet. In particular, while the code above should propagate intervals properly through f, it could easily be the case that some funny intermediate coercion step loses a ball radius somewhere. The integrator does depend on correct propagation of ball radii.

2019-06-05 13:11:46 -0600 answered a question Explicitly clean all memory usage

This is really a question about python memory management. If I'm not mistaken, python may under certain conditions give memory back to the OS, but claiming memory from the OS is quite an expensive operation, so for efficiency reasons, I'd expect python to be rather reluctant at doing so: most of the time it's better to keep a hold of the memory for reuse later.

Another thing to be aware of: just because you delete one reference to the data structure doesn't necessarily imply the data structure can be garbage collected. It could be that the IPython history buffer holds a reference to it or that there's a debugging dataframe lying around that is still referencing the data structure.

2019-05-30 17:24:48 -0600 answered a question AttributeError: 'dict' object has no attribute 'solve'

I don't think solve does what you hope it does. It seems from your code that you want to select elements from a groebner basis of bounded degree (I guess n is the length of G?) and want to find the solutions to those equations.

If the equations you select still define a 0-dimensional variety and you're interested in solutions that take values in the ground field, you might be able to do something like

J=ideal([f for f in I.groebner_basis() if f.degree() lt num])
J.variety()

Putting your selected polynomials in a dictionary is probably not a good idea. You'd be better off putting them in a list, i.e.

P=[]
...
    P.append(G[i])
    ...
2019-05-30 13:48:10 -0600 answered a question Why is exponentiation of points on elliptic curve so fast?

Note that by constructing the group in the way you do, you get a group that is explicitly represented as an additive cyclic group (with an explicit generator). When you create random elements, the system probably just takes an appropriate random element by taking a random multiple of the generator and store it as such.

As a consequence, if you then compute a multiple of THAT point, the system only has to multiply two integers and take it mod the order of the group to represent the element as a multiple of the generator. You're basically avoiding the discrete log problem by never taking "discrete exponentials". When you print the element, it looks like sage does perform the "discrete exp" (i.e., find the coordinate representation of the point).

If you take the use of the wrapper out and time something like

Integer(exponent[i])*E.gen(0)

you get something more realistic, like 0.01 seconds per operation.

2019-05-22 15:09:09 -0600 answered a question Formal determinant of symbolic matrix

I'm not so sure that xy-xy can ever be non-zero and still provide arithmetic in which linear algebra operations make sense. For non-commuting variables, one can get at least something:

sage: A.<x,y>=FreeAlgebra(QQ)
sage: M=matrix([[x,y],[y*x,y^2]])
sage: M
[  x   y]
[y*x y^2]
sage: M.determinant()
x*y^2 - y*x*y
2019-05-20 11:57:55 -0600 received badge  Nice Answer (source)
2019-05-18 02:28:57 -0600 answered a question How to recreate traceback?

You should probably look at IPython.core.ultratb . It looks like that's the part of IPython that produces the colourful tracebacks.

2019-05-16 17:07:07 -0600 answered a question Derivative of a recurrence equation

Does something like

L.subs(c(t)==x).diff(x).subs(x==c(t))

do the trick for you?

2019-04-24 20:36:16 -0600 commented question "from __future__ import print_function" fails on Sage scripts

This is a deficiency in the preparser: this is an example of possible valid python input into the preparser that gets preparsed into iinvalid python instructions. The preparser shouldn't do that. We should check if there is a from __future__ ...as a first (non-commented?) line in the file and put that on top. It's nice to have a work-around, but it's really a fixable bug. Anybody file a ticket? For the official rules about what a valid location for a "__future__" line is: https://docs.python.org/2/reference/s...

I'd suggest just taking all the "from __future__ ..." lines from the content and placing them on top. That way we could end up transforming invalid code into valid code, but that's not such a crime.

2019-04-23 10:39:39 -0600 commented answer Defining a 'nice' Compositum

Once you have the field as a relative extension, you can get it as a primitive extension of Q via L.absolute_field('b'). You can then use L.optimized_representation() to get a nice representation.

2019-04-21 02:18:12 -0600 answered a question REPL-like output

1: That's what Python and IPython do. However if you do

def loop():
    for i in range(4):
        i^2
loop()

then even at the REPL prompt you won't see output. The REPL doesn't get to execute the individual commands and print their return values for you, because the commands are already packaged up in a function.

2: If your input is in "long_input_file.sage" you could use

sage <long_input_file.sage

or

cat long_input_file.sage | sage

then your input is still entered into sage "through the REPL": by redirecting STDIN. (assuming a unix-type command line environment)

2019-04-19 07:45:39 -0600 received badge  Nice Answer (source)