Re: [sage-support] Re: PATH in OS X Jupyter notebook

2022-08-29 Thread John H Palmieri
I'm reviving this discussion because of another ask.sagemath.org post 
(https://ask.sagemath.org/question/63845/how-reach-octave-or-macaulay2-from-sage-notebook/):
 
someone who had installed octave and macaulay 2, but the app wasn't finding 
them because of its minimal setting for PATH. This makes me think that a 
preference panel to set the PATH would be a good idea. As far as I can 
tell, the app still reads $HOME/.sage/init.sage, so people can use that 
instead of modifying an IPython profile function, right? But a small 
preference panel might be nice.

-- 
John

On Friday, June 24, 2022 at 8:38:22 PM UTC-7 Marc Culler wrote:

> I should have mentioned that it is always possible to run the main 
> executable of a macOS app from the command line.  E.g.
>
> $ /Applications/SageMath.app/Contents/MacOS/SageMath
>
> When you do that, the process  that is launched is almost identical to the 
> one that is launched when you click on the icon, the difference being that 
> it does have a stdout and stderr.  So if you launch the app that way from 
> your terminal then you will be able to see any messages that are being 
> written to stderr.  (This is one of those situations for which a terminal 
> is an optimal tool.)
>
> - Marc
>
>
>
> On Fri, Jun 24, 2022 at 10:28 PM Marc Culler  wrote:
>
>> Hi John,
>>
>> A macOS app launched from an icon has no stdout or stderr.  Apple's NSLog 
>> command will write to stderr if it exists, and to a log file if it does not 
>> exist.  But simply writing to stderr as most unix programs do has no effect 
>> if stderr does not exist.  When using the terminal as the input for the 
>> sage app any stderr output generated by sage will go to the terminal.  But 
>> there is no place for such error messages to go if they are generated 
>> before sage is launched.  The /usr/local/bin/sage command is available as 
>> long as you install the recommended extra package, and anyone who is 
>> debugging should use it whenever necessary, as you did.
>>
>> I don't see any value in working hard to try to arrange that every 
>> possible thing can be done without ever using a terminal.  There is nothing 
>> wrong with using a terminal.  There are many tasks for which a terminal is 
>> the optimal tool.  So be it.
>>
>> - Marc
>>
>> On Fri, Jun 24, 2022 at 10:01 PM John H Palmieri  
>> wrote:
>>
>>> Hi Marc,
>>>
>>> Very good question. I think that allowing users to modify the standard 
>>> config files is the right thing to do, but I'm really not sure. I worry 
>>> that the next person will want to modify a different setting, and you don't 
>>> want to get dragged into recreating IPython/Jupyter preferences. For 
>>> debugging, would it be worth providing a warning if a config file is found, 
>>> or if a config file is found with any nonstandard settings? (The default 
>>> config file is entirely commented out.)
>>>
>>> By the way, I debugged Samuel's suggestion by running "./sage -n" with a 
>>> local installation: it printed error messages in the terminal where I ran 
>>> it that let me know that something was wrong. I figured out that I had to 
>>> use quotes, as in
>>>
>>>   c.InteractiveShellApp.exec_lines = ['import sys; ...']
>>>
>>> rather than
>>>
>>>   c.InteractiveShellApp.exec_lines = [import sys; ...]
>>>
>>> I don't know where to view the corresponding error messages for the OS X 
>>> app.
>>>
>>> A question for both of you: I think the standard situation is to not 
>>> have a profile directory, you have to run "sage --ipython profile create". 
>>> Is there a good way to do this instead from a Jupyter notebook? Then 
>>> someone could create a profile directory without having to use the 
>>> terminal, although they would need to use a text editor to modify it.
>>>
>>> -- 
>>> John
>>>
>>> On Friday, June 24, 2022 at 3:12:52 PM UTC-7 Marc Culler wrote:
>>>
 Thank you for figuring that out Samuel.  Now here is a question for 
 both of you.  The macOS app intentionally sets a minimal environment when 
 it starts sage.  It is intentionally minimal because it would be 
 dangerous, 
 in terms of security, but more importantly in terms of the potential for 
 creating hard-to-debug crashes of the app, to simply accept whatever weird 
 stuff the user happens to have in their environment.  The decision to set 
 a 
 specific minimal environment for the app was made after such a crash, 
 which 
 was related to traces of an obsolete Sage installation left in a user's 
 .bashrc file.

 But dangerous should not necessarily mean impossible.  It would be 
 feasible to add a preferences panel to the app which could include a PATH 
 string to be appended to the minimal default PATH at startup.  Being 
 forced 
 to type that string into a preferences dialog would at least alert the 
 user 
 to the possibility that the next weird crash might be their own fault.  
 But 
 Samuel's answer indicates that expert users 

Re: [sage-support] Error while finding a solution of the non linear equation by bisection method using loop in SageCellServer

2022-08-29 Thread G. M.-S.
Implicit assumptions are a great source of disasters (in programming and
elsewhere).
There are many other things that can go wrong in this "bisection"
procedure, I was just pointing at some of them.
Anyway, I am sorry if you took it badly.  I was only trying to help.

Best,

Guillermo

On Mon, 29 Aug 2022 at 10:48, Varun Kumar  wrote:

> In my problem the Bisection means a bisection method in numerical analysis.
> In this method, b > a always because we find the root of the equation in
> the interval (a, b) so for the formation of the interval it is necessary b
> > a.
>
> On Mon, Aug 29, 2022 at 12:18 AM G. M.-S.  wrote:
>
>>
>> Hi Varun.
>>
>> There are several problems (besides the confusion between "Bisection" and
>> "bisection").
>>
>> 1) As you know, in Python blocks are delimited by indentation.  So it
>> should be
>>
>> sage: *def* *bisection*(f, a, b, errorBound):
>>
>> : xm = (a+b)/*2*
>>
>> : *while* f(x) != *0* and (b-a) >= errorBound:
>>
>> : *if* f(a)*f(xm) < *0*:
>>
>> : b = xm
>>
>> : *else*:
>>
>> : a = xm
>>
>> : xm = (a+b)/*2*
>>
>> : *return* xm
>>
>> 2) The second problem is you suppose b>a which is not always true:
>>
>> sage: bisection(f,*3*,*2*,*.001*).n()
>>
>> 2.50
>>
>> which is totally wrong.
>>
>> 3) There is a third problem, as you can see with
>>
>> sage: f(x) = x^*2*-*9*
>>
>> sage: x = *3*
>>
>> sage: bisection(f,-*2*,*10*,*1*)
>>
>> 4
>>
>> which is totally wrong.
>>
>> This is because you use x instead of xm inside *bisection*.
>>
>>
>> 4) Also, the while loop is not guaranteed to terminate, so a finite loop
>> is better.
>>
>>
>> 5) Finally, as you are looking for a root, it is perhaps best to bound
>> both |f(xm)| and |b–a|.
>>
>>
>> 6) Do not forget that xm is a local variable, so it is not defined
>> outside *bisection*.
>>
>>
>> So you could do something similar to the following:
>>
>>
>> sage: *def* *mybisection*(f, aa, bb, maxvalueerror, maxrooterror,
>> maxiter):
>>
>> : *if* abs(f(aa)) < maxrooterror:
>>
>> : print("Solution found after 0 iterations.")
>>
>> : *return* aa
>>
>> : *if* abs(f(bb)) < maxrooterror:
>>
>> : print("Solution found after 0 iterations.")
>>
>> : *return* bb
>>
>> : *if* aa < bb:
>>
>> : a,b = aa,bb
>>
>> : *else*:
>>
>> : a,b = bb,aa
>>
>> : *if* f(a)*f(b) > *0*:
>>
>> : print("No guaranteed solution, stopping.")
>>
>> : *return* *None*
>>
>> : *for* i in range(maxiter):
>>
>> : xm = (a+b)/*2*
>>
>> : *if* abs(f(xm)) < maxvalueerror and (b-a)/*2* <
>> maxrooterror:
>>
>> : print("Solution found after "+str(i+*1*)+" iterations."
>> )
>>
>> : *return* xm
>>
>> : *if* f(a)*f(xm) < *0*:
>>
>> : b = xm
>>
>> : *else*:
>>
>> : a = xm
>>
>> : print("No solution found after "+str(maxiter)+" iterations")
>>
>> : *return* *None*
>>
>> :
>>
>> sage: *def* *f*(x):
>>
>> : *return* x^*3*-*9**x+*1*
>>
>> :
>>
>> sage: x0 = mybisection(f,*2*,*3*,*10*^-*12*,*10*^-*12*,*1000*)
>>
>> Solution found after 40 iterations.
>>
>> sage: x0.n(),f(x0).n()
>>
>> (2.94282005779587, 5.45047701991629e-13)
>>
>> sage:
>>
>> (Notice the name, to avoid any clash in case *bisection* already exists.)
>>
>> HTH,
>>
>> Guillermo
>>
>> On Sun, 28 Aug 2022 at 13:31, Varun Kumar  wrote:
>>
>>>  def Bisection(f, a, b, errorBound):
>>> xm = (a+b)/2
>>> while( f(x)!=0 and (b-a) >= errorBound):
>>> if(f(a)*f(xm)<0):
>>> b = xm
>>> else:
>>> a = xm
>>> xm = (a+b)/2
>>> return xm
>>> def f(x):
>>> return x^3-9*x+1
>>> bisection(f,2,3,0.001)
>>> print("root=", xm,"f(x)=",f(x))
>>> *After evaluating we get an error like: *
>>>
>>> * File "/tmp/ipykernel_997521/4223205321.py", line 6 else: ^
>>> SyntaxError: invalid syntax*
>>>
>>> What can I do and what is the tool that I can use?
>>> Help me
>>> Your's
>>> Varun
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CANnG18_STOtHiDrwbgp8ZR4x3G0np_GG4YYUks-A%3DCKyS45Azw%40mail.gmail.com.


Re: [sage-support] Error while finding a solution of the non linear equation by bisection method using loop in SageCellServer

2022-08-29 Thread Varun Kumar
In my problem the Bisection means a bisection method in numerical analysis.
In this method, b > a always because we find the root of the equation in
the interval (a, b) so for the formation of the interval it is necessary b
> a.



On Mon, Aug 29, 2022 at 12:18 AM G. M.-S.  wrote:

>
> Hi Varun.
>
> There are several problems (besides the confusion between "Bisection" and
> "bisection").
>
> 1) As you know, in Python blocks are delimited by indentation.  So it
> should be
>
> sage: *def* *bisection*(f, a, b, errorBound):
>
> : xm = (a+b)/*2*
>
> : *while* f(x) != *0* and (b-a) >= errorBound:
>
> : *if* f(a)*f(xm) < *0*:
>
> : b = xm
>
> : *else*:
>
> : a = xm
>
> : xm = (a+b)/*2*
>
> : *return* xm
>
> 2) The second problem is you suppose b>a which is not always true:
>
> sage: bisection(f,*3*,*2*,*.001*).n()
>
> 2.50
>
> which is totally wrong.
>
> 3) There is a third problem, as you can see with
>
> sage: f(x) = x^*2*-*9*
>
> sage: x = *3*
>
> sage: bisection(f,-*2*,*10*,*1*)
>
> 4
>
> which is totally wrong.
>
> This is because you use x instead of xm inside *bisection*.
>
>
> 4) Also, the while loop is not guaranteed to terminate, so a finite loop
> is better.
>
>
> 5) Finally, as you are looking for a root, it is perhaps best to bound
> both |f(xm)| and |b–a|.
>
>
> 6) Do not forget that xm is a local variable, so it is not defined
> outside *bisection*.
>
>
> So you could do something similar to the following:
>
>
> sage: *def* *mybisection*(f, aa, bb, maxvalueerror, maxrooterror,
> maxiter):
>
> : *if* abs(f(aa)) < maxrooterror:
>
> : print("Solution found after 0 iterations.")
>
> : *return* aa
>
> : *if* abs(f(bb)) < maxrooterror:
>
> : print("Solution found after 0 iterations.")
>
> : *return* bb
>
> : *if* aa < bb:
>
> : a,b = aa,bb
>
> : *else*:
>
> : a,b = bb,aa
>
> : *if* f(a)*f(b) > *0*:
>
> : print("No guaranteed solution, stopping.")
>
> : *return* *None*
>
> : *for* i in range(maxiter):
>
> : xm = (a+b)/*2*
>
> : *if* abs(f(xm)) < maxvalueerror and (b-a)/*2* <
> maxrooterror:
>
> : print("Solution found after "+str(i+*1*)+" iterations.")
>
> : *return* xm
>
> : *if* f(a)*f(xm) < *0*:
>
> : b = xm
>
> : *else*:
>
> : a = xm
>
> : print("No solution found after "+str(maxiter)+" iterations")
>
> : *return* *None*
>
> :
>
> sage: *def* *f*(x):
>
> : *return* x^*3*-*9**x+*1*
>
> :
>
> sage: x0 = mybisection(f,*2*,*3*,*10*^-*12*,*10*^-*12*,*1000*)
>
> Solution found after 40 iterations.
>
> sage: x0.n(),f(x0).n()
>
> (2.94282005779587, 5.45047701991629e-13)
>
> sage:
>
> (Notice the name, to avoid any clash in case *bisection* already exists.)
>
> HTH,
>
> Guillermo
>
> On Sun, 28 Aug 2022 at 13:31, Varun Kumar  wrote:
>
>>  def Bisection(f, a, b, errorBound):
>> xm = (a+b)/2
>> while( f(x)!=0 and (b-a) >= errorBound):
>> if(f(a)*f(xm)<0):
>> b = xm
>> else:
>> a = xm
>> xm = (a+b)/2
>> return xm
>> def f(x):
>> return x^3-9*x+1
>> bisection(f,2,3,0.001)
>> print("root=", xm,"f(x)=",f(x))
>> *After evaluating we get an error like: *
>>
>> * File "/tmp/ipykernel_997521/4223205321.py", line 6 else: ^ SyntaxError:
>> invalid syntax*
>>
>> What can I do and what is the tool that I can use?
>> Help me
>> Your's
>> Varun
>>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-support/CANnG18-hKhNKG6HFatdOVN1Q9D0A6cxDgpaEqS5Ne5zhsjCyHg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAB5NMdD90YLfTwmcoeBi7J36YFq4iYmRf5x_ea1M3kCXj%2B8Rgw%40mail.gmail.com.