Talk:Sequence of non-squares: Difference between revisions

added a section name to the first statement as a way to force the TOC to be in the proper place.
No edit summary
(added a section name to the first statement as a way to force the TOC to be in the proper place.)
 
(11 intermediate revisions by 4 users not shown)
Line 1:
== chose a way to investigate functions ==
I chose this as a way to show how easy it is to investigate functions in a programming language. --[[User:Paddy3118|Paddy3118]] 08:42, 24 August 2008 (UTC)
 
== Stability, Accuracy ==
The formula need to be investigated for numeric stability. Calculation of sqrt is inexact, it need to be shown that for all n in question, floor(1/2 + sqrt(n)) yields the exact result. A minimal requirement for this (though insufficient, I guess) is that sqrt has an error below 0.5. Note that the addition following to squaring will normalize for big n. Also conversion of those to floating point becomes quickly inexact when 32-bit floats are used. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 09:51, 24 August 2008 (UTC)
Line 39 ⟶ 41:
[[User:Sgeier|Sgeier]] 21:02, 28 September 2009 (UTC)
 
See GAP implementation for a way to use integers all the way. Of course, it will be best suited to languages with bigints, like python or ocaml, but others will do as long as you don't go past MAXINT/100. You also need to implement integer square root if it's not available in your language (not too difficult). The main idea is Sqrt(100*n) = 10*Sqrt(n) (let's call it x), so you get the first decimal of Sqrt(n) as floor(x) mod 10, or simply x mod 10 if using integer square root.
[[User:Toucan|Toucan]] 08:27, 15 June 2011 (UTC)
 
Line 71 ⟶ 73:
The task only asks to check that there are no squares in the sequence, but then we don't check that there are all non-squares ! However, it's easy to keep track of "the next square to come", and check that we go through all integers up to that number, then compute the next square, etc. Easiest with a generator, but a loop will do.
[[User:Toucan|Toucan]] 08:27, 15 June 2011 (UTC)
:What's the difference between "there are no squares" and "they are all non-squares"? --[[User:Ledrug|Ledrug]] 18:53, 15 June 2011 (UTC)
::(if(a) then (b)) says nothing about conditions when (a) is not true. (if("There are no squares") then ("they are all non-squares")) is a true statement, so if a number is, it must either be a square or a non-square--but this makes no guarantee that there are any values at all. However, we dp get that guarantee from the task's asking for a range from [1,22].
::Since there are values, and since those values must either be squares or non-squares, then if we show that there are no squares in the sequence, the resulting sequence must consist of non-squares. I don't see an ambiguity with the task description, though perhaps the reasons the existing requirements are sufficient could be more clear. --[[User:Short Circuit|Michael Mol]] 20:07, 15 June 2011 (UTC)
:::Heh, ask a rhetorical question, get a supersized answer. A nitpick though, an empty set S is normally considered to sastify the requirement "for every E in S, E is not an A". Kinda how an empty set is considered to have a permutation of 1, come to think of it. --[[User:Ledrug|Ledrug]] 20:29, 15 June 2011 (UTC)
::::What I wanted to say: if your sequence is u(n) = n^2 + 1, then there are no squares in the sequence (for n > 0), and by the task's proposed test, it would be accepted (I mean the second test, but it would be easy to build a list that is correct for its first 22 terms, then wrong). But not all non-squares are in the sequence. This is not a rhetorical question. [[User:Toucan|Toucan]] 03:42, 16 June 2011 (UTC)
:::::Ah, <i>that</i>'s what you meant, that the sequence should contain ALL non-squares. I'm not sure if the task did ask that, maybe the author should clarify. --[[User:Ledrug|Ledrug]] 05:01, 16 June 2011 (UTC)
::::::The task asks for the ''sequence of non-square natural numbers''. If in doubt, it even gives a link to OEIS sequence A000037. It's not really bad to check that there are no squares in this sequence, but it would be better to check that all non-squares are here. Since it's not difficult to do, there is no reason no to do it I think. [[User:Toucan|Toucan]] 06:14, 16 June 2011 (UTC)
:::::::(There is even a link explaining the natural numbers too). --[[User:Paddy3118|Paddy3118]] 06:28, 16 June 2011 (UTC)
 
:::::::With over fifty examples, it is too late to mess around with the task goals, although I probably did miss the chance to ensure that the non-square naturals are represented up to a limit. --[[User:Paddy3118|Paddy3118]] 06:28, 16 June 2011 (UTC)
::::::::Ok, no problem ;-) [[User:Toucan|Toucan]] 08:53, 16 June 2011 (UTC)