(I would love to hear from someone more knowledgeable about how to improve this answer.)
It is possible to redefine the ||
operator if you're willing to redefine the built-in Or
, but I would certainly not recommend that because Or
is a very common function upon which Mathematica probably relies internally all over the place.
Possibly more robust but still really scary is redefining the notation itself, using the Notation
package. (This will look much nicer when pasted into Mathematica.)
mean[l___] := HarmonicMean[l]/Length[l]
<< Notation`
Notation[ParsedBoxWrapper[
RowBox[{"x_", "||", " ", "y_", " "}]] \[DoubleLongLeftRightArrow]
ParsedBoxWrapper[
RowBox[List[" ",
RowBox[List["mean", "[",
RowBox[List["{", RowBox[List["x_", ",", "y_"]], "}"]], "]"]]]]]]
This will cause Mathematica to evaluate mean[{a,b}]
instead of Or[a,b]
when you type a || b
.
A similar trick will let you use ||[a,b,c]
. It's extremely odd, I have no idea how robust it is, and Mathematica's syntax highlighting will have a fit, but it works. It also doesn't interfere with Or
, that I can see.
Notation[ParsedBoxWrapper[
RowBox[{"||",
RowBox[{"[",
RowBox[{"a_", ",", "b_", ",", "c_"}],
"]"}]}]] \[DoubleLongLeftRightArrow]
ParsedBoxWrapper[
RowBox[{" ",
RowBox[{"mean", "[",
RowBox[{"{",
RowBox[{"a_", ",", "b_", ",", "c_"}], "}"}], "]"}]}]]]
Then || [a, b, c]
will output 1/(1/a + 1/b + 1/c)
.
As I see ciao has commented above, it is really much better to define your own symbol.
a ~p~ b
. $\endgroup$