Talk:Carmichael 3 strong pseudoprimes: Difference between revisions

Undo revision 256051 by Dinosaur (talk) see https://www.wordhippo.com/what-is/the-plural-of/division.html "In more general, commonly used, contexts, the plural form will also be division"
(Undo revision 256051 by Dinosaur (talk) see https://www.wordhippo.com/what-is/the-plural-of/division.html "In more general, commonly used, contexts, the plural form will also be division")
 
(8 intermediate revisions by 2 users not shown)
Line 1:
==Integer arithmetic==
Integer arithmetic can be a delicate matter, not just because of overflows. With division, sometimes the formula will never produce a remainder, as in n(n + 1)/2, and sometimes the divisor is always a factor for more complex reasons - as with <code>(P1 - 1)*(H3 + P1)/D</code>. But if a term produces a fractional part, is it to be discarded or not? Some languages (such as Pascal) insist on "div" instead of "/" so that one thinks about truncating division, others (such as pl/i) just generate the fractional part and proceed: perhaps the result will round? truncate? to the desired value, or perhaps other terms will cancel out the fractional parts and all will be well, or, perhaps they will combine and the result will be out by one, ''etc''. And some formulae require the fractional parts, as in the expression for the n'th Fibonacci number where each term generates an ''infinite'' non-repeating fractional part, and, they cancel ''exactly'', even for large values of n... In source code,
:<code>(((1 + SQRT(5))/2)**N - ((1 - SQRT(5))/2)**N)/SQRT(5)</code>
or, in mathematical notation (possibly not rendered),
:<math>\frac{1}{\sqrt{5}}\left[\left(\frac{1 + \sqrt{5}}{2}\right)^n - \left(\frac{1 - \sqrt{5}}{2}\right)^n\right]</math>
::All the division in this task should result in an integer value. So the best solution is probably to throw/raise an exception if it doesn't.--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 12:29, 24 October 2017 (UTC)
 
==What model MOD is your MOD?==
Directly translating the given formulae involves a trap. There is an expression ''-Prime1 squared mod h3'', and translating this to <code>MOD(-P1**2,H3)</code> may not work. The behaviour of the MOD function for negative numbers varies between language, compiler, and cpu. For positive numbers there is no confusion. However, in some cases one wants an affine shift as in day-of-the-week calculations from a daynumber, D: given MOD(D,7), one wants the same result with MOD(D - 7,7) or any other such shift and indeed, this happens with some versions of MOD. But not all, as Prof. Knuth remarks in his description of the calculation of the date for Easter. The MOD function can also work as follows:
<pre>
D -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7
MOD(D,3) -1 0 -2 -1 0 -2 -1 0 1 2 0 1 2 0 1
MOD(3 + MOD(D,3),3) 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1
</pre>
Thus, <code>MOD(-1,3) + MOD(4,3) = -1 + 1</code> and <code>MOD(3,3) = 0</code> so that ''(a + b) mod n'' does come out as ''[(a mod n) + (b mod n)] mod n'' as is expected, but in a different way: (-1 ''mod'' 3) + (4 ''mod'' 3) = 2 + 1, thus the need for the second ''mod''. So, MOD and ''mod'' are different. However, this MOD is consistent with integer division that truncates. If ''q·f = n/d'' where q is the integer part and f the fractional part of the division, then the remainder is ''fd'' and has a sign too. Another computer/compiler/language version of MOD may not differ from ''mod''.
 
Here I am supposing that ''(h3+Prime1)*(Prime1-1) mod d == 0 and -Prime1 squared mod h3 == d mod h3'' is evaluated as ''{[(h3 + Prime1)*(Prime1 - 1) mod d] == 0} and {[-(Prime1 squared) mod h3] == d mod h3}'' which is to say it is ''[-(Prime1 squared)] mod h3'' not ''-[(Prime1 squared) mod h3]'' where the first case involves the MOD(negative number) while the second is -MOD(positive number) and the only way that result could match ''d mod h3'' is when both are zero.
 
Testing with the peculiar sign ignored via <code>.AND. (MOD(P1**2,H3) .EQ. MOD(D,H3))) THEN</code> gives limited results:
<pre>
Carmichael numbers that are the product of three primes:
P1 x P2 x P3 = C
3 11 17 561
5 29 73 10585
7 19 67 8911
13 61 397 314821
13 37 241 115921
19 43 409 334153
31 991 15361 471905281
37 109 2017 8134561
41 1721 35281 2489462641
43 631 13567 368113411
43 271 5827 67902031
43 127 2731 14913991
61 421 12841 329769721
61 181 5521 60957361</pre>
Which turns out to be when the two terms have remainders of one.
:-p squared means -p*p. -p**2 or -p^2 may depend on the language's operator precedence. Use brackets if in doubt. mod of a negative numbers have caused me more problems than I anticipated. We have discussed them on another task to which I would link if I could find it. We concluded that C defined it as a remainder function and many languages have followed suit. It is used here to mean the mathematical modulus function. I think this is another solution to the solutions suggested somewhere else on RC. I promise than any further task using mod of a negative number will include a health warning!--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 11:51, 23 October 2017 (UTC)
 
==Formula in Fortran contribution invisible to most browsers==
 
In the Fortran contribution (now moved to the ''Discussion'', above), there is a formula which is at present invisible to all but a minority type of browser. The majority browser type, which displays a graphic file for &lt;math&gt; tag formula rather than generating text from locally installed fonts and local MathML processing, shows only a white space after the phrase: '''as in the expression for the n'th Fibonacci number:'''.
To see and test any fixes the problem, view the page in a mainstream browser like Chrome, Safari, or IE/Edge (rather than in one of the minority browsers like Firefox, which, when requisite fonts are installed, uses local MathML processing. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 17:32, 24 September 2016 (UTC)
 
:Huh? Firefox is a "minority" class browser? But yes, I have just dabbled with IE8 and indeed the formula is not rendered, instead there appears a box with a big red cross in it. Much the same happens when IE8 is pointed at wikipedia's Fibonacci_number article where their formulae do not appear either. The W. formula is slightly different and possibly I rearranged it a little - I don't quite recall where I found it, but I never expected this inability! Similar formula preparation language has been available in OpenOffice's text editor for some years now, for example, and I thoughthought it relatively standard. However, via mathproofs.blogspot.com I've found an image of the formula, but I'm not familiar with inserting such into Rosettacode... I could of course rewrite the formula in Fortran source style, but that lacks the far more pleasing layout and glyphs of the mathematical formula. [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 10:43, 25 September 2016 (UTC)
 
:: Yes, Firefox happens to be in the minority in respect of how it handles formulae (local processing of MathML, where requisite fonts are available) – most browsers currently take the route of displaying the graphic file – perhaps because of the font dependency issue). Support for the MathML route is at about 25%, and excludes Chrome, IE/Draft, and Safari. [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 10:49, 25 September 2016 (UTC)
Line 10 ⟶ 49:
::: Any visibility at all would be a "far more pleasing layout" than a blank space :-) [[User:Hout|Hout]] ([[User talk:Hout|talk]]) 10:54, 25 September 2016 (UTC)
 
:Agreed that a blank space is not at all informative. I noticed via IE8 that the W. page presentation included in the textbox onfor the non-rendered mathematical expression the text of that expression, whereas the R. page rendition does not. So another puzzle there, as there was nothing obvious in the source text that might present that in case of inability. I have provided a source code text for the formula since code ''is'' rendered, and it is noticeably more difficult to parse. It would help if arithmetic expressions could use {[()]} grouping, not just ((())). The particular merit of rendering from the formula is that the result has good glyphs for whatever size presentation is being made, whereas an ordinary image under expansion soon shows pixelation, unless presumably it is in the .svg style and rendered from that. (But, although Firefox renders .svg, do others?) Aside from the issue of finding a good image and persuading R. to incorporate it, I am unhappy about copying someone else's image. I could perhaps take a screenshot of Firefox's rendition to calm that quibble... [[User:Dinosaur|Dinosaur]] ([[User talk:Dinosaur|talk]]) 10:17, 26 September 2016 (UTC)
 
==clarification of Carmichael 3 strong pseudomprimes==
2,171

edits