Typo in provided documentation

65 views
Skip to first unread message

NahsiN

unread,
Oct 1, 2014, 4:06:50 PM10/1/14
to sage-s...@googlegroups.com
Hello, I don't know where to post this so redirect me as needed. I believe I have found a typo in the sage tutorial. Under Sage Tutorial v6.3 >> A Guided Tour >> Some Common Issues with Functions we have the lines
def h(x):
      if x<2:
         return 0  
      else:
          return x-2

The issue: plot(h(x), 0, 4) plots the line y=x2, not the multi-line function defined by h. The reason? In the command plot(h(x),0, 4), first h(x) is evaluated: this means plugging x into the function h, which means that x<2 is evaluated.                  

I think the else clause is evaluated and not the if x<2 clause. 
Thanks,
Nishan

luisfe

unread,
Oct 2, 2014, 4:43:44 AM10/2/14
to sage-s...@googlegroups.com
It looks right to me.

I am not a native English speaker so I could be (very) wrong, but I understand that the comparison x<2 is evaluated, which is completely true, independently if the condition is evaluated as True or False. In fact, next lines tell why x<2 is evaluated False and that h(x) returns x-2.

slelievre

unread,
Oct 2, 2014, 1:42:25 PM10/2/14
to sage-s...@googlegroups.com

You can work around this as follows:

    plot(lambda x: h(x), 0, 4)
 

NahsiN

unread,
Oct 2, 2014, 2:32:44 PM10/2/14
to sage-s...@googlegroups.com
@slelievre I was just pointing out what I think is a typo.
@slelievre You are right, the clause after the statement clarifies the situation. "When a symbolic equation is evaluated, as in the definition of h, if it is not obviously true, then it returns False. Thus h(x) evaluates to x-2, and this is the function that gets plotted" But I still feel the whole thing can be worded slightly better and more concisely. The if clause is evaluated anyway when one calls h(x) so there is no point in saying "x<2 is evaluated".

Vincent Delecroix

unread,
Oct 4, 2014, 5:21:15 AM10/4/14
to sage-s...@googlegroups.com
Hello,

Is it better worded as follows?

The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line
function defined by h. The reason? In the command plot(h(x), 0, 4),
first h(x) is evaluated: this means plugging the symbolic variable x
into the function h. The inequality "x < 2" evaluates to ``False`` and
hence ``h(x)`` evaluates to ``x - 2`` as it can be seen with
{{{
sage: bool(x < 2)
False
sage: h(x)
x - 2
}}}

I also find misleading to have a Python argument (the x in "def
h(x):") and a symbolic variable (here "x") having the same name. At
least it should be mentioned.

Vincent

2014-10-02 20:32 UTC+02:00, NahsiN <nishan.s...@gmail.com>:
> @slelievre I was just pointing out what I think is a typo.
> @slelievre You are right, the clause after the statement clarifies the
> situation. "When a symbolic equation is evaluated, as in the definition of
> h,
> if it is not obviously true, then it returns False. Thus h(x) evaluates to
> x-2, and this is the function that gets plotted" But I still feel the whole
>
> thing can be worded slightly better and more concisely. The if clause is
> evaluated anyway when one calls h(x) so there is no point in saying "x<2 is
> evaluated".
> On Thursday, 2 October 2014 13:42:25 UTC-4, slelievre wrote:
>>
>>
>>
>> Le mercredi 1 octobre 2014 22:06:50 UTC+2, NahsiN a écrit :
>>>
>>> Hello, I don't know where to post this so redirect me as needed. I
>>> believe I have found a typo in the sage tutorial. Under Sage Tutorial
>>> v6.3
>>> >> A Guided Tour >> Some Common Issues with Functions we have the lines
>>> def h(x):
>>> if x<2:
>>> return 0
>>> else:
>>> return x-2
>>>
>>> The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line
>>> function defined by h. The reason? In the command plot(h(x),0, 4), first
>>>
>>> h(x) is evaluated: this means plugging x into the function h, *which
>>> means that **x<2** is evaluated*.
>>>
>>> I think the else clause is evaluated and not the if x<2 clause.
>>> Thanks,
>>> Nishan
>>>
>>
>> You can work around this as follows:
>>
>> plot(lambda x: h(x), 0, 4)
>>
>>
>
> --
> 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.
>

NahsiN

unread,
Oct 6, 2014, 2:53:07 PM10/6/14
to sage-s...@googlegroups.com
Yes Vincent, that sounds much better,
Cheers,
Nishan

Vincent Delecroix

unread,
Oct 6, 2014, 4:53:59 PM10/6/14
to sage-s...@googlegroups.com
Dear Nishan,

I created a ticket for that, you can have a look at:
http://trac.sagemath.org/ticket/17107

Hopefully, this will be corrected in the next release of Sage.

Thanks for the report!
Vincent

2014-10-06 20:53 UTC+02:00, NahsiN <nishan.s...@gmail.com>:
> Yes Vincent, that sounds much better,
> Cheers,
> Nishan
>
> On Saturday, 4 October 2014 05:21:15 UTC-4, vdelecroix wrote:
>>
>> Hello,
>>
>> Is it better worded as follows?
>>
>> The issue: plot(h(x), 0, 4) plots the line y=x−2, not the multi-line
>> function defined by h. The reason? In the command plot(h(x), 0, 4),
>> first h(x) is evaluated: this means plugging the symbolic variable x
>> into the function h. The inequality "x < 2" evaluates to ``False`` and
>> hence ``h(x)`` evaluates to ``x - 2`` as it can be seen with
>> {{{
>> sage: bool(x < 2)
>> False
>> sage: h(x)
>> x - 2
>> }}}
>>
>> I also find misleading to have a Python argument (the x in "def
>> h(x):") and a symbolic variable (here "x") having the same name. At
>> least it should be mentioned.
>>
>> Vincent
>>
>> 2014-10-02 20:32 UTC+02:00, NahsiN <nishan.s...@gmail.com <javascript:>>:
>> > email to sage-support...@googlegroups.com <javascript:>.
>> > To post to this group, send email to sage-s...@googlegroups.com
>> <javascript:>.
Reply all
Reply to author
Forward
0 new messages