This site is supported by donations to The OEIS Foundation.

Template:~Distinct prime factors

From OeisWiki
(Redirected from Template:~dpf)
Jump to: navigation, search

The {{~Distinct prime factors}} (or {{~dpf}}) is the core function template used by the {{Distinct prime factors}} (or {{dpf}}) arithmetic function template.

This core function template has been written to avoid calling the expensive {{~mpf}} core function template ten times! Mediawiki templates only allow assignment-once (to argument variables of a function template,) since templates (and parser functions) are purely functional (albeit without recursion!)

Usage

{{~Distinct prime factors|mpf = (see valid input)|sep = list items separator (default , )}}

or

{{~dpf|mpf = (see valid input)|sep = list items separator (default , )}}

Valid input

  • mpf must be the result of {{~mpf|a nonzero integer|mpf_le_sqrt(n) = (see below)|sep = map items separator (default , )|key/val_sep = ^}};
  • mpf_le_sqrt(n) must be the result of {{mpf le sqrt(n)|a nonzero integer|sep = *|key/val_sep = ^}};
  • sep is the list items separator (default , ) and the map items separator (default , ) used in {{~mpf}};

where ,  gives , (comma followed by space.)

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)


{{~dpf|mpf = {{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}}

gives

2

{{~dpf|mpf = {{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|sep = ; |key/val_sep = ^}}|sep = ; }}

gives

2; 3; 5; 7

{{~dpf|mpf = {{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|sep =  * |key/val_sep = ^}}|sep =  * }}

gives

2 * 3 * 5 * 7

{{~dpf|mpf = {{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|sep =  + |key/val_sep = ^}}|sep =  + }}

gives

2 + 3 + 5 + 7
Code Result
{{~dpf|mpf = {{~mpf|-28|mpf_le_sqrt(n) = {{mpf le sqrt(n)|-28|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|-5|mpf_le_sqrt(n) = {{mpf le sqrt(n)|-5|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 5
{{~dpf|mpf = {{~mpf|1|mpf_le_sqrt(n) = {{mpf le sqrt(n)|1|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}}
{{~dpf|mpf = {{~mpf|7|mpf_le_sqrt(n) = {{mpf le sqrt(n)|7|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 7
{{~dpf|mpf = {{~mpf|15|mpf_le_sqrt(n) = {{mpf le sqrt(n)|15|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|27|mpf_le_sqrt(n) = {{mpf le sqrt(n)|27|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|30|mpf_le_sqrt(n) = {{mpf le sqrt(n)|30|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|97|mpf_le_sqrt(n) = {{mpf le sqrt(n)|97|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 97
{{~dpf|mpf = {{~mpf|111|mpf_le_sqrt(n) = {{mpf le sqrt(n)|111|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|199|mpf_le_sqrt(n) = {{mpf le sqrt(n)|199|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 199
{{~dpf|mpf = {{~mpf|211|mpf_le_sqrt(n) = {{mpf le sqrt(n)|211|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 211
{{~dpf|mpf = {{~mpf|5^3 * 11^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|5^3 * 11^2|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 5
{{~dpf|mpf = {{~mpf|2^5 * 3^3 * 5|mpf_le_sqrt(n) = {{mpf le sqrt(n)|2^5 * 3^3 * 5|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|2^9 * 3^3|mpf_le_sqrt(n) = {{mpf le sqrt(n)|2^9 * 3^3|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|37^2 + 8 * 37^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|37^2 + 8 * 37^2|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|2^9 * (26 + 1)|mpf_le_sqrt(n) = {{mpf le sqrt(n)|2^9 * (26 + 1)|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|89 * 113|mpf_le_sqrt(n) = {{mpf le sqrt(n)|89 * 113|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 89
{{~dpf|mpf = {{~mpf|79 * 79|mpf_le_sqrt(n) = {{mpf le sqrt(n)|79 * 79|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 79
{{~dpf|mpf = {{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|233^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|233^2|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 233
{{~dpf|mpf = {{~mpf|10000|mpf_le_sqrt(n) = {{mpf le sqrt(n)|10000|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|65535|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65535|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|65536|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65536|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 2
{{~dpf|mpf = {{~mpf|65537|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65537|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 65537
{{~dpf|mpf = {{~mpf|65539|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65539|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 65539
{{~dpf|mpf = {{~mpf|65541|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65541|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|65543|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65543|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 65543
{{~dpf|mpf = {{~mpf|65547|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65547|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|65549|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65549|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 11
{{~dpf|mpf = {{~mpf|65551|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65551|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 65551
{{~dpf|mpf = {{~mpf|65553|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65553|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3
{{~dpf|mpf = {{~mpf|65557|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65557|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 65557
{{~dpf|mpf = {{~mpf|65559|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65559|sep = *|key/val_sep = ^}}|key/val_sep = ^}}}} 3

Examples with invalid input

Input validation must be done by the {{Distinct prime factors}} (or {{dpf}}) arithmetic function template.

Code


{{#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 --> 
}}