Ask Your Question

B r u n o's profile - activity

2022-09-11 11:40:32 +0200 received badge  Famous Question (source)
2021-06-09 13:58:05 +0200 edited question Rewrite log in exponents

Rewrite log in exponents Does there exist a method in Sage's symbolic ring that would be able to (automatically) rewrite

2021-06-09 13:52:42 +0200 asked a question Rewrite log in exponents

Rewrite log in exponents Does there exist a method in Sage's symbolic ring that would be able to (automatically) rewrite

2021-04-07 19:36:23 +0200 received badge  Famous Question (source)
2021-04-03 08:23:22 +0200 received badge  Nice Answer (source)
2021-02-22 13:20:16 +0200 marked best answer Easiest way to work in the multiplicative group of Zmod(n)

Given an integer $n$, one can define in SageMath the additive group $\mathbb Z/n\mathbb Z$ by

sage: Zn = Zmod(n) # or Integers(n)

Now, I would like to work in the multiplicative group $(\mathbb Z/n\mathbb Z)^*$. Of course, I can write

sage: G = [a for a in Zn if gcd(a,n) == 1]
sage: Zn(4).multiplicative_order()
6

What I would like is an easier way of writing such a thing, such as:

sage: G = Zn.multiplicative_group() # does not exist!
sage: G(4).order() 
6

Does there exist something in SageMath to perform such kind of computations?

2021-02-22 13:20:13 +0200 received badge  Good Question (source)
2021-02-17 00:11:18 +0200 received badge  Good Answer (source)
2021-02-16 22:13:44 +0200 received badge  Nice Answer (source)
2021-02-07 20:01:27 +0200 received badge  Good Answer (source)
2021-01-31 15:27:53 +0200 received badge  Necromancer (source)
2020-10-03 01:03:14 +0200 received badge  Nice Answer (source)
2020-07-17 21:48:00 +0200 received badge  Great Answer (source)
2020-07-17 21:48:00 +0200 received badge  Guru (source)
2019-08-30 18:08:47 +0200 answered a question Is this a bug or intended behavior?

I'm not sure it is absolutely intended but it is at least an expected behavior: When you write f(x) = <expr>, SageMath actually creates a "callable symbolic expression" from <expr> (in which x is considered as a symbolic variable). This means that <expr> itself must initially be a symbolic expression (or anything that can be transformed into a symbolic expression). But this is not the case of divisors(n) since divisors is not a symbolic function applicable to a symbolic variable. Thus you must use the def ... return ... construction, or the equivalent lambda-expression f = lambda n: divisors(n).

In other words, there is a difference between a symbolic function, which is a Sage object made to represent mathematical functions (thus you can work with it, for instance derive it, integrate, etc.) and a Python function which is a function in the computer science sense, that is a subroutine. The shorthand f(x) = <expr> is a construction for symbolic functions and not for Python functions.

2019-08-30 17:41:00 +0200 commented answer weighted univariate polynomials

I need advice on 28420 which happens to be more complicated than I thought!

2019-08-30 09:57:38 +0200 received badge  Good Answer (source)
2019-08-28 19:07:49 +0200 received badge  Nice Answer (source)
2019-08-28 18:56:40 +0200 commented answer weighted univariate polynomials

@Thierry: I'll open one (or two for the two silent behaviors), soon ;-).

2019-08-28 16:49:39 +0200 answered a question weighted univariate polynomials

This (mainly) comes from the construction of your univariate polynomial ring. Compare

sage: R1 = PolynomialRing(QQ, 'x'); R1
Univariate Polynomial Ring in x over Rational Field
sage: R2 = PolynomialRing(QQ, 1, 'x'); R2
Multivariate Polynomial Ring in x over Rational Field

This means that if you explicitly give the number of variables, the polynomial ring is considered as a multivariate one (in this case a "one-variable multivariate polynomial ring") while if you don't, it is considered a univariate polynomial ring. As a consequence, R1 and R2 in my example use two completely distinct implementations.

Now you can do what you need:

sage: P = PolynomialRing(QQ, 1, 'x', order = TermOrder('wdegrevlex', (2,)))
sage: P.inject_variables()
Defining x
sage: x.degree()
2

Note the two changes: 1. add the number of variables ; 2. change (2) into (2,). The second change is due to the fact that TermOrder needs a tuple, and (2) is an integer for Python while (2,) is a 1-tuple containing an integer.

It is a pity that you did not get any warning: In my sense, you should have been told that order = ... has no effect for a univariate polynomial ring, and that TermOrder(...) requires a tuple rather than an integer.

2019-07-23 07:21:08 +0200 received badge  Notable Question (source)
2019-05-28 18:15:16 +0200 commented question Formal determinant of symbolic matrix

I do not know how suitable this is for your needs, but my idea here would be to use several distinct variables x1, x2, ....

2018-12-15 23:51:41 +0200 received badge  Good Answer (source)
2018-11-18 20:14:19 +0200 received badge  Nice Answer (source)
2018-10-19 21:47:44 +0200 received badge  Nice Answer (source)
2018-08-07 22:39:00 +0200 received badge  Nice Answer (source)
2018-07-12 15:51:35 +0200 commented question canonical polynomial vs shift polynomial

How is your question related to SageMath?

2018-07-03 14:49:46 +0200 answered a question gcd computation of two polynomial

I do not know whether there is a good solution. Actually, the problem you are trying to solve is NP-hard so there is probably no efficient algorithm. (Note that of course computing the GCD of two dense (or low-degree) polynomials in not hard, the problem here is the degree. )

2018-06-12 23:11:34 +0200 commented question Expand not working

You should give the full computation (definitions of A and x) because this way the problem you encounter is not reproducible. Also, instead of a picture, you can put code in your question and format it using the button "101 010".

2018-05-04 21:02:19 +0200 commented question gen = graphs.planar_graphs(4, dual=True) is not working

I cannot reproduce the error on SageMath 8.2beta8:

sage: gen = graphs.planar_graphs(4, dual=True)
sage: gen
<generator object planar_graphs at 0x7f6e75c08d70>
2018-04-27 12:05:40 +0200 commented question Algorithm to polynomial multiplication

Your algorithm is fine for multiplying the polynomials. What you get is the list of coefficients. (I don't know what you mean by "factors".) If you want a polynomial from this list, you have to build a polynomial ring and get the polynomial from the list of coefficients in the following way:

sage: R = PolynomialRing(ZZ, 'x') 
sage: L = [1, 2, 3, 4, 5]
sage: p = R(L)
sage: p
5*x^4 + 4*x^3 + 3*x^2 + 2*x + 1
2018-04-25 15:05:54 +0200 commented question Algorithm to polynomial multiplication

Some questions:

  1. How is that related to SageMath?
  2. What have you tried so far?
  3. Did you notice that SageMath already has algorithms for polynomial multiplication?
  4. Is that homework?
2018-04-18 11:55:48 +0200 commented question Element to sequence in field extension

First note that your p is not prime... You can find useful information in this related question.

2018-04-13 16:54:57 +0200 commented question Is K = QQ[polynomial_root] the same as K.<a> = QQ.extension(polynomial)?

Please format your question using the dedicated button (with zeroes and ones) since it is very hard to read right now!

2018-04-10 06:30:25 +0200 received badge  Nice Answer (source)
2018-03-30 16:35:00 +0200 answered a question Is there a command to find the place of an element in an array?

You can use v.index(a) to get the index of the first occurrence of a. An exception is raised if a is not in v.

2018-03-29 14:24:01 +0200 commented answer Is it possible to use Arb-library commands directly in Sagemath?

Of course it is ;-), see my edit (and tell me if I didn't understand your question...)!

2018-03-29 11:11:56 +0200 answered a question Is it possible to use Arb-library commands directly in Sagemath?

You can define the RealBallField (that uses Arb as backend) with:

sage: R = RealBallField()

Then you can use some Arb functions as methods of R:

sage: R.pi()
[3.141592653589793 +/- 5.61e-16]

You can read more on the documentation for the real ball field and the complex ball field.

[edit] Basic algebraic operations:

sage: x = R.pi()
sage: y = R.euler_constant()
sage: x + y
[3.718808318491326 +/- 6.85e-16]
sage: x * y
[1.813376492391603 +/- 9.04e-16]
2018-03-26 13:24:44 +0200 commented question What is the best way to work with ratios of polynomials?

The symbolic ring is the parent of symbolic expressions ("the place where they live"). And polynomial rings are specialized classes to handle polynomials specifically (rather than generic expressions).

How are your polynomials defined?

To work with more precision, you can either work with a real (or complex) field with more bits of precision (RealField(n) to get n bits of precision), or with interval or ball arithmetic to get guarantees (RealBallField(n) or RealIntervalField(n)), or with exactly represented algebraic numbers (using AlgebraicField() (complex) or AlgebraicRealField()). But the choice depends on your exact needs! (Finally note that do have quotients of polynomials over some ring R, you can use FractionField(PolynomialRing(R,'x')).)

2018-03-13 23:01:13 +0200 received badge  Nice Answer (source)
2018-03-10 22:35:49 +0200 answered a question irreducible polynomial defining the finite field

What you are looking for is the list of all degree-8 irreducible polynomials over $\mathbb F_2$. There is no built-in function for this, but they can be found very easily if you combine polynomials which iterates over all polynomials of a given degree and is_irreducible that tests irreducibilty.

For instance:

sage: R = GF(2)['x']
sage: for p in R.polynomials(8):
....:     if p.is_irreducible():
....:         print(p)
....:         
x^8 + x^4 + x^3 + x + 1
x^8 + x^4 + x^3 + x^2 + 1
x^8 + x^5 + x^3 + x + 1
[...]
x^8 + x^7 + x^6 + x^5 + x^4 + x^2 + 1
x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + 1

You can also built the list of all of them:

sage: Irr = [p for p in R.polynomials(8) if p is_irreducible()]
sage: len(Irr)
30

Finally, you can have access to some specific irreducible polynomials using R.irreducible_element(algorithm='...'). Have a look at the documentation of irreducible_element for details here.

2018-03-02 12:22:35 +0200 commented answer The use of %gp to switch to Pari/gp commands

You're right. In the Ipython shell, typing <ctrl>+D brings you back to "normal" SageMath. In notebooks, simply going to a new cell in enough.

2018-03-01 18:58:07 +0200 answered a question The use of %gp to switch to Pari/gp commands

Short answer: You probably need to use %%gp instead of %gp.

Explanations:

The behavior depends on the front-end you are using:

  • If you use the Ipython shell (running in a terminal),

    • typing %gpswitches to GP and you can use GP in a standard manner. The same thing occurs if you run SageMath using sage -gp.
    • typing %%gp allows you to write several lines of Pari/GP. (A final blank line is needed to evaluate the previous lines.)
  • If you use Jupyter notebooks, you have two options:

    • %gp <command> (on a single line) executes <command> from Pari/GP (example: %gp primepi(123456))
    • %%gp as the first line of a cell turns the cell into a Pari/GP cell (in the same way basically as %%gp in the Ipython shell).
  • If you use the old Sage notebook, you can turn a cell into a Pari/GP cell by using %gp on its first line. This is the same as the second option for Jupyter notebooks, but with one % instead of %%. You cannot use %%gp in this case.

As far as I understand, Cocalc's choice is to mimic the behavior of the old Sage notebook.

Examples of use in Jupyter notebooks:

%gp primepi(123456)
11601

or

%%gp
n = primepi(123456)
n + 1
11601
11602
2018-03-01 18:30:13 +0200 commented question faster GCD computation

You should simply give an example of the computation you are trying to perform! Because I am not able to make any sense of you latest comment.

2018-03-01 15:56:53 +0200 commented question faster GCD computation

May you be more precise? First, $p=256$ is not a prime, so you're note working over a large prime field, but on the contrary in a large extension of some small prime field... And what size of polynomials do you want to handle? A very quick test on polynomials of degree up to 250 (with a common factor of degree 100) is for instance fast enough to appear instant on my (standard) laptop.