This site is supported by donations to The OEIS Foundation.

Template:Distinct prime factors/doc

From OeisWiki
Jump to: navigation, search

alt = This template is under construction...
This template is under construction.            

Please do not use this unfinished and/or still unreliable template.            


Warning: All templates/parser functions nesting levels are used, so you can't nest it any further (e.g. you can't transclude the {{distinct prime factors/doc}} subpage) without causing deeply nested templates to fail to render, giving wrong results (prime factor greater than square root is missing for some numbers).


The {{distinct prime factors}} (or {{dpf}}) arithmetic function template returns a list of distinct prime factors of a nonzero integer, otherwise returns an error message.

Usage

{{distinct prime factors|a nonzero integer|sep = list items separator (default , )}}

or

{{distinct prime factors|a nonzero integer|list items separator (default , )}}

or

{{dpf|a nonzero integer|sep = list items separator (default , )}}

or

{{dpf|a nonzero integer|list items separator (default , )}}

where the sep default ,  gives , (comma followed by space.)

Valid input

A nonzero integer with absolute value less than 1031 2 = 1062961.

Examples

Examples with valid input (check primes with https://oeis.org/A000040/a000040.txt N. J. A. Sloane, Table of n, prime(n) for n = 1..100000)

Unfortunately, with the transclusion of {{Distinct prime factors/doc}} via the {{documentation}} template the precious limited nesting levels of templates and/or parser functions were exhausted! :-( Check {{Distinct prime factors/doc}} directly to see that all the tests are successful. Fortunately (not quite yet...), by transcluding {{Distinct prime factors/doc}} directly, borrowing the minimum code needed here from the {{documentation}} template, we manage to not exhaust the limit for most tests, but not for some of the largest numbers... :-( So you still have to check directly {{Distinct prime factors/doc}} to save some templates/parser functions nesting levels by avoiding the transclusion... You can see that all the tests are successful there.

Code Result
{{dpf|210^2}} 2, 3, 5, 7
{{dpf|210^2|sep = ; }} 2; 3; 5; 7
{{dpf|210^2|sep =  * }} 2 * 3 * 5 * 7
{{dpf|210^2|sep =  + }} 2 + 3 + 5 + 7
{{dpf|-28}} 2, 7
{{dpf|-5}} 5
{{dpf|1}}
{{dpf|7}} 7
{{dpf|15}} 3, 5
{{dpf|27}} 3
{{dpf|30}} 2, 3, 5
{{dpf|111}} 3, 37
{{dpf|5^3 * 11^2}} 5, 11
{{dpf|2^5 * 3^3 * 5}} 2, 3, 5
{{dpf|2^9 * 3^3}} 2, 3
{{dpf|37^2 + 8 * 37^2}} 3, 37
{{dpf|2^9 * (26 + 1)}} 2, 3
{{dpf|89 * 113}} 89, 113
{{dpf|79 * 79}} 79
{{dpf|210^2}} 2, 3, 5, 7
{{dpf|233^2}} 233
{{dpf|10000}} 2, 5
{{dpf|65535}} 3, 5, 17, 257
{{dpf|65536}} 2
{{dpf|65537}} 65537
{{dpf|65539}} 65539
{{dpf|65540}} 2, 5, 29, 113
{{dpf|65541}} 3, 7, 3121
{{dpf|65542}} 2, 32771
{{dpf|65543}} 65543
{{dpf|65547}} 3, 7283
{{dpf|65549}} 11, 59, 101
{{dpf|65551}} 65551
{{dpf|65553}} 3, 21851
{{dpf|65557}} 65557
{{dpf|65559}} 3, 13, 41
{{dpf|65561}} 53, 1237
{{dpf|65563}} 65563
{{dpf|65567}} 173, 379
{{dpf|65569}} 7, 17, 19, 29
{{dpf|65571}} 3, 11, 1987
{{dpf|65573}} 23, 2851
{{dpf|65577}} 3, 21859
{{dpf|65579}} 65579
{{dpf|265536}} 2, 3, 461
{{dpf|265537}} 131, 2027
{{dpf|265539}} 3, 88513
{{dpf|265541}} 265541
{{dpf|265543}} 265543
{{dpf|265547}} 265547
{{dpf|265549}} 37, 7177
{{dpf|265551}} 3, 11, 13, 619
{{dpf|265553}} 29, 9157
{{dpf|265557}} 3, 17, 41, 127
{{dpf|265559}} 7, 59, 643
{{dpf|265561}} 265561
{{dpf|265563}} 3, 19, 1553
{{dpf|265567}} 265567
{{dpf|265569}} 3, 88523
{{dpf|97 * 211}} 97, 211
{{dpf|216 * 211}} 2, 3, 211
{{dpf|1024 * 45}} 2, 3, 5
{{dpf|97 * 257}} 97, 257
{{dpf|3^6 * 5^2}} 3, 5
{{dpf|3 * 5^5}} 3, 5
{{dpf|17^2 * 191}} 17, 191
{{dpf|5 * 7 * 13 * 29}} 5, 7, 13, 29
{{dpf|5 * 7 * 13 * 29|sep = ; }} 5; 7; 13; 29
{{dpf|965536}} 2, 11, 13, 211
{{dpf|965537}} 67, 14411
{{dpf|965539}} 83, 11633
{{dpf|965541}} 3, 321847
{{dpf|965543}} 383, 2521
{{dpf|965547}} 3, 11, 3251
{{dpf|965549}} 13, 17, 257
{{dpf|965551}} 965551
{{dpf|965553}} 3, 321851
{{dpf|965557}} 31, 31147
{{dpf|965559}} 3, 7, 45979
{{dpf|965561}} 19, 89, 571
{{dpf|965563}} 23, 41981
{{dpf|965567}} 965567
{{dpf|965569}} 11, 61, 1439
{{dpf|997 * 1019}} 997, 1019
{{dpf|1015943}} 997, 1019

Examples with invalid input

code result
{{dpf|0}} Distinct prime factors error: Argument must be a nonzero integer
{{dpf|1031^2}} Distinct prime factors error: Argument must be a nonzero integer with absolute value < 1031 2 = 1062961

Formatted numbers

This template requires unformatted numbers, it will not recognize formatted numbers, e.g. comma separated, which is by design since formatted numbers will break expression parsers. To remove the formatting from a number, you can wrap the number first in {{formatnum:number|R}}.[1]

code result
{{distinct prime factors|1,000}} Distinct prime factors error: Argument must be a nonzero integer
{{distinct prime factors|{{formatnum:1,000|R}}}} 2, 5

Code

{{Distinct prime factors}} (or {{dpf}}) arithmetic function template

<noinclude><!-- {{documentation}} --><!-- We can't use it here, the precious limited nesting levels of templates and/or parser functions get exhausted! 

So we just borrow the necessary code from it instead.

--><div style="text-align: center; font-size: smaller;">The following [[Help:Documenting templates|documentation]] is located at [[Template:{{PAGENAME}}/doc]].</div>{{Template:{{PAGENAME}}/doc}}<!--

--></noinclude></noinclude><includeonly>{{ifint| {{{1|NAN}}}
| {{#ifexpr: ( ( abs ({{{1}}}) ) > 1 ) and ( ( abs ({{{1}}}) ) < 1031^2 ) 
  | {{~dpf
    | mpf = {{~mpf
            | {{{1}}}
            | mpf_le_sqrt(n) = {{mpf le sqrt(n)
                               | {{{1}}}
                               | sep = *
                               | key/val_sep = ^
                               }}
            | sep = {{{sep|{{{2|, }}}}}}
            | key/val_sep = ^
            }}
    | sep = {{{sep|{{{2|, }}}}}}
    }}
  | {{#ifexpr: ( abs ({{{1}}}) ) = 0
    | {{error| Distinct prime factors error: Argument must be a nonzero integer }}
    }}<!--
 -->{{#ifexpr: ( abs ({{{1}}}) ) >= 1031^2
    | {{error| Distinct prime factors error: Argument must be a nonzero integer with absolute value < 1031{{^|2}} {{=}} {{#expr: 1031^2 }} }}
    }}
  }} 
| {{error| Distinct prime factors error: Argument must be a nonzero integer }}
}}</includeonly>

{{~Distinct prime factors}} (or {{~dpf}}) core function template

{{#if: {{{mpf|}}}  
| <!--
 
  2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 = 9699690
  2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 = 223092870
  2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 = 6469693230
  2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23 * 29 * 31 = 200560490130 

-->{{trim|<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|0}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|1}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|2}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|3}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|4}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|5}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|6}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|7}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|8}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{#explode:{{#explode:{{{mpf}}}|{{{sep|{{{2|, }}}}}}|9}}|^|0}}{{{sep|{{{2|, }}}}}}<!--
  -->{{{sep|{{{2|, }}}}}}<!-- we need {{{sep|{{{2|, }}}}}} at least twice at the end for the {{trim}} template 
-->|{{{sep|{{{2|, }}}}}}<!--
-->}}
| <!-- empty list: empty product of primes for the units (+/-)1, undefined prime factorization for 0 --> 
}}

See also







External links


Notes