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.Thu, 05 Dec 2019 11:36:44 -0600Creating an object of the Magmatic Algebras categoryhttp://ask.sagemath.org/question/48953/creating-an-object-of-the-magmatic-algebras-category/ For the moment being, the category of Sage for nonassociative algebras is called MagmaticAlgebras. I want to know which methods are available in this category, and specifically how to create an object (i.e., a nonassociative algebra). In particular, what I want is to get the free nonassociative algebra in four variables (a,b,c,d) over the rational field. The MagmaticAlgebras reference page is of no use to me. Thank you!Jose BroxThu, 05 Dec 2019 11:36:44 -0600http://ask.sagemath.org/question/48953/How to use a string in a symbolic expression with SageMath?http://ask.sagemath.org/question/48949/how-to-use-a-string-in-a-symbolic-expression-with-sagemath/I would like to use a string as part of a symbolic expression. For instance:
> function('P') var('x1 x2 x3 y1 y2 y3') <br>
> st = eval('y1,0,1') <br>
> sum(P(x1,y1,y2,y3),st) <br>
How could I use st which is a string in the symbolic expression sum?
I want the same result as if I had typed directly:
> sum(P(x1,y1,y2,y3),y1,0,1)JarenKThu, 05 Dec 2019 07:57:48 -0600http://ask.sagemath.org/question/48949/How to use a string in a symbolic expression with SageMath?http://ask.sagemath.org/question/48948/how-to-use-a-string-in-a-symbolic-expression-with-sagemath/I would like to use a string as part of a symbolic expression. For instance:
> function('P') var('x1 x2 x3 y1 y2 y3') <br>
> st = eval('y1,0,1') <br>
> sum(P(x1,y1,y2,y3),st) <br>
How could I use st which is a string in the symbolic expression sum?
I want the same result as if I had typed directly:
> sum(P(x1,y1,y2,y3),y1,0,1)JarenKThu, 05 Dec 2019 07:56:25 -0600http://ask.sagemath.org/question/48948/importing .sage fileshttp://ask.sagemath.org/question/7867/importing-sage-files/What's the recommended approach for importing .sage scripts as a module, i.e. into their own namespace? I have a file with ~10k functions and it'd be much nicer to keep them filed tidily away.
I've written a hack sage_import wrapper which seems to work for my use case, but hopefully there's a better way. DSMThu, 13 Jan 2011 03:19:28 -0600http://ask.sagemath.org/question/7867/How can I define a field of numbers by hitting to the field of rationals two roots of the same polynomial ?http://ask.sagemath.org/question/48938/how-can-i-define-a-field-of-numbers-by-hitting-to-the-field-of-rationals-two-roots-of-the-same-polynomial/I tried:
sage: alpha=sqrt(-11/2 + sqrt(11^2-4(11))/2)
sage: alpha=sqrt(-11/2 - sqrt(11^2-4(11))/2)
sage: K=QQ[alpha,beta]julioWed, 04 Dec 2019 13:43:05 -0600http://ask.sagemath.org/question/48938/SEND+MORE=MONEY (one more time)http://ask.sagemath.org/question/48931/sendmoremoney-one-more-time/I have some heavy problems of formulation with Sagemath. It's certainly a formulation problem --- I will add the theoretrical aspect of the model at the end of the question :
I have corrected my code. May be some errors could stay. But even if I am wrong I need some information on how to write my program. You can find the source in the free paper https://pubsonline.informs.org/doi/pdf/10.1287/ited.2016.0163. There is also an Excel code on the internet. Here is my code
p = MixedIntegerLinearProgram(maximization=True,solver='PPL')
v = p.new_variable(nonnegative=True)# permet de définir v[i, j] aussi bien que v[i]
c = p.new_variable(nonnegative=True)# permet de définir v[i, j] aussi bien que v[i]
p.set_objective(v[0,0])
for i in range(7) : # nombre de lettres (8)
for j in range(9) : #nombre de chiffres
p.set_binary(v[i,j])
#S=sum(j*v[0,j] for j in range(9))
#E=sum(j*v[1,j] for j in range(9))
#N=sum(j*v[2,j] for j in range(9))
#D=sum(j*v[3,j] for j in range(9))
#M=sum(j*v[4,j] for j in range(9))
#O=sum(j*v[5,j] for j in range(9))
#R=sum(j*v[6,j] for j in range(9))
#Y=sum(j*v[7,j] for j in range(9))
for k in range(1,4) :
p.set_binary(c[k])
# Une lettre n'est représentée que par un chiffre
for j in range(8) :
p.add_constraint(0<= sum(v[i,j] for i in range(7)) <= 1)
# Un chiffre n'est associé qu'à une seule lettre
for i in range(7) :
p.add_constraint(sum(v[i,j] for j in range(9)) == 1)
# D + E = Y + 10 C_1
p.add_constraint(sum(j*v[3,j] for j in range(7))+sum(j*v[1,j] for j in range(9))==
sum(j*v[7,j] for j in range(7))+10*c[1])#
# C_1 + R + N = E + 10 C_2
p.add_constraint(c[1]+sum(j*v[6,j] for j in range(7))+sum(j*v[2,j] for j in range(9))==
sum(j*v[1,j] for j in range(9))+10*c[2])#
# C_2 + E + O = N + 10 C_3
p.add_constraint(c[2]+sum(j*v[5,j] for j in range(8))+sum(j*v[1,j] for j in range(9))==
sum(j*v[2,j] for j in range(9))+10*c[3])#
# C_3 + S + M = O + 10 C_4
p.add_constraint(c[3]+sum(j*v[0,j] for j in range(9)) + sum(j*v[4,j] for j in range(9))==
sum(j*v[5,j] for j in range(9))+10*c[4])#
# C_4 = M
p.add_constraint(c[4]==sum(j*v[4,j] for j in range(9)))
p.solve()
p.show()
xx=p.get_values(v)
show(xx)
for j in range(9) :
if xx[0,j]== 1 : print('S='+ `j`)
for j in range(9) :
if xx[1,j]== 1 : print('E='+ `j`)
for j in range(9) :
if xx[2,j]== 1 : print('N='+ `j`)
for j in range(9) :
if xx[3,j]== 1 : print('D='+ `j`)
for j in range(9) :
if xx[4,j]== 1 : print('M='+ `j`)
for j in range(9) :
if xx[5,j]== 1 : print('O='+ `j`)
for j in range(9) :
if xx[6,j]== 1 : print('R='+ `j`)
for j in range(9) :
if xx[7,j]== 1 : print('Y='+ `j`)
I have 8x10 = 80, v[i,j] variables v[i, j] and 4 c[j] variables. I have asked all to be binary. But when I look the printed model I see only 73 variables and from $x_{66}$ to $x_{73}$ they are not binary. More than that the (7,6) variables takes a value of 3/6. It's not particularly simple to associate the variables internal variables to the internal ones.
I need help! (Thanks by advance). The documentation is of no help for me.
MODELIZATION CLUES
In this so called "cryptarythm" one use 8 letters $S_{(1)}E_{(2)}N_{(3)}D_{(4)}M_{(5)}O_{(6)}R_{(7)}Y_{(8)}$ so we define the binary variables
$x_{ij} =
\begin{cases}
1 & \text{if letter } i (i= 1, \ldots 8) \text{ is associated to th digit } j (j = 0,\ldots, 9)\\\\
0 & \text{sinon}
\end{cases}$
We need also 4 variables $C_k$ for the retention.
From this one can write $S = \sum_{1}^9 j x_{1j }$, $E = \sum_{1}^9 j x_{2j }$ and so on. For the constraints one have 17 general constraints
--- each letter is associated to a unic digit $\sum_{j=0}^9 x_{ij} = 1, \text{ for }
i = 1, \ldots 8$
--- each digit is associated to a only one letter $\sum_{i=0}^8 x_{ij} \leq 1, \text{ for }
j = 1, \ldots 9$
Then one hase the pure addition constraints :
$D + E = Y + 10 C_1 \Longleftrightarrow \sum_{j=0}^9 j x_{2j} +\sum_{j=0}^9 j x_{4j}= \sum_{j=0}^9 j x_{8j} + 10 C_1$
$C_1 + R + N = Y + 10 C_2 \Longleftrightarrow C_1+\sum_{j=0}^9 j x_{3j} +\sum_{j=0}^9 j x_{4j}= \sum_{j=0}^9 j x_{2j} + 10 C_2$
$C_2 + E + O = N + 10 C_3 \Longleftrightarrow C_2+\sum_{j=0}^9 j x_{2j} +\sum_{j=0}^9 j x_{6j}= \sum_{j=0}^9 j x_{3j} + 10 C_3$
$C_3 + S + M = O + 10 C_4 \Longleftrightarrow C_3+\sum_{j=0}^9 j x_{1j} +\sum_{j=0}^9 j x_{5j}= \sum_{j=0}^9 j x_{6j} + 10 C_4$
$C_4 = M \Longleftrightarrow C_4 = \sum_{j=0}^9 j x_{5j}$
Here is the solution
$(S=9). (E=5). (N=6). (D=7).$
$+. (M=1). (O=0).(R=8). (E=5).$
$= (M=1). (O=0). (N=6). (E=5). (y=2)$CyrilleTue, 03 Dec 2019 09:01:23 -0600http://ask.sagemath.org/question/48931/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/Mistake in SageMathCell code, finding integral points on elliptic curveshttp://ask.sagemath.org/question/48933/mistake-in-sagemathcell-code-finding-integral-points-on-elliptic-curves/ I've the following number:
$$12\left(n-2\right)^2x^3+36\left(n-2\right)x^2-12\left(n-5\right)\left(n-2\right)x+9\left(n-4\right)^2\tag1$$
Now I know that $n\in\mathbb{N}^+$ and $n\ge3$ (and $n$ has a given value) besides that $x\in\mathbb{N}^+$ and $x\ge2$.
I want to check if the number is a perfect square, so I can rewrite $(1)$ as follows:
$$y^2=12\left(n-2\right)^2x^3+36\left(n-2\right)x^2-12\left(n-5\right)\left(n-2\right)x+9\left(n-4\right)^2\tag2$$
Where $y\in\mathbb{Z}$.
In this problem I've: $n=71$, the number is equal to;
$$y^2=57132x^3+2484x^2-54648x+40401\tag3$$
So, I used SageMathCell to look for the integral points on the elliptic curve and the code that was used is the following:
E = EllipticCurve([0, β, 0, γ, δ])
P = E.integral_points()
for p in P:
if p[0] % α == 0:
print(p[0] // α, p[1] // α)
I found the coeficients I need to use using equation $(2)$ and $(3)$ (but I do not know if they are corect):
- $$\alpha=12(71-2)^2=57132\tag4$$
- $$\beta=36(71-2)=2484\tag5$$
- $$\gamma=-144(71-5)(71-2)^3=-3122149536\tag6$$
- $$\delta=1296(71-4)^2(71-2)^4=131871507195024\tag7$$
So the final code looks like:
E = EllipticCurve([0, 2484, 0, -3122149536, 131871507195024])
P = E.integral_points()
for p in P:
if p[0] % 57132 == 0:
print(p[0] // 57132, p[1] // 57132)
But I found no solutions and it should give at least one solution at $x=1585$.
>What mistake have I made?Jan123Tue, 03 Dec 2019 10:13:08 -0600http://ask.sagemath.org/question/48933/IPython.display.clear_output() functionality for SageMathCell.http://ask.sagemath.org/question/48932/ipythondisplayclear_output-functionality-for-sagemathcell/ I have a loop which outputs a graphic object (a plot) for each step. But I would like to replace the plot with the plot from the next iteration so I can see the progress as the loop runs. When I am using a jupyter notebook I can do this using the clear_output() function from IPython.display.
However, I am trying to use the SageMathCell server to make the program able to run completely in the browser (without having to go through CoCalc). But I am trouble clearing the output in the sage cell after each iterate of a loop..
metallicmural99Tue, 03 Dec 2019 10:12:08 -0600http://ask.sagemath.org/question/48932/Standard use of underscores in numeralshttp://ask.sagemath.org/question/48926/standard-use-of-underscores-in-numerals/ Hello, Sage Community!
Since Python (and pretty soon Sage) supports underscores in numbers, like in `11_000_000`, as an alternative to `11000000`, I was wondering if Sage or Python have any requirement or standard style for their use.
Let me explain, in English, the 11000000 is written 11,000,000, so i could write it as `11_000_000` in Sage. However, in Spanish, we use a small space after every thee-digit group, except if the number is four digits long. Also, the integer and the decimal parts are treated separatedly. For example:
- 4,321 is written as 4321, because it only has four digits, so I should write `4321` in Sage.
- 54,321 is written as 54 321 (with a small space between 4 and 3), so I should write `54_321` in Sage.
- 21, 1234 is written as 21,123 (because the integer part has only two digits, and the decimal part has only four), so I should write `21.1234` in Sage.
However, if I were to work with an international team of people, I suppose there should be some standard, because some will write `4_321` and `21.123_4`, while I will write `4321` and `21.1234`.
Is there any standard for using underscores in Sage numerals?
Thanks in advance for your answers!
32.12345 is written as dsejasSun, 01 Dec 2019 14:47:05 -0600http://ask.sagemath.org/question/48926/The annulus problem in linear programminghttp://ask.sagemath.org/question/48924/the-annulus-problem-in-linear-programming/ I do not know if the following question is a question about Sagemath or a question about my incapacity to use `MixedIntegerLinearProgram`
The problem is to find the smallest annulus for a set of points. Here is a reference `https://www.ti.inf.ethz.ch/ew/courses/CG12/lecture/Chapter%2011%20and%2012.pdf`
# list of point
lis=[(4,1),(5,6),(2,2),(3,4),(6,3.2),(2.6,2.5),(5.8, 2.4),(2,3.4),(4.2,4),(5.6,1)]
from sage.plot.circle import Circle
# Evaluation of the norm of each point
d = [sqrt(lis[i][0]^2+lis[i][1]^2) for i in range(len(lis)-1)]
anmin = MixedIntegerLinearProgram(maximization=True, solver = "GLPK")# création du programme
nvar=len(lis)-1 # nombre de variables
x = anmin.new_variable(integer=False, indices=[0..nvar-1],nonnegative=True) # les nouvelles variables sont x[0] ... x[3]
anmin.set_objective(x[0]-x[1])# fixe l’objectif
# Constraints
for i in range(nvar) :
anmin.add_constraint(x[0]+ 2*(lis[i][0]*x[2]+lis[i][1]*x[3]), min=0, max=n(d[i]^2, digits = 2))
for i in range(nvar) :
anmin.add_constraint(x[1]+ 2*(lis[i][0]*x[2]+lis[i][1]*x[3]), min=n(d[i]^2, digits = 2), max=oo)
anmin.show()
anmin.solve()
xx=anmin.get_values(x)
show(xx)
The result is obviously false. It would be great if somebody helps me find the good answer.
CyrilleSun, 01 Dec 2019 09:58:04 -0600http://ask.sagemath.org/question/48924/sagetex young_diagram sizehttp://ask.sagemath.org/question/48919/sagetex-young_diagram-size/Hello, I am printing a list of young diagramas in sagetex with something like
<code><pre>\sage{[p for p in Partitions(28) if p.is_symmetric()]}</code></pre>
How can I change the size of the cells so that they can actually fit in paper?heluaniFri, 29 Nov 2019 07:27:30 -0600http://ask.sagemath.org/question/48919/Is the PDF for "Euclidean Spaces and Vector Calculus" available?http://ask.sagemath.org/question/48917/is-the-pdf-for-euclidean-spaces-and-vector-calculus-available/ The link to it seems to be broken.gjamesThu, 28 Nov 2019 20:38:11 -0600http://ask.sagemath.org/question/48917/Check if a curve is a geodesichttp://ask.sagemath.org/question/48915/check-if-a-curve-is-a-geodesic/Suppose you have a curve `gamma` on a riemannian manifold `(M,g)`. Can you check if `gamma` is a geodesic?
I tried
nabla =g.connection()
nabla(gamma.nabla.tangent_vector_fields())
But it seems to be impossible to compute covariant derivatives of vectors field along curves. Is there any way to do this?MLainzThu, 28 Nov 2019 09:37:01 -0600http://ask.sagemath.org/question/48915/How to avoid scientific notation of numbers in the Mathematica interfacehttp://ask.sagemath.org/question/48908/how-to-avoid-scientific-notation-of-numbers-in-the-mathematica-interface/ I use the mathematica interface to compute numerical values of an extended hyper-geometric function MeijerG for real arguments. This function is provided only by Mathematica:
var('x,mx')
x=0.00001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]')
For real arguments x >= 0.00001 I get useful numeric results, e.g.
resp=0.00025871503616237216
for x =0.00001.
However, for 0< x < 0.00001 this method fails. With a small argument x and
var('x,y,mx')
x=0.000000001
resp=mathematica.set(mx,x)
mathematica('MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, mx]'),
With this small argument, I obtain:
resp=MeijerG[{{1, 3/2}, {}}, {{1, 1}, {1/2}}, -9. + 1.*e]
Obviously, this behavious is caused by the python interpreter: It converts pure decimal presentation of numbers (see previous example) into their scientific presentation. And, as I have learned from contributions in the Mathematica's stack exchange, Mathematica doesn't accept formatted numbers like ScientficForm, etc, for numerical evaluation of functions. Thus, Mathematica lets requested numeric evaluation undone. I haven't found any hints how to prevent python from expressing the argument in scientific format. Is it possible by any means to circumvent this problem?
bekalphWed, 27 Nov 2019 09:30:46 -0600http://ask.sagemath.org/question/48908/conditions among the variableshttp://ask.sagemath.org/question/48809/conditions-among-the-variables/ Suppose I am defining some variables in sagemath. How can I give conditions among the variables such that the condition is applied in the future calculations?
Thank You.user789Tue, 19 Nov 2019 06:55:04 -0600http://ask.sagemath.org/question/48809/Equation solver with assumehttp://ask.sagemath.org/question/48899/equation-solver-with-assume/Odd behaviour: the following gives a solution:
x, c, k = var('x, c, k')
assume(k > 0)
assume(k, "integer")
solve(x**k == (k/c), x)
but the following does not:
x, c, k = var('x, c, k')
assume(k > 0)
assume(k, "real")
solve(x**k == (k/c), x)
I should be able to remove the assume(k, "datatype") completely, right?technossomyTue, 26 Nov 2019 14:10:48 -0600http://ask.sagemath.org/question/48899/Is there a macro solving transportation problems stage by stage?http://ask.sagemath.org/question/48897/is-there-a-macro-solving-transportation-problems-stage-by-stage/ I would like something using the special structure of the problem, for teaching purposes, like the wonderful
InteractiveLPProblem for linear programming. ThanksflorinTue, 26 Nov 2019 11:46:35 -0600http://ask.sagemath.org/question/48897/How to plot a list of circleshttp://ask.sagemath.org/question/48887/how-to-plot-a-list-of-circles/ I would like to know if there is a mechanism in SageMath to do the following.
lis=[(4,1),(5,6),(2,2),(3,4),(6,3.2),(2.6,2.5),(5.8, 2.4),(2,3.4),(4.2,4),(5.6,1)]
from sage.plot.circle import Circle
for i in len(lis-1):
p[i]=circle(lis[i], .05, fill=true, color='red')
(unfortunately my code is wrong) and then to do a sum of the `p[i]` to plot the circles ?CyrilleTue, 26 Nov 2019 03:09:46 -0600http://ask.sagemath.org/question/48887/Grabbing Output in Linuxhttp://ask.sagemath.org/question/48884/grabbing-output-in-linux/Hello!
I have a great deal of code written in Pascal, and this code runs on a linux terminal. Currently, the only way I can run sage math through this program is to do the following: type a list of commands to run in sage as a concatenated strings separated by semicolons, and I then write the output to a textfile. For example 'load(''whatever'');function_call(something);... > sometextfile.txt'. This entire line is written in a call to the terminal. Effectively what is fed is *sage -c that-string*. The problem with this method is it adds time because sage has to open and close every time it runs. Is there a command in sage that allows me to keep the sage terminal persistent and I then ping that terminal with new commands. I assume the way to ping with new commands is to pipe from one terminal to the one running sage, but I am not a unix connisseur.
Of course, the easiest method is to run my code via python and have python run the pascal code. This is, unfortunately, not an option.KraigMon, 25 Nov 2019 18:03:50 -0600http://ask.sagemath.org/question/48884/Bug: Gap3 interface confuses variableshttp://ask.sagemath.org/question/48786/bug-gap3-interface-confuses-variables/Running
gap3('4', name = 'x')
gap3('5', name = 'y')
gap3('6', name = 'z')
followed up by
gap3('x')
gap3('y')
gap3('z')
gap3('x')
yields
4
5
6
6
instead of 4,5,6,4. Is this a bug or am I doing this wrong?
Update: I've tried it on a different computer (which uses a slightly older version of Sage) and did not have any issues there. I'm running the latest version of Sage here; any idea what might be causing this?
Update2: I'm experiencing the exact same problem on the other computer, when running slightly more complicated code: the gap3 interface seems to override its variables with other outputs.Bob67846Sun, 17 Nov 2019 07:41:52 -0600http://ask.sagemath.org/question/48786/Latex typesetting conditionalhttp://ask.sagemath.org/question/47992/latex-typesetting-conditional/How can I type set :
If x est positive write in Latex "H>0" else "H<=0"CyrilleFri, 20 Sep 2019 12:26:32 -0500http://ask.sagemath.org/question/47992/Sagemath and TI-83 giving different answershttp://ask.sagemath.org/question/48848/sagemath-and-ti-83-giving-different-answers/My expression
```
(-3)^(1/3)
```
SageMath returns a complex number:
```bash
sage: n((-3)^(1/3))
0.721124785153704 + 1.24902476648341*I
```
while TI-83 returns `-1.4422` (expected answer)ggFri, 22 Nov 2019 02:45:44 -0600http://ask.sagemath.org/question/48848/Check if code is running in SageMath Cell or Jupyter notebookhttp://ask.sagemath.org/question/48881/check-if-code-is-running-in-sagemath-cell-or-jupyter-notebook/ I am preparing interacts to be run either in a Jupyter notebook or in SageMath Cell. I would like to write code valid for both environments, taking into account the differences between them. For example, I have not seen a common way to change the default text in auto update buttons. The following code would work in both environments if I would know how to automatically set up the `running_in_Jupyter` boolean:
if running_in_Jupyter:
auto = False
else:
auto = UpdateButton(text="Press to update")
@interact
def test(n=slider(0,20,1), auto_update=auto):
print n
if running_in_Jupyter:
test.widget.children[-2].description="Press to update"
So, is there a simple test I could implement to detect where the code is running?
JuanjoMon, 25 Nov 2019 06:48:00 -0600http://ask.sagemath.org/question/48881/Field between 3 functionshttp://ask.sagemath.org/question/48845/field-between-3-functions/What need to change in that code because it doesn't work? In python it works good but in Sage show error.
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-5, 3, 0.01)
y_1 = 4 - x ** 2
y_2 = 3 * x
y_3 = x*0 + 3
y_4 = np.minimum(y_1, y_3)
plt.fill_between(x, y_2, y_4, where=y_2<=y_4, color='grey', alpha='0.5')
plt.plot(x, y_1, 'r')
plt.plot(x, y_2, 'b')
plt.plot(x, y_3, 'g')
plt.show()
In Notebook, Sage 8.9, Ubuntu ![image description](https://ask.sagemath.org/upfiles/1574425134832783.png)precelinaThu, 21 Nov 2019 15:48:39 -0600http://ask.sagemath.org/question/48845/test if v.norm <> zero pbhttp://ask.sagemath.org/question/48872/test-if-vnorm-zero-pb/ HI
I do not understand why if v.norm !=0 does not work here.
**ZeroDivisionError: rational division by zero**
def normalizeVectorL(vectorList) :
vNormList=[]
for l in vectorList :
lMatrixList=[]
for v in l :
v=vector(v)
z=zero_vector(v.length())
#if v != z :
if v.norm() != 0 :
show("v :\t",v,"v.norm() :\t",v.norm())
lMatrixList.append(matrix(v/v.norm()).transpose())
else :
lMatrixList.append(matrix(v).transpose())
vNormList.append(lMatrixList)
return vNormList
VVVlist=[]
VVVlist0=[]
VVVlist0.append([1,1,1])
VVVlist0.append([1,1,2])
VVVlist0.append([1,0,0])
VVVlist.append(VVVlist0)
VVVlist1=[]
VVVlist1.append([1,3,1])
VVVlist1.append([1,2,2])
VVVlist1.append([0,0,0])
VVVlist.append(VVVlist1)
show(VVVlist)
show(normalizeVectorList(VVVlist))
ortolljMon, 25 Nov 2019 04:46:00 -0600http://ask.sagemath.org/question/48872/How to solve an equation over finite field for exponent variable?http://ask.sagemath.org/question/48869/how-to-solve-an-equation-over-finite-field-for-exponent-variable/I want to resolve the following equation for exponent $n$ for given value $v$:
$$ v\equiv(r\cdot ((b+r)^n- (b-r)^n)) \cdot (2 \cdot r \cdot ((b+r)^{n-1}- (b-r)^{n-1}))^{-1} \mod P$$
with
$$r^2 = 4\cdot a+b^2 \mod P$$
and a prime $P$
Looking for a function $f(v) = n$.
The values $a,b$ are chosen in that way that for $n=[1,..,P]$ the results $v$ will be all values in ${{0,..,P-1 }\brace{ }}=\mathbb{F}_P $. That works iff there is no such root $r$ in $\mathbb{F}_P$ exists for $a, b$. If both parts in formula above are expanded only $r^2$ is left over.
*Example*:
$P=11; a=5; b=3 -> r^2=7$
R.<a,b,r,v,n>=PolynomialRing(GF(11))
[ r*((b+r)^n-(b-r)^n)/ (2* r*((b+r)^(n-1)-(b-r)^(n-1)) ) for n in R.base() if n>1]
[b,
(-5*b^2 + 2*r^2)/(-3*b),
(-3*b^3 - 3*b*r^2)/(b^2 + 4*r^2),
(-b^4 - 2*b^2*r^2 + 2*r^4)/(5*b^3 + 5*b*r^2),
(b^5 - 4*b^3*r^2 + b*r^4)/(-2*b^4 - 4*b^2*r^2 + 4*r^4),
(3*b^6 + 4*b^4*r^2 - 2*b^2*r^4 + 2*r^6)/(2*b^5 + 3*b^3*r^2 + 2*b*r^4),
(5*b^7 + 2*b^5*r^2 + 2*b^3*r^4 + 5*b*r^6)/(-5*b^6 - 3*b^4*r^2 - 4*b^2*r^4 + 4*r^6),
(-4*b^8 + 3*b^6*r^2 - b^4*r^4 - 5*b^2*r^6 + 2*r^8)/(-b^7 + 4*b^5*r^2 + 4*b^3*r^4 - b*r^6),
(-2*b^9 - 2*b^7*r^2 - 2*b^5*r^4 - 2*b^3*r^6 - 2*b*r^8)/(3*b^8 - 5*b^6*r^2 - 2*b^4*r^4 + b^2*r^6 + 4*r^8)]
in values: $0, 3 , 1 , 8 , 5 , 4 , 7 ,10 , 9 , 6 , 2 , 0 , 3 , 1 , ...$
There is some special case for $n=1$. With this the part which need to be inverted is $0$. In that case $v$ is assigned to 0.
-----------------------------------------
As a alternative form without any root $r$ (for $n>2$):
$$v\equiv \frac{2 \cdot \sum_{k=1}^{\lfloor n/2\rfloor} {n-1\choose 2k-1} b^{n-2k}(r^2)^{k} }{4\cdot \sum_{k=1}^{\lfloor (n-1)/2 \rfloor} {n-2 \choose 2k- 1} b^{n-2k-1} (r^2)^{k } } \mod P$$
in sagemath:
a,b,r,v,k,n=var('a b r v k n')
(sum( 2*binomial(n-1, 2*k-1) * b^(n-2*k)*(4*a+b^2)^(k) , k,1,floor( n/2) ))*(sum(4* binomial(n-2, 2*k-1) * b^(n-2*k-1)*(4*a+b^2)^(k) , k,1, floor( (n-1)/2) ))^(-1)-v
But only got it working with normal variables.
-------
How can I solve such equation in sagemath?
R.<n>=PolynomialRing(GF(11))
(2*k-8).roots(); #multiplication works
(2^k-8).roots(); #power not working
($a,b,r^2$ can be exchanged with current values)maanSun, 24 Nov 2019 21:25:03 -0600http://ask.sagemath.org/question/48869/How to fix problem when creating image histogramhttp://ask.sagemath.org/question/48833/how-to-fix-problem-when-creating-image-histogram/ Hello,
I'm trying to develop a function that calculates histograms for the colored images.
When I run my program it says 'too many values to unpack (expected 2)'. What am I doing wrong here?
Below is my code
Collor_Channel =("r" , "g", "b")
PixelNum, Collor_Channel = im.shape
ImageHistogram = np.zeros(256)
for i in range(PixelNum[0]):
for j in range(PixelNum[1]):
for x in range(PixelNum[2]):
totalvalue = im [j,i,x]
ImageHistogram[int(totalvalue)] += 1
return ImageHistogram
isidaThu, 21 Nov 2019 06:02:42 -0600http://ask.sagemath.org/question/48833/sage interactive disable auto update?http://ask.sagemath.org/question/46022/sage-interactive-disable-auto-update/ i have a sheet with interactive sliders which generates plots.
when I alter a value on a slider, the plot is executed not only at the destination value,
but also on many steps between starting point and destination. As the plot takes some time,
it is very slow to get the result.
Is there a possibility to deactivate autoupdate, and for example make a Button for executing the script with the new values?msageFri, 05 Apr 2019 08:09:31 -0500http://ask.sagemath.org/question/46022/Absence of column vectorshttp://ask.sagemath.org/question/48860/absence-of-column-vectors/ I'm curious as to why column vecotrs seem to be non-existent in sage. To give you some context, I work with the following system:
R3 = IntegerModRing(3)
c_7_4 = [
[1, 0, -2, 0, 0, 0, 1],
[1, 1, 0, 0, -2, 0, 0],
[0, 1, 1, 0, 0, -2, 0],
[0, 0, 1, 1, 0, 0, -2],
[0, -2, 0, 1, 1, 0, 0],
[-2, 0, 0, 0, 1, 1, 0],
[0, 0, 0, -2, 0, 1, 1]
]
C3 = Matrix(R3, c_7_4)
B3 = C3.right_kernel().basis()
Clearly, the right kernel of C3 is a column vector, but if you run this code, you would find that
print(B3[0]) # returns a row vector
print(B3[0] * C3) # returns an answer
print(C3 * B3[0]) # returns an answer
Given that a column matrix should reasonably be written
[[a],[b]]
Why is this not the case? Specifically, is there a coding limitation to what the programmers can do which forces them to implement it in this way, or is there some mathematical usefulness to this which is beyond my understanding?
Thanks!
KraigSat, 23 Nov 2019 11:44:38 -0600http://ask.sagemath.org/question/48860/