Ask Your Question

tmonteil's profile - activity

2019-12-01 15:19:32 -0600 answered a question Standard use of underscores in numerals

Sage does not have any precise recommandation about that. I guess you should just follow Python's PEP 515/, which is not that strict either.

2019-11-26 04:28:01 -0600 answered a question How to plot a list of circles

You can start from an empty graphics, and add circles to it directly as follows:

sage: G = Graphics()
sage: for c in lis:
....:     G += circle(c, .05, fill=true,  color='red')

Then, you can show it with:

sage: G
2019-11-21 09:23:29 -0600 commented question How to fix problem when creating image histogram

Could you please provide the whole code. In particular, how is im defined ?

2019-11-20 08:45:53 -0600 commented answer How to find all roots with solve?

Ticket ?

2019-11-18 11:07:09 -0600 answered a question SEND+MORE=MONEY (Milp programming)

I don't know the problem, but when you write things like sum(j*v[3,j] for i in range(0,7)) are you sure that you do not confuse i and j ?

2019-11-11 11:31:10 -0600 commented question The Cayley Table Question

homework ?

2019-11-08 14:18:29 -0600 commented answer Trigonometric simplifications and matrices

It might depend on how "complex" are the expressions.

2019-11-08 10:56:01 -0600 received badge  Good Answer (source)
2019-11-08 10:15:08 -0600 received badge  Nice Answer (source)
2019-11-08 09:50:23 -0600 answered a question Trigonometric simplifications and matrices

Apparently trig_reduce is not idempotent and you have to apply it twice to get the correct result:

sage: produit.apply_map(lambda x: x.trig_reduce().trig_reduce())
[ cos(theta1 + theta2 + theta3) -sin(theta1 + theta2 + theta3)]
[ sin(theta1 + theta2 + theta3)  cos(theta1 + theta2 + theta3)]
2019-11-06 13:24:11 -0600 commented question Kernel died when computing nullspace of a large matrix

Could you please provide the code that you used to construct your matrix ?

2019-11-06 13:23:30 -0600 answered a question Entries in canonical_matrix for Coxeter groups

a is the square root of 3, as the coefficients of this matrix are defined on the number field with defining polynomial x^2 - 3, see:

sage: M = s[2].canonical_matrix()
sage: M.parent()
Full MatrixSpace of 2 by 2 dense matrices over Number Field in a with defining polynomial x^2 - 3 with a = 1.732050807568878?
sage: M
[ 1  0]
[ a -1]
sage: M[1,0]
a
sage: M[1,0]^2
3
2019-11-06 13:19:37 -0600 commented question Bug report (z[0]+z[1]+z[2])^5 == z0^5 + z1^5 + z2^5

What is wrong ? What did you expect ?

2019-11-06 06:03:14 -0600 received badge  Good Answer (source)
2019-11-06 04:58:30 -0600 received badge  Nice Answer (source)
2019-11-06 04:44:07 -0600 commented answer How to create 31-tuples with nonnegative entries that sum to 1

Note that this random generation is not uniform on the simplex, as it comes from the projection of an hypercube (think of a square projected on its diagonal).

2019-11-06 04:42:33 -0600 answered a question How to create 31-tuples with nonnegative entries that sum to 1

If you want to consider all the points satisfying some properties, i guess the best way it to consider those points as forming a set. In your case, the set of points is a polytope. By convenience, you can construct it from a linear program as follows:

sage: p = MixedIntegerLinearProgram()
sage: x = p.new_variable(real=True, nonnegative=True)
sage: p.add_constraint(sum(x[i] for i in range(31)) == 1)
sage: P = p.polyhedron() ; P
A 30-dimensional polyhedron in RDF^31 defined as the convex hull of 31 vertices

Then you can do things like:

sage: P.contains([1/2,1/2,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
True
sage: P.contains([1/2,1/3,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
False

sage: P.random_integral_point()
(0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)

sage: P.integral_points_count()
31

sage: P.dim()
30

sage: P.is_simplex()
True

sage: P.vertices_list()
...
2019-10-29 20:56:56 -0600 received badge  Good Answer (source)
2019-10-28 09:33:28 -0600 received badge  Good Answer (source)
2019-10-26 04:34:32 -0600 received badge  Nice Answer (source)
2019-10-25 17:18:43 -0600 received badge  Nice Answer (source)
2019-10-25 16:53:12 -0600 received badge  Nice Answer (source)
2019-10-21 13:32:00 -0600 commented answer Sage stalls during computation

Could you please provide all the pieces of code that lead to your conclusions (about Glpk being used despite Coin being installed, about the non-working use of alarm, about the working use of @parallel, etc) ?

2019-10-21 06:47:06 -0600 commented answer Sage stalls during computation

Anyway, thanks a lot for your exploration of the problem.

2019-10-21 06:45:35 -0600 commented answer Sage stalls during computation

Yes i will, but i have to find some time to confirm your hypothesis.

2019-10-20 14:25:38 -0600 answered a question Stop Sage from overriding Python number types

There are at least two possilbilies:

disable the preparser with preparser(False):

sage: type(1)
<type 'sage.rings.integer.Integer'>
sage: preparser(False)
sage: type(1)
<type 'int'>

or use r suffix to say that the numbers are raw:

sage: type(1)
<type 'sage.rings.integer.Integer'>
sage: type(1r)
<type 'int'>
sage: type(1.0r)
<type 'float'>
2019-10-20 06:22:58 -0600 answered a question How to find common solution of inequalities in Sage

See https://doc.sagemath.org/html/en/them... and use the binary=True argument.

2019-10-19 10:13:10 -0600 answered a question Taylor expansion crashing (python3)

It is indeed a bug, thanks for reporting,

That said, you should notice that the symbolic ring does not handle numerical values very well, see for example https://trac.sagemath.org/ticket/14821

So here is a workaround:

sage: f = (x+1)^(1/10)+exp(x)
....: f.taylor(x,0,3)
1171/6000*x^3 + 91/200*x^2 + 11/10*x + 2

Note that it is not Python3 specific, i can reproduce it on a Python2 build.

2019-10-19 07:52:42 -0600 commented question False perpendicular bisector

Could you please provide the code that leads to the issue ?

2019-10-19 07:51:32 -0600 answered a question False perpendicular bisector
2019-10-19 04:36:14 -0600 commented answer How to iterate over symbolic coefficients

Indeed ! I was thinking of a tutorial instead of just doc, since the way it works is by overriding a default class, not by calling a function. This is a standard pattern in some Python programs, but not in Sage. In particular, i had to copy a part of the source code to insert my hook, so i guess it is not very handy. Perhaps should we propose a better user interface.

2019-10-19 03:42:39 -0600 received badge  Nice Answer (source)
2019-10-19 03:20:10 -0600 answered a question How do I write and implement a program in Sage for Windows?

You just have to learn the Python language and put your sequence of computations into a function. Basically, you can se Sage as Python bootsted with mathematical typse such as matrices, graphs, etc. There are tons of nice tutorials about the Python language on the web. See also this piece of doc

2019-10-18 17:25:41 -0600 commented question possible invalid latex translation from fricas result

I tend not to agree with your last statement, if such a weird %iint appears in Sage, it means that there is a missing corresponding Sage function. It is better not to hide the problem, and instead definite such missing function correctly, and it will come with its own latex representation (e.g. dilog(x) is transformed into {\rm Li}_2\left(x\right), not just \dilog(x)).

2019-10-18 17:17:25 -0600 answered a question How to iterate over symbolic coefficients

Okay, i am not sure to understand your question in whole generality. However, here is a solution that could be generalized and adapted to your needs. Let me assume that you want to rewrite the exponents of your expression and that those exponents are polynomials. Working on polynomials has the good property that instead of doing some pattern matching as in the symbolic ring, you can use quotient rings.

For example, here is what you can do in your previous example:

sage: R.<b_m,b_s> = PolynomialRing(QQ)
sage: R
Multivariate Polynomial Ring in b_m, b_s over Rational Field
sage: S = R.quotient(b_m + (b_s-b_m)^3 - b_m)
sage: S
Quotient of Multivariate Polynomial Ring in b_m, b_s over Rational Field by the ideal (-b_m^3 + 3*b_m^2*b_s - 3*b_m*b_s^2 + b_s^3)
sage: p = -b_m^3 + 3*b_m^2*b_s - 3*b_m*b_s^2 + b_s^3 + b_m
sage: p
-b_m^3 + 3*b_m^2*b_s - 3*b_m*b_s^2 + b_s^3 + b_m
sage: S(p)
b_mbar
sage: lift(S(p))
b_m

Now, what you have to do is to walk along the expression and apply this recipe to all exponents of the powers that are encountered. A power is a kind of arithmetic operation, so you will have to override the arithmetic method of ExpressionTreeWalker. Here is how to:

from sage.symbolic.expression_conversions import ExpressionTreeWalker
class RewritePolynomialPowers(ExpressionTreeWalker):
    def __init__(self, ring):
        self.ring = ring
    def arithmetic(self, ex, op):
        if op is operator.pow:
            base, exponent = ex.operands()
            exponent = SR(str(lift(self.ring(exponent))))
            return base ** exponent
        else:
            return reduce(op, map(self, ex.operands()))

Let us try with your example:

sage: var('a,x,b,b_s,b_m')
(a, x, b, b_s, b_m)
sage: f_m = a*x^b
sage: expr = expand(f_m.subs({b : b_m + (b_s-b_m)^3})).derivative(b_m).full_simplify()
sage: RewritePolynomialPowers(S)(expr)
-(3*a*b_m^2 - 6*a*b_m*b_s + 3*a*b_s^2 - a)*x^b_m*log(x)

Please tell if this is sufficient for your general case. Anyway, you see the TreeWalker strategy, you can also replace other kind of operators (composition, derivation, relation,...), see the (not documented) https://doc.sagemath.org/html/en/refe...

2019-10-18 15:04:49 -0600 commented answer possible invalid latex translation from fricas result

I am not an expert of that part of Sage, but other devs will know more.