Ask Your Question

SL's profile - activity

2021-01-20 01:06:39 +0200 received badge  Notable Question (source)
2021-01-20 01:06:39 +0200 received badge  Popular Question (source)
2017-01-08 12:14:59 +0200 received badge  Popular Question (source)
2016-07-14 22:52:08 +0200 received badge  Popular Question (source)
2016-07-14 22:52:08 +0200 received badge  Famous Question (source)
2016-07-14 22:52:08 +0200 received badge  Notable Question (source)
2015-07-28 08:14:14 +0200 received badge  Scholar (source)
2015-07-27 10:39:17 +0200 asked a question imports in sage/combinat/

I was reading the code in sage/combinat/ and I noticed some weirdness in the imports. In the second line there is a

from sage.structure.element import Element, have_same_parent

and then in the fourth line there is

from sage.structure.element import have_same_parent

and later on we find

import sage.structure.element

Why is this so? Can't some of these lines be erased?

2015-03-02 12:37:04 +0200 received badge  Self-Learner (source)
2015-03-01 16:25:01 +0200 answered a question quaternion-valued differential forms

This seems to work fine:

sage: quat_alg = QuaternionAlgebra(QQ,-1,-1)
sage: ext_alg.<x0,x1,x2,x3> = ExteriorAlgebra(quat_alg)
sage: x = x0+x1*i+x2*j+x3*k
sage: x_dag = x0-x1*i-x2*j-x3*k
# now some computations
sage: x*x_dag
-2*i*x0^x1 - 2*j*x0^x2 - 2*k*x0^x3 - 2*k*x1^x2 + 2*j*x1^x3 - 2*i*x2^x3
sage: x*x_dag*x
-6*k*x0^x1^x2 + 6*j*x0^x1^x3 - 6*i*x0^x2^x3 + 6*x1^x2^x3
sage: x*x_dag*x*x_dag
2015-02-28 21:44:34 +0200 commented question substitute x*y by u

It doesn't look like there's support for substituting products. Instead you can do

ff = f.subs(x = u/y)
2015-02-26 17:27:04 +0200 received badge  Nice Question (source)
2015-02-26 08:47:09 +0200 received badge  Student (source)
2015-02-26 06:44:08 +0200 asked a question quaternion-valued differential forms

I'm trying to define quaternion-valued differential forms in Sage. For example, take $e_0$, $e_1$, $e_2$, $e_3$ to be the quaternion generators and $d x^0$, $d x^1$, $d x^2$, $d x^3$ be the generators of the exterior algebra. So for example I'd like to be able to compute $d X \wedge d X^\dagger$, where $d X = e_0 d x^0 + e_1 d x^1 + e_2 d x^2 + e_3 d x^3$, $d X^\dagger = e_0 d x^0 - e_1 d x^1 - e_2 d x^2 - e_3 d x^3$.

Edit: I tried taking a tensor product between an exterior algebra and a quaternion algebra

sage: ext_alg.<x0,x1,x2,x3> = ExteriorAlgebra(QQ)
sage: ext_alg in Algebras(QQ)
sage: quat_alg = QuaternionAlgebra(QQ,-1,-1)
sage: quat_alg in Algebras(QQ)
sage: tensor((ext_alg, quat_alg))  # this doesn't work!
2015-02-26 06:37:16 +0200 commented answer Incorrect parsing of docstring of sage.structure.indexed_generators.IndexedGenerators

@kcrisman, I don't have a Trac account yet, I should probably get one. I did find another instance of this problem in the documentation of dodecahedron.

2015-02-19 10:34:08 +0200 commented answer Incorrect parsing of docstring of sage.structure.indexed_generators.IndexedGenerators

Another such issues appear for dirac_delta, heaviside, unit_step. A \left gets replaced by <=ft.

2015-02-14 14:56:09 +0200 received badge  Supporter (source)
2015-02-14 14:54:41 +0200 commented answer Incorrect parsing of docstring of sage.structure.indexed_generators.IndexedGenerators

I noticed another similar (related?) issue in the help for the timeit command. The help contains

 sage: timeit("a = 2nb=131nfactor(a^b-1)", number=25)
  25 loops, best of 3: ... per loop

where some \n have been replaced by n.

2015-02-07 10:28:31 +0200 asked a question Incorrect parsing of docstring of sage.structure.indexed_generators.IndexedGenerators

[This is more of a bug report, but I'm not sure how to report bugs.]

I'm running 'Sage Version 6.5.rc0, Release Date: 2015-01-29' and when I display the help for sage.structure.indexed_generators.IndexedGenerators I get some weird formatting error. It's coming from line 103 of the file $SAGE_ROOT/local/lib/python2.7/site-packages/sage/structure/ where a \left is displayed as <=ft. It seems that \le in \left gets replaced by <=.

2015-01-21 10:01:46 +0200 received badge  Enlightened (source)
2015-01-19 22:00:49 +0200 received badge  Good Answer (source)
2015-01-17 13:22:53 +0200 received badge  Nice Answer (source)
2015-01-15 08:46:04 +0200 commented answer Transpose of a column vector

Sage is written in the Python language. Python is an object-oriented programming language. You can think of an object as a way to store some data together with functions which operate on it an modify it. Everything in Python is an object; numbers are objects, lists are objects, etc. List is a very basic object which does not support many operations; you can index a list, you can join two lists, and you can do a few other things. Matrix is an object which supports many more operations. For example, you can compute the Jordan form of a matrix, you can multiply two matrices of appropriate sizes, etc. So a object of type Matrix corresponds better to the abstract mathematical notion of matrix than does an object of type list.

2015-01-15 08:40:14 +0200 answered a question what does ratpoly.<t> = PolynomialRing(QQ) mean

Sage does some preparsing on what you type. You can see what happens with the command preparse

 sage: preparse('ratpoly.<t> = PolynomialRing(QQ)')
 "ratpoly = PolynomialRing(QQ, names=('t',)); (t,) = ratpoly._first_ngens(1)"
2015-01-14 06:50:16 +0200 commented answer why don't sage return exact value in some functions

@Chong Wang: Here you are in the situation where you already know the answer to a problem and you want the computer to show it to you in the exact form you had in mind. This rarely works and most often leads to frustration. A way out of frustration is to understand the reasons why the computer produced the answer you don't like. In the factorization above \sqrt(2) and 1.414213562373095? are equally valid names for the same number except that the second one is more general. The first one only applies for the rare numbers which can be written in terms of radicals.

2015-01-14 06:35:43 +0200 received badge  Editor (source)
2015-01-14 06:24:46 +0200 answered a question why don't sage return exact value in some functions

The first thing to realize is that the form the factorization should take depends on the base field for the polynomial. The classical example is the polynomial x^2+1. It can be factorized as (x+i)(x-i) but only over the complex numbers. It seems that most of the symbolic mathematics software chooses to work over the real numbers and does not factorize x^2+1. This is of course an arbitrary choice and is not what Sage is doing. This is one reason why you must specify a base field when defining a polynomial.

In your case, the answer is not exact because the field RR is not exact. Here's what the documentation for RR (obtainable by typing RR?) says:

An approximation to the field of real numbers using floating point numbers with any specified precision. Answers derived from calculations in this approximation may differ from what they would be if those calculations were performed in the true field of real numbers. This is due to the rounding errors inherent to finite precision calculations.

Instead of using RR, you could use the algebraic numbers QQbar.

realpoly.<z> = PolynomialRing(QQbar)
(z - 1.414213562373095?) * (z + 1.414213562373095?)

Notice the question mark in the decimal expansion. It indicates that the expansion continues but since it may be very long or infinite can not be fully displayed.

I'm not completely sure how to make Sage show the output you would like to get, but of course this is only going to work in simple situations where the roots of the polynomials can be written using radicals. The vast majority of algebraic numbers are not of this type.

Maybe Sage should have a field of numbers which can be written using radicals, then you could factor your polynomial over that field which, it seems to me, is what you would like to get. It seems to me like this might be a good field to have, but it doesn't seem to be implemented at this point.

2015-01-13 10:11:23 +0200 received badge  Teacher (source)
2015-01-12 23:42:17 +0200 answered a question Transpose of a column vector

Note that you are trying to multiply a matrix by a list. Instead of using a list you should use another matrix. Here's a way you can do it:

m = Matrix([[1, 0, 0],[0, 1, 0], [0, 0, 1]])
v = Matrix(3,1,[1,2,3])
m * v

Note several things

  • m is the identity matrix, which you can create as m = Matrix.identity(3)
  • the vector v is created by giving the dimensions, 3x1 in this case, and then giving a list of entries read along the rows from left to right and from top to bottom.
2014-12-10 07:20:00 +0200 commented question tab completion for mathematica fails

OK, I forgot to mention that I'm using version 10 of Mathematica. Are you using the same version? It could be that something broke starting with version 10...

2014-12-09 23:05:06 +0200 asked a question tab completion for mathematica fails


In sage 5.6 if I type mathematica and then TAB, the program hangs. I think it's probably waiting for some input from Mathematica. I can see that a Mathematica process is started. For Maple, the TAB completion works well. Can you confirm this?

I'm using 'Sage Version 6.5.beta2, Release Date: 2014-12-04'

2014-11-26 10:09:07 +0200 commented question How does one graph this?

You can try plotting separately and then combine

p1 = implicit_plot(x^2+y^2+sin(4*x)+sin(4*y)==4,(x,-3,3),(y,-3,3), color='red')
p2 = plot(tan(x), (x,-3,3), ymin=-3, ymax=3, color='blue')
2014-09-22 19:04:32 +0200 commented question Difficulties with resultants and Tschirnhaus transformations

If I declare variables, then solve also works

    sage: a, b = var('a b')
    sage: solve([rc[-2],rc[-3]],[a,b])
    [[a == (-11/7), b == (-2/7)], [a == -3, b == 0]]

2014-09-22 14:07:45 +0200 asked a question pattern matching

Is it possible to use pattern matching in Sage? I have some experience with Mathematica and I'm currently thinking about switching, and I'm evaluating what Sage can do. As far as I can see pattern matching is not supported. Is this true? If yes, are there any plans to support it in the future?

See here for some examples.