This site is supported by donations to The OEIS Foundation.
Template:MAX
[⧼Purge⧽ Template:MAX]
The {{MAX}} mathematical function template gives the maximum of one to eighty-one numbers or mathematical expressions. (For up to three arguments, please use {{max}} instead.)
Contents
Usage
- {{MAX|expression}} (trivial case)
or
- {{MAX|expression 1|...|expression 81}}
Valid arguments
One to eighty-one numbers or mathematical expressions as arguments.
Examples
Examples with valid arguments
Code Result {{MAX|7|2|15}} 15 {{MAX|2|-7|-15}} 2 {{MAX|-7|2|-15}} 2 {{MAX|2|-15|-7}} 2 {{MAX|-7|-15|2}} 2 {{MAX|-15|2|-7}} 2 {{MAX|-15|-7|2}} 2 {{MAX|34|-3}} 34 {{MAX|-34|-3}} -3 {{MAX|-34}} -34 {{MAX|7|2|15|40}} 40
{{MAX|7|2|15|56|90|34|-65}} yields
- 90
{{MAX|7|2|15|56|90|34|-65|-8|78|878|-74|867|564|75|-67|77836|53565|-2|837|873|-84|2874|287|4289|93|9927|-2731}} yields
- 77836
{{MAX|7|2|15|56|90|34|-65|{{formatnum:2,000|R}}|78}} yields (remove format from formatted numbers)
- 2000
{{MAX | 7| 2| 15| 56| 90| 34| -65| -8| 78| 878| -74| 867| 564| 75| -67|77836|53565| -2| 837| 873| -84| 2874| 287| 4289| 93| 9927|-2731 | 3| 0| 35| 56| 90| 34| -65| -8| 67| 878| -74| 367| 564| 75| -62| -789|53565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-7771 }}
yields
- 77836
{{MAX | 7| 2| 15| 56| 90| 34| -65| -8| 78| 878| -74| 867| 564| 75| -67|77836|53565| -2| 837| 873| -84| 2874| 287| 4289| 93| 9927|-2731 | 3| 0| 35| 56| 90| 34| -65| -8| 67| 878| -74| 367| 564| 75| -62| -789|53565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-7771 |3645| 0| 2335| -756|-890| 34| -65| -8| 67| 878|-653| 367| 564| 75| -62| -789|99565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-9995 }}
yields
- 77836
{{MAX | 7| 2| 15| 56| 90| 34| -65| -8| 78| 878| -74| 867| 564| 75| -67|77836|53565| -2| 837| 873| -84| 2874| 287| 4289| 93| 9927|-2731 | 3| 0| 35| 56| 90| 34| -65| -8| 67| 878| -74| 367| 564| 75| -62| -789|53565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-7771 |3645| 0| 2335| -756|-890| 34| -65| -8| 67| 878|-653| 367| 564| 75| -62| -789|99565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-7771 }}
yields
- 77836
Examples with invalid arguments
Code Result {{MAX}} MAX error: One to eighty-one unformatted numbers required as arguments {{MAX|one}} MAX error: One to eighty-one unformatted numbers required as arguments {{MAX|34|-3 blobs}} Expression error: Unexpected < operator. {{MAX|34|blobs}} Expression error: Unexpected < operator. {{MAX|7|blob|15}} Expression error: Unexpected < operator. {{MAX|7|15|blob}} Expression error: Unexpected < operator. {{MAX|34|-3,000}} Expression error: Unexpected < operator.
{{MAX | 7| 2| 15| 56| 90| 34| -65| -8| 78| 878| -74| 867| 564| 75| -67|77836|53565| -2| 837| 873| -84| 2874| 287| 4289| 93| 9927|-2731 | 3| 0| 35| 56| 90| 34| -65| -8| 67| 878| -74| 367| 564| 75| -62| -789|53565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-7771 |3645| 0| 2335| -756|-890| 34| -65| -8| 67| 878|-653| 367| 564| 75| -62| -789|-9565| -2| 837| 873|-2884| 2874| 287| 4289| 93| 9927|-7771 |99995 }}
yields
- MAX error: Too many arguments (one to eighty-one unformatted numbers required as arguments)
{{MAX|7|2|15|56|90|34|-65|-8|78|878|-74|867|564|75|-67|oops|837|873|-84|2874|287|4289|93|9927|-2731|63}} yields
- Expression error: Unexpected < operator.
{{MAX|7|2|15|56|90|34|-65|-8|78|878|-74|867|564|75|-67|2,000|837|873|-84|2874|287|4289|93|9927|-2731|63}} yields
- Expression error: Unexpected < operator. (formatted numbers are not allowed!)
Code
<noinclude>{{Documentation}}</noinclude><includeonly><!-- This function uses the core functions * {{tlxb|~Max3}}, {{tlxb|~Max9}}, {{tlxb|~Max27}}, {{tlxb|~Max81}} -->{{#if: {{{82|}}} | {{error| MAX error: Too many arguments (one to eighty-one [[unformatted numbers]] required as arguments) }} | {{ifnum| {{{1}}} | {{#if: {{{4|}}} | {{#if: {{{10|}}} | {{#if: {{{28|}}} | {{~Max81 | {{{1|}}} | {{{2|}}} | {{{3|}}} | {{{4|}}} | {{{5|}}} | {{{6|}}} | {{{7|}}} | {{{8|}}} | {{{9|}}} | {{{10|}}} | {{{11|}}} | {{{12|}}} | {{{13|}}} | {{{14|}}} | {{{15|}}} | {{{16|}}} | {{{17|}}} | {{{18|}}} | {{{19|}}} | {{{20|}}} | {{{21|}}} | {{{22|}}} | {{{23|}}} | {{{24|}}} | {{{25|}}} | {{{26|}}} | {{{27|}}} | {{{28|}}} | {{{29|}}} | {{{30|}}} | {{{31|}}} | {{{32|}}} | {{{33|}}} | {{{34|}}} | {{{35|}}} | {{{36|}}} | {{{37|}}} | {{{38|}}} | {{{39|}}} | {{{40|}}} | {{{41|}}} | {{{42|}}} | {{{43|}}} | {{{44|}}} | {{{45|}}} | {{{46|}}} | {{{47|}}} | {{{48|}}} | {{{49|}}} | {{{50|}}} | {{{51|}}} | {{{52|}}} | {{{53|}}} | {{{54|}}} | {{{55|}}} | {{{56|}}} | {{{57|}}} | {{{58|}}} | {{{59|}}} | {{{60|}}} | {{{61|}}} | {{{62|}}} | {{{63|}}} | {{{64|}}} | {{{65|}}} | {{{66|}}} | {{{67|}}} | {{{68|}}} | {{{69|}}} | {{{70|}}} | {{{71|}}} | {{{72|}}} | {{{73|}}} | {{{74|}}} | {{{75|}}} | {{{76|}}} | {{{77|}}} | {{{78|}}} | {{{79|}}} | {{{80|}}} | {{{81|}}} }} | {{~Max27 | {{{1|}}} | {{{2|}}} | {{{3|}}} | {{{4|}}} | {{{5|}}} | {{{6|}}} | {{{7|}}} | {{{8|}}} | {{{9|}}} | {{{10|}}} | {{{11|}}} | {{{12|}}} | {{{13|}}} | {{{14|}}} | {{{15|}}} | {{{16|}}} | {{{17|}}} | {{{18|}}} | {{{19|}}} | {{{20|}}} | {{{21|}}} | {{{22|}}} | {{{23|}}} | {{{24|}}} | {{{25|}}} | {{{26|}}} | {{{27|}}} }} }} | {{~Max9 | {{{1|}}} | {{{2|}}} | {{{3|}}} | {{{4|}}} | {{{5|}}} | {{{6|}}} | {{{7|}}} | {{{8|}}} | {{{9|}}} }} }} | {{~Max3 | {{{1|}}} | {{{2|}}} | {{{3|}}} }} }} | {{error| MAX error: One to eighty-one [[unformatted numbers]] required as arguments }} }} }}</includeonly>
Alternate code using the arithmetic form of De Morgan's laws
The following code sample uses the arithmetic form of De Morgan's laws
-
MAX(a, b, c, ...) = ~ MIN(~a, ~b, ~c, ...) -
MIN(a, b, c, ...) = ~ MAX(~a, ~b, ~c, ...)
Unfortunately, it doesn't work when we negate arguments which are empty string or white space only, unless we wrap each parameter {{{nn|}}} thusly
- {{#if: {{{nn|}}} | -({{{nn|}}}) }}
which uses one more [parser function and/or template] nesting level (MediaWiki imposes a low limit for those), on top of another nesting level used by {{#expr: -( ) }} which is done before returning the result.
<noinclude>{{Documentation}}</noinclude><includeonly><!-- The MAX function uses the core functions * {{tlxb|~Min3}}, {{tlxb|~Min9}}, {{tlxb|~Min27}}, {{tlxb|~Min81}} -->{{#if: {{{82|}}} | {{error| MAX error: Too many arguments (one to eighty-one [[unformatted numbers]] required as arguments) }} | {{ifnum| {{{1}}} | {{#expr: -( {{#if: {{{4|}}} | {{#if: {{{10|}}} | {{#if: {{{28|}}} | {{~Min81 | -( {{{1|}}}) | -( {{{2|}}}) | -( {{{3|}}}) | -( {{{4|}}}) | -( {{{5|}}}) | -( {{{6|}}}) | -( {{{7|}}}) | -( {{{8|}}}) | -( {{{9|}}}) | -({{{10|}}}) | -({{{11|}}}) | -({{{12|}}}) | -({{{13|}}}) | -({{{14|}}}) | -({{{15|}}}) | -({{{16|}}}) | -({{{17|}}}) | -({{{18|}}}) | -({{{19|}}}) | -({{{20|}}}) | -({{{21|}}}) | -({{{22|}}}) | -({{{23|}}}) | -({{{24|}}}) | -({{{25|}}}) | -({{{26|}}}) | -({{{27|}}}) | -({{{28|}}}) | -({{{29|}}}) | -({{{30|}}}) | -({{{31|}}}) | -({{{32|}}}) | -({{{33|}}}) | -({{{34|}}}) | -({{{35|}}}) | -({{{36|}}}) | -({{{37|}}}) | -({{{38|}}}) | -({{{39|}}}) | -({{{40|}}}) | -({{{41|}}}) | -({{{42|}}}) | -({{{43|}}}) | -({{{44|}}}) | -({{{45|}}}) | -({{{46|}}}) | -({{{47|}}}) | -({{{48|}}}) | -({{{49|}}}) | -({{{50|}}}) | -({{{51|}}}) | -({{{52|}}}) | -({{{53|}}}) | -({{{54|}}}) | -({{{55|}}}) | -({{{56|}}}) | -({{{57|}}}) | -({{{58|}}}) | -({{{59|}}}) | -({{{60|}}}) | -({{{61|}}}) | -({{{62|}}}) | -({{{63|}}}) | -({{{64|}}}) | -({{{65|}}}) | -({{{66|}}}) | -({{{67|}}}) | -({{{68|}}}) | -({{{69|}}}) | -({{{70|}}}) | -({{{71|}}}) | -({{{72|}}}) | -({{{73|}}}) | -({{{74|}}}) | -({{{75|}}}) | -({{{76|}}}) | -({{{77|}}}) | -({{{78|}}}) | -({{{79|}}}) | -({{{80|}}}) | -({{{81|}}}) }} | {{~Min27 | -( {{{1|}}}) | -( {{{2|}}}) | -( {{{3|}}}) | -( {{{4|}}}) | -( {{{5|}}}) | -( {{{6|}}}) | -( {{{7|}}}) | -( {{{8|}}}) | -( {{{9|}}}) | -({{{10|}}}) | -({{{11|}}}) | -({{{12|}}}) | -({{{13|}}}) | -({{{14|}}}) | -({{{15|}}}) | -({{{16|}}}) | -({{{17|}}}) | -({{{18|}}}) | -({{{19|}}}) | -({{{20|}}}) | -({{{21|}}}) | -({{{22|}}}) | -({{{23|}}}) | -({{{24|}}}) | -({{{25|}}}) | -({{{26|}}}) | -({{{27|}}}) }} }} | {{~Min9 | -({{{1|}}}) | -({{{2|}}}) | -({{{3|}}}) | -({{{4|}}}) | -({{{5|}}}) | -({{{6|}}}) | -({{{7|}}}) | -({{{8|}}}) | -({{{9|}}}) }} }} | {{~Min3 | -({{{1|}}}) | -({{{2|}}}) | -({{{3|}}}) }} }} ) }} | {{error| MAX error: One to eighty-one [[unformatted numbers]] required as arguments }} }} }}</includeonly>
See also
- {{min}} minimum of one to three expressions yielding numbers
- {{max}} maximum of one to three expressions yielding numbers
- {{MIN}} minimum of one to eighty-one expressions yielding numbers
- {{MAX}} maximum of one to eighty-one expressions yielding numbers
- Core function templates (used ONLY by {{MIN}}; do NOT use directly!)
- {{~Min3}} (should be used for up to three numbers or mathematical expressions)
- {{~Min9}} (should be used for four to nine numbers or mathematical expressions)
- {{~Min27}} (should be used for ten to twenty-seven numbers or mathematical expressions)
- {{~Min81}} (should be used for twenty-eight to eighty-one numbers or mathematical expressions)
- Core function templates (used ONLY by {{MAX}}; do NOT use directly!)
- {{~Max3}} (should be used for up to three numbers or mathematical expressions)
- {{~Max9}} (should be used for four to nine numbers or mathematical expressions)
- {{~Max27}} (should be used for ten to twenty-seven numbers or mathematical expressions)
- {{~Max81}} (should be used for twenty-eight to eighty-one numbers or mathematical expressions)