User:Arseniiv/Factorization/Doc: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
Arseniiv (talk | contribs)
doc
 
Arseniiv (talk | contribs)
updated for mk2
Line 1: Line 1:
This template outputs a pleasant prime factorization given primes and their exponents, up to eight of each (this should be enough?). If an exponent is simply 1, leave the argument blank and it will be omitted.
This template outputs prime factorization in a pleasant form, given a plain-text expression.
 
For multiplication use <code>*</code> or simply space. For exponentiation use <code>**</code> or <code>^</code>. You can add extra spaces around all these, just not between <code>-</code> and an exponent.
 
One of good choices to write a readable source text is using spaces between factors and no space around exponentiation (the first two examples below).


{| class="wikitable"
{| class="wikitable"
Line 5: Line 9:
! Output
! Output
|-
|-
| <code><nowiki>{{</nowiki>{{BASEPAGENAME}}<nowiki>|2|3|5|−1}}</nowiki></code>  
| <pre>{{Factorization|2^3 5 23^-3 31}}</pre>
| {{../|2|3|5|−1}}  
| {{#replace: {{#regex: {{#regex: 2^3 5 23^-3 31|/(\d+)\s*(?:(?:\*\*{{!}}\^)\s*([-−]?\d+))?(?:\s*\*)?\s*/u|\1<sup>\2</sup> ⋅&nbsp;}}|/\s⋅&nbsp;$/u|}}|-|}}
|-
| <pre>{{Factorization| 2**3 * 5 * 7**-5 * 11**9 19**-4 }}</pre>
| {{#replace: {{#regex: {{#regex:  2**3 * 5 * 7**-5 * 11**9 * 19**-4 |/(\d+)\s*(?:(?:\*\*{{!}}\^)\s*([-−]?\d+))?(?:\s*\*)?\s*/u|\1<sup>\2</sup> ⋅&nbsp;}}|/\s⋅&nbsp;$/u|}}|-|}}
|-
|-
| <code><nowiki>{{</nowiki>{{BASEPAGENAME}}<nowiki>|3|−4|7||19|−1|31}}</nowiki></code>  
| <pre>{{Factorization|3*7^-2*11*13^-1}}</pre>
| {{../|3|−4|7||19|−1|31}}  
| {{#replace: {{#regex: {{#regex: 3*7^-2*11 13^-1|/(\d+)\s*(?:(?:\*\*{{!}}\^)\s*([-−]?\d+))?(?:\s*\*)?\s*/u|\1<sup>\2</sup> ⋅&nbsp;}}|/\s⋅&nbsp;$/u|}}|-|}}
|-
|-
| <code><nowiki>{{</nowiki>{{BASEPAGENAME}}<nowiki>}}</nowiki></code>
| <pre>{{Factorization}}</pre>
| {{../}}  
| {{#replace: {{#regex: {{#regex: 1|/(\d+)\s*(?:(?:\*\*{{!}}\^)\s*([-−]?\d+))?(?:\s*\*)?\s*/u|\1<sup>\2</sup> ⋅&nbsp;}}|/\s⋅&nbsp;$/u|}}|-|}}
|}
|}

Revision as of 23:10, 7 November 2020

This template outputs prime factorization in a pleasant form, given a plain-text expression.

For multiplication use * or simply space. For exponentiation use ** or ^. You can add extra spaces around all these, just not between - and an exponent.

One of good choices to write a readable source text is using spaces between factors and no space around exponentiation (the first two examples below).

Input Output
{{Factorization|2^3 5 23^-3 31}}
/(\d+)\s*(?:(?:\*\*|\^)\s*([−−]?\d+))?(?:\s*\*)?\s*/u|\1\2 ⋅ }}|/\s⋅ $/u|}}
{{Factorization| 2**3 * 5 * 7**-5 * 11**9 19**-4 }}
/(\d+)\s*(?:(?:\*\*|\^)\s*([−−]?\d+))?(?:\s*\*)?\s*/u|\1\2 ⋅ }}|/\s⋅ $/u|}}
{{Factorization|3*7^-2*11*13^-1}}
/(\d+)\s*(?:(?:\*\*|\^)\s*([−−]?\d+))?(?:\s*\*)?\s*/u|\1\2 ⋅ }}|/\s⋅ $/u|}}
{{Factorization}}
/(\d+)\s*(?:(?:\*\*|\^)\s*([−−]?\d+))?(?:\s*\*)?\s*/u|\1\2 ⋅ }}|/\s⋅ $/u|}}