Category talk:Mathematical function templates

Clean up
This 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. J IM ptalk·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). J IM ptalk·cont 00:26, 2 November 2011 (UTC)

Oom
returned the order of magnitude of a number ... plus one. This was the code.

It was limited to the domain of 0.1 to 1016. Order of magnitude does a better job (with less code). was deleted in Septemer 2011. J IM ptalk·cont 00:45, 30 September 2011 (UTC)

Aboslute value and Abs
returned the absolute value of a number. This was the code.

It would have been more efficient to have used the  parser function instead of the nested  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.

Note, though, the above doesn't check for the existance of  so an   might be needed or you might use an   to deal with non-numeric inputs.

This template was also deleted in September 2011. J IM ptalk·cont 00:58, 30 September 2011 (UTC)

did the same. Here's the code.

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. J IM ptalk·cont 01:05, 13 October 2011 (UTC)

Sgn
The next to go was. This returned 1, 0 and -1 for positive numbers, zero and negative numbers respectively. J IM ptalk·cont 03:32, 27 September 2011 (UTC)

This template used nested s but instead we could use the following, which is simpler and, I believe, more efficient.

J IM ptalk·cont 05:08, 27 September 2011 (UTC)

Root
is supposed to give us the nth root of some real number, x. Here's the code:

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

... But 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  does the job. J IM ptalk·cont 06:29, 27 September 2011 (UTC)

Addition and Add optional
Addition and simply add numbers. I don't see the point. These templates differ in two respects.

Firstly they differ wrt how they handle unspecified parameters. sets them to zero like this.

, on the other hand, uses s like this

Secondly, they differ with respect to capacity. can take up to ten parameters as shown in the code above. , on the other hand, takes up to one hundred parameters. The above code is an abbreviated version.

J IM ptalk·cont 01:21, 29 September 2011 (UTC)

Subtraction
subtracts parameter two from parameter one. Here's the code.

That's it. is shorter than. This is pointless. I've sent it to TDF. J IM ptalk·cont 01:32, 29 September 2011 (UTC)

Factorial
Here's another template we probably don't need. 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  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 ... =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{{#ifeq:{{#expr:{{{1}}}>=11}}|1|*11{{#ifeq:{{#expr:{{{1}}}>=12}}|1|*12{{#ifeq:{{#expr:{{{1}}}>=13}}|1|*13{{#ifeq:{{#expr:{{{1}}}>=14}}|1|*14{{#ifeq:{{#expr:{{{1}}}>=15}}|1|*15{{#ifeq:{{#expr:{{{1}}}>=16}}|1|*16{{#ifeq:{{#expr:{{{1}}}>=17}}|1|*17{{#ifeq:{{#expr:{{{1}}}>=18}}|1|*18{{#ifeq:{{#expr:{{{1}}}>=19}}|1|*19{{#ifeq:{{#expr:{{{1}}}>=20}}|1|*20{{#ifeq:{{#expr:{{{1}}}>=21}}|1|*21{{#ifeq:{{#expr:{{{1}}}>=22}}|1|*22{{#ifeq:{{#expr:{{{1}}}>=23}}|1|*23{{#ifeq:{{#expr:{{{1}}}>=24}}|1|*24{{#ifeq:{{#expr:{{{1}}}>=25}}|1|*25{{#ifeq:{{#expr:{{{1}}}>=26}}|1|*26{{#ifeq:{{#expr:{{{1}}}>=27}}|1|*27{{#ifeq:{{#expr:{{{1}}}>=28}}|1|*28{{#ifeq:{{#expr:{{{1}}}>=29}}|1|*29{{#ifeq:{{#expr:{{{1}}}>=30}}|1|*30{{#ifeq:{{#expr:{{{1}}}>=31}}|1|*31{{#ifeq:{{#expr:{{{1}}}>=32}}|1|*32{{#ifeq:{{#expr:{{{1}}}>=33}}|1|*33{{#ifeq:{{#expr:{{{1}}}>=34}}|1|*34{{#ifeq:{{#expr:{{{1}}}>=35}}|1|*35{{#ifeq:{{#expr:{{{1}}}>=36}}|1|*36{{#ifeq:{{#expr:{{{1}}}>=37}}|1|*37{{#ifeq:{{#expr:{{{1}}}>=38}}|1|*38{{#ifeq:{{#expr:{{{1}}}>=39}}|1|*39{{#ifeq:{{#expr:{{{1}}}>=40}}|1|*40{{#ifeq:{{#expr:{{{1}}}>=41}}|1|*41{{#ifeq:{{#expr:{{{1}}}>=42}}|1|*42{{#ifeq:{{#expr:{{{1}}}>=43}}|1|*43{{#ifeq:{{#expr:{{{1}}}>=44}}|1|*44{{#ifeq:{{#expr:{{{1}}}>=45}}|1|*45{{#ifeq:{{#expr:{{{1}}}>=46}}|1|*46{{#ifeq:{{#expr:{{{1}}}>=47}}|1|*47{{#ifeq:{{#expr:{{{1}}}>=48}}|1|*48{{#ifeq:{{#expr:{{{1}}}>=49}}|1|*49{{#ifeq:{{#expr:{{{1}}}>=50}}|1|*50{{#ifeq:{{#expr:{{{1}}}>=51}}|1|*51{{#ifeq:{{#expr:{{{1}}}>=52}}|1|*52{{#ifeq:{{#expr:{{{1}}}>=53}}|1|*53{{#ifeq:{{#expr:{{{1}}}>=54}}|1|*54{{#ifeq:{{#expr:{{{1}}}>=55}}|1|*55{{#ifeq:{{#expr:{{{1}}}>=56}}|1|*56{{#ifeq:{{#expr:{{{1}}}>=57}}|1|*57{{#ifeq:{{#expr:{{{1}}}>=58}}|1|*58{{#ifeq:{{#expr:{{{1}}}>=59}}|1|*59{{#ifeq:{{#expr:{{{1}}}>=60}}|1|*60{{#ifeq:{{#expr:{{{1}}}>=61}}|1|*61{{#ifeq:{{#expr:{{{1}}}>=62}}|1|*62{{#ifeq:{{#expr:{{{1}}}>=63}}|1|*63{{#ifeq:{{#expr:{{{1}}}>=64}}|1|*64{{#ifeq:{{#expr:{{{1}}}>=65}}|1|*65{{#ifeq:{{#expr:{{{1}}}>=66}}|1|*66{{#ifeq:{{#expr:{{{1}}}>=67}}|1|*67{{#ifeq:{{#expr:{{{1}}}>=68}}|1|*68{{#ifeq:{{#expr:{{{1}}}>=69}}|1|*69{{#ifeq:{{#expr:{{{1}}}>=70}}|1|*70{{#ifeq:{{#expr:{{{1}}}>=71}}|1|*71{{#ifeq:{{#expr:{{{1}}}>=72}}|1|*72{{#ifeq:{{#expr:{{{1}}}>=73}}|1|*73{{#ifeq:{{#expr:{{{1}}}>=74}}|1|*74{{#ifeq:{{#expr:{{{1}}}>=75}}|1|*75{{#ifeq:{{#expr:{{{1}}}>=76}}|1|*76{{#ifeq:{{#expr:{{{1}}}>=77}}|1|*77{{#ifeq:{{#expr:{{{1}}}>=78}}|1|*78{{#ifeq:{{#expr:{{{1}}}>=79}}|1|*79{{#ifeq:{{#expr:{{{1}}}>=80}}|1|*80{{#ifeq:{{#expr:{{{1}}}>=81}}|1|*81{{#ifeq:{{#expr:{{{1}}}>=82}}|1|*82{{#ifeq:{{#expr:{{{1}}}>=83}}|1|*83{{#ifeq:{{#expr:{{{1}}}>=84}}|1|*84{{#ifeq:{{#expr:{{{1}}}>=85}}|1|*85{{#ifeq:{{#expr:{{{1}}}>=86}}|1|*86{{#ifeq:{{#expr:{{{1}}}>=87}}|1|*87{{#ifeq:{{#expr:{{{1}}}>=88}}|1|*88{{#ifeq:{{#expr:{{{1}}}>=89}}|1|*89{{#ifeq:{{#expr:{{{1}}}>=90}}|1|*90{{#ifeq:{{#expr:{{{1}}}>=91}}|1|*91{{#ifeq:{{#expr:{{{1}}}>=92}}|1|*92{{#ifeq:{{#expr:{{{1}}}>=93}}|1|*93{{#ifeq:{{#expr:{{{1}}}>=94}}|1|*94{{#ifeq:{{#expr:{{{1}}}>=95}}|1|*95{{#ifeq:{{#expr:{{{1}}}>=96}}|1|*96{{#ifeq:{{#expr:{{{1}}}>=97}}|1|*97{{#ifeq:{{#expr:{{{1}}}>=98}}|1|*98{{#ifeq:{{#expr:{{{1}}}>=99}}|1|*99}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}} -->

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 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 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 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.

J IM p{{sub| talk·cont}} 03:29, 29 September 2011 (UTC)

Rangemap
According to the documentation "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.

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  parameter x. We're mapping xs (the domain) to ys (the range). Let's call  and   x0 and x1 respectively. Let's similarly call  and   y0 and y1 respectively. Ignoring the rounding we can then write


 * $$y = \frac{x - x_0}{x_1 - x_0} (y_1 - y_0) + y_0,\,$$

which we can rearrange as


 * $$\frac{y - y_0}{x - x_0} = \frac{y_1 - y_0}{x_1 - x_0}\,$$

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. J IM ptalk·cont 02:53, 30 September 2011 (UTC)

It's now up for deletion. J IM ptalk·cont 02:19, 6 October 2011 (UTC)

Now gone. J IM ptalk·cont 15:11, 12 October 2011 (UTC)

Factor
checks whether parameter two is a factor of parameter one. Here's the code.

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. J IM ptalk·cont 01:11, 9 October 2011 (UTC)

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.

This template is also four and a half years old and without any transclusions at all. J IM ptalk·cont 01:11, 9 October 2011 (UTC)

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.

does a similar job but with a few important differences.
 * works with strings of characters whereas looks at numbers.  Decimal points and digits after them count for  but not for .   fails (appending "value out of range") for negative numbers whereas  just considers the hyphen (the minus) to be another character.   will stick zero onto an nonnumeric string whereas  will give a parser function error message.
 * returns strings of twelve charaters or more as they are.  fails (appending "value out of range") for numbers $1$ or greater.

The code of could be rewritten to make use of  but the question would be "What's the point?" What is the point of ? 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. J IM ptalk·cont 01:11, 9 October 2011 (UTC)

Digit
is almost five years old and is never used. Here's the code:

Here's the description of its usage

This template gives the numeric value of the digit in a specified numeral system. 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")
 * 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.


 * Usage&#58;
 * All parameters must be positive integers.
 * All parameters must be positive integers.

We don't need this. J IM ptalk·cont 15:26, 12 October 2011 (UTC)