ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 10 Apr 2020 08:54:33 -0500Symbolic product in Sage?http://ask.sagemath.org/question/9047/symbolic-product-in-sage/Suppose I'd like to compute
prod(1/x^4, x, 1, oo)
How can this be done?
I found an old [thread](https://groups.google.com/forum/?fromgroups#!topic/sage-support/ZLfVooTBLvw), but with no answers.bk322Fri, 08 Jun 2012 07:13:32 -0500http://ask.sagemath.org/question/9047/Definition of symbolic functions on path algebrahttp://ask.sagemath.org/question/50655/definition-of-symbolic-functions-on-path-algebra/I tried to define a symbolic function on path algbera like that:
G = DiGraph({1:{2:['a']}, 2:{3:['b']}})
P = G.path_semigroup()
A = P.algebra(GF(7))
A.inject_variables()
def ev(self, x): return 2*x
foo = function("foo", nargs=1, eval_func=ev)
foo(a)
But I get an error: TypeError: cannot coerce arguments: no canonical coercion from Path algebra of Multi-digraph on 3 vertices over Finite Field of size 7 to Symbolic Ring. My question how can I define a symbolic function to accept path algebra variables?
Thanks.Z3r0Fri, 10 Apr 2020 08:54:33 -0500http://ask.sagemath.org/question/50655/20 monomials of degree 3 in 4 variables in lexicographic orderinghttp://ask.sagemath.org/question/50082/20-monomials-of-degree-3-in-4-variables-in-lexicographic-ordering/ Hey community,
I've recently wanted to switch over to sage (very new) from Maple and I am having trouble understanding how to make monomials of degree 3 in 4 variables (hopefully in lexographic ordering think of the w coordinate as one). I am not very good at english, but this is for a Clebsch map up and down for a surface that I am studying.
These are the maps:
m1:=p-->p[1]^3;
m2:=p-->p[1]^2*p;
m3:=p-->p[1]^2*p[3];
m4:=p-->p[1]^2;
m5:=p-->p[1]*p[2]^2;
m6:=p-->p[1]*p[2]*p[3];
m7:=p-->p[1]*p[2];
m8:=p-->p[1]*p[3]^2;
m9:=p-->p[1]*p[3];
m10:=p-->p[1];
m11:=p-->p[2]^3;
m12:=p-->p[2]^2*p[3];
m13:=p-->p[2]^2;
m14:=p-->p[2]*p[3]^2;
m15:=p-->p[2]*p[3];
m16:=p-->p[2];
m17:=p-->p[3]^3;
m18:=p-->p[3]^2;
m19:=p-->p[3];
m20:=p-->1;
Then M:=[m1,m2,m3,m4,m5,m6,m7,m8,m9,m10,m11,m12,m13,m14,m15,m16,m17,m18,m19,m20]bllooiWed, 26 Feb 2020 15:41:38 -0600http://ask.sagemath.org/question/50082/Symbolic expression of `sng()` which isn’t zero at `sgn(0)`http://ask.sagemath.org/question/49935/symbolic-expression-of-sng-which-isnt-zero-at-sgn0/ `sng(0) = 0` but I need a symbolic function or expression that evaluates to `+1` or `-1` as per the following definition:
$$\mathrm{side}\left(u\right) =
\begin{cases}
+1, & \text{if $u \geq 0$} \\\
-1, & \text{if $u \lt 0$}
\end{cases}$$
I’ve tried the following but each have their own problems:
side = sgn(u) # Evaluates to 0 at u = 0
side = u/abs(u) # “ValueError: power::eval(): division by zero” at u = 0
side = 1 - (u < 0)*2 # “TypeError: unable to simplify to float approximation”
# These next two use a Python expression so ‘u’ gets evaluated too early.
side = -1 if u < 0 else 1
side = lambda u: -1 if u < 0 else 1
Is there a way I can define this function symbolically?Dan-KSat, 15 Feb 2020 13:45:59 -0600http://ask.sagemath.org/question/49935/another factoring polynomials questionhttp://ask.sagemath.org/question/49709/another-factoring-polynomials-question/I have the following expression:
f = u^2*v*x + 3*u*v^2*x + 2*v^3*x + u^2*x^2 + 5*u*v*x^2 + 5*v^2*x^2 + 2*u*x^3 + 4*v*x^3 + x^4 + 2*u^2*v*y + 6*u*v^2*y + 4*v^3*y + 2*u^2*x*y + 12*u*v*x*y + 12*v^2*x*y + 6*u*x^2*y + 12*v*x^2*y + 4*x^3*y + u^2*y^2 + 6*u*v*y^2 + 6*v^2*y^2 + 6*u*x*y^2 + 12*v*x*y^2 + 5*x^2*y^2 + 2*u*y^3 + 4*v*y^3 + 2*x*y^3 + u^2*v*z + 3*u*v^2*z + 2*v^3*z + u^2*x*z + 6*u*v*x*z + 6*v^2*x*z + 3*u*x^2*z + 6*v*x^2*z + 2*x^3*z + u^2*y*z + 6*u*v*y*z + 6*v^2*y*z + 6*u*x*y*z + 12*v*x*y*z + 5*x^2*y*z + 3*u*y^2*z + 6*v*y^2*z + 3*x*y^2*z + u*v*z^2 + v^2*z^2 + u*x*z^2 + 2*v*x*z^2 + x^2*z^2 + u*y*z^2 + 2*v*y*z^2 + x*y*z^2
and I would like to simplify it by gathering and factoring partial sums
u, u+v,...,u+v+x+y+z
v, v+x,...,v+x+y+z
x, x+y,x+y+z,
y,y+z
z
(I have reason to expect that the expression will look quite a bit nicer if I do this, introducing notation for the sums of course, like h_{ij} = the sum of variables i up to j)
My first lame try at this was to ask sage to rational_simplify() quotients f/(u+v+x+y+z),...,f/(u+v), and so on, hoping to see more than just one big fraction. It didn't work.
Any insights/suggestions/corrections would be much appreciated!
Thanks,
anneWed, 29 Jan 2020 11:27:50 -0600http://ask.sagemath.org/question/49709/how to best simplify/factor symbolic expressionshttp://ask.sagemath.org/question/49616/how-to-best-simplifyfactor-symbolic-expressions/Define symbolic expressions T3 and T3s.
q1,q2,q3 = var('q1,q2,q3')
T3 = (q1^2*q2^2 + 1)*(q1^2*q3^2 + 1)*(q2^2*q3^2 + 1)*(q1*q2 + 1)*(q1*q2 - 1)*(q1*q3 + 1)*(q1*q3 - 1)*(q2*q3 + 1)*(q2*q3 - 1)/((q1^2*q2^2*q3^2 + 1)*(q1*q2*q3 + 1)*(q1*q2*q3 - 1)*(q1^2 + 1)*(q2^2 + 1)*(q3^2 + 1)*(q1 + 1)*(q1 - 1)*(q2 + 1)*(q2 - 1)*(q3 + 1)*(q3 - 1))
T3s = (q1^4*q2^4 - 1)*(q1^4*q3^4 - 1)*(q2^4*q3^4 - 1)/((q1^4*q2^4*q3^4 - 1)*(q1^4 - 1)*(q2^4 - 1)*(q3^4 - 1))
Is there any method to reduce T3 to its simpler (at least for a human) form T3s in Sage?rue82Tue, 21 Jan 2020 05:07:05 -0600http://ask.sagemath.org/question/49616/how to best simplify product of square rootshttp://ask.sagemath.org/question/49512/how-to-best-simplify-product-of-square-roots/I'd like to simplify expressions like
p1,p2,p3 = var('p1 p2 p3')
assume(p1>0,p2>0,p3>0)
R = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)
R
without using `R.canonicalize_radical()`, which unfortunately messes up other factors. I understand there are some options using `R.simplify_chain_real()`, but what else can I try?
Let us see an example where also `R.simplify_chain_real()` messes things up:
p1,p2,p3 = var('p1 p2 p3')
assume(p1>0,p2>0,p3>0)
# R = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)
R = p1*p2*sqrt(p3)*sqrt(p3/p1)*sqrt(p3/p2)/((p1 - p3)*(p2 - p3)*(p3 - 1))
%display latex
from sage.manifolds.utilities import simplify_chain_real
simplify_chain_real(R)
#Rrue82Sun, 12 Jan 2020 04:17:34 -0600http://ask.sagemath.org/question/49512/symbolic differentiation of unknown functionhttp://ask.sagemath.org/question/49362/symbolic-differentiation-of-unknown-function/I want to do some formal calculus with unknown functions
for the purpose of solving differential equations.
Say `F(t) = v(t)*t^2`, where `v` is an unknown differentiable function.
Then I would like to declare `v` as such and be able to get
`F.diff(t) = 2*t*v+t^2*v.diff(t)`
It is similar to [Ask Sage question 8822](https://ask.sagemath.org/question/8822)
but the solution does not seem to work anymore, as `function()` takes
only one argument and not 2 as in the description.
Anyone know what the syntax is in 8.9? Or in 9.0, when that becomes available?asgerSat, 04 Jan 2020 14:10:03 -0600http://ask.sagemath.org/question/49362/Keeping zeros after matrix multiplicationhttp://ask.sagemath.org/question/48925/keeping-zeros-after-matrix-multiplication/ Hello, Sage Community!
Suppose I do the following:
var('x y z')
u = vector([0, 1, 1])
v = vector([x, y, z])
u * v
The result is obviously `y+z`. I would like to keep the zeros after the multiplication, in order to have `0x+y+z` as my result. Is it possible?
Thanks in advance for your answers!dsejasSun, 01 Dec 2019 10:46:45 -0600http://ask.sagemath.org/question/48925/can you programmatically define a [mathematical] function?http://ask.sagemath.org/question/49072/can-you-programmatically-define-a-mathematical-function/I want to take an array of coefficients and turn that into a function, a math function not a python function. for example take
[2, 0, 2, 7]
and turn this into
$$f(x) = 2x^3 + 2x + 7$$
something like
def createSym(coefficients, degree, x):
symbolicEqn = ''
for i in poly:
symbolicEqn += ' + ', (x**deg)*i
deg -= 1
return symbolicEqn
pass
then call my definition in the script like
x = var('x')
coeffArray = [2, 0, 2, 7]
degree = 3
polynomialEqn = createSym(coeffArray, degree, x)
But symbolicEqn is just a string and not an expression. Is there a sage/python way to do this?alienfetuseaterWed, 18 Dec 2019 15:33:25 -0600http://ask.sagemath.org/question/49072/linear algebra derivative expressionshttp://ask.sagemath.org/question/48598/linear-algebra-derivative-expressions/How do I differentiate $\mathbf{y}=\mathbf{A}\mathbf{x}$ symbolically in sagemath with respect to the vector $\mathbf{x}$? The result is obviously $\mathbf{A}$. Similarly, I would like to be able to calculate the derivative of the quadratic form $\alpha=\mathbf{x}'\mathbf{A}\mathbf{x}$. I would need these calculations in a more complex setting.
I started off with sympy as follows
from sympy import *
n=7
A = MatrixSymbol('A', n, n)
x = MatrixSymbol('x', n, 1)
Or is there a different library from sympy available for such a problem?Tintin1Sun, 03 Nov 2019 06:46:47 -0600http://ask.sagemath.org/question/48598/Not understanding behavior with solution to simultaneous quadratic equationshttp://ask.sagemath.org/question/48466/not-understanding-behavior-with-solution-to-simultaneous-quadratic-equations/Hello,
I should preface this by saying I'm brand-new to sage so am probably missing some basics.
I'm writing because I wanted to use Sage to explore the behavior of a system of quadratic equations.
Here's my code
c = 299792458
eps1 = ( vector([9, 10, 10]).norm() -1 ) / c
eps2 = ( vector([9, -10, 10]).norm() -1 ) / c
eps3 = ( vector([-11, 10, 10]).norm() -1 ) / c
eps4 = ( vector([-11, -10, 10]).norm() -1 ) / c
x,y,z,D = var('x y z D') # GPS solution
x1,y1,z1 = var('x1 y1 z1') # Coordinates of P1
eq1 = (x - 10)^2 + (y - 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps1 - D)^2
eq2 = (x - 10)^2 + (y + 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps2 - D)^2
eq3 = (x + 10)^2 + (y - 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps3 - D)^2
eq4 = (x + 10)^2 + (y + 10)^2 + (z - 10)^2 == ( vector([x1, y1 -1, z1]).norm() + c*eps4 - D)^2
If I solve the system with `S = solve([eq1, eq2, eq3, eq4,D==0], x, y, z, D)`I get symbolic solutions as expected (y is constantly 0 which is unexpected and doesn't seem right, but that's a different matter).
However, if I try to specify values for x1,y1,z1 by using `solve([eq1, eq2, eq3, eq4, x1==0, y1==0, z1==0, D==0], x, y, z)` it returns an empty list, which I assume means no solution. On the other hand, if I use my solution `S` from before and explicitly substitute `x1==0, y1==0, z1==0, D==0` I get the solutions I'm expecting.
Could anyone explain this behavior? Is it somehow easier for Sage to solve the more general equation than the one with parameters plugged in? Will Sage sometimes fail to find existent solutions to such systems, or have I just done something wrong?
Many thanks,
Justin Justin BrodyTue, 22 Oct 2019 07:52:47 -0500http://ask.sagemath.org/question/48466/generate his own symbolic math functionhttp://ask.sagemath.org/question/48243/generate-his-own-symbolic-math-function/Hi
If I would like to generate my own symbolic math function : **general_falling_factorial(x, j, n)** .
What I should add and modify in the code below ? (I do not know what to do with the two lines below
I know it is ok for the first one, but what must I write for the second one ?)
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
[code on sageCell ](https://sagecell.sagemath.org/?q=iskopi)
j,n=var('j,n')
N=11
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)= \
\text{general_falling_factorial() is not the falling_factorial() SageMath Function} \
\, = \, "),falling_factorial(x, n))
print "https://math.stackexchange.com/questions/497616/is-there-an-explicit-formula-for-the-bernoulli-numbers-that-doesnt-implicitly-r"
print "http://youngp.people.cofc.edu/factbern.pdf"
show(LatexExpr(r"B_n=\sum_{j=1}^{n+1}\frac{(-1)^{j-1}}{j}{n+1\choose j}\sum_{i=0}^{j-1}(i|j)_n"))
show(LatexExpr(r"\text{with }\, \,(i|j)_n:=i(i-j)\cdots(i-(n-1)j)"))
def general_falling_factorial_latex(self, x,j,n):
return '{' + '('+str(x) + ' | ' + str(j) + ')'+'}_{' + str(n) + '}'
general_falling_factorial = function('general_falling_factorial', nargs=3, print_latex_func=general_falling_factorial_latex)
def general_falling_factorial(x, j, n):
r""" to fill up """
from sage.symbolic.expression import Expression
from sage.structure.coerce import py_scalar_to_element
x = py_scalar_to_element(x)
j = py_scalar_to_element(j)
n = py_scalar_to_element(n)
if ((isinstance(j, Integer) or
(isinstance(j, Expression) and
j.is_integer())) and j >= 0) and \
((isinstance(n, Integer) or
(isinstance(n, Expression) and
n.is_integer())) and n >= 0) :
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
return prod((((x)-(k*(j))) for k in (0..(n-1))), z=x.parent().one())
def bernoulliExplicit(N) :
bernoulliSL=[]
for n in range(0,N) :
bernoulliSLt=[]
for j in range (1,n+2):
#show("j : ",j)
bernoulliSLt.append((((-1)^(j-1)/j) *(factorial(n+1))/((factorial(j)*(factorial((n+1-j))))))* \
sum([general_falling_factorial(i,j,n) for i in range(0,j)]))
bernoulliSL.append(sum(bernoulliSLt))
return bernoulliSL
show("Explicit Bernoulli List : ",bernoulliExplicit(N))
bernoulliL=[]
for i in range(0,N) :
bernoulliL.append(bernoulli(i))
show("SageMath Bernoulli List : ",bernoulliL)ortolljWed, 09 Oct 2019 06:10:37 -0500http://ask.sagemath.org/question/48243/Defining q-binomial coefficients $\binom{n}{k}_q$ symbolic in $n, k$http://ask.sagemath.org/question/48013/defining-q-binomial-coefficients-binomnk_q-symbolic-in-n-k/I would like to verify certain identities involving sums of [$q$-binomial coefficients $\binom{n}{k}_q$](https://en.wikipedia.org/wiki/Gaussian_binomial_coefficient) and as such, I would like to treat the $q$-binomial coefficients as if they were symbolic in $n$ and $k$. But the version of $q$-binomial coefficients that are implemented in Sage cannot be used as a symbolic variable in $n$ and $k$ according to [this thread](https://ask.sagemath.org/question/36788/symbolic-sum-with-q_binomial/). So, to this end I defined my own:
var('q,n,k')
qint = lambda n: sum([q^i for i in range(n)])
qfac = lambda n: 1 if n==0 else prod([qint(i) for i in range(1,n+1)])
qbin = lambda n,k:qfac(n)/(qfac(k)*qfac(n-k))
But if I write
sum(qbin(n,k),k,0,n)
I get the following error:
ValueError: cannot convert n + 1 to int
Is there a way to do these types of summations in Sage? I should note that, for my purposes, it would be enough to limit myself to the case when $n$ and $k$ are non-negative integers.
EDIT: As an example, I would like to prove something like the $q$-binomial theorem, which says
$$\sum_{k=0}^n q^{k(k-1)/2} \binom{n}{k}_q x^k = \prod_{k=0}^{n-1} (1+q^k x)$$
EDIT2: Fixed a typo.joakim_uhlinSat, 21 Sep 2019 09:37:29 -0500http://ask.sagemath.org/question/48013/Why do computations with pi default to symbolic?http://ask.sagemath.org/question/47217/why-do-computations-with-pi-default-to-symbolic/Hello, Sage community,
It is known fact that SageMath uses symbolic computations by default. For example,
sqrt(8)
returns `2*sqrt(2)`. But it is also known that this behavior can be easily changed using decimals, like in the following case:
sqrt(8.0)
which returns `2.82842712474619`.
However, this technique doesn't seem to work with symbolic constants like `pi` and `e`. For example,
80 / pi
returns the expected `80/pi`, but
80.0 / pi
returns `80.0000000000000/pi` instead of the numerical value `25.4647908947033`.
I was wondering why is this the case.
Thanks in advance for your answers!dsejasFri, 19 Jul 2019 16:58:44 -0500http://ask.sagemath.org/question/47217/Converting a symbolic expression to an element of a number fieldhttp://ask.sagemath.org/question/35184/converting-a-symbolic-expression-to-an-element-of-a-number-field/At some point in a calculation in the symbolic ring I end up with some numbers which are complex rationals of the form (a/b + I*(c/d). At this point I would like to no longer treat them as symbolic expressions and rather work with them in a more well behaved field. Since all of the computation I will be doing will keep things as complex rationals it seems like the number field `QQ[I]` is my best option.
**My question is**: How can I convert a symbolic expression like `SR(2/3+4/5*I)` to an element of `QQ[I]`. In general, there is no coercion from the symbolic ring to a number field, but in this special case there is a pretty clear map I would like to use.
Edit: I suppose since the map from the symbolic ring to the number field depends on an assumed embedding of the number field in the complex numbers, this might not be doable in any clean way. For now the following helper function works
<pre>
def SRtoQQI(v, imGen): # imGen = the immaginary unit in a ring QQ[I]
rp = QQ(v.real_part()) # get real part of input
ip = QQ(v.imag_part()) # get immaginary part of input
return rp + ip*imGen # combine parts to get output
</pre>
I am still interested to know if there is a build in way, maybe making use of the embedding maps from `QQ[I]` to `SR`.rlg23Tue, 18 Oct 2016 22:35:58 -0500http://ask.sagemath.org/question/35184/create a sequence symbolically and then find a series based on this sequencehttp://ask.sagemath.org/question/46734/create-a-sequence-symbolically-and-then-find-a-series-based-on-this-sequence/I would like to create an infinite sequence (a_o,a_1,a_2,...) symbolically and then find an infinite series sum(a_0+a_1*z+a_2*z+...) based on this sequence with the coefficients based n the initial symbolical sequence. After that I would like to manipulate this sequence further.
I am rather new to Sagemath. How can this be done?
ThanksTintinFri, 31 May 2019 04:27:32 -0500http://ask.sagemath.org/question/46734/How to print the numeric part of a symbolic expression with arbitrary precision?http://ask.sagemath.org/question/46468/how-to-print-the-numeric-part-of-a-symbolic-expression-with-arbitrary-precision/How to print the numeric part of a symbolic expression with arbitrary precision?
I have a matrix `Hf`, it is a 3 by 3 matrix. It's a symbolic matrix, with just one variable 'E'. But on printing it, I get the as shown below. Basically what I want is to approximate the numerical part of the expression to arbitrary precision (let's say 3 decimal points), so that I can get a much cleaner expression.
sage: Hf.str()
[(𝟼.𝟶𝟿𝟶𝟻𝟸𝟼𝟺𝟼𝟻𝟿𝟺𝟺𝟿𝟽𝚎⎯𝟼)*(𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒))/𝙴⎯𝟶.𝟶𝟶𝟶𝟸𝟷𝟽𝟼𝟷𝟹𝟾𝟸𝟻𝟷𝟶𝟶𝟶𝟶𝟼*(𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒))/𝙴+𝟷𝟶𝟶𝟶⎯𝟶.𝟶𝟶𝟶𝟸𝟷𝟽𝟼𝟷𝟹𝟾𝟸𝟻𝟷𝟶𝟶𝟶𝟶𝟼*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))/𝙴+(𝟼.𝟶𝟿𝟶𝟻𝟸𝟼𝟺𝟼𝟻𝟿𝟺𝟺𝟿𝟽𝚎⎯𝟼)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))/𝙴𝟶.𝟶𝟶𝟶𝟸𝟷𝟷𝟻𝟸𝟹𝟸𝟿𝟾𝟼𝟹𝟺𝟶𝟼𝟷*𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴][⎯𝟶.𝟶𝟶𝟶𝟷𝟻𝟼𝟸𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶*𝚜𝚚𝚛𝚝(𝟸)*(𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒))*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴+(𝟺.𝟼𝟾𝟽𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝚎⎯𝟼)*(𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒))*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))/𝙴⎯𝟶.𝟶𝟶𝟶𝟷𝟻𝟼𝟸𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶*𝚜𝚚𝚛𝚝(𝟸)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴+(𝟺.𝟼𝟾𝟽𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝚎⎯𝟼)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))ˆ𝟸/𝙴⎯(𝟺.𝟼𝟾𝟽𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝚎⎯𝟼)*𝚜𝚚𝚛𝚝(𝟸)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴+𝟶.𝟶𝟶𝟶𝟹𝟷𝟸𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)ˆ𝟸/𝙴][⎯𝟶.𝟶𝟶𝟶𝟷𝟻𝟼𝟸𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶*𝚜𝚚𝚛𝚝(𝟸)*(𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒))*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴+(𝟺.𝟼𝟾𝟽𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝚎⎯𝟼)*(𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒))*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))/𝙴⎯𝟶.𝟶𝟶𝟶𝟷𝟻𝟼𝟸𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶*𝚜𝚚𝚛𝚝(𝟸)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴+(𝟺.𝟼𝟾𝟽𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝚎⎯𝟼)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)⎯𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))/𝙴⎯(𝟺.𝟼𝟾𝟽𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝚎⎯𝟼)*𝚜𝚚𝚛𝚝(𝟸)*(𝚜𝚚𝚛𝚝(𝟸)*𝚜𝚒𝚗(𝟽/𝟹𝟼*𝚙𝚒)*𝚜𝚒𝚗(𝟷/𝟷𝟾*𝚙𝚒)+𝚜𝚚𝚛𝚝(𝟸)*𝚌𝚘𝚜(𝟽/𝟹𝟼*𝚙𝚒))*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)/𝙴+𝟶.𝟶𝟶𝟶𝟹𝟷𝟸𝟻𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶𝟶*𝚌𝚘𝚜(𝟷/𝟷𝟾*𝚙𝚒)ˆ𝟸/𝙴]jonespanickerMon, 06 May 2019 15:18:37 -0500http://ask.sagemath.org/question/46468/Symbolic sum/product of Laurent/power serieshttp://ask.sagemath.org/question/46367/symbolic-sumproduct-of-laurentpower-series/ How can I do something like this?
#f = some Laurent/power series in x e.g.
#a,b,w are symbolic such that e.g. 2*w**2 = 3
f = 1/x + w + a*x + b*x**2 + ((a+b)/w)**2*x**3 + O(x**7)
#g[i] = some power series in x derived from f, c[i], d[i], e.g.
g[i] = (x*f + c[i])/(d[i]*f + x**2)
#product of n first g[i]
#n is symbolic
G = product(g[i], i=1..n)
#extract coefficients of x in G
G.coeff(x,-1), G.coeff(x,0), G.coeff(x,1)
Thank you.RoadFri, 26 Apr 2019 12:44:06 -0500http://ask.sagemath.org/question/46367/Solve symbolic matrix cellhttp://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/I'm trying to take a cell from a matrix and solve for a variable symbolically. When I run this, I get the error:
TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.
This is the code I am trying to execute:
var('a','b','c','x','y','z')
Rz = matrix([[cos(a),-sin(a),0,0],[sin(a),cos(a),0,0],[0,0,1,0],[0,0,0,1]])
Ry = matrix([[cos(b),0,sin(b),0],[0,1,0,0],[-sin(b),0,cos(b),0],[0,0,0,1]])
Rx = matrix([[1,0,0,0],[0,cos(c),-sin(c),0],[0,sin(c),cos(c),0],[0,0,0,1]])
P = matrix([[x],[y],[z],[1]])
Rzyxp = Rz * Ry * Rx * P
show(Rzyxp)
eqn2 = Rzyxp[2]
show(eqn2)
result1 = solve(eqn2==0, b)
show(result1)
Any help would be appreciatedMickey_PhippsTue, 19 Mar 2019 14:44:52 -0500http://ask.sagemath.org/question/45841/convert .solve output to functionhttp://ask.sagemath.org/question/45692/convert-solve-output-to-function/ I have a function of two variables and would like to solve for one of the variables and make that a function, eg
t=var('t',domain='real')
z,w=var('z,w')
p(z,w)=5*z^2*w + 3*z*w +2*z
solns=p(e^(I*t),w).solve(w)
solns
and then somehow have the output of that:
[w == -2/(5*e^(I*t) + 3)]
become a function
f(t)=-2/(5*e^(I*t)+3)
Does anyone know a good way to do this? The main issue I'm having is the w== part.
meresarWed, 06 Mar 2019 16:35:42 -0600http://ask.sagemath.org/question/45692/Symbolic computations in a finite fieldhttp://ask.sagemath.org/question/10371/symbolic-computations-in-a-finite-field/Hallo
I am interested in symbolic computations in a file field. Working in the field $GF(2^8)$ with $x$ as a generator and a variable $y$, also there is a function $f:GF(2^8)\rightarrow GF(2^8)$ of which the exact definition is not given. Can sage do the following:
$(x + y) ^ {2^8} \mapsto x + y$
$(x + y) ^ {2^6} \mapsto x ^ {2^6} + y ^ {2^6}$
$f(y) + f(y) \mapsto 0\cdot x$
If sage cannot do it does there exist another program which can?
_______________________________________________________________
Below is my question updated:
For the function I have a partial solution but I cannot mix it with an element of an finite field
<pre>
<code>
import sympy
f = sympy.Function('f')
y = var('y')
sympy.expand((f(y)+f(y)), modulus=2)
</code>
</pre>
When I want to add an element of a finite field
<pre>
<code>
import sympy
f = sympy.Function('f')
x = GF(2^8,'x').gen()
f(x)
f(x) + x
</code>
</pre>
the statement $f(x) +x$ give me an error that makes sense ... TypeError: unsupported operand parent(s) for '+': 'f' and 'Finite Field
in g of size 2^8'
To create a variable in a finite field I decided to use a Polynomial ring
<pre>
<code>
import sympy
f = sympy.Function('f')
R.< x > = PolynomialRing(GF(2))
f(x)
f(x) + x
</code>
</pre>
both $f(x)$ and $f(x) + x$ fails with a very long Trace message.
RegardsJohanSun, 21 Jul 2013 22:49:28 -0500http://ask.sagemath.org/question/10371/long traceback when calling solve()http://ask.sagemath.org/question/45473/long-traceback-when-calling-solve/After https://ask.sagemath.org/question/45463/solvex-does-not-fully-isolate-x-how-can-i-help-along/ I substituted variables with numbers (in RIF format) so that sage might have an easier time solving for d_k. I got this:
0 == -v_ges + 1/(sqrt(4*d_k^2 + 0.57?)*d_k*((3.?e-11)/(d_k - 0.1?) + 1.?e-8)) - 1/(sqrt(4*d_k^2 + 0.0625000000000000)*d_k*((3.?e-11)/(d_k - 0.1?) + 1.?e-8)) + 3.7?e9
But now, when I try to solve the above for d_k, I get this long traceback, which is above my sage skills. How can I solve this? The worksheet is https://cocalc.com/share/f7766c5e-2f4d-4916-bb0d-74a7182e5fd5/2019-02-09-203517.sagews?viewer=share
*** WARNING: Code contains possible implicit multiplication ***
*** Check if any of [ 5e, 5e ] need a "*" sign for multiplication, e.g. 5x should be 5*x ! ***
Error in lines 42-42
Traceback (most recent call last):
File "/cocalc/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 1188, in execute
flags=compile_flags) in namespace, locals
File "", line 1, in <module>
File "sage/symbolic/expression.pyx", line 11568, in sage.symbolic.expression.Expression.solve (build/cythonized/sage/symbolic/expression.cpp:59905)
return solve(self, x, multiplicities=multiplicities,
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 1044, in solve
return _solve_expression(f, x, explicit_solutions, multiplicities, to_poly_solve, solution_dict, algorithm, domain)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/relation.py", line 1282, in _solve_expression
m = ex._maxima_()
File "sage/symbolic/expression.pyx", line 817, in sage.symbolic.expression.Expression._maxima_ (build/cythonized/sage/symbolic/expression.cpp:7898)
return super(Expression, self)._interface_(maxima)
File "sage/structure/sage_object.pyx", line 663, in sage.structure.sage_object.SageObject._interface_ (build/cythonized/sage/structure/sage_object.c:5290)
s = init_func()
File "sage/structure/sage_object.pyx", line 769, in sage.structure.sage_object.SageObject._maxima_lib_init_ (build/cythonized/sage/structure/sage_object.c:7971)
return self._maxima_init_()
File "sage/structure/sage_object.pyx", line 762, in sage.structure.sage_object.SageObject._maxima_init_ (build/cythonized/sage/structure/sage_object.c:7742)
return self._interface_init_(I)
File "sage/symbolic/expression.pyx", line 854, in sage.symbolic.expression.Expression._interface_init_ (build/cythonized/sage/symbolic/expression.cpp:8069)
return InterfaceInit(I)(self)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 219, in __call__
return self.relation(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 471, in relation
self(ex.rhs()))
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 217, in __call__
return self.arithmetic(ex, operator)
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 624, in arithmetic
args = ["(%s)"%self(op) for op in ex.operands()]
File "/ext/sage/sage-8.6_1804/local/lib/python2.7/site-packages/sage/symbolic/expression_conversions.py", line 207, in __call__
raise err
TypeError
stockh0lmFri, 15 Feb 2019 16:30:38 -0600http://ask.sagemath.org/question/45473/plot parametric curve from symbolic expressionshttp://ask.sagemath.org/question/44865/plot-parametric-curve-from-symbolic-expressions/I would like to get the plot of the parametric curve $(x1(t),x2(t)$ for $t$ in $[0,1]$.
> var('ts')
> x1sol=vector([-cos(ts),sin(ts)])*exp(ts/2)
>
> x11 = x1sol[0]
>
>
> show(plot(x11(ts),x12(ts),(ts,0,1)))
I get the error:
*TypeError: unable to simplify to float approximation*
I would like to avoid formulation as :
> def x1(t): ....sagenotdeadThu, 03 Jan 2019 08:22:42 -0600http://ask.sagemath.org/question/44865/Verifying inequalitieshttp://ask.sagemath.org/question/44645/verifying-inequalities/ I would like to give SageMath some inequalities, and then ask it if other inequalities follow from them.
For example, I would like to tell SageMath "a > 2*b > 0" and then ask it whether "a - b > b/2" and the answer should be "True", but if I ask whether "a - b > 3*b/2" the answer should be "False" (since it is not implied by the given inequalities).
How can I do this?
Erel Segal-HaleviTue, 11 Dec 2018 22:41:14 -0600http://ask.sagemath.org/question/44645/Solving linear congruencehttp://ask.sagemath.org/question/44618/solving-linear-congruence/ Is there a simple way to solve a linear congruence modulo an integer with large prime factors in Sage? `solve_mod` function cannot handle such large moduli apparently.kdr01Sun, 09 Dec 2018 13:28:31 -0600http://ask.sagemath.org/question/44618/Error integrate with Fricas as algorithm fresnel_sin calledhttp://ask.sagemath.org/question/44369/error-integrate-with-fricas-as-algorithm-fresnel_sin-called/ reference question [https://ask.sagemath.org/question/43237/does-sagemath-support-fresnels-function/](https://ask.sagemath.org/question/43237/does-sagemath-support-fresnels-function/)
I am using
sage: version()
'SageMath version 8.5.beta2, Release Date: 2018-11-01'
Here is the problem. When I type
from sympy import fresnelc, fresnels
var('a b c d e m n x ')
r=integrate(x^7*fresnels(b*x),x,algorithm="fricas")
sage gives the error
TypeError: An error occurred when FriCAS evaluated '((x)^(7))*(fresnel_sin((b)*(x)))':
There are no library operations named fresnel_sin
But FriCAS does not have fresnel_sin. It has fresnelS and fresnelC , link [here](http://fricas.github.io/api/FloatLiouvilianFunctions.html)
When running the same command inside Fricas 1.3.4 itself, it works OK
integrate(x^7*fresnelS(b*x),x)
(3)
2 2
5 2 5 b %pi x 8 4 8
(- 7 b %pi x + 105 b x)sin(--------) + (b %pi x - 105)fresnelS(b x)
2
+
2 2
7 3 7 3 3 b %pi x
(b %pi x - 35 b %pi x )cos(--------)
2
/
8 4
8 b %pi
Why the error says `when FriCAS evaluated '((x)^(7))*(fresnel_sin((b)*(x)))` when Fricas itself does not have this function?
Notice that there is no problem using default integrate algorithm in sage
sage: integrate(x^7*fresnels(b*x),x)
1/8*x^8*fresnel_sin(b*x) - 1/16*sqrt(1/2)*((105*I + 105)*(1/4)^(1/4)*pi*erf(sqrt(1/2*I*pi)*b*x) - (105*I - 105)*(1/4)^(1/4)*pi*erf(sqrt(-1/2*I*pi)*b*x) - 4*(sqrt(1/2)*pi^4*b^7*x^7 - 35*sqrt(1/2)*pi^2*b^3*x^3)*cos(1/2*pi*b^2*x^2) + 28*(sqrt(1/2)*pi^3*b^5*x^5 - 15*sqrt(1/2)*pi*b*x)*sin(1/2*pi*b^2*x^2))/(pi^5*b^8)
I was not sure if I am doing something wrong myself, or if I should enter a ticket on this.
Thanks,
--Nasser
NasserWed, 21 Nov 2018 14:01:59 -0600http://ask.sagemath.org/question/44369/Conversion from symbolic expression to polynomial stuckhttp://ask.sagemath.org/question/44302/conversion-from-symbolic-expression-to-polynomial-stuck/I have a very long symbolic expression with six variables:
> (E_mu, E_xi3, ISP, T, V_mu, V_xi3, Z,
> m, mu, n_I, n_P, xi_1, xi_3)
I call the expression AN. I want to convert it in a polynomial of two variables (mu and xi_3). I tried the following command:
AP = AN.polynomial(None,ring=SR['mu,xi_3'])
This works for simple expressions but the command remains stuck for the given expression. My aim is to get the monomials of the polynomial. mu and xi_3 are random variables and I want to compute the expectation of AN (E[AN]). Thus, I could substitute the expectations in the expression.
AN is a numerator, so it is not a fraction. Moreover, I also tried simply_rational but it did not help to convert.
Is there anyway to convert easily ?
EDIT : [I put the symbolic expression in a framabin.](https://framabin.org/p/?2417942055fc9fc9#Oenpb+BI567QXYcVCzjO4zkLRC0byQaNdhi2XW/CUkY=)borostackFri, 16 Nov 2018 05:53:39 -0600http://ask.sagemath.org/question/44302/Print symbolic variables like a_1 in A[1] stylehttp://ask.sagemath.org/question/43838/print-symbolic-variables-like-a_1-in-a1-style/Because of Sagemath's problem with symbolic arrays, I have defined my vectors like this:
A =[0 for j in range(4)]
for j in range(4):
A[j]=var('a_'+str(j))
I have some symbolic variables stored in another variable. Lets say I have a subroutine that works with `A[i]` and in the end, `L` becomes something such as: `L=a_1+a_2*a_3`. When I print `L`, I want to have it printed in the original vector format. So when I type `L` or `print(L)` in a cell and press enter, my desired output is `A[1]+A[2]*A[3]` and not `a_1+a_2*a_3`. I want this type of output because I am transferring SageMath outputs to C where I employ indexed arrays. How can I achieve this? DanialBaghFri, 05 Oct 2018 22:30:25 -0500http://ask.sagemath.org/question/43838/Setting relations between variableshttp://ask.sagemath.org/question/43559/setting-relations-between-variables/I have a question about doing this in SAGE.
I have a set of variables S_ijkl for i, j, k l in [1..4] and I would like to set the following relations without having to manually type everything in:
S_ijkl = S_jikl = S_ijlk = S_jilk,
how can I go about doing this?mousestarSun, 02 Sep 2018 19:50:25 -0500http://ask.sagemath.org/question/43559/