This site is supported by donations to The OEIS Foundation.

Template:~Prime factors (with multiplicity)

From OeisWiki
Jump to: navigation, search

The {{~Prime factors (with multiplicity)}} (or {{~mpf}}) is the core function template used by the {{Prime factors (with multiplicity)}} (or {{mpf}} or {{factorization}}) arithmetic function template.

This core function template has been written to avoid calling the computationally expensive {{mpf le sqrt(n)}} arithmetic function template four times! MediaWiki templates only allow assignment-once (to parameters [argument variables] of a function template, since templates (and parser functions) are purely functional (albeit without recursion, i.e. templates cannot call themselves, either directly or indirectly!).

Usage

{{~Prime factors (with multiplicity)|a nonzero integer|mpf_le_sqrt(n) = (see valid input)|sep = map items separator (default  * )|key/val_sep = key/value separator (default ^)}}

or

{{~mpf|a nonzero integer|mpf_le_sqrt(n) = (see valid input)|sep = map items separator (default  * )|key/val_sep = key/value separator (default ^)}}

Valid input

  • the first argument must be the nonzero integer first argument of {{Prime factors (with multiplicity)}} (or {{mpf}} or {{factorization}});
  • mpf_le_sqrt(n) must be the result of {{mpf le sqrt(n)|the same nonzero integer|sep = *|key/val_sep = ^}};
  • sep is the map items separator (default  * );
  • key/val_sep is the key/value separator (default ^);

where the sep default  *  gives " * " (asterisk surrounded by spaces) and the key/val_sep default is ^.

Examples

To check the results, you may use

Examples with valid input

Note that the prime factorization of integer units −1 and 1 gives the empty product, hence the empty string is returned.

Code Result
{{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|sep = , |key/val_sep = : }} 2: 2, 3: 2, 5: 2, 7: 2
{{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|sep = ; |key/val_sep =  → }} 2 → 2; 3 → 2; 5 → 2; 7 → 2
{{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}|sep =  + |key/val_sep = *}} 2*2 + 3*2 + 5*2 + 7*2
{{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}}} 2^2 * 3^2 * 5^2 * 7^2
{{~mpf|-28|mpf_le_sqrt(n) = {{mpf le sqrt(n)|-28|sep = *|key/val_sep = ^}}}} 2^2 * 7^1
{{~mpf|-5|mpf_le_sqrt(n) = {{mpf le sqrt(n)|-5|sep = *|key/val_sep = ^}}}} 5^1
{{~mpf|1|mpf_le_sqrt(n) = {{mpf le sqrt(n)|1|sep = *|key/val_sep = ^}}}}
{{~mpf|7|mpf_le_sqrt(n) = {{mpf le sqrt(n)|7|sep = *|key/val_sep = ^}}}} 7^1
{{~mpf|15|mpf_le_sqrt(n) = {{mpf le sqrt(n)|15|sep = *|key/val_sep = ^}}}} 3^1 * 5^1
{{~mpf|27|mpf_le_sqrt(n) = {{mpf le sqrt(n)|27|sep = *|key/val_sep = ^}}}} 3^3
{{~mpf|30|mpf_le_sqrt(n) = {{mpf le sqrt(n)|30|sep = *|key/val_sep = ^}}}} 2^1 * 3^1 * 5^1
{{~mpf|97|mpf_le_sqrt(n) = {{mpf le sqrt(n)|97|sep = *|key/val_sep = ^}}}} 97^1
{{~mpf|111|mpf_le_sqrt(n) = {{mpf le sqrt(n)|111|sep = *|key/val_sep = ^}}}} 3^1 * 37^1
{{~mpf|199|mpf_le_sqrt(n) = {{mpf le sqrt(n)|199|sep = *|key/val_sep = ^}}}} 199^1
{{~mpf|211|mpf_le_sqrt(n) = {{mpf le sqrt(n)|211|sep = *|key/val_sep = ^}}}} 211^1
{{~mpf|5^3 * 11^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|5^3 * 11^2|sep = *|key/val_sep = ^}}}} 5^3 * 11^2
{{~mpf|2^5 * 3^3 * 5|mpf_le_sqrt(n) = {{mpf le sqrt(n)|2^5 * 3^3 * 5|sep = *|key/val_sep = ^}}}} 2^5 * 3^3 * 5^1
{{~mpf|2^9 * 3^3|mpf_le_sqrt(n) = {{mpf le sqrt(n)|2^9 * 3^3|sep = *|key/val_sep = ^}}}} 2^9 * 3^3
{{~mpf|37^2 + 8 * 37^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|37^2 + 8 * 37^2|sep = *|key/val_sep = ^}}}} 3^2 * 37^2
{{~mpf|2^9 * (26 + 1)|mpf_le_sqrt(n) = {{mpf le sqrt(n)|2^9 * (26 + 1)|sep = *|key/val_sep = ^}}}} 2^9 * 3^3
{{~mpf|89 * 113|mpf_le_sqrt(n) = {{mpf le sqrt(n)|89 * 113|sep = *|key/val_sep = ^}}}} 89^1 * 113^1
{{~mpf|79 * 79|mpf_le_sqrt(n) = {{mpf le sqrt(n)|79 * 79|sep = *|key/val_sep = ^}}}} 79^2
{{~mpf|210^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|210^2|sep = *|key/val_sep = ^}}}} 2^2 * 3^2 * 5^2 * 7^2
{{~mpf|233^2|mpf_le_sqrt(n) = {{mpf le sqrt(n)|233^2|sep = *|key/val_sep = ^}}}} 233^2
{{~mpf|10000|mpf_le_sqrt(n) = {{mpf le sqrt(n)|10000|sep = *|key/val_sep = ^}}}} 2^4 * 5^4
{{~mpf|65535|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65535|sep = *|key/val_sep = ^}}}} 3^1 * 5^1 * 17^1 * 257^1
{{~mpf|65536|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65536|sep = *|key/val_sep = ^}}}} 2^16
{{~mpf|65537|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65537|sep = *|key/val_sep = ^}}}} 65537^1
{{~mpf|65539|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65539|sep = *|key/val_sep = ^}}}} 65539^1
{{~mpf|65541|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65541|sep = *|key/val_sep = ^}}}} 3^1 * 7^1 * 3121^1
{{~mpf|65543|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65543|sep = *|key/val_sep = ^}}}} 65543^1
{{~mpf|65547|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65547|sep = *|key/val_sep = ^}}}} 3^2 * 7283^1
{{~mpf|65549|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65549|sep = *|key/val_sep = ^}}}} 11^1 * 59^1 * 101^1
{{~mpf|65551|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65551|sep = *|key/val_sep = ^}}}} 65551^1
{{~mpf|65553|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65553|sep = *|key/val_sep = ^}}}} 3^1 * 21851^1
{{~mpf|65557|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65557|sep = *|key/val_sep = ^}}}} 65557^1
{{~mpf|65559|mpf_le_sqrt(n) = {{mpf le sqrt(n)|65559|sep = *|key/val_sep = ^}}}} 3^1 * 13^1 * 41^2
{{~mpf|865535|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865535|sep = *|key/val_sep = ^}}}} 5^1 * 11^1 * 15737^1
{{~mpf|865536|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865536|sep = *|key/val_sep = ^}}}} 2^8 * 3^1 * 7^2 * 23^1
{{~mpf|865537|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865537|sep = *|key/val_sep = ^}}}} 865537^1
{{~mpf|865539|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865539|sep = *|key/val_sep = ^}}}} 3^3 * 32057^1
{{~mpf|865541|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865541|sep = *|key/val_sep = ^}}}} 37^1 * 149^1 * 157^1
{{~mpf|865543|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865543|sep = *|key/val_sep = ^}}}} 7^1 * 53^1 * 2333^1
{{~mpf|865547|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865547|sep = *|key/val_sep = ^}}}} 43^1 * 20129^1
{{~mpf|865549|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865549|sep = *|key/val_sep = ^}}}} 359^1 * 2411^1
{{~mpf|865551|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865551|sep = *|key/val_sep = ^}}}} 3^1 * 31^1 * 41^1 * 227^1
{{~mpf|865553|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865553|sep = *|key/val_sep = ^}}}} 13^1 * 139^1 * 479^1
{{~mpf|865557|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865557|sep = *|key/val_sep = ^}}}} 3^2 * 7^1 * 11^1 * 1249^1
{{~mpf|865559|mpf_le_sqrt(n) = {{mpf le sqrt(n)|865559|sep = *|key/val_sep = ^}}}} 23^1 * 37633^1

Examples with invalid input

Input validation must be done by the {{Prime factors (with multiplicity)}} (or {{mpf}} or {{factorization}}) arithmetic function template.

Code


{{#replace:{{#replace:{{{mpf_le_sqrt(n)|}}}|*|{{{sep| * }}}}}|^|{{{key/val_sep|^}}}}}<!--
-->{{#if: {{{mpf_le_sqrt(n)|}}}
| {{#ifexpr: ( ( abs ({{{1}}}) ) / ( {{{mpf_le_sqrt(n)}}} ) ) > 1
  | {{{sep| * }}}{{#expr: ( abs ({{{1}}}) ) / ( {{{mpf_le_sqrt(n)}}} ) }}{{{key/val_sep|^}}}1
  | <!-- no prime factor greater than sqrt(n) needs to be added -->
  }}
| {{#ifexpr: ( abs ({{{1}}}) ) > 1
  | {{#expr: abs ({{{1}}}) }}{{{key/val_sep|^}}}1 <!-- A prime number! --> 
  | <!-- empty list: empty product of primes for the units (+/-)1, undefined prime factorization for 0 -->
  }}  
}}