Ask Your Question

Shaolinux's profile - activity

2024-04-04 00:54:23 +0200 received badge  Notable Question (source)
2024-04-04 00:54:23 +0200 received badge  Popular Question (source)
2023-02-23 18:10:04 +0200 received badge  Famous Question (source)
2022-11-01 18:43:46 +0200 received badge  Notable Question (source)
2021-06-04 14:49:44 +0200 received badge  Self-Learner (source)
2021-06-02 19:25:40 +0200 received badge  Popular Question (source)
2020-10-22 23:28:25 +0200 received badge  Scholar (source)
2020-10-21 13:29:21 +0200 received badge  Commentator
2020-10-21 13:29:21 +0200 commented question Uniting new and old forum account?

Good to know. I am glad that I am not alone in this.

2020-10-19 22:52:32 +0200 commented answer Uniting new and old forum account?

Thanks for this kind reply (I was expecting the reply to start by accepting my apology ;) ). Good news (and impressive level of coordination, I must say), No rush about the timing. While we are on organizational matters, and to avoid raising a separate question to Askbot of little interest to the general public: how can I contact a Sage admin and ask for contact/consultation with Sage experts and/or decision makers (on matters such as publishing the lecture notes of graduate courses with the systematic use of SageMath)? Concretely, I want to consult with Sage on two such cases where the material is expected to be completely ready for publication early in 2022. (If this contact info is not to be shared with the general public in a response here, reply to my contact email address instead.)

2020-10-19 06:00:53 +0200 asked a question 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...)

2020-10-19 01:57:46 +0200 commented question Defining a function with different symbolic expressions in different parts of its domain specified by conditional statements

Point taken. In the future I shall refrain from joking at the forum and I suggest that you refrain from joking, too.

2020-10-19 01:50:46 +0200 answered a question Defining a function with different symbolic expressions in different parts of its domain specified by conditional statements

This is a report on the updated question after the replies by rburing and tmonteil.

The answer and recommendations of rburing concerning the 1-variate example worked beautifully also for the newly proposed 2D example, as follows:

x, y = var('x,y')
def f(x,y):    
    if -2.<=x<=0.:
        return 0.
    elif -2.<=y<=0.:
        return 0.
    elif 1-x-y<=0.:
        return 0.
    elif 1.<=x<=2.:
        return 0.
    elif 1.<=y<=2.:
        return 0.
        return 0.1*exp(-0.01*((x-1/3)^2+(y-1/3)^2)/(((1-x-y)^2)*(x^2)*(y^2)))
def g(x,y):
    return x
def h(x,y):
    return y
P=parametric_plot3d([g, h, f], (x, -2, 2), (y, -2, 2), plot_points=[128,128], frame=False, color="silver", opacity=1.)'threejs')

This is solving completely the part of the problem of plotting the graph. However, the use of conditional statements yielded the graph on the whole rectangle [-2,2]^2. Although we have used x and y as barycentric coordinates here, this is still not convenient to be used as a triangular patch.

The following is a suggestion how to resolve this difficulty WITHOUT ANY USE OF CONDITIONAL STATEMENTS, by using reparametrization instead.

After a Jacobi change of variables for the triangle,

x=s(1-t), y=st

the triangle is reparametrized, with the square (s,t) \in [0,1]^2 being the new parametric domain. In the new variables, the expression in the 'else' statement above becomes


and there follows the new code (this time including also s and t coordinate lines):

s, t = var('s,t')
def F(s,t):
    return 0.1*exp(-0.01*((1-t-1/(3.*s))^2+(t-1/(3.*s))^2)/(((1-s)^2)*(s^2)*((1-t)^2)*(t^2)))
def G(s,t):
    return s*(1-t)
def H(s,t):
    return s*t
Q0=parametric_plot3d([G, H, F], (s, 0, 1), (t, 0, 1), plot_points=[128,128], frame=False, color="gray", opacity=1.)
m=var('m', domain='integer')
n=var('n', domain='integer')
curve3dplot_uline=[0 for i in range(M)] 
curve3dplot_vline=[0 for j in range(N)]
curve3dplot_uline=[parametric_plot3d([G(s,eps+m*(1.-2.*eps)/M), H(s,eps+m*(1.-2.*eps)/M), F(s,eps+m*(1.-2.*eps)/M)],  (s, 0, 1), plot_points=128, color='silver', thickness=.5, opacity=1.) for m in range(M)] 
curve3dplot_vline=[parametric_plot3d([G(eps+n*(1.-2.*eps)/N,t), H(eps+n*(1.-2.*eps)/N,t), F(eps+n*(1.-2.*eps)/N,t)],  (t, 0, 1), plot_points=128, color='silver', thickness=.5, opacity=1.) for n in range(N)]
Q1=sum(curve3dplot_uline[i] for i in range(M)) 
Q2=sum(curve3dplot_vline[j] for j in range(N))

In this solution all conditional statements have been eliminated, the resulting graph is the graph of a parametric triangular patch. Many years ago, underflow error would have been reported at the boundary of the triangle, but numpy handles the exception well and interprets the value as 0., as needed. However, the computation of the coordinate s- and t-lines requires the introduction of a small positive parameter eps; otherwise, if eps=0, the result will be error of symbolic division by zero.

This construction by parametrization avoiding the use of conditional constraints can be straightforwardly generalized for a tetrahedron in 3D (and generally for a simplex in n-dimensions, n=2,3,4,...) . The needed generalization of the Jacobi reparametrization to n-dimensional simplex is well known (see, e.g. the 3rd volume of Fihtenholz).

2020-10-18 05:58:46 +0200 answered a question plotting multiple functions from a for loop

There seems to be a partial overlap with question #29857, see

The answers given there might be of some interest to you.

2020-10-18 03:11:08 +0200 commented answer Defining a function with different symbolic expressions in different parts of its domain specified by conditional statements

I thank also tmonteil for providing this valuable addition to the answer of rburing above, and especially for the cited link which promises to be helpful in many ways. Everything which I wrote in my remark to rburing's answer above is valid, mutatis mutandis, also for this answer.

I will now proceed to upgrade my question above to the case of 2D. A successful solution will have applications to triangulation techniques for 2D domains for parametric surfaces and will almost certainly be possible to extend straightforwardly to tetrahedralization techniques for 3D domains, 3D-volume deformations, scalar and vector-field visualization in 3D and other issues which are likely to be of general interest for diverse parts of the SageMath user communty.

2020-10-18 02:49:13 +0200 commented answer Defining a function with different symbolic expressions in different parts of its domain specified by conditional statements

I thank rburing for providing this valuable shortcut in my education in SageMath. I shall study carefully all of the above variants and now have confidence that the problem about defining and processing piecewise-defined 1-variate functions (hence, also parametric curves in 3D) is essentially resolved (point taken, concerning the specifics of the range of applications of numpy vs. sympy). I am still new here and do not have the needed points yet to mark the question as answered but will certainly do so when I have the necessary number of points.

This rapidly provided comprehensive solution gives me hope that with the help of asksage community will be resolved also the 2D problem I am facing now. So, after posting this remark, I shall upgrade my question to include also the 2D problem.

2020-10-17 19:31:09 +0200 asked a question 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... :) :) :)


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?

2020-10-15 08:39:43 +0200 commented answer Use of threejs and jmol in sage 9.1 for windows

Tried, but did not have enough points to accept it. By the way, Shao-Linux is my earlier account -- maybe you wish to unite them under the new name Shaolinux?

2020-10-14 20:08:00 +0200 commented answer Use of threejs and jmol in sage 9.1 for windows

The promised shortcut:

  1. Install Chrome and Sage 9.1 (full installation, with the 3 icons).
  2. 2-click on the Jupyter NB icon. Terminal window appears and at the end MS PDF-converted page of Jupyter NB appears.
  3. Erase the webpage; keep the terminal window with the full history of the Jupyter NB launching.
  4. Open a new Chrome webpage.
  5. In the terminal window, copy the specified localhost full address (including the token).
  6. Paste this address into the Chrome webpage and navigate to it. The Jupyter NB webpage REAPPEARS. In it, select a new Sage 9.1 environment and verify that NOW BOTH JMOL AND THREEJS WORK!

The same procedure works for the use of jmol and threejs in JupyterNB in environments other than SageMath in Anaconda in Windows 10.

2020-10-14 19:50:16 +0200 received badge  Nice Answer (source)
2020-10-13 09:14:09 +0200 received badge  Self-Learner (source)
2020-10-13 09:14:09 +0200 received badge  Teacher (source)
2020-10-13 06:33:49 +0200 answered a question Use of threejs and jmol in sage 9.1 for windows

I proposed the following solution some time ago, and now figured out a simplification of this solution, which I post separately in my remark to this solution -- see below. The users who are interested only in the practical solution of making jmol and threejs work under Windows 10, should skip the rest of the text here and read only my remark following this text. Users who are interested to know more about the reasons why jmol and threejs do not work under the default settings of Windows 10 can read the remaining part of this text, and then treat my remark below only as a shortcut of the solution given here.

See first my remark to the remarks of Slelievre and Iguananaut above. I will need to explain the parts of the solution in order reverse to the order in which they were discovered. The last and most important observation is that Iguananaut is right and both jmol and threejs work (used in the way described in the question) if the Jupyter NB is opened in Chrome. The second observation is that the default settings in Windows 10 make it impossible for Jupyter NB to open in Chrome, that is, administrative rights are needed to disable some components off. The third observation is that as soon as these changes are made, the operating system forbids the automatic access to the Jupyter NB config file. From this moment on, the problem about launching Jupyter NB js solved in the same way for SageMath and for Anaconda (and the solution (for the case of Anaconda) can be found in the Internet): the Jupyter NB config file is opened in, say, Notepad, and it is found to contain a certain link which, when pasted into Chrome, launches Jupyter NB with full functionality of jmol and almost full functionality of threejs (some of the spatial, opacity, etc. controls of three.js are missing, but the effect of this is minor).

The steps of the solution in order of their execution:

  1. Uninstall SageMath (if there is a previous installation, even if it is of the latest version - currently Sage 9.1);
  2. Open MS start menu; 2-click on Settings at the leftmost vertical menu;
  3. 2-Click on Apps.
  4. Upper-right, 2-click on 'Programs and Features';
  5. Upper-left, 2-click on 'Turn Windows features on or off'
  6. Provide administrative name and password
  7. In the appearing menu, turn OFF: 1. Internet Explorer 11 and 2. Microsoft Print to PDF (otherwise this one converts Chrome pages to PDF version in which Jupyter NB is accessible but both jmol and threejs are not working), 3. Media Features (I am not sure about item 3 but turned it off, anyway). If something does not work at the end of the algorithm, you should return to step 7 and consider turning more features off, until success (working jmol and threejs in Jupyter NB) is achieved.
  8. Uninstall any browser other than Chrome and Microsoft Edge. (In my case, I uninstalled Firefox. Without doing this, after the execution of step 7 above, and despite the fact that Chrome was selected as the primary browser in the operating system, in the newly installed Sage 9.1 (see step 9 below) Jupyter NB opened in Firefox, and not in Chrome (!!!).) Microsoft Edge proved to be irrelevant in this context. 9 Reinstall (full installation) Sage 9.1. At the end of the installation, Jupyter NB DOES NOT OPEN -- IN CHROME OR ANYWHERE. Information from the terminal indicates that the reason for this is that at this point the operating system (i.e., Windows 10) forbids automatic access to the config file of Jupyter NB (the exact path to, and name of, the file is given in the terminal message). (These were a lot of 'this' and 'that'! :) )
  9. Open the said config file, say, in Notepad, and copy the full internet address given there.
  10. Paste the full internet address from step 10 into a new Chrome webpage: the Jupyter NB is launched; open a new Sage 9.1 notebook and verify on an appropriate 3d example that the viewers jmol and threejs work properly, alongside tachyon.

I believe that after this, one can reinstall Firefox and other browsers as secondary browsers, but I have not done this myself, so the correctness of this claim has not been tested yet.

Iguananaut, for your valuable input you deserve to be raised to rank Godzillanaut! :) Thanks once again.

2020-10-13 04:12:57 +0200 commented question Use of threejs and jmol in sage 9.1 for windows

First of all, thanks to slelievre for the serious response and the recommendations which are clearly in correct positive direction. As slelievre notes, these are workarounds, so I decided to continue the search of a more direct and comprehensive solution before eventually resorting to following slelievre's recommendations. Second, SPECIAL THANKS to iguananaut for the second comment above. There is indeed connection between the present question and the question iguananaut refers to in the comment above. The two questions have a key non-void intersection, although they do not fully overlap. More important is that the solution proposed there is one of the three key points in the solution/answer of the present problem/question. I will now post my suggested solution in the answer section.

2020-10-12 14:26:17 +0200 received badge  Student (source)
2020-10-12 13:35:15 +0200 asked a question Use of threejs and jmol in sage 9.1 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.

2020-06-14 03:21:57 +0200 commented answer installing from conda-forge

Thank you for your response. There is some progress, but we are not done yet. Here is what I get after running from bash on the terminal:

(base) lubomir@lubomir-HP-ZBook-17-G6:~$ echo $SHELL


(base) lubomir@lubomir-HP-ZBook-17-G6:~$ sage --docbuild tutorial html --mathjax

/home/lubomir/anaconda3/bin/python: Error while finding module specification for 'sage_setup.docbuild' (ModuleNotFoundError: No module named 'sage_setup')

I'd like to add also that in the text in 'help()' in sage prompt ON THE TERMINAL, there is something which is unclear to me at this point: while I am reading help() in the terminal (in sage prompt) the expression used there is: '... to view the Sage tutorial IN YOUR WEB BROWSER...'. I am expecting to read it in my terminal not in a web browser. ???

2020-06-13 03:15:01 +0200 received badge  Editor (source)
2020-06-13 03:11:41 +0200 answered a question installing from conda-forge

It seems that no one of the moderators is willing to go through the above simple chunk of text from the sage environment. This is why I am going to simplify the question (it can be seen easily from the above text that the question essentially remains the same).

Why after typing in the sage environment, according to the instruction in help()

sage -docbuild tutorial html --mathjax

the result is SyntaxError: invalid syntax

instead of the expected result: building the document 'tutorial'.


It seems to me that something at the repository at conda-forge is incomplete for the case of Python 3.7.

2020-06-12 23:29:05 +0200 commented question installing from conda-forge

I just followed the instructions in the conda page in the manual. Installation was smooth, without any problems. Then, I entered the new sage environment after activating it. Then typed 'ḧelp()' and then typed 'tutorial()' according to the instruction in 'ḧelp()'. The rest is given in the text above.

2020-06-12 16:20:58 +0200 asked a question installing from conda-forge

I have now used the info on the conda page of Sage manual in both variants proposed there (1. via mamba and 2. via conda with Python=3.7). In both cases the install seems to be successful but when activating the sage environment and entering it, I tried to follow the instructions in help() and build the tutorial, manual. etc. via the prescribed in the help() line, I ultimately get

sage: tutorial()
OSError                                   Traceback (most recent call last)
<ipython-input-2-c50b110aacc5> in <module>()
----> 1 tutorial()

/home/lubomir/anaconda3/envs/sage/lib/python3.7/site-packages/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (build/cythonized/sage/misc/lazy_import.c:3685)()
    351             True
    352         """
--> 353         return self.get_object()(*args, **kwds)
    355     def __repr__(self):

/home/lubomir/anaconda3/envs/sage/lib/python3.7/site-packages/sage/misc/ in tutorial(self)
   1538             sage: tutorial()  # indirect doctest, not tested
   1539         """
-> 1540         self._open("tutorial")
   1542     def reference(self):

/home/lubomir/anaconda3/envs/sage/lib/python3.7/site-packages/sage/misc/ in _open(self, name, testing)
   1519         if not os.path.exists(path):
   1520             raise OSError("""The document '{0}' does not exist.  Please build it
-> 1521 with 'sage -docbuild {0} html --mathjax' and try again.""".format(name))
   1523         if testing:

OSError: The document 'tutorial' does not exist.  Please build it
with 'sage -docbuild tutorial html --mathjax' and try again.
sage: sage -docbuild tutorial html --mathjax
  File "<ipython-input-3-aab87ab7e211>", line 1
    sage -docbuild tutorial html --mathjax
SyntaxError: invalid syntax


What am I doing wrongly?