[sage-support] Re: Whats wrong with my function syntax?

2015-04-01 Thread Eric Gourgoulhon
Hi,

In 
p(x) = x^3 – 3*x^2 + x - 1
the first minus sign is incorrect (probably, it comes from some cut and 
paste): delete it and replace it by a minus sign typed with the keyboard:
p(x) = x^3 - 3*x^2 + x - 1
Then everything works fine. 

Eric. 

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Whats wrong with my function syntax?

2015-04-01 Thread John H Palmieri
If I copy and paste your code, I also get an error. The reason is that the 
first symbol you use for subtraction is not a hyphen, but some other symbol 
which looks very much like a hyphen, but which Sage does not recognize. 
(The second subtraction symbol seems to be okay.) Try using hyphens instead.

  John


On Wednesday, April 1, 2015 at 11:19:12 AM UTC-7, CR wrote:
>
> I've been using sagemath throughout the semester with few problems, but I 
> just can't seem to figure out what's wrong with my syntax here. 
>
> x = var('x')
> 
> p(x) = x^3 – 3*x^2 + x - 1
> Dp(x) = derivative(p(x), x)
> 
> plot(p(x), -1, 1)
>
> I'm getting this error: 
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "_sage_input_2.py", line 10, in 
> exec compile(u'open("___code___.py","w").write("# -*- coding: 
> utf-8 -*-\\n" + 
> _support_.preparse_worksheet_cell(base64.b64decode("eCA9IHZhcigneCcpCgpwKHgpID0geF4zIOKAkyAzKnheMiArICh4IC0gMSkKRHAoeCkgPSBkZXJpdmF0aXZlKHAoeCksIHgpCgpwbG90KHAoeCksIC0xLCAxKQ=="),globals())+"\\n");
>  
> execfile(os.path.abspath("___code___.py"))
>   File "", line 1, in 
> 
>   File "/tmp/tmpd2XXUV/___code___.py", line 5
> __tmp__=var("x"); p = symbolic_expression(x**_sage_const_3  – 
> _sage_const_3 *x**_sage_const_2  + (x - _sage_const_1 )).function(x)
> ^
> SyntaxError: invalid syntax
>
> So appears that the function is in error...
>

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Whats wrong with my function syntax?

2015-04-01 Thread Volker Braun
Thats an en dash (– in HTML). It often sneaks in when copy/pasting 
equations from PDF. 

We could translate en dash into hypen on the commandline to avoid that 
surprise...


On Wednesday, April 1, 2015 at 9:05:22 PM UTC+2, John H Palmieri wrote:
>
> If I copy and paste your code, I also get an error. The reason is that the 
> first symbol you use for subtraction is not a hyphen, but some other symbol 
> which looks very much like a hyphen, but which Sage does not recognize. 
> (The second subtraction symbol seems to be okay.) Try using hyphens instead.
>
>   John
>
>
> On Wednesday, April 1, 2015 at 11:19:12 AM UTC-7, CR wrote:
>>
>> I've been using sagemath throughout the semester with few problems, but I 
>> just can't seem to figure out what's wrong with my syntax here. 
>>
>> x = var('x')
>> 
>> p(x) = x^3 – 3*x^2 + x - 1
>> Dp(x) = derivative(p(x), x)
>> 
>> plot(p(x), -1, 1)
>>
>> I'm getting this error: 
>>
>> Traceback (most recent call last):
>>   File "", line 1, in 
>>   File "_sage_input_2.py", line 10, in 
>> exec compile(u'open("___code___.py","w").write("# -*- coding: 
>> utf-8 -*-\\n" + 
>> _support_.preparse_worksheet_cell(base64.b64decode("eCA9IHZhcigneCcpCgpwKHgpID0geF4zIOKAkyAzKnheMiArICh4IC0gMSkKRHAoeCkgPSBkZXJpdmF0aXZlKHAoeCksIHgpCgpwbG90KHAoeCksIC0xLCAxKQ=="),globals())+"\\n");
>>  
>> execfile(os.path.abspath("___code___.py"))
>>   File "", line 1, in 
>> 
>>   File "/tmp/tmpd2XXUV/___code___.py", line 5
>> __tmp__=var("x"); p = symbolic_expression(x**_sage_const_3  – 
>> _sage_const_3 *x**_sage_const_2  + (x - _sage_const_1 )).function(x)
>> ^
>> SyntaxError: invalid syntax
>>
>> So appears that the function is in error...
>>
>

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


[sage-support] Re: Whats wrong with my function syntax?

2015-04-02 Thread kcrisman

>
>
> We could translate en dash into hypen on the commandline to avoid that 
> surprise...
>

Interesting idea, though what if it was intended in something, such as a 
plot legend? 

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Whats wrong with my function syntax?

2015-04-02 Thread William Stein
On Thu, Apr 2, 2015 at 7:02 AM, kcrisman  wrote:
>>
>> We could translate en dash into hypen on the commandline to avoid that
>> surprise...
>
>
> Interesting idea, though what if it was intended in something, such as a
> plot legend?
>

Another idea would be to do something only if an exception is actually
raised.   I.e., if a user interactively runs some block of input (in a
notebook, command line, whatever), and it raises an exception, we
could have a library of tests we run on that input which could then be
used to provide further help to the user.  For example, if the input
string is

   "x sin(x)"

which by default results in

Traceback (most recent call last):
...
SyntaxError: invalid syntax

then the UI could call a function such as

  sage.misc.error_hints("x sin(x)", stack trace info, globals())

that in this case might return something like

"In Python multiplication is denoted using an asterisk.  For example
to multiply 2 times 3 write '2*3'."

The hint could then be displayed before or after or next to the traceback.

We would slowly build up a body of hint heuristics based on questions
we get from users.The very first one might involve an em-dash.

Another example is the following.  Suppose the user types

  var('x')

and gets the error "TypeError: 'str' object is not callable".  Then
our hint would point out that they have set var equal to a string and
should set it back to var by typing reset('var').   I have to answer
exactly this question somewhat regularly.

Another: suppose the user types

   x + y

and gets "NameError: name 'y' is not defined"... then we tell them about var.

A large amount of common help/support questions could have the answers
automated and built in.   This would be 100% optional, triggered only
on interactive errors, and not change Sage's library in any way
(except possibly with the addition of this).

 -- William


> --
> 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 post to this group, send email to sage-support@googlegroups.com.
> Visit this group at http://groups.google.com/group/sage-support.
> For more options, visit https://groups.google.com/d/optout.



-- 
William (http://wstein.org)

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Whats wrong with my function syntax?

2015-04-02 Thread Jeroen Demeyer

On 2015-04-02 16:02, kcrisman wrote:


We could translate en dash into hypen on the commandline to avoid
that surprise...


Interesting idea, though what if it was intended in something, such as a
plot legend?

The preparser never changes strings, so that's not an issue.

--
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Whats wrong with my function syntax?

2015-04-02 Thread Volker Braun
Its of course a quite difficult machine learning exercise to find the 
optimal match from tracebacks to hints that are helpful to a beginner. 
Though deciding based on a regex on the input and traceback is probably a 
good start. 



On Thursday, April 2, 2015 at 4:16:39 PM UTC+2, William wrote:
>
> On Thu, Apr 2, 2015 at 7:02 AM, kcrisman > 
> wrote: 
> >> 
> >> We could translate en dash into hypen on the commandline to avoid that 
> >> surprise... 
> > 
> > 
> > Interesting idea, though what if it was intended in something, such as a 
> > plot legend? 
> > 
>
> Another idea would be to do something only if an exception is actually 
> raised.   I.e., if a user interactively runs some block of input (in a 
> notebook, command line, whatever), and it raises an exception, we 
> could have a library of tests we run on that input which could then be 
> used to provide further help to the user.  For example, if the input 
> string is 
>
>"x sin(x)" 
>
> which by default results in 
>
> Traceback (most recent call last): 
> ... 
> SyntaxError: invalid syntax 
>
> then the UI could call a function such as 
>
>   sage.misc.error_hints("x sin(x)", stack trace info, globals()) 
>
> that in this case might return something like 
>
> "In Python multiplication is denoted using an asterisk.  For example 
> to multiply 2 times 3 write '2*3'." 
>
> The hint could then be displayed before or after or next to the traceback. 
>
> We would slowly build up a body of hint heuristics based on questions 
> we get from users.The very first one might involve an em-dash. 
>
> Another example is the following.  Suppose the user types 
>
>   var('x') 
>
> and gets the error "TypeError: 'str' object is not callable".  Then 
> our hint would point out that they have set var equal to a string and 
> should set it back to var by typing reset('var').   I have to answer 
> exactly this question somewhat regularly. 
>
> Another: suppose the user types 
>
>x + y 
>
> and gets "NameError: name 'y' is not defined"... then we tell them about 
> var. 
>
> A large amount of common help/support questions could have the answers 
> automated and built in.   This would be 100% optional, triggered only 
> on interactive errors, and not change Sage's library in any way 
> (except possibly with the addition of this). 
>
>  -- William 
>
>
> > -- 
> > 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...@googlegroups.com . 
> > To post to this group, send email to sage-s...@googlegroups.com 
> . 
> > Visit this group at http://groups.google.com/group/sage-support. 
> > For more options, visit https://groups.google.com/d/optout. 
>
>
>
> -- 
> William (http://wstein.org) 
>

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.


Re: [sage-support] Re: Whats wrong with my function syntax?

2015-04-04 Thread martin . vgagern
On Thu, Apr 2, 2015 at 7:02 AM, kcrisman > 
wrote: 

> Interesting idea, though what if it was intended in something, such as a 
> plot legend? 
>
 
Perhaps we could run such substitutions at a time where strings have been 
removed from the code during preparse. The preparser works by stripping 
strings and comments, then transforming the code, then putting them back 
in. So while strings and comments can contain arbitrarily ugly stuff, the 
rest should be reasonably sane, and any of the dashes U+2010 through U+2015 
could be turned into minus, while ×, ∙ and U+2062 (invisible times, often 
used in MathML) could become times. Unless you want × as cross_product, or 
something like that…

-- 
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 post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.