Category talk:Mathematical function templates
![]() | This category does not require a rating on Wikipedia's content assessment scale. It is of interest to the following WikiProjects: | ||||||||||||||
|
Clean up
editThis category contains a bunch of templates which will probably never be used. I believe it's time to clean up. I've already sent a couple of them to WP:TFD. I'll be sending more I think. JIMp talk·cont 02:19, 27 September 2011 (UTC)
Σ has asked for some of these templates to be put into his/her userspace (at User:Σ/Testing facility/xxx). This has been done (except for the addition templates which are still kicking around). JIMp talk·cont 00:26, 2 November 2011 (UTC)
Oom
edit{{Oom}} returned the order of magnitude of a number ... plus one. This was the code.
{{{{{subst|}}}#expr:(({{{1}}})>=0)-1+(({{{1}}})>=1)+(({{{1}}})>=10)+(({{{1}}})>=100)+(({{{1}}})>=1000)+(({{{1}}})>=10000)+(({{{1}}})>=100000)+(({{{1}}})>=1000000)+(({{{1}}})>=10000000)+(({{{1}}})>=100000000)+(({{{1}}})>=1000000000)+(({{{1}}})>=10000000000)+(({{{1}}})>=100000000000)+(({{{1}}})>=1000000000000)+(({{{1}}})>=10000000000000)+(({{{1}}})>=100000000000000)+(({{{1}}})>=1000000000000000)}}
It was limited to the domain of 0.1 to 1016. {{Order of magnitude}} does a better job (with less code). {{Oom}} was deleted in Septemer 2011. JIMp talk·cont 00:45, 30 September 2011 (UTC)
Aboslute value and Abs
edit{{Absolute value}} returned the absolute value of a number. This was the code.
{{#if:{{{1|}}}|{{#ifexpr:({{{1}}})>0|{{{1|}}}|{{#ifexpr:({{{1}}})=0|0|{{#expr:-{{{1|}}}}}}}}}}}
It would have been more efficient to have used the abs
parser function instead of the nested #ifexpr:
s. But the real question is why we need a template for this at all given that there exists the parser function. Just use this.
{{#expr:abs({{{1}}})}}
Note, though, the above doesn't check for the existance of {{{1}}}
so an #if:
might be needed or you might use an #iferror:
to deal with non-numeric inputs.
This template was also deleted in September 2011. JIMp talk·cont 00:58, 30 September 2011 (UTC)
{{Abs}} did the same. Here's the code.
{{#expr:abs({{{1|0}}})}}
It has no significant transclusions (only a handful of testpages, talk pages, archives, etc.). It has been wasting space for just over five years. It's time for it to go also. JIMp talk·cont 01:05, 13 October 2011 (UTC)
Sgn
editThe next to go was {{Sgn}}. This returned 1, 0 and -1 for positive numbers, zero and negative numbers respectively. JIMp talk·cont 03:32, 27 September 2011 (UTC)
This template used nested #ifexpr
s but instead we could use the following, which is simpler and, I believe, more efficient.
{{#expr:({{{1}}}>0)-({{{1}}}<0)}}
JIMp talk·cont 05:08, 27 September 2011 (UTC)
Root
edit{{Root|x|n}} is supposed to give us the nth root of some real number, x. Here's the code:
{{#expr: abs({{{1}}})^(1/{{{2|2}}}) }}{{#ifexpr:{{{1}}}<0 and {{{2|2}}} mod 2 = 0 |i}}
Can you spot the problem?
Created in the dark old days before the operator ^
was available, this originally gave us the square root of a number via a rather involved algorithm. The new parser function allowed for a great simplification of code. In May 2008 the template was extended to handle x less than zero and, two minutes later, to handle n greater than two. Here's the thing: what happens when x<0 and n>2? It doesn't work.
Do we fix it up so it'll give us the proper complex roots of complex numbers? We can make these fancy templates which do this fancy stuff. We can amass a wonderous collection. The question is whether they'll ever be used. We might as well forget complex number, stick to reals instead and simply use this
{{#expr:({{{1}}})^(1/{{{2|2}}})}}
... But {{root}} has been hanging around for four and a half years and has only six transclusions:
- one on the template doc page & thence one on the template page itself,
- two in the User and User talk space,
- one in the Help desk archives and
- one on Help:Calculation.
We don't need it. Plain old #expr
does the job. JIMp talk·cont 06:29, 27 September 2011 (UTC)
Addition and Add optional
edit{{Addition}} and {{add optional}} simply add numbers. I don't see the point. These templates differ in two respects.
Firstly they differ wrt how they handle unspecified parameters. {{Addition}} sets them to zero like this.
{{ #expr:{{{1|0}}}+{{{2|0}}}+{{{3|0}}}+{{{4|0}}}+{{{5|0}}}+{{{6|0}}}+{{{7|0}}}+{{{8|0}}}+{{{9|0}}}+{{{10|0}}}}}
{{Add optional}}, on the other hand, uses #if
s like this
{{#expr:(0 {{#if:{{{1|}}}|+{{{1}}}}} {{#if:{{{2|}}}|+{{{2}}}}} {{#if:{{{3|}}}|+{{{3}}}}} {{#if:{{{4|}}}|+{{{4}}}}} {{#if:{{{5|}}}|+{{{5}}}}} {{#if:{{{6|}}}|+{{{6}}}}} {{#if:{{{7|}}}|+{{{7}}}}} {{#if:{{{8|}}}|+{{{8}}}}} {{#if:{{{9|}}}|+{{{9}}}}} {{#if:{{{10|}}}|+{{{10}}}}} )}}
Secondly, they differ with respect to capacity. {{Addition}} can take up to ten parameters as shown in the code above. {{Add optional}}, on the other hand, takes up to one hundred parameters. The above code is an abbreviated version.
JIMp talk·cont 01:21, 29 September 2011 (UTC)
Subtraction
edit{{Subtraction}} subtracts parameter two from parameter one. Here's the code.
{{#expr:{{{1|0}}}-{{{2|0}}}}}
That's it. {{#expr:10|5
}} is shorter than {{subtraction|10|5
}}. This is pointless. I've sent it to TDF. JIMp talk·cont 01:32, 29 September 2011 (UTC)
Factorial
editHere's another template we probably don't need. {{Factorial|n}} returns n!. It works for n up to 99. The code starts out like this. (Note the elipsis isn't part of the code. The code goes on to 99 then all the #ifeq:
s get closed.
{{#expr:{{#ifeq:{{#expr:{{{1}}}>=00}}|1|01{{#ifeq:{{#expr:{{{1}}}>=01}}|1|*01{{#ifeq:{{#expr:{{{1}}}>=02}}|1|*02{{#ifeq:{{#expr:{{{1}}}>=03}}|1|*03{{#ifeq:{{#expr:{{{1}}}>=04}}|1|*04{{#ifeq:{{#expr:{{{1}}}>=05}}|1|*05{{#ifeq:{{#expr:{{{1}}}>=06}}|1|*06{{#ifeq:{{#expr:{{{1}}}>=07}}|1|*07{{#ifeq:{{#expr:{{{1}}}>=08}}|1|*08{{#ifeq:{{#expr:{{{1}}}>=09}}|1|*09{{#ifeq:{{#expr:{{{1}}}>=10}}|1|*10 ...
Let me rearrange this for ease of comprehension.
{{#expr: {{#ifeq:{{#expr:{{{1}}}>=00}}|1|01 {{#ifeq:{{#expr:{{{1}}}>=01}}|1|*01 {{#ifeq:{{#expr:{{{1}}}>=02}}|1|*02 {{#ifeq:{{#expr:{{{1}}}>=03}}|1|*03 {{#ifeq:{{#expr:{{{1}}}>=04}}|1|*04 {{#ifeq:{{#expr:{{{1}}}>=05}}|1|*05 {{#ifeq:{{#expr:{{{1}}}>=06}}|1|*06 {{#ifeq:{{#expr:{{{1}}}>=07}}|1|*07 {{#ifeq:{{#expr:{{{1}}}>=08}}|1|*08 {{#ifeq:{{#expr:{{{1}}}>=09}}|1|*09 {{#ifeq:{{#expr:{{{1}}}>=10}}|1|*10 ...
This could be simplified as follows.
{{#expr: {{#ifexpr:{{{1}}}>=0|1 {{#ifexpr:{{{1}}}>=1|*1 {{#ifexpr:{{{1}}}>=2|*2 {{#ifexpr:{{{1}}}>=3|*3 {{#ifexpr:{{{1}}}>=4|*4 {{#ifexpr:{{{1}}}>=5|*5 {{#ifexpr:{{{1}}}>=6|*6 {{#ifexpr:{{{1}}}>=7|*7 {{#ifexpr:{{{1}}}>=8|*8 {{#ifexpr:{{{1}}}>=9|*9 {{#ifexpr:{{{1}}}>=10|*10 ...
We could instead get rid of the if
s all together like this.
{{#expr:1 *2^({{{1}}}>=2) *3^({{{1}}}>=3) *4^({{{1}}}>=4) *5^({{{1}}}>=5) *6^({{{1}}}>=6) *7^({{{1}}}>=7) *8^({{{1}}}>=8) *9^({{{1}}}>=9) *10^({{{1}}}>=10) }}
There's a trade-off here though. We're cutting out the if
s but making a long expression (lots of multiplying by one). Which would be best would depend on the size of the number. I'd actually go for a sort of hybrid. I'd check every for tenth integer using nested ifexpr:
s then multiply the remaining nine using a code like the above which would be off on a subtemplate. But I'm letting myself get carried away.
Yes, it's so much fun designing these. It seems to me that to some degree we can explain the proliferation of maths function templates in terms of how much fun it is to design the things. It's not everyone's cup of tea but some of us like to make them. The problem is, of course, the template space is not the place for this. We should refrain from creating maths function templates just because we can. We've got to ask whether they're useful.
This particular template is a perfect example. It was created about four and a half years ago. It is currently transcluded on its own doc page and thence on the template page itself. And that's the extent of its use. We just don't need it. It's time for it to go.
JIMp talk·cont 03:29, 29 September 2011 (UTC)
Rangemap
editAccording to the documentation {{rangemap}} "Re-maps a number from one range to another. That is, a value of from_low would get mapped to to_low, a value of from_high to to_high, values in-between to values in-between, etc." This is the code.
{{#expr: (({{{value|{{{1}}}}}}-{{{from_low|{{{2}}}}}}) / ({{{from_high|{{{3}}}}}} - {{{from_low|{{{2}}}}}}) * ({{{to_high|{{{5|1}}}}}} - {{{to_low|{{{4|0}}}}}}) + {{{to_low|{{{4|0}}}}}}) {{#if:{{{precision|}}}| round {{{precision}}}}}}}
Perhaps you'll recognise this linear function (if you've taken high school Cartesian geometry). Let's rewrite it as a mathematical formula. Let's call the output y and the value
parameter x. We're mapping xs (the domain) to ys (the range). Let's call from_low
and from_high
x0 and x1 respectively. Let's similarly call to_low
and to_high
y0 and y1 respectively. Ignoring the rounding we can then write
which we can rearrange as
Does it look familiar? We can define a linear function by specifying two points, (x0, y0) and (x1, y1), on the x-y plane then for a given x in the domain we can determine the corresponding y in the range. This is what the template does.
Is this any use? Well, it was created two years ago by Zocky "for use in the new version of Template:Location map". It's used on {{Location map/rangemaplat}} and {{Location map/rangemaplon}}. The only other place it's used is in the archived discussion about the new version. Was this an abondoned project? I'd better ask Zocky. JIMp talk·cont 02:53, 30 September 2011 (UTC)
It's now up for deletion. JIMp talk·cont 02:19, 6 October 2011 (UTC)
Now gone. JIMp talk·cont 15:11, 12 October 2011 (UTC)
Factor
edit{{Factor}} checks whether parameter two is a factor of parameter one. Here's the code.
{{#ifeq:{{#expr:floor({{{1}}}/{{{2}}})}}|{{#expr:({{{1}}}/{{{2}}})}}|{{{then|1}}}|{{{else|0}}}}}
I was created four and a half years ago and is currently transcluded on its own doc page, thence on the template page and nowhere else. We don't need it. JIMp talk·cont 01:11, 9 October 2011 (UTC)
Ifbetween
edit{{Ifbetween}} evaluates its first numeric parameter to see whether it is in the closed range defined by its second and third numeric parameters. Here's the code.
{{#ifexpr:({{{1}}})>=({{{2}}})and({{{1}}})<=({{{3}}})|{{{4|}}}|{{{5|}}}}}
This template is also four and a half years old and without any transclusions at all. JIMp talk·cont 01:11, 9 October 2011 (UTC)
Lz12
edit{{Lz12}} adds leading zeros to a number until there are twelve digits before the decimal point (or where the decimal point would be). Here's the code.
{{{{{subst|}}}#switch: {{{{{subst|}}}#expr: -1+(0 <= {{{1}}})+(1 <= ({{{1}}}))+(10 <= ({{{1}}}))+(100 <= ({{{1}}}))+(1000 <= ({{{1}}}))+(10000 <= ({{{1}}}))+(100000 <= ({{{1}}}))+(1000000 <= ({{{1}}}))+(10000000 <= ({{{1}}}))+(100000000 <= ({{{1}}}))+(1000000000 <= ({{{1}}}))+(10000000000 <= ({{{1}}}))+(100000000000 <= ({{{1}}}))+(1000000000000 <= ({{{1}}}))+(10000000000000 <= ({{{1}}}))+(100000000000000 <= ({{{1}}}))+(1000000000000000 <= ({{{1}}}))}} |0|1=00000000000 | 2=0000000000 | 3=000000000 | 4=00000000 | 5=0000000 | 6=000000 | 7=00000 | 8=0000 | 9=000 | 10=00 | 11=0 | 12= |value out of range:}}{{{{{subst|}}}#expr: {{{1}}}}}
{{padleft:{{{1}}}|12|0
}} does a similar job but with a few important differences.
- {{
padleft:{{{1}}}|12|0
}} works with strings of characters whereas {{lz12}} looks at numbers. Decimal points and digits after them count for {{padleft:{{{1}}}|12|0
}} but not for {{lz12}}. {{Lz12}} fails (appending "value out of range") for negative numbers whereas {{padleft:{{{1}}}|12|0
}} just considers the hyphen (the minus) to be another character. {{padleft:{{{1}}}|12|0
}} will stick zero onto an nonnumeric string whereas {{lz12}} will give a parser function error message. - {{
padleft:{{{1}}}|12|0
}} returns strings of twelve charaters or more as they are. {{Lz12}} fails (appending "value out of range") for numbers 1×1013 or greater.
The code of {{lz12}} could be rewritten to make use of {{padleft:
}} but the question would be "What's the point?" What is the point of {{lz12}}? In August 2007 Fran Rogers imported "this very useful template from meta". It is currently used only on itself. I say that calling it "very useful" is not quite correct (perhaps it was at the time but not currently), "very useless" is seems more accurate. JIMp talk·cont 01:11, 9 October 2011 (UTC)
Digit
edit{{Digit}} is almost five years old and is never used. Here's the code:
{{#expr:floor({{{1}}}/({{{3}}}^({{{2}}}-1)))mod{{{3}}}}}
Here's the description of its usage
This template gives the numeric value of the digit in a specified numeral system.
- The first parameter gives the decimal value.
- The second parameter is the digit (1 being the rightmost, 2 the one to the left etcetera).
- The third parameter is the numeral system, 2 for binary, 8 for octal, 16 for hexadecimal.
For systems > 10, the value is given in decimals, for instance, 15 in the hexadecimal system will give for the rightmost digit 15 (which should be "F")
- Usage:
{{Digit|decimal integer|digit no|numeral system number}}
- All parameters must be positive integers.
We don't need this. JIMp talk·cont 15:26, 12 October 2011 (UTC)