Skip to content

Commit

Permalink
Document customizable binary operators (#33479)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
JeffFessler authored and StefanKarpinski committed Nov 4, 2019
1 parent 5294219 commit f45b6be
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions doc/src/base/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit f45b6be

Please sign in to comment.