Re: [sage-support] checking if a function is odd, even, or periodic
Dear Vince, Thank you for your helpful reply. I'm trying to do something similar to check whether a function is periodic, I tried: > bool(sin(x) == sin(x + 2*pi)) which gave 'True' as 2*pi is the period of sine. However, I wanted to figure out what is the period of the function, so I tried: > var('p') > solve(sin(x) == sin(x + p), p) I though this would give me 2*pi (and I guess it should also give 4*pi, 6*pi, etc.) but it gave me: [p == -x + arcsin(sin(x))] Am I doing something wrong? Regards, and thanks, Avril On Saturday, October 12, 2013 11:08:18 AM UTC+1, Vincent Knight wrote: > > Hi Avril, > > One approach to check parity for example could be: > > sage: f(x) = 1/(1-x^2) > sage: bool(f(x) == f(-x)) > True > > whereas f is not odd as: > > sage: bool(f(x) == -f(-x)) > False > > There might well be an attribute, method on functions that does this also > but I'm not aware of it. > Vince > > > On 12 October 2013 11:03, Avril Coghlan > > wrote: > >> Dear all, >> >> I'm wondering whether there is a way to use SAGE to test whether a >> function such as: >> f(x) = 1/(1 - x^2) >> or >> f(x) = sin(x) >> is an odd function, even function, or periodic? >> >> I'm a Maths student, and am not sure if this is possible, or is a silly >> question (it seems to me quite a hard thing to check, but I could be >> totally wrong), >> >> Regards, >> Avril >> Avril Coghlan >> >> -- >> 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/groups/opt_out. >> > > > > -- > Dr Vincent Knight > Cardiff School of Mathematics > Senghennydd Road, > Cardiff > CF24 4AG > (+44) 29 2087 5548 > www.vincent-knight.com > +Vincent Knight > @drvinceknight > Skype: drvinceknight > -- 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/groups/opt_out.
[sage-support] checking if a function is odd, even, or periodic
Dear all, I'm wondering whether there is a way to use SAGE to test whether a function such as: f(x) = 1/(1 - x^2) or f(x) = sin(x) is an odd function, even function, or periodic? I'm a Maths student, and am not sure if this is possible, or is a silly question (it seems to me quite a hard thing to check, but I could be totally wrong), Regards, Avril Avril Coghlan -- 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/groups/opt_out.
[sage-support] Re: a multiplicative cipher in SAGE
Dear Keshav, Thanks very much, that helps a lot and makes lots of sense now. Using what you said, I was able to encode 'HAPPYNEWYEAR' using a 1-based system (A=1, B=2, C=3,Z=26) by applying (i) a multiplicative cipher with a=1,b=1 to change to a 1-based system (ii) then a multiplicative cipher with a=9,b=0, (iii) then a multiplicative cipher with a=1,b=25 to change back to the 0-based system to get the answer. I did this by typing: A = AffineCryptosystem(AlphabeticStrings()) P = A.encoding("HAPPYNEWYEAR"); P a, b = (1, 1) C = A.enciphering(a, b, P); C a, b = (9, 0) C2 = A.enciphering(a, b, C); C2 a, b = (1, 25) C3 = A.enciphering(a, b, C2); C3 This gives 'TINNQVSYQSIF', which is what I expected. Thanks again for your help, I appreciate it a lot. Regards, Avril On Tuesday, April 17, 2012 11:50:22 AM UTC+1, Avril Coghlan wrote: > > Dear all, > > I'm trying to figure out how to make a multiplicative cipher in SAGE. > For example, to make a multiplicative cipher: > M_9{m} = 9 x_{26} m > and to use it to encipher the text 'HAPPYNEWYEAR', I tried typing: > >A = AffineCryptosystem(AlphabeticStrings()) >P = A.encoding("HAPPYNEWYEAR"); P >a, b = (9, 0) >C = A.enciphering(a, b, P); C > > I get back: > LAFFINKQIKAX > > However, I think I should get back: > TINNQVSYQSIF > assuming A=1, B=2, C=3, D=4 Y=25, Z=26 > > In order to get 'TINNQVSYQSIF', I have to type: >a, b = (9, 8) > instead of >a, b = (9, 0) > I am wondering why this is? > > I had thought: >a, b = (9, 0) > should give the multiplicative cipher: > M_9{m} = 9 x_{26} m > Is this wrong? > > I would be grateful for any pointers. > > Kind Regards, > Avril > > Avril Coghlan > > > -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] a multiplicative cipher in SAGE
Dear all, I'm trying to figure out how to make a multiplicative cipher in SAGE. For example, to make a multiplicative cipher: M_9{m} = 9 x_{26} m and to use it to encipher the text 'HAPPYNEWYEAR', I tried typing: A = AffineCryptosystem(AlphabeticStrings()) P = A.encoding("HAPPYNEWYEAR"); P a, b = (9, 0) C = A.enciphering(a, b, P); C I get back: LAFFINKQIKAX However, I think I should get back: TINNQVSYQSIF assuming A=1, B=2, C=3, D=4 Y=25, Z=26 In order to get 'TINNQVSYQSIF', I have to type: a, b = (9, 8) instead of a, b = (9, 0) I am wondering why this is? I had thought: a, b = (9, 0) should give the multiplicative cipher: M_9{m} = 9 x_{26} m Is this wrong? I would be grateful for any pointers. Kind Regards, Avril Avril Coghlan -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] colouring documents about SAGE, written using sphinx
Dear all, I'd like to write a little document about using SAGE, using sphinx to write it, and host my document at readthedocs.org I'm wondering how can I get the beautiful colouring of sphinx documentation on SAGE, which I see at http://www.sagemath.org/doc/ ? As far as I can see, there is no specific 'sage' formatting available in sphinx (like there is for R, python, and many other languages), is that true? By the way, I wasn't sure if this query should go to the SAGE 'edu' mailing list, I hope I haven't sent it to the wrong one. Kind Regards, Avril Avril Coghlan Cork, Ireland -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: finding a p-cycle of a real function
Thank you very much to both of you for your help with this, that is great, I appreciate it a lot. On Feb 11, 9:43 pm, John Cremona wrote: > Numerical precision issues would make it preferable (surely?) to use > exact arithmetic by replacing 1.76 by 176/100. > > Do you know the standard trick (as used for instance in the Pollard > rho method of factorization) which avoids storing lots of terms of the > sequence and instead runs two variables through the sequence > simultaneously, starting at the same point, but with one sequence > applying the iteration twice? then you just have to check when the > two values coincide. > > Details left to the reader, or > seehttp://en.wikipedia.org/wiki/Floyd%27s_cycle-finding_algorithm#Tortoi... > > John > > On 11 February 2012 20:34, D. S. McNeil wrote: > > > > > > > > > Warning: I haven't thought this through, but the ideas might be useful. > > > It looks like you'd call something a 3-cycle if for some x_0 we had > > f(f(f(x_0))) == x_0, right? Then we should be able to do this > > numerically, with some caveats: > > > # can't remember the slick way, so brute force > > def iter_apply(f0, n): > > fs = [f0()] > > for i in xrange(n-1): > > last = fs[-1] > > fs.append(f0(last)) > > return fs > > > def find_pcycles(f0, n): > > fs = iter_apply(f0, n) > > req = fs[-1] == x # defining equation of the cycle > > roots = req.roots(ring=RR) > > for root, mult in roots: > > yield [fi(x=root) for fi in fs] > > > which gives > > > sage: f(x) = x^2-1.76 > > sage: > > sage: p1 = list(find_pcycles(f, 1)) > > sage: p1 > > [[-0.917744687875782], [1.91774468787578]] > > sage: f(p1[0][0]) > > -0.917744687875783 > > sage: f(p1[1][0]) > > 1.91774468787578 > > sage: list(find_pcycles(f, 2)) > > [[0.504987562112089, -1.50498756211209], [-0.917744687875783, > > -0.917744687875782], [-1.50498756211209, 0.504987562112089], > > [1.91774468787578, 1.91774468787578]] > > sage: list(find_pcycles(f, 3)) > > [[1.33560128916886, 0.0238308036295167, -1.75943209279837], > > [1.27545967679486, -0.133202612870350, -1.74225706392451], > > [-0.917744687875783, -0.917744687875782, -0.917744687875783], > > [-1.74225706392451, 1.27545967679486, -0.133202612870348], > > [-1.75943209279837, 1.33560128916886, 0.0238308036295143], > > [-0.133202612870349, -1.74225706392451, 1.27545967679486], > > [0.0238308036295150, -1.75943209279837, 1.33560128916886], > > [1.91774468787578, 1.91774468787578, 1.91774468787578]] > > > Note that this says [-0.917744687875783, -0.917744687875782, > > -0.917744687875783] is a 3-cycle, which it kind of is.. > > > Anyway, maybe playing off of something like that would help? > > > Doug > > > -- > > To post to this group, send email to sage-support@googlegroups.com > > To unsubscribe from this group, send email to > > sage-support+unsubscr...@googlegroups.com > > For more options, visit this group > > athttp://groups.google.com/group/sage-support > > URL:http://www.sagemath.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] finding a p-cycle of a real function
Dear SAGE users and developers, Is it possible for me to find a p-cycle of a real function using SAGE? For example, the sequence x_{n+1} = x_{n}^2 - 1.76, x_{0} =0 (n = 0,1,2...) has a three-cycle, so it alternates indefinitely between three numbers (approximately 1.3, 0.0, and -1.8). How can I find this three-cycle, or any p-cycle, using SAGE? I would be very grateful for any advice. Kind Regards, Avril Avril Coghlan Cork, Ireland -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] finding the closed form for a linear second order recurrence sequence
Dear all, I am new to SAGE (since today) but am excited about learning how to use it! I'm wondering is it possible to use SAGE to find the close form for a linear second order recurrence sequence? For example, can SAGE find a closed form for an equation such as: u_{n+2} = 2 * u_{n+1} + 8 * u_{n}, where we know u_{0} = 2 and u_{1} = 7 ? I will be very grateful for any help, or if you can point me towards the right documentation page to look at. Kind Regards, Avril Avril Coghlan Cork, Ireland -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org