From f45b6be6079de447a1de2c47e8432edfd604dc1d Mon Sep 17 00:00:00 2001 From: Jeff Fessler Date: Mon, 4 Nov 2019 08:12:03 -0500 Subject: [PATCH] Document customizable binary operators (#33479) * Document customizable binary operators I learned indirectly through comments on a PR that \otimes and \oplus and \odot can be extended as binary operators yet I cannot find this fact anywhere in the documentation. Search the docs for `oplus` yields nothing. Somewhere there must be a list of which characters can be extended this way and it should be documented in the manual. This PR is an attempt to get that ball rolling! * Add url for list and fix prefix typo * Expand docs of infix binary operators. --- doc/src/base/math.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/src/base/math.md b/doc/src/base/math.md index 343c71f03c4b4..387b32fab8049 100644 --- a/doc/src/base/math.md +++ b/doc/src/base/math.md @@ -176,3 +176,29 @@ Base.widemul Base.Math.@evalpoly Base.FastMath.@fastmath ``` + +## Customizable binary operators + +Some unicode characters can be used to define new binary operators +that support infix notation. +For example +```⊗(x,y) = kron(x,y)``` +defines the `⊗` (otimes) function to be the Kronecker product, +and one can call it as binary operator using infix syntax: +```C = A ⊗ B``` +as well as with the usual prefix syntax +```C = ⊗(A,B)```. + +Other characters that support such extensions include +\odot `⊙` +and +\oplus `⊕` + +The complete list is in the parser code: +https://github.com/JuliaLang/julia/blob/master/src/julia-parser.scm + +Those that are parsed like `*` (in terms of precedence) include +`* / ÷ % & ⋅ ∘ × |\\| ∩ ∧ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ ⊓ ∗ ∙ ∤ ⅋ ≀ ⊼ ⋄ ⋆ ⋇ ⋉ ⋊ ⋋ ⋌ ⋏ ⋒ ⟑ ⦸ ⦼ ⦾ ⦿ ⧶ ⧷ ⨇ ⨰ ⨱ ⨲ ⨳ ⨴ ⨵ ⨶ ⨷ ⨸ ⨻ ⨼ ⨽ ⩀ ⩃ ⩄ ⩋ ⩍ ⩎ ⩑ ⩓ ⩕ ⩘ ⩚ ⩜ ⩞ ⩟ ⩠ ⫛ ⊍ ▷ ⨝ ⟕ ⟖ ⟗` +and those that are parsed like `+` include +`+ - |\|| ⊕ ⊖ ⊞ ⊟ |++| ∪ ∨ ⊔ ± ∓ ∔ ∸ ≏ ⊎ ⊻ ⊽ ⋎ ⋓ ⧺ ⧻ ⨈ ⨢ ⨣ ⨤ ⨥ ⨦ ⨧ ⨨ ⨩ ⨪ ⨫ ⨬ ⨭ ⨮ ⨹ ⨺ ⩁ ⩂ ⩅ ⩊ ⩌ ⩏ ⩐ ⩒ ⩔ ⩖ ⩗ ⩛ ⩝ ⩡ ⩢ ⩣` +There are many others that are related to arrows, comparisons, and powers.