This site is supported by donations to The OEIS Foundation.

Template talk:Acos

From OeisWiki
Jump to: navigation, search

Error handling

The template does its own error checking abs(x) <= 1. IMO it should simply build on what {{#expr: acos(x)}} already does:

  • {{acos|2}} yields Invalid argument for acos: < -1 or > 1.
  • {{#expr: acos(2)}} yields Invalid argument for acos: < -1 or > 1.

Unrelated, 2*acos(0)=π is my one and only use case for this function elsewhere. –Frank Ellermann 10:01, 22 September 2011 (UTC)


The motivation for doing the error checking in the templates was to have a consistent style on the displayed message for different kinds of error, e.g. compare when the invalid argument is real (but out of range) or complex...
  • {{acos|2}} yields Invalid argument for acos: < -1 or > 1.
  • {{acos|i}} yields Expression error: Unrecognized word "i".
  • {{#expr: acos 2}} yields Invalid argument for acos: < -1 or > 1.
  • {{#expr: acos i}} yields Expression error: Unrecognized word "i".


  • {{log|-2}} yields Log error: Argument must be a positive real number
  • {{log|i}} yields Log error: Argument must be a positive real number
  • {{#expr: ln -2}} yields Invalid argument for ln: <= 0.
  • {{#expr: ln i}} yields Expression error: Unrecognized word "i".

Should I remove the error checking from the templates?

Daniel Forgues 16:05, 22 September 2011 (UTC)

So far the "built in" error messages are good enough. In rxshell I use complex result as error message in the numerical cases (excl. i, REXX and rxshell don't support complex numbers, any i would be a variable or undefined symbol). But MediaWiki templates are no scripting language; in the spirit of KISS it would be simpler (in future templates) to use the "built in" error messages, consistent or not. The existing templates can stay as they are, the overhead for the server should be minimal. But there might be some deep #expr nesting limit (?) –Frank Ellermann 17:35, 22 September 2011 (UTC)
OK, I'll use the 'built in" error messages then. MediaWiki templates are no scripting language, you are absolutely right, you cant' have iteration or recursion, you can't even assign to a variable! You can implement pseudo-iteration or pseudo-recursion, so to speak, but it's ugly, and likely very inefficient. There are some parser function extensions to do those things, but they are not installed with the OEIS MediaWiki server. From some tests I did before, it seems that the nesting limit for templates is 8. I don't know what is the nesting limit for parser functions, or whether the nesting limit is for templates and/or parser functions combined.

In the future, there might be support for a scripting language for MediaWiki end-users, you probably know, but just in case here are two links

Daniel Forgues 04:04, 25 September 2011 (UTC)

Pseudo-recursion: I vaguely recall a horrible template on Meta where I tried to find all supported language codes consisting of two or three letters, roughly at the time when the first set of #expr: functions was introduced. From what you wrote there can be two limits: Template nesting, e.g., using {{acos|0}} instead of {{#expr: acos 0}}, and #expr: nesting, e.g., an additional {{#ifexpr: abs 0 <= 1|…|error}} check counts. I found an experimental help page Help:Expansion_depth on Meta, User:Patrick was also curious how that works. Thanks for the mw:-links, I didn't know that. –Frank Ellermann 12:12, 26 September 2011 (UTC)