Periodic inabilitity of sin()

47 views
Skip to first unread message

Duc Trung Ha

unread,
Apr 22, 2012, 8:39:51 AM4/22/12
to sage-s...@googlegroups.com
Hola,         
              
Am I missing something or is this behavior rather peculiar:

sage: bool(sin(x) == sin(x+2*pi))
True

...however:

plot(sin(x) - sin(x+2*pi))

gives out the result:
http://aleph.sagemath.org/?c=plot%28sin%28%282%2Api%29+%2B+x%29+-+sin%28x%29%2C-100%2C100%29
              
Moreover, example below isn't even recognized as an identity:

sage: bool ( sin((2*pi^2 + x)/pi) == sin(x/pi) )
False

Is this a bug or is it covered somewhere else?

Thanks for replies.
Duc Trung Ha
Sage Version 4.8, Release Date: 2012-01-20
Intel(R) Core(TM) i5-2410M CPU @ 2.30GHz
Ubuntu 11.10

Johan Grönqvist

unread,
Apr 22, 2012, 10:35:19 AM4/22/12
to sage-s...@googlegroups.com
2012-04-22 14:39, Duc Trung Ha skrev:
> Am I missing something or is this behavior rather peculiar:
>
> sage: bool(sin(x) == sin(x+2*pi))
> True
>
> ...however:
>
> plot(sin(x) - sin(x+2*pi))
>
> gives out the result:
> [plot showing inaccuracies of floats]

I typed this instead, and got a nice line at 0:

plot(simplify(sin((2*pi) + x) - sin(x)),-100,100)

It seems that your plot evaluates both sin-calls numerically, and as we
use floating point numbers of a certain precision, they will differ
around the 15-th digit, which is what you see.

Perhaps the simplify-call uses the identity you mention to replace the
expression by 0, and then plots 0.

> Moreover, example below isn't even recognized as an identity:
>
> sage: bool ( sin((2*pi^2 + x)/pi) == sin(x/pi) )
> False
>

You could use:
bool (sin(((2*pi^2 + x)/pi).expand()).full_simplify() == sin(x/pi))

> Is this a bug or is it covered somewhere else?
>

I might consider it a bug that not every identity is used by default,
but I would add that I expect it to be an unsolvable problem:

1) We want it fast.
2) We want it to use all simplification methods.
3) We _need_ a yes/no answer.

I will let the experts tell the story in more detail.

Regards

Johan

Duc Trung Ha

unread,
Apr 22, 2012, 1:02:27 PM4/22/12
to sage-s...@googlegroups.com
Thanks a lot for an explanatory reply :-)

Unfortunately I still have some comments...


    I typed this instead, and got a nice line at 0:

    plot(simplify(sin((2*pi) + x) - sin(x)),-100,100)

This is not working for a little bit more complicated arguments, for
instance, the second sin(x/pi) function:
http://aleph.sagemath.org/?c=plot%28simplify%28sin%28%282%2Api%5E2+%2B+x%29%2Fpi%29+-+sin%28x%2Fpi%29%29%2C-100%2C100%29


    You could use:
    bool (sin(((2*pi^2 + x)/pi).expand()).full_simplify() == sin(x/pi))

What a nice hack :-)

Nonetheless, is there a way to do this trick in a more general way? The
thing is, I need all this for testing periodicity of real-valued
functions given by user.
E. g. Through investigating stationary points my program is able to find
out that 1 candidate for the potential period of `sin(x/pi)` is `2*pi^2`.

Nevertheless, I cannot just test this candidate with:
||
iff(x)==f(x +period):...
now, can I?
                                                                                                                                                                         
||I would need to expand the inner function (which is, in addition to                                                                                                    
that, in general *not* always the inner function) but I can't get access                                                                                                 
to it since the input function is a blackbox for the program.                                                                                                            
                                                                                                                                                                         
Is it somehow possible to /force/ full testing of (at least) goniometric
identities?


    I might consider it a bug that not every identity is used by default,

    but I would add that I expect it to be an unsolvable problem:

    1) We want it fast.
    2) We want it to use all simplification methods.

In my case I would want that second option - can I make Sage to always go this
way for me?
Reply all
Reply to author
Forward
0 new messages