ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 10 Jul 2020 19:21:22 +0200Possible bug in Sage-Giac integration interface needs confirmationhttps://ask.sagemath.org/question/49192/possible-bug-in-sage-giac-integration-interface-needs-confirmation/Hello, Sage Community! Trying to answer [this related question](https://ask.sagemath.org/question/49176/unable-to-parse-giac-output-error/?answer=49191#post-id-49191), I think I have found a bug along with user @Nasser. Although my answer there explains what I think to be wrong, let me summarize it here.
When calling
integrate(x+1,x, algorithm="giac")
Sage works perfectly, but when calling
integrate((1-2*x^(1/3))^(3/4)/x,x, algorithm="giac")
we get the following traceback:
---------------------------------------------------------------------------
SyntaxError Traceback (most recent call last)
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/interfaces/giac.py in _sage_(self, locals)
1101 return symbolic_expression_from_string(result, lsymbols,
-> 1102 accept_sequence=True)
1103
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/calculus/calculus.py in symbolic_expression_from_string(s, syms, accept_sequence)
2384 _augmented_syms = syms
-> 2385 return parse_func(s)
2386 finally:
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:5479)()
537
--> 538 cpdef parse_sequence(self, s):
539 """
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_sequence (build/cythonized/sage/misc/parser.c:5369)()
555 if tokens.next() != EOS:
--> 556 self.parse_error(tokens)
557 if len(all) == 1 and isinstance(all, list):
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/misc/parser.pyx in sage.misc.parser.Parser.parse_error (build/cythonized/sage/misc/parser.c:9742)()
1006 cdef parse_error(self, Tokenizer tokens, msg="Malformed expression"):
-> 1007 raise SyntaxError(msg, tokens.s, tokens.pos)
1008
SyntaxError: Malformed expression
During handling of the above exception, another exception occurred:
NotImplementedError Traceback (most recent call last)
<ipython-input-92-987ddabbc645> in <module>()
----> 1 integrate((Integer(1)-Integer(2)*x**(Integer(1)/Integer(3)))**(Integer(3)/Integer(4))/x,x, algorithm="giac")
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/misc/functional.py in integral(x, *args, **kwds)
751 """
752 if hasattr(x, 'integral'):
--> 753 return x.integral(*args, **kwds)
754 else:
755 from sage.symbolic.ring import SR
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.integral (build/cythonized/sage/symbolic/expression.cpp:64541)()
12370 R = ring.SR
12371 return R(integral(f, v, a, b, **kwds))
> 12372 return integral(self, *args, **kwds)
12373
12374 integrate = integral
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/symbolic/integration/integral.py in integrate(expression, v, a, b, algorithm, hold)
917 if not integrator:
918 raise ValueError("Unknown algorithm: %s" % algorithm)
--> 919 return integrator(expression, v, a, b)
920 if a is None:
921 return indefinite_integral(expression, v, hold=hold)
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/symbolic/integration/external.py in giac_integrator(expression, v, a, b)
430 return expression.integrate(v, a, b, hold=True)
431 else:
--> 432 return result._sage_()
/Scientific/SageMath/local/lib/python3.7/site-packages/sage/interfaces/giac.py in _sage_(self, locals)
1103
1104 except Exception:
-> 1105 raise NotImplementedError("Unable to parse Giac output: %s" % result)
1106 else:
1107 return [entry.sage() for entry in self]
NotImplementedError: Unable to parse Giac output: Evaluation time: 1.18
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)
Here is what I could deduce after reading a lot of source code and playing with examples: When we call something like this in Sage, the following process occurs at low level:
ex = (x+1)._giac_()
result = ex.integrate(x._giac_())
result._sage_()
The first line converts the Sage expression to Giac representation; the second calls the Giac `integrate` function, with respect to the variable `x`, which must also be converted to Giac representation (that's the `x._giac_()`); finally, the third line converts the result back to Sage representation (for example, replacing `ln` from Giac to `log` from Sage). This last step seems to be the problem. In this particular case, `print(result)` shows
x^2/2 + x
However, with a more complex expression, which takes more time to be integrated:
ex=((1-2*x^(1/3))^(3/4)/x)._giac_()
result = ex.integrate(x._giac_())
print(result)
the same process gives a different result:
Evaluation time: 1.19
12*(1/4*ln(abs((-2*x^(1/3)+1)^(1/4)-1))-1/4*ln((-2*x^(1/3)+1)^(1/4)+1)+1/2*atan((-2*x^(1/3)+1)^(1/4))+1/3*((-2*x^(1/3)+1)^(1/4))^3)
Notice the "Evaluation time" bit that was absent in the previous example? This is Giac saying it took more time than usual to perform the integration. When that string makes presence is when Sage fails:
result._sage_()
will raise the exception in the traceback.
Can somebody confirm this is a bug?dsejasWed, 25 Dec 2019 22:04:33 +0100https://ask.sagemath.org/question/49192/How to wrap a sympy function as a sage function ?https://ask.sagemath.org/question/52407/how-to-wrap-a-sympy-function-as-a-sage-function/ Inspired by a [recent question](https://ask.sagemath.org/question/52397/isympysympy-sagemath-integration/) :
`import`ing a function from sympy allows *apparently* to use a sympy function in sage:
sage: import sympy
sage: from sympy import sympify, sin as ssin
sage: ssin(sympify(a+b))
sin(a + b)
But this is purely cosmetic : this result does not have the methods of a Sage symbolic expression:
sage: ssin(sympify(a+b)).trig_expand()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-15-859c8e851702> in <module>()
----> 1 ssin(sympify(a+b)).trig_expand()
AttributeError: 'sin' object has no attribute 'trig_expand'
sage: ssin(sympify(a+b)).operator()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-16-d52ecf6bce28> in <module>()
----> 1 ssin(sympify(a+b)).operator()
AttributeError: 'sin' object has no attribute 'operator'
In fact, this is a sympy object :
sage: type(ssin(sympify(a+b)))
sin
whereas:
sage: type(sin(a+b))
<class 'sage.symbolic.expression.Expression'>
So, my question is :how toi create a Sage function that :
- translates all its argument to the relevant sympy types
- calls somehow the sympy functin on these arguments
- translates back the result to Sage ?
This is done for some Sage functions, implemented by Maxima or sympy, in the Sage library. Is it possible to make this "lightly" *at run time* in some Sage source code without having to recompile the Sage library ?
Emmanuel CharpentierFri, 10 Jul 2020 19:21:22 +0200https://ask.sagemath.org/question/52407/Print (input/)output numbershttps://ask.sagemath.org/question/51536/print-inputoutput-numbers/Hey,
when I use the sage it looks like this:
`sage: factor(100)`<br>
`2^2 * 5^2`<br><br>
`sage: kronecker_symbol(3,5)`<br>
`-1`<br><br>
`sage: %hist`<br>
`factor(100)`<br>
`kronecker_symbol(3,5)`<br>
`%hist`
How can I get sage to look like this: (?)
`sage: factor(100)`<br>
`_1 = 2^2 * 5^2`<br><br>
`sage: kronecker_symbol(3,5)`<br>
`_2 = -1`<br><br>
`sage: %hist`<br>
`1: factor(100)`<br>
`2: kronecker_symbol(3,5)`<br>
`3: %hist`
And can i edit the prompt to view the input number? I.e. to look like
`sage[2]: kronecker_symbol(3,5)`
If somebody has an idea please let me know.
Thanks a lot!jbirnickSun, 24 May 2020 18:06:12 +0200https://ask.sagemath.org/question/51536/Other than "Jupyter Notebook", is there any other way to use Sage?https://ask.sagemath.org/question/42876/other-than-jupyter-notebook-is-there-any-other-way-to-use-sage/I am searching for a "compiler" way to use Sage.
Something like TeXShop, I write everything in a single file and press compile to get the results.
Is there an easy way to accomplish this?
Currently I am using the "Notebook" form of Sage which is neat but kind of gets in the way of more complicated programming.
(To be more clear, I am looking for something like an IDE "Integrated development environment", something like PyCharm for Python.)
Thanks a lot.yoyosteinTue, 10 Jul 2018 09:25:30 +0200https://ask.sagemath.org/question/42876/SageMath cannot access Mathematicahttps://ask.sagemath.org/question/48785/sagemath-cannot-access-mathematica/I have installed Mathematica Version 11.3 at a Linux system (openSUSE Leap 15.1) on a partition "math", i.e. separated from the Linux home and system partition. I have tried to send Mathematica expressions from SageMath to Mathematica in the manner described in the SageMath reference by using a SageMath Notebook or its command line interface. They are rejected with:
> TypeError: unable to start mathematica: End Of File (EOF). Exception style platform.
Mathematica finished running /usr/bin/sh -c stty -echo; math -rawterm
command: /usr/bin/sh
args: ['/usr/bin/sh', '-c', 'stty -echo; math -rawterm']
buffer (last 100 chars): ''
before (last 100 chars): 'es/Linux/WolframKernel\r\nnot found. Your Mathematica installation may be i incomplete\r\nor corrupted.\r\n'
after: <class 'pexpect.exceptions.EOF'>
In the course of the installation of Mathematica I added the path to the math command line interface of Mathematica to the common PATH-sequence. Therefore I am able to access the Mathematica command line interface by simply entering math or the command:
> /usr/bin/sh -c stty -echo; math -rawterm
using a bash-terminal outside SageMath. I have checked that I can do it without the need for specifying the complete path to math. However, entering the same command within a Sage-session by using the Python's OS- interface is only successful if the full path to math is specified:
> /usr/bin/sh -c stty -echo; /run/media/bernhardi/math/math -rawterm
The error appearing otherwise is the same as that one returned by the above described trials to send mathematica objects. The protocol shows that the mathematica objects are sent to Mathematica without detailed path info. Thus, obviously the SageMath-Mathematica interface does not recognize the complete path info that is availabe in the basic Linux system. Maybe the missing info is caused by the fact that Mathematica is located on a remote partition. Therefore my question: Is it possible to provide sageMath with the needed full path to math?
Unfortunately it is not possible to attach the complete output of SageMath.bekalphSun, 17 Nov 2019 13:41:42 +0100https://ask.sagemath.org/question/48785/how to Load in Jupyterhttps://ask.sagemath.org/question/48215/how-to-load-in-jupyter/This doesn't works (latex_milp.py is on my desktop) on Windows10
load("latex_milp.py")
load("/latex_milp.py")
load("c:/latex_milp.py")
load("c:\\latex_milp.py")
What can I test ?CyrilleMon, 07 Oct 2019 08:01:41 +0200https://ask.sagemath.org/question/48215/Get output of a .py file in a browserhttps://ask.sagemath.org/question/46004/get-output-of-a-py-file-in-a-browser/It seems like basic question, but I already spent about 2 hours, tried jupyter, command line, different combinations, different commands, lots of stuffâ€¦
Basically, I have file `test.py` with one line of content, taken straight from docs:
```
plot(graphs.HeawoodGraph())
```
I want to evaluate it, and get a picture of the plot in a browser.
What I don't want:
* to open some external app for PNG files because in future I gonna need interactivity
* to open the file in some text editor inside a browser because I already have it opened in Emacs
* to get errors about `graphs` being undefined because when I execute in `sage` terminal, it's all correctly defined.
* to search for `import`s to run every particular sage example from docs, because typing those examples directly in `sage` interactive interpreter works just fine *(the examples don't include `import`s)*, so I see no reason to put an unnecessary effort over that.Hi-AngelWed, 03 Apr 2019 16:21:06 +0200https://ask.sagemath.org/question/46004/Evaluate sage pyhttps://ask.sagemath.org/question/46003/evaluate-sage-py/ It seems like basic question, but I already spent about 2 hours, tried jupyter, command line, different combinations, different commands, lots of stuffâ€¦
Basically, I have file `test.py` with one line of content, taken straight from docs:
```
plot(graphs.HeawoodGraph())
```
I want to evaluate it in a browser.
What I don't want:
* to open some external app for PNG files because in future I gonna need interactivity
* to open the file in some text editor inside a browser because I already have it opened in Emacs
* to get errors about `graphs` being undefined because when I execute in `sage` terminal, it's all correctly defined.Hi-AngelWed, 03 Apr 2019 16:18:45 +0200https://ask.sagemath.org/question/46003/Is there a way to start a Sage session from a session of its Python interpreter ?https://ask.sagemath.org/question/43258/is-there-a-way-to-start-a-sage-session-from-a-session-of-its-python-interpreter/Yes, I know its sounds silly. But there *is* a point...
The R library [reticulate](https://github.com/rstudio/reticulate) allows to use a *persistent* Python session from a R session. One of its main uses is to allow to use Python code as well as R code in the creation of reports or papers. This is really useful for everyday statistics use...
One can do similar things with Sage and SageTeX, but using R and R objects is a bit awkward. Furthermore, the R tools offer abilities not easily emulated from within Sage. One *can* create composite documents using R facilities for R code (`knitr`) and SageTeX (or PythonTeX, better maintained nowadays) for supporting Sage code ; but usng such composite documents is a bit awkward : passing from the source to the compiled document entails :
* `knit` the R code of the `.Rnw` file, getting a `.tex` file ;
* `\LaTeX` the `.tex` file at least once ;
* `sage` (or `pythontex`) the resultant file
* re-`\LaTeX` the `.tex` file at least once.
This is a bit hard to automate... The same thing applies with aggravation to Markdown texts : the Sage chunks have to be wrapped in \LaTeX-only chunks, and the sage steps have to be done manually from the command line (or from emacs, which amounts to the same thing).
The availability of a persistent Sage session would solve the problem.
A small trial using Sage's R (launched by `sage -R`) shows that this is *almost* possible :
> library(reticulate)
> use_python("/usr/local/sage-8/sage") ## This is the main Sage script file
> repl_python()
Python 2.7.15 (/usr/local/sage-8/sage)
Reticulate 1.10 REPL -- A Python interpreter in R.
>>> 2^3
1
We are in python, no preparsing takes place.
>>> arctan
NameError: name 'arctan' is not defined
`arctan` is not defined : noting Sage-specific is known.
>>> from sage.all import *
>>> arctan
arctan
The import succeeded.
>>> x
NameError: name 'x' is not defined
But the (default) definition of x as a symbolic variable has not been done.
>>> var("x")
x
>>> x
x
>>> foo=arctan(x).integrate(x)
>>> exit
We are back to R, from which we can access toplevel objects in the Python session :
> py$foo
x*arctan(x) - 1/2*log(x^2 + 1)
> py$latex(py$foo)
x \arctan\left(x\right) - \frac{1}{2} \, \log\left(x^{2} + 1\right)
> py_to_r(py$latex(py$foo))
x \arctan\left(x\right) - \frac{1}{2} \, \log\left(x^{2} + 1\right)
Not a "standard" R characer vector :
> class(py_to_r(py$latex(py$foo)))
[1] "sage.misc.latex.LatexExpr" "python.builtin.str"
[3] "python.builtin.basestring" "python.builtin.object"
But it can be used as such :
> paste("** ",py$latex(py$foo)," **", sep="")
[1] "** x \\arctan\\left(x\\right) - \\frac{1}{2} \\, \\log\\left(x^{2} + 1\\right) **"
Now, it is possible to insert the loading of a *Python* module *before* the launch of the Python REPL : From the doc of `repl_python` :
module: An (optional) Python module to be imported before the REPL is
launched.
So the question is : is it possible to write a module correctly importing `sage.all` **AND** whose `__init__` function would ***replace*** Python's REPL by Sage's ?
ISTR that a few years ago, before the introduction of Sage's Jupyter notebook, such tricks were used in Jupyter to start a Sage session (complete with preparser) from an "ordinary" Jupyter notebook. But for the life of me, I haven't been able to retrieve the relevant pages...
Any thoughts ?
**EDIT :** A bit of googling using the former name "IPython notebook" led me to this StackOverflow [question](https://stackoverflow.com/questions/23384070/taking-advantage-of-sage-and-ipython-notebook-in-the-same-page-or-rather-combi), whose first answer, by no other than William Stein, tells the user that using `%load_ext sage` would start Sage from a (conventient) IPython session. Indeed :
charpent@asus16-ec:~$ sage -ipython
Python 2.7.15 (default, May 19 2018, 18:46:27)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: 2^3
Out[1]: 1
So we are in Python, no preprocessing
In [2]: x
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-2-6fcf9dfbd479> in <module>()
----> 1 x
NameError: name 'x' is not defined
x not defined.
In [3]: %load_ext sage
In [4]: 2^3
Out[4]: 8
We are in Sage !
In [5]: x
Out[5]: x
x has been defined
In [6]: quit()
Exiting Sage (CPU time 0m0.13s, Wall time 0m14.53s).
So this `sage` notebook extension to IPython still exists, and does what I want. Its dissection should give me what I need to write my helper module.
But for the life of me, I have been unable to divine its source. what is it, and where is it ?
**EDIT on 2018-08-13 :** that source is in `$SAGE_ROOT/src/sage/repl/ipython_extension.py`, but is insufficient (to me !) to build a solution. Question re-asked on [sage-devel](https://groups.google.com/forum/#!topic/sage-devel/xGbk8FD-3LA) in order to reach new eyeballs...Emmanuel CharpentierSun, 05 Aug 2018 21:11:20 +0200https://ask.sagemath.org/question/43258/PARI/GP error in wrapping custom-defined PARI functions in Sage using the command gp.set()https://ask.sagemath.org/question/42638/parigp-error-in-wrapping-custom-defined-pari-functions-in-sage-using-the-command-gpset/ I have a library in PARI/GP and since Sage also supports the GP calculator I have been trying to shift my library using gp.set() and gp.get() commands. So far all functions are working but I got a PARI/GP error while implementing this function in Sage using gp.set(). Here is the code of that function:
compareSides(printedgesonscreen=0) =
{
local( edge, edgesCheckList1:list, edgesCheckList2:list, cancelCriterion);
edgesCheckList1 = listcreate(2*numberOfLines);
edgesCheckList2 = listcreate(2*numberOfLines);
for (j = 1, numberOfSpheres,
if( deleteFlag[j] == 0,
if( printedgesonscreen == 1,
print("Cell ",j," lies on the hemisphere with center at ",
divideInNumberField(K,Lambda[j],Mu[j]) );
print(" with radius square ", radiusSquare[j],
" and has the following edges:");
);
for( s = 1, length( pointsOfLine[j]),
edge = setintersect(Set(pointsOfLine[j][s]),
Set(pointsOfSphere[j]:list));
if(length(edge) == 2,
if(printedgesonscreen == 1, print(edge); );
if( setsearch(Set(edgesCheckList1),edge),
if(setsearch(Set(edgesCheckList2),edge),
if (printedgesonscreen == 1,
print("***Error in function compareSides: triple edge in cell diagram");
);
,
listput(edgesCheckList2,edge);
);
, /* else not yet entered in edgesCheckList1 */
listput(edgesCheckList1,edge);
);
);
if(length(edge) > 2,
print("***Error in function compareSides: edge with three corners");
);
);
);
);
if(Set(edgesCheckList1) == Set(edgesCheckList2),
print("All ", length(edgesCheckList1), " = ",
length(edgesCheckList2)," edges appear twice.");
if( length(edgesCheckList1) > 3,
cancelCriterion = 1
,
cancelCriterion = 0
);
, /* else some edges do not appear twice. */
print("Some edges do not appear twice:");
print(setminus(Set(edgesCheckList1),Set(edgesCheckList2)));
);
listkill(edgesCheckList1); listkill(edgesCheckList2);
/* Return */ cancelCriterion
};
I have run this function in the GP calculator of Sage using the gp.console() command and it works fine but I don't understand why it is not working using gp.set(). Here is the implementation I did:
gp.set('compareSides(printedgesonscreen=0)','{ local( edge, edgesCheckList1:list, edgesCheckList2:list, cancelCriterion); edgesCheckList1 = listcreate(2*numberOfLines); edgesCheckList2 = listcreate(2*numberOfLines); for (j = 1, numberOfSpheres, if( deleteFlag[j] == 0, if( printedgesonscreen == 1, print("Cell ",j," lies on the hemisphere with center at ", divideInNumberField(K,Lambda[j],Mu[j]) ); print(" with radius square ", radiusSquare[j], " and has the following edges:"); ); for( s = 1, length( pointsOfLine[j]), edge = setintersect(Set(pointsOfLine[j][s]), Set(pointsOfSphere[j]:list)); if(length(edge) == 2, if(printedgesonscreen == 1, print(edge); ); if( setsearch(Set(edgesCheckList1),edge), if(setsearch(Set(edgesCheckList2),edge), if (printedgesonscreen == 1, print("***Error in function compareSides: triple edge in cell diagram"); ); , listput(edgesCheckList2,edge); ); , /* else not yet entered in edgesCheckList1 */ listput(edgesCheckList1,edge); ); ); if(length(edge) > 2, print("***Error in function compareSides: edge with three corners"); ); ); ); ); if(Set(edgesCheckList1) == Set(edgesCheckList2), print("All ", length(edgesCheckList1), " = ", length(edgesCheckList2)," edges appear twice."); if( length(edgesCheckList1) > 3, cancelCriterion = 1; , cancelCriterion = 0; ); , /* else some edges do not appear twice. */ print("Some edges do not appear twice:"); print(setminus(Set(edgesCheckList1),Set(edgesCheckList2))); ); listkill(edgesCheckList1); listkill(edgesCheckList2); /* Return */ cancelCriterion}')
When I run this in Sage it shows a PARI/GP error and outputs the whole code. I have been trying to find the bug since the last 3 days. Please help me regarding this. Thank you.MathematicianMon, 18 Jun 2018 09:20:09 +0200https://ask.sagemath.org/question/42638/Could anyone explain this unexpected behaviour of the interface?https://ask.sagemath.org/question/42509/could-anyone-explain-this-unexpected-behaviour-of-the-interface/
Input
w = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
w
Output
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
Input
w = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
w
Output
[0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22]
zivaoupasTue, 05 Jun 2018 17:48:02 +0200https://ask.sagemath.org/question/42509/Make SageMath allow for Error of Mathematicahttps://ask.sagemath.org/question/42223/make-sagemath-allow-for-error-of-mathematica/Hello everyone!
I am currently trying on the interface of SageMath to Mathematica for the solution of polynomial equations and inequalities. Whilst doing that I came across an instance that is typical for Mathematica when solving systems of polynomial equation and inequalities. I tried to solve the system and Mathematica returned the error
> "Mathematica ERROR: Solve::ratnz:
> Solve was unable to solve the system
> with inexact coefficients.
> The answer was obtained by solving a corresponding exact system and
> numericizing the result. "
and as a result Sage raised the error and returned no solution.
I am trying to get solutions to the system:
sys={0.500000000000000*lamda2*theta3 - 3*x1^2 + 2*lamda1 - lamda3 + 5==0,lamda1 + lamda2 - lamda4 + 3*theta1 - 6*x2==0,lamda1*(theta2 + 2*x1 + x2 - 7.50000000000000)==0,(0.500000000000000*theta3*x1 + x2 - 1.50000000000000)*lamda2==0,-lamda3*x1==0,-lamda4*x2==0}
for the variables
var={x1,x2,lamda1,lamda2,lamda3,lamda4}
and a sample of the code for the solve is:
from sage.interfaces.mathematica import mathematica
sys = mathematica(sys)
var=mathematica(var)
sys.Solve(var)
Is it possible to make an exception for specific Mathematica errors so as to get the solution?
Many thanks,
Jason :)JasonKMon, 30 Apr 2018 13:45:47 +0200https://ask.sagemath.org/question/42223/Mathematica misinterprets some underscored symbolic variableshttps://ask.sagemath.org/question/41666/mathematica-misinterprets-some-underscored-symbolic-variables/Following examples show that the interface between sage and Mathematica misinterprets symbolic variables if they are underscored with numbers:
sage: h_20,h_10,h_2,h_3,h20,h10,h_ij,h_kl=var("h_20,h_10,h_2,h_3,h20,h10,h_ij,h_kl");
sage: mexpr=mathematica((h_20+h_10)^3);
sage: print(mexpr);
3
27000 (h_)
sage: mexpr1=mathematica((h20+h10)^3);
sage: print(mexpr1);
3
(h10 + h20)
sage: mexpr2=mathematica((h_2+h_3)^3);
sage: print(mexpr2);
3
125 (h_)
sage: mexpr3=mathematica((h_ij+h_kl)^3);
sage: print(mexpr3);
3
((h_ij) + (h_kl))
I use sage-8.1 and Mathematica 11.2.0 at Linux OpenSUSE Leap v42.3. In this forum I haven't found any other comment regarding this funny behaviour.bekalphWed, 21 Mar 2018 08:25:24 +0100https://ask.sagemath.org/question/41666/jupyter interface vs. sagenbhttps://ask.sagemath.org/question/38679/jupyter-interface-vs-sagenb/I'm converting to jupyter from sagenb, and am having trouble finding equivalent interface shortcuts for a couple of features.
(a) In sagenb, to get a new cell I can hit a +/wordballoon icon. In jupyter, do I have to go through the pulldown menu or is there some way to get a new cell by mousing inside the notebook?
(b) In sagenb, there is a wysiwyg interface for the explanatory-text cells. In jupyter, I'm not finding one; I seem to have to code everything manually in markdown.
Am I missing something, or are those time-saving features gone?
Also: One feature I wanted that was not present in sagenb was the ability to delete output cells. (This is so I can make a lab notebook for a class without having to make a test copy and then copy/paste all the input cells to a fresh notebook.) Is that possible somehow in jupyter? I see that I can hide output cells, but it's not exactly the same.smbelcasTue, 29 Aug 2017 05:30:00 +0200https://ask.sagemath.org/question/38679/Accessing GAP's in function through the C Interfacehttps://ask.sagemath.org/question/36458/accessing-gaps-in-function-through-the-c-interface/Is there a way to access GAP's `in` function through Sage's C Interface to GAP?
gap> Identity(G) in G;
true
EDIT:
I was wondering how to call this from Sage:
sage: G = libgap.SymmetricGroup(5)
sage: g = libgap.eval('(1,2,3)(4,5)')
How do I test if `g` is in `G`?jaebondSun, 05 Feb 2017 17:24:58 +0100https://ask.sagemath.org/question/36458/help Sage find Magmahttps://ask.sagemath.org/question/36969/help-sage-find-magma/I have both Sage and Magma installed in my machine, but when type
sage: magma_console()
I get this error message
/Applications/Sage-6.5.app/Contents/Resources/sage/local/bin/sage-native\
-execute: line 8: magma: command not found
How do help Sage find Magma?ha55555Fri, 17 Mar 2017 23:01:13 +0100https://ask.sagemath.org/question/36969/How to increase GAP's recursion limithttps://ask.sagemath.org/question/36466/how-to-increase-gaps-recursion-limit/Is there a way to increase the recursion limit of (lib)GAP processes? I am hitting a recursion limit when computing a double coset:
`--> 531 coset_space = libgap.DoubleCosets(G, C_G_s0, C_G_s1)`
`ValueError: libGAP: Error, recursion depth trap (5000)`jaebondMon, 06 Feb 2017 20:22:46 +0100https://ask.sagemath.org/question/36466/Sage interfacehttps://ask.sagemath.org/question/35116/sage-interface/Why is the Sage interface opened in an internet browser? Is there any way to change it so that the Sage notebooks and worksheets are local in the computer?yhsaiTue, 11 Oct 2016 01:23:30 +0200https://ask.sagemath.org/question/35116/convert polynomial rings from Sage to Singularhttps://ask.sagemath.org/question/32596/convert-polynomial-rings-from-sage-to-singular/Suppose I have a ring R in sage (I have in mind a polynomial ring modulo some ideal). Is there a way to convert it into a ring in Singular?
I want to use the tensor product function (which singular provides) on two rings (and then convert back to sage) but singular doesn't have (natural) constructors for the rings I'd like to tensor. admiraltsoFri, 19 Feb 2016 19:03:01 +0100https://ask.sagemath.org/question/32596/Sagemath cloud user interfacehttps://ask.sagemath.org/question/32547/sagemath-cloud-user-interface/ Hi
I have a lot a trouble with Sagemath Cloud user interface (respect to Sagenote book interface).
Some questions to have a better online experience.
How do you remove toolbar ?
How do you remove menu bar ?
How do you delete all output ?
How do you execute all the code cells ?
How to remove many consecutive cells whatever type they are ?
[the later is easily done within the Sage Notebook interface for providing access to the source code in **text format** by means of a very handy *Edit* button allowing cutting, pasting or exchanging chunks of a worksheet]
Thanks
candideFri, 12 Feb 2016 00:05:06 +0100https://ask.sagemath.org/question/32547/Sage code appears in different places on different compileshttps://ask.sagemath.org/question/31027/sage-code-appears-in-different-places-on-different-compiles/Hello!
I write things like exams for math classes, and like to use sagetex to create random problems and the appropriate solutions (for multiple choice exams). Everything with sagetex works fine in terms of the installation (using it on a chromebook, and I have sage fully installed and synced up with the local latex installation). I compile the latex code by doing a pdflatex, then sagetex, then pdflatex again.
The problem I seem to have is that the sagetex code locations seem to appear in the wrong places, and it moves around each time I compile the same code. Thus I will get equations that are suppose to be the questions placed in answers and vice versa, even across different questions.
I've been trying to figure out what the issue is, but haven't had much luck. I originally used code to randomize locations of things, and set the seed to update slowly enough that it wouldn't change over while it was compiling to make sure stuff lined up (and most of it did). Then to try a failsafe I fixed the seed to a static value so that it always locates things to the same places every time, and the problem still persists.
The odd thing is it persists in a totally non-uniform way. Sometimes I will compile the code and everything is where it should be. Sometimes everything after the 10th sage entry is jumbled. Sometimes just the last couple.
When it fails, it always completely fails after a certain point, and what it 'looks' like is the case is that it skips some of the sage input and moves ahead to future input (so that the last few sage inputs are left as ??? after the second pdflatex run). So it works fine up to a point, then jumbles things by skipping seemingly random sagetex code.
So. Any idea what gives? My sample code is sort of involved, so I can post it if you guys want but it involves a long latex file and a rather significant cls file, so I didn't want to post it all here (I can maybe post a link to the files if it helps).
Thanks for the help, I've been trying to figure this quirk out for months with no luck.
PS
A MWE doesn't really work because this seems to be a problem that crops up more reliably the longer the example is. Here are the files that seem to (fairly reliably) recreate the problem...
CLS file: [HERE](https://www.dropbox.com/s/0vdrzady9trdip8/uf-math-exam-rnd.cls?dl=0)
MWE: [HERE](https://www.dropbox.com/s/6ej3hrk5sdyjlwd/MWE.tex?dl=0)Jason021Wed, 25 Nov 2015 01:10:34 +0100https://ask.sagemath.org/question/31027/Unable to Install Sage NOtebook interfacehttps://ask.sagemath.org/question/24483/unable-to-install-sage-notebook-interface/ I installed Python. I see the two files as python. exe and phytonw.exe. I intalled the VM Virtual Box. It opens as window. I cannot make the Sage interface to show. I downloaded something called Sage6-3.ova but it won't do anything. I need help getting the installation to work and to get the SAge interface to run . CAn anyone help? I have Microsoft Windows 8.
thanks
JohnJohnBarrosoTue, 14 Oct 2014 20:36:21 +0200https://ask.sagemath.org/question/24483/Condition of type: SIMPLE-CONDITIONhttps://ask.sagemath.org/question/23438/condition-of-type-simple-condition/Executing
limit(((x^(2*x)-2*factorial(x)+x*log(x,10))^((x^(2*x))/factorial(x)))/(x^(((2*x)^(2*x))/(factorial(x-1)))),x=infinity)
on my Sagemath's server web interface, I obtain:
Condition of type: SIMPLE-CONDITION
Undefined limit product $INFINITY * $ZEROA in lim-times
Available restarts:
1. (CONTINUE) Return from BREAK.
Top level in: #<process TOP-LEVEL>.
>
What can I do?
'Sage Version 6.1.1, Release Date: 2014-02-04'
CaterpillarWed, 16 Jul 2014 16:18:33 +0200https://ask.sagemath.org/question/23438/How do I split a cell in two in sagemath?https://ask.sagemath.org/question/11003/how-do-i-split-a-cell-in-two-in-sagemath/I have two input lines in a notebook at sagecloud, and evaluating either evaluates both, and prints the output for both below. How do I separate them into two separate cells? (As I might with cmd-shift-D in mathematica.)Scott MorrisonTue, 18 Feb 2014 08:49:25 +0100https://ask.sagemath.org/question/11003/interface with mathematica in notebookhttps://ask.sagemath.org/question/7777/interface-with-mathematica-in-notebook/I am transitioning from mathematica to sage. I tried running mathematica commands in the console and they work just fine as mentioned in the sage documentation. However, when I try to call mathematica from notebook it takes forever and nothing happens. It there anything more than having the 'math' command in PATH I need to do to get mathematica working in notebook. I am trying this on a OSX. Does that cause any problems?ShashankMon, 29 Nov 2010 17:06:42 +0100https://ask.sagemath.org/question/7777/My notebook interface doesn't workhttps://ask.sagemath.org/question/9640/my-notebook-interface-doesnt-work/I have a problem when I try to use sage with the notebook interface on my mac (a macbook pro under MacOS 10.7). When I launch a notebook interface, sage doesn't work. If I type 2+2 and click "evaluate", nothing happens. However, what is weird is that if I close the window and reopen it, then the answer is here "4".
Also, when I launch sage in a terminal instead, things work quite normally.
I have no idea of what is happening here. It used to work normally, until about two months ago. Since then I have tried everything I could think of, without success:
quitting sage and relaunching it, killing all processes related to sage, restarting the computer,
changing the browser (from safari to mozilla), reloading a new version of sage from the internet...
If anyone has any idea of what is happening and what I should try, thank youJoel B.Sun, 16 Dec 2012 20:24:35 +0100https://ask.sagemath.org/question/9640/Call pure python code from SAGEhttps://ask.sagemath.org/question/8938/call-pure-python-code-from-sage/Dear all,
I want to move from matlab for my image processing tasks. Nevertheless, to load the file formats I use (SPIDER, MRC, etc..), I only have some python code. Is it possible to directly invoke such python code from SAGE?. If so.. how? (I have looked for a Python inteface, but no luck for SAGE invoking Python). If not.. what is the recommended workflow to program and publish my codes for the community?.
Thanks in advance!kankamusoMon, 30 Apr 2012 12:23:18 +0200https://ask.sagemath.org/question/8938/Math Display in SageNB webinterface resizeable?https://ask.sagemath.org/question/8905/math-display-in-sagenb-webinterface-resizeable/Is the MathDisplay portion of the sagenb.org interface (the one that shows the jsmath output) resizeable? I have some big matrix displayed that does not fit in the default height. The fact that it has horizontal scrolling but no vertical scrolling is a bit weird!d3banjanThu, 19 Apr 2012 07:15:14 +0200https://ask.sagemath.org/question/8905/Defining symbolic functions in Sage and importing from Maximahttps://ask.sagemath.org/question/8651/defining-symbolic-functions-in-sage-and-importing-from-maxima/Still following [this thread](http://ask.sagemath.org/question/1077/symbolic-expectations-and-double-integrals), I would like to know how to
1. import in Sage a function defined in Maxima?
In my context, I'm interested in Maxima's pdf_normal so I started to
maxima("load(distrib)");
but how do I proceed from there?<br/>
2. What is the equivalent of Maxima's := symbolic function definition?Green diodSat, 21 Jan 2012 10:44:26 +0100https://ask.sagemath.org/question/8651/read from serial porthttps://ask.sagemath.org/question/8208/read-from-serial-port/I'm trying to get sagemath to read from my USB port which has an arduino attached to it. The arduino is throwing a bunch of text to the serial port with address /dev/ttyUSB0
A preliminary Google search reveals that there is a python library pySerial which is designed to do just this. Can I make sagemath recognize this library somehow?
Thanks!
BillMon, 01 Aug 2011 18:47:22 +0200https://ask.sagemath.org/question/8208/