ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 19 Oct 2020 17:04:35 -0500- Why does plot choke on x to the 1/3 power, when it will calculate it just fine?https://ask.sagemath.org/question/53976/why-does-plot-choke-on-x-to-the-13-power-when-it-will-calculate-it-just-fine/plot(x^(1/3),-10,10) fails for negative numbers:
'can't convert complex to float'
OTOH, sage will calculate a negative to the 1/3 just fine.
-10^(1/3).n()
-2.15443469003188
cybervigilanteMon, 19 Oct 2020 17:04:35 -0500https://ask.sagemath.org/question/53976/
- Uniting new and old forum account?https://ask.sagemath.org/question/53972/uniting-new-and-old-forum-account/My current account at the forum is shaolinux, from June 2020, but I have an old account shao-linux from October 2015. I have been away from SageMath in the period late 2015-early 2020 but now expect to be regular visitor. The contact email for the old account is the same but I have lost the password for it long time ago. Is it possible to join the new account to the old one keeping the old name, transferring the info on questions/answers from the new to the old, erase the new account and live on happily as a mere mortal shao-linux? (Please, accept my apology if this question is above the acceptable stupidity threshold...)ShaolinuxSun, 18 Oct 2020 23:00:53 -0500https://ask.sagemath.org/question/53972/
- Problem with factor and imag.https://ask.sagemath.org/question/53947/problem-with-factor-and-imag/I'm new to SageMath, and I'm not sure what's going wrong.
Here are the commands I enter and results I get:
sage: a, b, z = var('a, b, z')
sage: P = a*x - b*x
sage: Q = a*imag(z) - b*imag(z)
sage: P.factor()
(a - b)*x
sage: Q.factor()
0
Why is `Q` factoring to `0`?lfcSat, 17 Oct 2020 13:56:49 -0500https://ask.sagemath.org/question/53947/
- Defining a function with different symbolic expressions in different parts of its domain specified by conditional statementshttps://ask.sagemath.org/question/53946/defining-a-function-with-different-symbolic-expressions-in-different-parts-of-its-domain-specified-by-conditional-statements/I am struggling with a definition of a functional surface z=z(x,y) where z is positive in the interior of a triangle, zero on its boundary, and zero outside of it everywhere on a rectangle for (x,y) which contains the triangle. All necessary formulae can be provided in if/elif/else/return, etc. statements. Yet, I get errors when using def and return (I have never worked with simpy and would prefer to avoid using lambdas and stay as close to the mathematical expressions as possible). I think that if someone helps with explaining how to handle a simple definition of a 1-variate function of x=var('x'), I'll figure what I am not doing right also in the 2-variate case x, y = var('x,y'). So here is a very simple example:
f has definition domain -2<=x<=3 and is defined with different formulae on different parts of its domain, e.g.,
f(x)=x+1 when x is between -2 and -1,
f(x)=0 when x is between -1 and 0,
f(x)=x^2 when x is between 0 and 1,
f(x)=x^3 when x is between 1 and 3,
(naturally, without overlapping at the boundaries, although this function is continuous there, so no problems arise there -- I skipped the use of inequalities because the preview program got confused).
After the definition I would like to use f(x) while specifying for x the WHOLE range [-2,+3]. (For example, plot the graph of y=f(x) for all x between -2 and +3.) Can someone please provide a simple working code, say, using def and conditional statements but not resorting to tuples, classes (ok, if there is absolutely not a simple way, lambdas can be used as a last resort :) )? Or maybe this question has been answered earlier? Please help :)
Following the fairly exhaustive answers of rburing and tmonteil below to the 1-variate version of my question, I now proceed to upgrading it for 2-variate functions with a maximally simplified concrete problem which, if solved, can immediately be upgraded also to the 3-variate case. (In the formulation, I shall use latex notation.)
Consider the square domain (x,y) \in A=[-2,2]x[-2,2] and a subset of its interior: the 'canonical' triangle B with vertices P_0=O=(0,0), P_1=(1,0) and P_2=(0,1). The reason for this 'canonical' choice is that the cartesian coordinates x and y coincide with two of the three barycentric coordinates of an arbitrary point P in the plane Oxy:
P=(x,y)=(1-x-y).P_0+x.P_1+y.P_2; moreover, if P is in B or on its boundary, then the combination is CONVEX; (moreover, if P is on the interior of an edge of the boundary of B, then 1 of the three coefficients is 0, and if it is coincides with one of the vertices, then 2 of these coefficients are 0). Now I proceed to define mathematically the needed functional surface z=z(x,y), as follows:
Consider first a point P_3=(x_3, y_3) which lies in the interior of B, i.e. all the three coefficients 1-x-y, x and y are strictly positive and strictly less than 1.
if 1-x-y leq 0 or x leq 0 or y leq 0 (this is exactly the case when P=(x,y) is outside of B or lies on its boundary), then z(x,y)=0;
elsewhere on A (i.e., exactly when P lies in the interior of B), define
z(x,y)=exp{-[(x-x_3)^2+(y-y_3)^2]/[(1-x-y)^2(x^2)(y^2)]}.
Now z(x,y) is defined on the whole A and has several remarkable properties there. As a non-exhaustive example:
it is analytic everywhere on A except the boundary of B where it is still C^\infty - smooth but not analytic (the Taylor expansion series is not convergent there, but is convergent everywhere else on A).
it takes strictly positive values less than 1 (good as coefficient in a convex combination!) and reaches its global maximum equal to 1 exctly and only in the prescribed point P_3.
To define this type of functional surface on an arbitrary triangle in Oxy or as a parametric surface in 3D one now uses a standard approach (used in finite/boundary element theory, geometric design, etc, etc.) via applying a non-singular affine transformation. The technique is easy to extend to tetrahedra in 3D.
To explain why this function has numerous prospective valuable applications is a very long story. To cut it short, I promise that if you help solve this particular problem, you will soon read about some of its new applications in the newspapers... :) :) :)
Summarizing:
the primary, maximally simplified, task I ask to be solved here is to provide SageMath (Python 3) code to use parametric_plot3d to plot the parametric surface X(u,v)=u, Y(u,v)=v, Z(u,v)=z(u,v) for (u,v) in the parametric domain A given above and to view it in Ubuntu using threejs and/or jmol. (Forget about all the extra options, Windows limitations, etc).
Can you help, please?ShaolinuxSat, 17 Oct 2020 12:31:09 -0500https://ask.sagemath.org/question/53946/
- plotting multiple functions from a for loophttps://ask.sagemath.org/question/46357/plotting-multiple-functions-from-a-for-loop/ This solution:
https://ask.sagemath.org/question/9024/plotting-multiple-functions-from-a-for-loop/#
is not working any more
The error is:
Error in lines 3-3
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 "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 492, in wrapper
return func(*args, **options)
File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1956, in plot
G = _plot(funcs, (xmin, xmax), **kwds)
File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/plot/plot.py", line 2224, in _plot
legend_label=legend_label_entry, legend_color=legend_color_entry, **options_temp)
File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/misc/decorators.py", line 492, in wrapper
return func(*args, **options)
File "/ext/sage/sage-8.7_1804/local/lib/python2.7/site-packages/sage/plot/plot.py", line 1941, in plot
G = funcs.plot(*args, **original_opts)
TypeError: plot() takes exactly 1 argument (17 given)thethaThu, 25 Apr 2019 04:06:52 -0500https://ask.sagemath.org/question/46357/
- plot of sine, parabola intersection works but solve makes no sensehttps://ask.sagemath.org/question/53958/plot-of-sine-parabola-intersection-works-but-solve-makes-no-sense/When I plot a sine and parabola I get two obvious intersections
plot(x^2-5,-10,10,ymax=20) + plot(sin(x),-10,10)
But when I solve to get the two numeric x values, the answer makes no sense.
solve(x^2-5==sin(x),x)
[x == -sqrt(sin(x) + 5), x == sqrt(sin(x) + 5)]
![image description](/upfiles/16030024791456171.png)cybervigilanteSun, 18 Oct 2020 01:14:31 -0500https://ask.sagemath.org/question/53958/
- %display latex vs. ipywidgetshttps://ask.sagemath.org/question/53950/display-latex-vs-ipywidgets/This is part informational and part a question of style
In Sage Manifolds, `%display latex` is set to produce "pretty" output like thus
%display plain
var('a, g')
display(sqrt(a + g))
%display latex
sqrt(a + g)
which everybody knows, but a more insidious thing is that it breaks `ipywidgets.Hbox()` "display".
I did a hack in this code below; but does anybody know of a more elegant (re. automatic) means.
This is a little long but illustrates what is lost. Try changing `%display` lines at the bottom.
%display latex # Just to copy the problem in
import matplotlib.pyplot as plt
from IPython.display import display, HTML
import ipywidgets
# Save
file_name = 'rings.html'
save_desc = 'save as' + file_name
save_box = ipywidgets.Checkbox(False, description=save_desc)
# Red ring
red_ring = Horizon()
red_box=red_ring.box(desc='red ring')
red_ring.color = 'red'
red_ring.radius =2
# Black ring
black_ring = Horizon()
black_box = black_ring.box(desc='black ring')
black_ring.color = 'black'
black_ring.radius = 3
# Green ring
green_ring = Horizon()
green_box = green_ring.box(desc='green ring')
green_ring.color = 'green'
green_ring.radius = 4
ui = ipywidgets.HBox([red_box, black_box, green_box, save_box])
def f(red, black, green, save_f):
global plt_obj
plt_obj = sphere((1, 0, 0), .6)
if red:
plt_obj += red_ring.gobject()
if black:
plt_obj += black_ring.gobject()
if green:
plt_obj += green_ring.gobject()
if save_f:
save(plt_obj,file_name)
show(plt_obj, viewer='threejs')
out_show = ipywidgets.interactive_output(f, {'red': red_box,
'black': black_box,
'green': green_box,
'save_f' : save_box})
%display plain
display(ui)
display(out_show)
%display latexrrogersSat, 17 Oct 2020 17:00:38 -0500https://ask.sagemath.org/question/53950/
- 'builtin_function_or_method' object has no attribute 'split'https://ask.sagemath.org/question/53941/builtin_function_or_method-object-has-no-attribute-split/Code:
import matplotlib.pyplot as plt
%matplotlib inline
import numpy as np
file = 'IV meas -1.50E+0 V to 1.50E+0 V PHY 364 Practical_Dark_temp_25.57oC_Intensity_0.000suns -light OFF- 0 sec wait at 0 Volt.txt'
f=open(file,'r')
delimiter = ','
line=f.readline()
while (line != ''):
data=line.split(delimiter)
V1L.append(float(data[0]))
I1L.append(float(data[1]))
line=f.readline
each line in the txt file is of the form
-1.50000E+0,-3.22013E-3werner1717Fri, 16 Oct 2020 09:24:56 -0500https://ask.sagemath.org/question/53941/
- Can attributes of sage classes be changed?https://ask.sagemath.org/question/53892/can-attributes-of-sage-classes-be-changed/ I want to change the way vectors are rendered in sagetex. For example, consider `v = vector([1, 2, 3])`. In sagetex, the command `$v=\sage{v}$` renders as
$$
v=(1, 2, 3)
$$
Instead, I want my vectors to take the form
$$
v=\left[\begin{array}{rrr}1&2&3\end{array}\right]^\intercal
$$
I thought I could do this by resetting the `_latex_` method of the `sage.modules.free_module_element.FreeModuleElement` class as follows.
def my_vector_latex(self):
return matrix(v)._latex_() + r'^\intercal'
setattr(sage.modules.free_module_element.FreeModuleElement, '_latex_', my_vector_latex)
However, this code throws the following error:
TypeError: can't set attributes of built-in/extension type 'sage.modules.free_module_element.FreeModuleElement'
So, it looks like I can't modify the methods of `FreeModuleElement` in this way. Is there anything else I could do?more_weightTue, 13 Oct 2020 12:37:51 -0500https://ask.sagemath.org/question/53892/
- How to draw a graph in Sage and read GAP file added to the same projecthttps://ask.sagemath.org/question/53878/how-to-draw-a-graph-in-sage-and-read-gap-file-added-to-the-same-project/I have created a project in CoCalc with the kernel SageMath. There I have opened a new file (New1) and did some computations using the GAP commands, and "gap.eval" before each command enabled me to obtain the results successfully.
Question 1: Next by using some values obtained as a result of the GAP commands, if I need to plot a graph what is the command I will have to use, which will read GAP data successfully? (The output is in the form [[1,2],[1,3],[2,5],...], as an array)
Question 2: I have written another function(Program1) in GAP file and have uploaded it to the same Project. I would like to call this function to the file New1, where I have been working and use it. How can I call it succesfully?
I tried %run Program1.gap , but it didn't work.
The section of the program relevant to Question 2:
When I try to run the .gap file I get the below error,
%run UndirectedGeneratingSets.gap
File "/home/user/UndirectedGeneratingSets.gap", line 9
IsIrredundant := function(G,S)
^
SyntaxError: invalid syntax
I added gap.eval command to places where there are commands and updated the .gap file but still I am getting errors as below.
%run UndirectedGeneratingSetsedited.gap
File "/home/user/UndirectedGeneratingSetsedited.gap", line 12
gap.eval("return ForAll(S, s -> not(s in Subgroup(G, Filtered(S, t -> (t <> s)))));
^
SyntaxError: EOL while scanning string literal
I don't know why it says as syntax error. I have closed all the brackets in the code as below:
gap.eval("return ForAll(S, s -> not(s in Subgroup(G, Filtered(S, t -> (t <> s)))));
end;")
gap.eval("IrredGenSetsFromAvailable := function(G, GensRequired, GensAvailable)")
# return a list of the irredundant generating sets of G that contain the set GensRequired
# and are contained in the union of GensRequired and GensAvailable
# (It is assumed that GensRequired is irredundant)
local GenSets, i, S;
gap.eval("GenSets := [];") # GenSets is a list of the generating sets that have been constructed so far
gap.eval("if Subgroup(G, GensRequired) = G then
# do not add any additional generators
return [AsSortedList(GensRequired)];
else
# for each available generator, recursively find all irredundant generating sets
# that can be obtained by adding it (and perhaps later elements of GensAvailable)
# to GensRequired
for i in [1..Length(GensAvailable)] do
S := Concatenation(GensRequired, [GensAvailable[i]]);
if IsIrredundant(G,S) then
Append(GenSets, IrredGenSetsFromAvailable(G, S,
GensAvailable{[i+1 .. Length(GensAvailable)]}));
fi;
od;
fi;
return GenSets;
end;")
and similarly for the rest of the codes in that program as well.
Many many thanks in advance.BuddhiangMon, 12 Oct 2020 14:46:24 -0500https://ask.sagemath.org/question/53878/
- how to join functions with an intermediate fit to obtain smooth derivativeshttps://ask.sagemath.org/question/53909/how-to-join-functions-with-an-intermediate-fit-to-obtain-smooth-derivatives/I want to modify a function which contains a pole for numerical simulations, e.g. limit it to a maximum value around the pole.
My idea is to connect two original functions f1 and f2 (e.g. one with pole and one constant) with an intermediate fit function between two x values x1 and x2. The fit function should continue the two original functions between x1 and x2 as well as their first two derivatives, and it should be monotonic in this range.
I found some hints how to fit (x,y) points with a lagrange_polynomial or find_fit to match a given function template, but these approaches do not seem to be extendable to fit the derivatives at the same time, e.g. fit points from (f1,f1', f1'') and (f2,f2',f2''). At least this seems to me what needs to be done. Is this a feasible approach, and how can it be solved?
Constructing a set of splines between x1 and x2 might be an alternative, but the implementation in the simulation system would be more complicated compared to a single polynomial. I guess 3 spline segments might be sufficient to create a "connector template", but a subsequent fit of a single function to this set of splines (to obtain a simpler implementation for the simulation) would probably violate the continuity of the derivatives, and I worry that construction of suitable intermediate points to obtain a monotonic fit function is another complication. Thus, again, this seems to result in a general multi-function fitting problem to which a genius may have found a general approach already?gg@gWed, 14 Oct 2020 07:05:17 -0500https://ask.sagemath.org/question/53909/
- Hidden features of Sagehttps://ask.sagemath.org/question/10073/hidden-features-of-sage/In the spirit of the [StackOverflow threads of "hidden" language features](http://stackoverflow.com/questions/101268/hidden-features-of-python), we can use this thread (community wiki) to aggregate useful but little-known features or tricks of Sage. Perhaps these can be collected and added to the documentation in the future.Eviatar BachSun, 28 Apr 2013 18:09:50 -0500https://ask.sagemath.org/question/10073/
- Weird behaviour of MixedIntegerLinearProgramhttps://ask.sagemath.org/question/53875/weird-behaviour-of-mixedintegerlinearprogram/Not really a question, more of an observation, perhaps a bug, I do not know.
p = MixedIntegerLinearProgram(maximization=False, solver="GLPK")
x = p.new_variable(real=True, nonnegative=True)
p.set_integer(x[2])
p.add_constraint(2*x[0] + 2*x[1] + 3*x[2] - 10*x[3] <= 0)
p.add_constraint(6*x[1] + 4*x[2] - 11*x[3] >= 0)
p.add_constraint(2*x[2] - 6*x[3] <= 0)
p.add_constraint(x[0] - x[1] - x[2] >= 0)
p.add_constraint(x[3] >= 1)
p.set_objective(3*x[1] + 6*x[2] - 3*x[3])
p.show()
This code sets `x[0]` integer when it should be `x[2]`.
The following code works:
p = MixedIntegerLinearProgram(maximization=False, solver="GLPK")
x = p.new_variable(real=True, nonnegative=True)
p.set_real(x[0])
p.set_real(x[1])
p.set_integer(x[2])
p.add_constraint(2*x[0] + 2*x[1] + 3*x[2] - 10*x[3] <= 0)
p.add_constraint(6*x[1] + 4*x[2] - 11*x[3] >= 0)
p.add_constraint(2*x[2] - 6*x[3] <= 0)
p.add_constraint(x[0] - x[1] - x[2] >= 0)
p.add_constraint(x[3] >= 1)
p.set_objective(3*x[1] + 6*x[2] - 3*x[3])
p.show()
I find this weird. If I code `p.set_integer(x[2])`, I expect `x[2]` to be integer.
(If I do not add `p.set_real(x[1])`, `x[1]` is set to integer).
Certainly one more time, somebody will say I did not read the documentation correctly.CyrilleMon, 12 Oct 2020 11:03:01 -0500https://ask.sagemath.org/question/53875/
- Use of threejs and jmol in sage 9.1 for windowshttps://ask.sagemath.org/question/53861/use-of-threejs-and-jmol-in-sage-91-for-windows/ I have been using SageMath 9.1 in Ubuntu 18.04 and the performance is excellent -- no questions asked.
Now I am trying to use SageMath 9.1 in a Msc level course, but the students' computers are all under Windows 10, and so on the classroom computer I have installed the latest 64 version of SageMath 9.1(with the 3 icons in the desktop, including the Jupyter NB which is the environment I always use). Using it, 3D scenes can only be seen as still images using "viewer='tachyon'". When using "viewer='jmol'" or "viewer='threejs'",there is no error message a scene is created, but it is empty -- blank space, no image. It seems that threejs and jmol are bundled in the repo for the Windows version of SageMath but for some reasons do not work.
In Windows 10 I have anaconda3 installed with Python 3 environment and Jupyter NB. Using it, I have tried to install Sagemath 9.1 from conda-forge using 'conda' (insluding conda-forge as a channel, with and without 'mamba' -- according to the respective instructions in the Sage manual for installing sage from anaconda) and this worked well in Ubuntu but not in Windows 10 -- in the latter case I get error message on the anaconda prompt:
Encountered problems while solving.
Problem: nothing provides requested sage
I have now also installed node.js and npm and, via the latter, also three.js . However, the installed SageMath does not recognize this version, and I do not know how to import it in the installed SageMath 9.1.
As a last measure, I have also installed the latest 64 version of Java and the latest 64 version of jmol (to be used via double-click on jmol.jar in the decompressed jmol bundle). The problem is similar as with threejs: the SageMath 9.1 does not recognize the installed jmol, and I do not know how to make it do so.
This is the situation. Can you help resolve this? I need to be able to use at least one of threejs and/or jmol (preferably, threejs!!) as alternative to tachyon in visualizing 3D scenes. Otherwise, I will have to radically restructure the course without using SageMath, since using Linux instead of Windows is, unfortunately, not an option. ShaolinuxMon, 12 Oct 2020 06:35:15 -0500https://ask.sagemath.org/question/53861/
- Is there a reliable way to check if an object is a vector?https://ask.sagemath.org/question/53911/is-there-a-reliable-way-to-check-if-an-object-is-a-vector/ I'm want to check if a given sage object `obj` is a vector or not. I'd like to do this as efficiently as possible. Currently my best idea is:
sage_input(obj).__repr__().startswith('vector')
This works, assuming that `sage_input` is smart enough to identify every vector without false positives. However, this solution feels inefficient (and also inelegant!). Is there a better way?more_weightWed, 14 Oct 2020 10:57:18 -0500https://ask.sagemath.org/question/53911/
- Creating a function in Sagehttps://ask.sagemath.org/question/53910/creating-a-function-in-sage/ Hi I have a sequence of commands which does Lagrangian optimization
var('a, b, x, y, lam')
assume(a>=0,b>=0,x>= 0)
f = x*y #minimiser et maximiser sous contrainte d'egalite h=0
h = x^2/a^2 + y^2/b^2-1
L = f + h * lam
DL = L.gradient([x, y])
sol = solve([DL[k] == 0 for k in range(len(DL))]+[ h == 0],x, y, lam,
solution_dict=True)
ti=[["$\\lambda$","$x$", "$y$", "$f(x, y)$"]]
re=[(sol[j]
[lam],sol[j][x], sol[j][y],f(x=sol[j][x], y=sol[j][y])) for j in
range(4)]
table(ti + re, header_row = True)
and I would like to turn it into a function. I add the declaration, but I get no output. I know neither why, nor how to debug this. Thanks for any help :)
def optL(f,h):
var('a, b, x, y, lam')
assume(a>=0,b>=0,x>= 0)
L = f + h * lam
DL = L.gradient([x, y])
sol = solve([DL[k] == 0 for k in range(len(DL))]+[ h == 0],x, y, lam,
solution_dict=True)
ti=[["$\\lambda$","$x$", "$y$", "$f(x, y)$"]]
re=[(sol[j][lam],sol[j][x], sol[j][y],f(x=sol[j][x], y=sol[j][y])) for j in range(4)]
table(ti + re, header_row = True)
optL(x*y,x^2/a^2 + y^2/b^2-1)florinWed, 14 Oct 2020 10:29:52 -0500https://ask.sagemath.org/question/53910/
- find maximum value of Fhttps://ask.sagemath.org/question/53907/find-maximum-value-of-f/ F = (4*x+4*y+9*z-2*w),
G = (2*x+2*y +z+ w)==0,
H = (x^2+y^2+z-4)==0,
* x ,y, z, w is symbolic expressions in 4 variables.
* The symbolic expressions G and H represent constraints.
* find the maximum value of F , subject to the constraints G=0 and H=0 ?????????
* please help meDalin ArangaWed, 14 Oct 2020 04:45:51 -0500https://ask.sagemath.org/question/53907/
- substituting vars for a poly quotient in a list comprehension blows uphttps://ask.sagemath.org/question/53896/substituting-vars-for-a-poly-quotient-in-a-list-comprehension-blows-up/ If I run this but don't substitute the a and b for the polynomials:
a = 3*x^2 + 2*x + 1
b = 5*x^3 - 2*x^2 + 3
c = [((3*x^2 + 2*x + 1)/(5*x^3 - 2*x^2 + 3)).n() for x in [100..30000,step=100]]
for num in c:
print(num)
I get a numeric list, as expected.
If I use f = [(a/b) for x in [100..30000,step=100]] however,
I only get variables in x, all the same: (3.00000000000000*x^2 + 2.00000000000000*x + 1.00000000000000)/(5.00000000000000*x^3 - 2.00000000000000*x^2 + 3.00000000000000)
And if I try (a/b).n(), I get an error: TypeError: unable to coerce to a ComplexNumber: <class 'sage.rings.fraction_field_element.FractionFieldElement_1poly_field'>
What's going wrong?
cybervigilanteTue, 13 Oct 2020 21:57:27 -0500https://ask.sagemath.org/question/53896/
- How would I transfer code from a notebook to this forum?https://ask.sagemath.org/question/53895/how-would-i-transfer-code-from-a-notebook-to-this-forum/From within a Jupyter notebook, if I do Edit > Copy Cells, followed by Edit > Paste Cells Above (or Below), it works. But Edit > Copy Cells does not copy to the clipboard in 'code mode'... It works in 'markdown mode', but the demarcation between the cell input/output is not clear. There has got to be a simple way to transfer a notebook's content to this forum to illustrate a question. What is it?
erw1Tue, 13 Oct 2020 20:37:28 -0500https://ask.sagemath.org/question/53895/
- how to limit the verbosity in case of errorhttps://ask.sagemath.org/question/53889/how-to-limit-the-verbosity-in-case-of-error/ The following problem has no solution. But, often, I need only the last line of the Sagemath comments to debug the problem. I have tried use `set_verbose()` but it doesn't change any thing.
%display latex
m=3 #nombre de contraintes
n=2 # nombre de variables
A=matrix(m,n,(0,1,1,0,6,18))
bmin=[12,0,70]
bmax=[oo,10,70]
c=matrix(1,n,(4.1,8))
p = MixedIntegerLinearProgram(maximization=False, solver = "GLPK") # CrÃ©ation du MILP
# on peut remplacer GLPK par PPL pour obtenir une optimisation fractionnaire.
x = p.new_variable(integer=False, indices=[0..n-1]) # les nouvelles variables seront x[1]... x[7]}
B = A * x # m
# Construction des contraintes
for i in range(m):
p.add_constraint(B[i], min=bmin[i], max=bmax[i])
# remove_constraint() pour en retirer une
for i in range(n):
p.set_min(x[i],0)
p.set_objective(4.1*x[0]+8*x[1])# dÃ©finition de l'objectif
sol=p.solve()
show(sol)CyrilleTue, 13 Oct 2020 08:19:21 -0500https://ask.sagemath.org/question/53889/
- Tensor decomposition and Tensorlyhttps://ask.sagemath.org/question/53886/tensor-decomposition-and-tensorly/I have a 3 x 3 x 3 tensor and I am looking to compute its tensor rank (https://en.wikipedia.org/wiki/Tensor_rank_decomposition), aka CP rank. The only software in Python that I am currently aware of to do this is Tensorly, a Python package.
Is there anything in Sage itself that deals with tensor decomposition or any implementation of the Alternative Least Squares method (I believe this is the most common method for tensor decomposition) within Sage?
I am currently running Sage v 8.1
Thank you for your time!BarkTue, 13 Oct 2020 00:49:18 -0500https://ask.sagemath.org/question/53886/
- Finding MV algebras with Sagehttps://ask.sagemath.org/question/53877/finding-mv-algebras-with-sage/I would like to find with Sage in a quick way all finite lattices
having a partial operation $x\cdot y$, defined for $x\geq y$,
satisfying the following properties:
(a) $\forall x\geq y\geq z:\ x\cdot z \leq x\cdot y$ and $(x\cdot y)\cdot (x\cdot z) = y\cdot z$
(b) $\forall x\geq y, z:\ x\cdot (y \wedge z) = x\cdot y \wedge x\cdot z$
(c) $(x \vee y)\cdot y = x\cdot (x \wedge y) $
(d) $\forall x\geq y:\ y\leq x\cdot y$ and $(x\cdot y)\cdot y = x$
This is equivalent to having the structure of an MV algebra (see Prop. 44 on page 34 of [https://pnp.mathematik.uni-stuttgart.de/iaz/iaz1/Rump/32-35.pdf](https://pnp.mathematik.uni-stuttgart.de/iaz/iaz1/Rump/32-35.pdf)).
Such lattices are always distributive.
I would be grateful for any help.BernMon, 12 Oct 2020 12:59:47 -0500https://ask.sagemath.org/question/53877/
- "how to test if two matrices are similar by a signed permutation matrix" code sagehttps://ask.sagemath.org/question/50025/how-to-test-if-two-matrices-are-similar-by-a-signed-permutation-matrix-code-sage/"how to test if two matrices are similar by a signed permutation matrix" code sageimySat, 22 Feb 2020 13:44:59 -0600https://ask.sagemath.org/question/50025/
- How to find the permutation matrix associated with the similarity transformation in the following codehttps://ask.sagemath.org/question/39515/how-to-find-the-permutation-matrix-associated-with-the-similarity-transformation-in-the-following-code/
m = matrix(QQbar,6,[2,-1,-I,0,0,0,
-1,2,-1,0,0,0,i,-1,3,-1,0,0,
0,0,-1,2,-1,0,
0,0,0,-1,2,-1,
0,0,0,0,-1,1])
j=matrix(QQbar,6,[2,-1,0,-I,0,0,
-1,2,-1,0,0,0,0,-1,2,-1,0,0,
I,0,-1,3,0,-1,
0,0,0,0,1,-1,
0,0,0,-1,-1,2])
the matrices m,j are similar via a permutation matrix. How I can find that matrix.
KuldeepMon, 13 Nov 2017 12:23:18 -0600https://ask.sagemath.org/question/39515/
- Google sign-in brokenhttps://ask.sagemath.org/question/53871/google-sign-in-broken/ When signing into ask.sagemath.org using Google I get
Authorization Error
Error 400: redirect_uri_mismatch
The redirect URI in the request, https://ask.sagemath.org/account/signin/complete-oauth2/, does not match the ones authorized for the OAuth client. To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/${your_client_id}?project=${your_project_number}IguananautMon, 12 Oct 2020 09:02:37 -0500https://ask.sagemath.org/question/53871/
- How is curve C(b) converted to elliptic curve?https://ask.sagemath.org/question/53864/how-is-curve-cb-converted-to-elliptic-curve/How can we transform curve
$$
C(b)\ :\ (3+b)X^2Y + (9+b)XY^2 - (4+b)X^2Z + (3-b^2)XYZ + (-4+b)Y^2Z + (-9+b)XZ^2+bYZ^2
$$
into an elliptic curve without valuing $b$?
Edited: Expression in code format:
(3+b)*X^2*Y + (9+b)*X*Y^2 - (4+b)*X^2*Z + (3-b^2)*X*Y*Z + (-4+b)*Y^2*Z + (-9+b)*X*Z^2 + b*Y*Z^2GamzeeeMon, 12 Oct 2020 07:57:38 -0500https://ask.sagemath.org/question/53864/
- How to define algebra via generators and relations?https://ask.sagemath.org/question/53782/how-to-define-algebra-via-generators-and-relations/Say I want to implement [Sweedler's Hopf algebra](https://en.wikipedia.org/wiki/Sweedler%27s_Hopf_algebra), just as an algebra, over an algebraically closed field.
I would define the free algebra on the generators, then the ideal by which I want to quotient, and the quotient should behave like I want to.
F.<x,g,ginv> = FreeAlgebra(QQbar)
I = F*[ x^2, g^2 - 1, g*ginv - 1, g*x + x*g ]*F
H = F.quo(I)
But if I now do
H(x*g + g*x)
the output is
xbar*gbar + gbar*xbar
instead of `0`.
How do I get sage to actually use the relations? The docs are not helpful here.
Jo BeThu, 08 Oct 2020 04:44:25 -0500https://ask.sagemath.org/question/53782/
- Plotting in base n?https://ask.sagemath.org/question/53815/plotting-in-base-n/In sagemath is there a way to represent plots in bases other then base10? If at all possible being able to plot from base2 to base36.nooniensoong97Sat, 10 Oct 2020 08:20:18 -0500https://ask.sagemath.org/question/53815/
- How can I restart the dead kernel of SageMathhttps://ask.sagemath.org/question/53857/how-can-i-restart-the-dead-kernel-of-sagemath/ Hello,
My kernel of Sage is dead, please anyone can help me, how to restart it?Nirina AlbertSun, 11 Oct 2020 21:27:23 -0500https://ask.sagemath.org/question/53857/
- Using matrices in Cythonhttps://ask.sagemath.org/question/53856/using-matrices-in-cython/I want to work with matrices in Cython.
But I cannot even define a matrix. Here is the code in my Sage notebook:
sage:%%cython
sage:A=Matrix([[1,0],[0,1]])
Here is the error messsage:
RuntimeError: Error compiling Cython file:
------------------------------------------------------------
...
from sage import all
A=Matrix([[1,0],[0,1]]) ^
------------------------------------------------------------
_Users_macbook__sage_temp_bogon_52702_tmp_jzby0ki0_pyx_0.pyx:2:2: undeclared name not builtin: Matrix
In the end, my goal is to make use of this library in Cython:
matrix/matrix_integer_dense.pyx
Thanks for your help1571Sun, 11 Oct 2020 20:21:48 -0500https://ask.sagemath.org/question/53856/