# bekalph's profile - activity

2019-01-12 11:00:58 -0600 asked a question How to configure jupyter for Sage-specific use?

I am an absolute beginner in using jupyter-notebooks. Since SageMath version 8.5 the user is asked to be prepared for using jupyter as the standard notebook in the future. So, in Linux I activate jupyter with ./ sage -n jupyter and do some experiments. In this way, obviously, SageMath activates an internal jupyter package via an internal notebook-interface (and not via an external jupyter installation e.g. in anaconda). I tried also to edit python code within a jupyter cell. I got some unexpected errors, so editing code in jupyter cells seems to be problematic. Also, I want to figure out, why editing python code within a jupyter cell changes the color marks of some 'if' statements to red? Sometimes, after re-opening a closed jupyter session appears as plain text only, i.e., without cells.

My simple question is therefore: Is there any documentation available for the sage-specific use of jupyter (e.g., meaning of color code for the elements of the python language, extra necessary import of additional sage objects for jupyter, configuration of jupyter, etc)?.

2018-06-04 14:57:09 -0600 answered a question convert charpoly()-generated characteristic polynom to symbolic expression

I just found that characteristic polynomals of matrices can also be converted to SR by substituting one of their symbols with subs.

2018-06-04 13:51:16 -0600 commented answer convert charpoly()-generated characteristic polynom to symbolic expression

Thank you very much for the hint. I need the conversion to SR in order to simplify the expression with canonicalize_radical() or with factor(). This seems not be possible if I apply them on the unconverted expression (unimplemented error or attribute error). I just found that characteristic polynomals of matrices can also be converted to SR by substituting one of their symbols with subs.

2018-06-04 13:21:46 -0600 answered a question convert charpoly()-generated characteristic polynom to symbolic expression

Thank you very much for the quick response, However, I want to calculate the characteristic polynom of a matrix containing symbols, e.g.:

a,b,c,d=var("a,b,c,d")

m=matrix(SR,[[ a , 1 , b],[ 0 , c , 1],[ d , 1 ,-1]])

2018-06-03 12:33:33 -0600 asked a question convert charpoly()-generated characteristic polynom to symbolic expression

A characteristic polynom that is generated by the procedure charpoly() has the type:

sage.rings.polynomial.polynomial_ring.PolynomialRing_field_with_category.element_class.

How can I convert it to one of type 'symbolic expression' without doing 'copy and paste'?

2018-03-22 15:37:27 -0600 commented answer Mathematica misinterprets some underscored symbolic variables

I agree, The best method to circumvent this problem is substituting the "_"- symbol by unique identifiers in sage and subsequently replacing them in Mathematica by its appropriate underscoring. key combination. This workaround should be applied to all kinds of underscored symbols (not only for underscored numbers).

2018-03-21 02:25:24 -0600 asked a question 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.

2017-05-09 09:48:50 -0600 asked a question Interactive solving differential equations with MAXIMA's desolve

I am using Maxima's "desolve" to handle a system of linear differential equations. During processing, Maxima arrives at an intermediate expression (in my case this is a complicated argument of a sqareroot) that may be positive, negative or zero. Maxima asks me interactively if this expression is negative, positive or zero. If I use "desolve" directly within the Maxima's notebook, I can give my answer interactively (e.g., "pos") to Maxima. Consequently, Maxima can continue processing immediately. Thus, in Maxima's notebook there is no need to use an 'assume' statement that includes the whole complicate expression in question. On the contrary, processing this system via Maxima's 'desolve ' at a sage's notebook is very inconvenient, since, according to sage's documentation, one can answer such questions only via assumes given prior to 'desolve'. Moreover, in the treated case Maxima ignores such 'assume'-statements. Thus, solving my equation system at Maxima via sage turns out to be impossible.
Thus my question: Is it really impossible to answer Maxima's interactive questions via sage? If not, one should implement this feature in future save-versions. This would enable sage to solve linear differential equations that cannot be treated by sage up to now.

Here is a simlpe executable example for interactive working with Maxima. (Members of Maxima's discussion forum gave this example to me for demonstration) I tried to answer this question interactively at a sage- notebook. Unfortunately, This leads to a deadlock in the sage-platform (version 7.4).

(%i1) integrate(x^a,x);
Is a equal to -1?

no;
(%o1) x^(a+1)/(a+1)

2016-09-05 17:17:12 -0600 commented answer ATAN2 AssertionError while plotting complex squareroot function

I have checked this in the cloud and also in my private 7.3 version. I made additional checks: An integer delta=1 is ok, but unfortunately a real delta=1.0 results in the same error. Also delta=real(1) is ok, but not delta=real(1.0). Thus, the problem persists, which obviously is caused by a wrong type conversation.

2016-09-05 14:59:22 -0600 asked a question ATAN2 AssertionError while plotting complex squareroot function

I want to plot the real part of a a squareroot function with complex argument by using the SAGE plot method.
This plot method combines function evaluation and plotting within one single python statement.
It fails with the error message :ATAN2 Assertion error.
However, doing the job in two separate consecutive steps , i.e., evaluating the needed function values first and plotting them afterwards with SAGE's line method is successful without error.
The following example code demonstrates this behaviour.
Meaning of variables:
f_exampl: test function calling the real part of a square-root function;
exx=1 uses the method "plot" ;
exx=2 uses the method "line" to plot a pre-calculated list of values.
delta =0: the argument of the square-root is real
delta /= 0 : I*delta is the imaginary part of the squareroot argument.

The result:
testcase exx=2 is successful for delta=0 and delta != 0.
testcase exx=1 is successful for delta=0.
testcase exx=1 aborts with ATAN2 Assertion error if the squareroot must evaluate complex numbers.

Apparently there is a conflict between the evaluation of complex sqareroots during SAGE's plot method.
Evaluating the complex sqareroots without plotting them can be done without problems.
However, In my case it is more convenient to use SAGE's plot instead of SAGE's line method.
Is it possible to avoid the assertion error in the preferred plot method?

I used SAGE Version 7.1 within a Linux opensuse 42.1 OS.

x,delta,exx=var('x', 'delta', 'exx')
delta=0.0
exx=1
def f_exampl(xx):
return sqrt(xx-I*delta)
xmin=1.0
plotpts=2
plotpts_1=plotpts+1
xmax=3.0
ym=2.0
if exx==2:
# exampl_2: no assertion error, if delta != 0:
list_exampl=[[xmin+(xmax-xmin)*i/plotpts,real_part(f_exampl(xmin+(xmax-xmin)*i/plotpts))]for i in range(plotpts_1)]
exampl_2=line(list_exampl,thickness= 2,color='red',marker='+')
show(exampl_2)
else:
# exampl_1: assertion error, if delta != 0:
exampl_1=plot (real_part(f_exampl(x)),(x,xmin,xmax),ymin=1.0,ymax=+ym,plot_points=plotpts,color='blue',marker='+')
show(exampl_1)

2016-04-24 17:09:59 -0600 asked a question store python code from a notebook cell to a file

During a notebook session I enter a series of SAGE-statements (python code) in a notebook cell. How can I let SAGE store/save this code automatically (not via copy&paste) in a file? The purpose is to reload the stored code in a cell of another session for later processing . I tried to perform this via the "save-session" -command. However, this results in a data volume of several MB, which is much larger than the total length of the code of the session. This I want to avoid.

2015-11-09 07:48:26 -0600 asked a question Substituting derivatives in Taylor expansions

Within Taylor expansions, as well as in results of 'Derivative'- operations, derivatives are marked by symbol "D[ ]" . I want to substitute them by other symbolic expressions/functions in order to get the usual presentation of derivative symbols via Latex. The following testprogram demonstrates that derivatives triggered by the "derivative"-operation can indeed be substituted by user-defined symbols, but not derivatives in Taylor expansions.

x,x_0=var("x,x_0")
a_4=var('a_4',latex_name='a_4')
a_5=var('a_5',latex_name='a_5')
T_e=function('T_e',nargs=1)
dt1=function('dt1',nargs=1)
dt2=function('dt2',nargs=1)
dTedx=var('dTedx',latex_name='\\frac{\operatorname{d}{T_e}}{\operatorname{d}x}')
type(T_e)
dt1=T_e(x).derivative(x)
print'dt1:',dt1
dt2=T_e(x_0).derivative(x_0)
print'dt2:',dt2
a3(x)=a_4+a_5*T_e(x)
print 'a3(x):',a3(x)
da3=a3(x).derivative(x)
print 'da3:', da3
print '### After a "derivative"-operation, substituting dt1 by dTedx works:'
da4=da3.subs(T_e(x).derivative(x)==dTedx)
print 'da4:',da4
ata=a3(x).taylor(x,x_0,1)
print 'Taylor series ata:',ata
print '### After Taylor expansion, substituting dt2 by dTedx does not work:'
atb=ata.subs(T_e(x_0).derivative(x_0)==dTedx)
print 'Taylor series atb:',atb


I run this program within In a SAGE6.8 notebook-session. The output is:

dt1: D[0](T_e)(x)
dt2: D[0](T_e)(x_0)
a3(x): a_5*T_e(x) + a_4


### After a "derivative"-operation, substituting dt1 by dTedx works:

da3: a_5*D[0](T_e)(x)
da4: a_5*dTedx


### After Taylor expansion, substituting dt2 by dTedx does not work:

Taylor series ata: a_5*(x - x_0)*D[0](T_e)(x_0) + a_5*T_e(x_0) + a_4
Taylor series atb: a_5*(x - x_0)*D[0](T_e)(x_0) + a_5*T_e(x_0) + a_4


What is the reason for this difference? Maybe, I merely must access the derivative expression within a Taylor expansion in a different way. Thus: which is the correct way to do this?

2014-11-29 16:34:34 -0600 commented answer How to define more complicated differential expressions in Sage?

I want to add a remark concerning the real problem with D0(y).

You can substitute the default output of an derivative-operation, e.g. D[0] (fxx)(z)

by any symbolic function you want by using the 'derivative_func'- option of 'function'.

Following Example using symbolic function definition

• fx with this option,

• fxx without this option.:

var('z')

dfxdz=function('dfxdz',latex_name='\frac{\operatorname{d}{x}}{\operatorname{d}{z}}')

def dfx(self,args,*kwds):return dfxdz(z)

fxx=function('fxx',latex_name='x')

fx=function('fx',derivative_func=dfx,latex_name='x')

For the input

fx(z).derivative(z) #with derivative_func

you get the output :

dfxdz(z)

For the input

fxx(z).derivative(z) #without derivative_func

you get the output: D[0] (fxx)(z)

2014-11-25 12:08:57 -0600 answered a question How to define more complicated differential expressions in Sage?

Perhaps the answer I have given for the question "latex typesetting for derivatives" at 31.Oct. can help you. One can utilize the option "derivative_func" of Function to let perform a list containing the requested results of the partial differentiations during processing a product rule or a chain of differentiations.

2014-10-31 13:28:36 -0600 answered a question latex typesetting for derivatives like g'

Obviously it is possible to assign any latex text to derivatives by using the ' derivative_func' -option of the 'function'- procedure. Below I have addad an example that I have executed in the SAGE V63 environment.

var('z')

def dfx(self,args,*kwds):return dfxdz(z)

def dfy(self,args,*kwds):return dfydz(z)

fx=function('fx',derivative_func=dfx,latex_name='x')

fy=function('fy',derivative_func=dfy,latex_name='y')

dfxdz=function('dfxdz',latex_name='\frac{\operatorname{d}{x}}{\operatorname{d}{z}}')

dfydz=function('dfydz',latex_name='\frac{\operatorname{d}{y}}{\operatorname{d}{z}}')

dgdx=function('dgdx',latex_name='\frac{\partial{g}}{\partial{x}}')

dgdy=function('dgdy',latex_name='\frac{\partial{g}}{\partial{y}}')

pdev=[dgdx(fx(z)),dgdy(fy(z))]

xf=fx(z)

yf=fy(z)

def pderivg(self, args, *kwds): print "args:",args; print "kwds:",kwds,pdev[kwds['diff_param']]; return pdev[int(kwds['diff_param'])]

gf = function('gf', latex_name='g',nargs=2, derivative_func=pderivg)

g=gf(xf,yf)

deriv=g.derivative(z)

show(deriv)