This site is supported by donations to The OEIS Foundation.

Template:Lambda/doc

From OeisWiki
Jump to: navigation, search

This documentation subpage contains instructions, categories, or other information for Template:Lambda. [<Edit> Template:Lambda]

[⧼Purge⧽ Template:Lambda/doc]

The {{lambda}} mathematical function template evaluates a lambda expression if it is numeric (although an undefined parameter or empty string evaluates as an empty string), otherwise returns an error message.

The lambda expression may refer up to eight numeric values.

Note: currently, the {{lambda}} template is exactly the same as the {{expr}} template, although they may differ in the future.

Usage

To use it, enter

{{lambda|lambda expression using <<<1>>> up to <<<8>>> as numeric values placeholders|up to eight numeric values separated by semicolons}}

or

{{lambda|function(argument)}} (as a shorthand for {{lambda|function <<<1>>>|argument}})

Examples

Code Result Comment
{{lambda}} (empty string)
{{lambda|<<<1>>>|-1}} -1  
{{lambda|<<<1>>>|-0}} -0  
{{lambda|<<<1>>>|-(5-5)}} -0  
{{lambda|<<<1>>>|123/100}} 1.23  
{{lambda|sin <<<1>>>|pi/4}} 0.70710678118655  
{{lambda|sin(pi/4)}} 0.70710678118655 (shorthand for {{lambda|sin <<<1>>>|pi/4}})
{{lambda|(sin pi)/4}} 3.0616169978684E-17 (should be exactly 0)
{{lambda|sin pi/4}} 3.0616169978684E-17 GOTCHA! Evaluates as {{lambda|(sin pi)/4}}
{{lambda|(sin <<<1>>>)^2|pi/4}} 0.5  
{{lambda|<<<1>>>|1+9}} 10  
{{lambda|<<<1>>>^2|1+9}} 100  
{{lambda|<<<1>>>|not 10}} 0  
{{lambda|<<<1>>>|(7 <= 6) * 9}} 0  
{{lambda|<<<1>>>|(7 <= 8) * 9}} 9  
{{lambda|<<<1>>>|2+3}} 5  
{{lambda|<<<1>>>|0^(-1)}} INF  
{{lambda|<<<1>>>|-0^(-1)}} -INF  
{{lambda|<<<1>>>|(-0)^(-1)}} -INF  
{{lambda|<<<1>>>|-(0^(-1))}} -INF  
{{lambda|<<<1>>>|0^0}} 1  
{{lambda|<<<1>>>|0^1}} 0  
{{lambda|<<<1>>> + <<<2>>>| 3; 4}} 7  
{{lambda|<<<2>>> - <<<1>>>| 3; 4}} 1  
{{lambda|<<<1>>> ^ <<<2>>>| 3; 4}} 81  
{{lambda|<<<1>>> ^ <<<2>>>| 5-2; 2+2}} 81  
{{lambda|<<<2>>> ^ <<<1>>>| 3; 4}} 64  
{{lambda|<<<2>>>^2 - <<<1>>>| 3; 4}} 13  
{{lambda|<<<2>>> - <<<1>>>^2|1+9; 5^3}} 25  
{{lambda|<<<1>>>^2 + <<<2>>>^2| 3; 4}} 25  
{{lambda|5*<<<1>>> + <<<2>>>| 3; 4}} 19  

Examples with more arguments

Code Result
{{lambda|<<<1>>>+<<<2>>>+<<<3>>>+<<<4>>>+<<<5>>>+<<<6>>>+<<<7>>>+<<<8>>>| 1; 20; 300; 4000; 50000; 600000; 7000000; 80000000}} 87654321

Examples with invalid input

Code Result
{{lambda|<<<1>>>|1/0}} Division by zero.
{{lambda|<<<1>>>|0/0}} Division by zero.
{{lambda|<<<1>>>|6,500}} Expression error: Unrecognized punctuation character ",".
{{lambda|<<<1>>>|- one}} Expression error: Unrecognized word "one".
{{lambda|<<<1>>>|3 blobs}} Expression error: Unrecognized word "blobs".
{{lambda|<<<1>>>|INF}} Expression error: Unrecognized word "inf".
{{lambda|<<<1>>>|NAN}} Expression error: Unrecognized word "nan".

Formatted numbers

This template requires unformatted numbers, it will not recognize formatted numbers, e.g. comma separated, which is by design since formatted numbers will break expression parsers. To remove the formatting from a number, you can wrap the number first in {{formatnum:number|R}}.[1]

Code Result
{{lambda|<<<1>>>|1,000.50}} Expression error: Unrecognized punctuation character ",".
{{lambda|<<<1>>>|{{formatnum:1,000.50|R}}}} 1000.5

Maximum and minimum numbers allowed

Testing for maximum and minimum numbers allowed with {{lambda}}

Code Result Code Result
{{lambda|{{formatnum:99,999,999,999,999|R}}}} 99999999999999   {{lambda|{{formatnum:-99,999,999,999,999|R}}}} -99999999999999
{{lambda|{{formatnum:999,999,999,999,999|R}}}} 1.0E+15   {{lambda|{{formatnum:-999,999,999,999,999|R}}}} -1.0E+15
{{lambda|2^1023}} 8.9884656743116E+307   {{lambda|2^(-1023)}} 1.1125369292536E-308
{{lambda|(2*0.999999999999)*(2^1023)}} 1.7976931348605E+308   {{lambda|1 / ((2*0.999999999999)*(2^1023))}} 5.5626846462736E-309
{{lambda|2^1024 - 1}} INF   {{lambda|1 / (2^1024 -1)}} 0
{{lambda|2^1024}} INF   {{lambda|2^(-1024)}} 5.562684646268E-309
{{lambda|2^(-1025)}} 2.781342323134E-309   {{lambda|2^(-1026)}} 1.390671161567E-309
{{lambda|2^(-1027)}} 6.953355807835E-310   {{lambda|2^(-1028)}} 3.4766779039175E-310
{{lambda|2^(-1029)}} 1.7383389519588E-310   {{lambda|2^(-1074)}} 4.9406564584125E-324
{{lambda|2^(-1075)}} 0   {{lambda|2^(-2048)}} 0
{{lambda|2^1024}} INF   {{lambda|-(2^(2^1024))}} -INF
{{lambda|2^1024 - 2^1024}} NAN   {{lambda|(2^1024 - 1) / (2^1024 - 1)}} NAN
{{lambda|(2^1024)^0}} 1   {{lambda|(2^1024)^-(2^1024)}} 0
{{lambda|(2^1024 - 1) + ((2^1024 - 1) / (2^1024 - 1))}} NAN

Code

{{#expr: 
  {{#replace:
    {{#replace:
      {{#replace:
        {{#replace:
          {{#replace:
            {{#replace:
              {{#replace:
                {{#replace:{{{1|}}}
                |<<<1>>>|({{#explode:{{{2|}}}|;|0}})
                }}
              |<<<2>>>|({{#explode:{{{2|}}}|;|1}})
              }}
            |<<<3>>>|({{#explode:{{{2|}}}|;|2}})
            }}
          |<<<4>>>|({{#explode:{{{2|}}}|;|3}})
          }}
        |<<<5>>>|({{#explode:{{{2|}}}|;|4}})
        }}
      |<<<6>>>|({{#explode:{{{2|}}}|;|5}})
      }}
    |<<<7>>>|({{#explode:{{{2|}}}|;|6}})
    }}
  |<<<8>>>|({{#explode:{{{2|}}}|;|7}})
  }}
}}

See also

Notes