# Error I don't understand involving infix operator

**URL:** <https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212>\
**Category:** New to Julia\
**Tags:** infix\
**Created:** [September 26, 2019, 11:19pm UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212 "2019-09-26T23:19:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [September 26, 2019, 11:19pm UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/1 "2019-09-26T23:19:53Z")

</div>

So, I defined a function like so (using \parallel):

```julia-auto
julia> ∥(a,b) = 1/(1/a+1/b)
∥ (generic function with 1 method)

julia> ∥(10,10)
5.0

julia> 10∥10
5.0

julia> 10∥10∥10
ERROR: TypeError: non-boolean (Float64) used in boolean context
Stacktrace:
 [1] top-level scope at REPL[40]:1

julia> (10∥10)∥10
3.333333333333333

```

What explains the TypeError? Thanks!

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 27, 2019, 12:28am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/2 "2019-09-27T00:28:04Z")

</div>

The problem is that this gets lowered as `||(a,b,c)`, which gets dispatched to Boolean or.

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [September 27, 2019, 1:03am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/3 "2019-09-27T01:03:33Z")

</div>

Hi @Oscar_Smith, how do you know that? @code\_lowered doesn’t seem to be helpful here.

This works

```julia
julia> @code_lowered (10∥10)∥10
CodeInfo(
1 ─ %1 = 1 / a
│ %2 = 1 / b
│ %3 = %1 + %2
│ %4 = 1 / %3
└── return %4
)

```

but this doesn’t:

```julia
julia> ∥(a,b,c) = 1/(1/a+1/b+1/c)
∥ (generic function with 2 methods)

julia> @code_lowered 10∥10∥10
ERROR: expression is not a function call, or is too complex for @code_lowered to analyze; break it down to simpler parts if possible
Stacktrace:
 [1] error(::String) at .\error.jl:33
 [2] top-level scope at C:\cygwin\home\Administrator\buildbot\worker\package_win64\build\usr\share\julia\stdlib\v1.2\InteractiveUtils\src\macros.jl:151

```

Nor does defining it with three arguments resolve the original error:

```julia
julia> 10∥10∥10
ERROR: TypeError: non-boolean (Float64) used in boolean context
Stacktrace:
 [1] top-level scope at REPL[53]:1

```

so I’m not sure that it really calls ∥(10,10,10).

Also, please note that I named the function `∥` which is a unicode character entered by \parallel followed by tab, not `||` (two pipe characters in a row).

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [September 27, 2019, 1:04am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/4 "2019-09-27T01:04:47Z")

</div>

Oh, oops, misread. Not sure what’s happening then.

---

<div class="post-metadata">

**Author:** ![kevbonham](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kevbonham/32/216165_2.png) [@kevbonham](https://discourse.julialang.org/u/kevbonham)\
**Post date:** [September 27, 2019, 1:15am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/5 "2019-09-27T01:15:38Z")

</div>

> [@klaff](#):
>
> What explains the TypeError? Thanks!

I don’t know the answer, but have you tried with some other infix operator? Would be good to know if it’s a general problem with the way it’s defined or if there’s something special about \parallel

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 27, 2019, 1:17am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/6 "2019-09-27T01:17:00Z")

</div>

The problem is that the `∥` symbol ([U+2225](https://www.fileformat.info/info/unicode/char/2225/index.htm)) is parsed as a comparison operator, like `==` or `>=`, so `a ∥ b ∥ c` gets parsed as a “chained comparison” and is essentially `a ∥ b && b ∥ c`, just as `a == b == c` is equivalent to `a == b && b == c`.

The reason it is parsed as a comparison operator is that the official Unicode meaning of the symbol is boolean: _PARALLEL TO_.

You are using `∥` because you want the formula for adding resistors in parallel, I’m guessing. But I would use some other symbol, e.g. `⧺` (`\doubleplus` tab) or `+ᵣ` (`+\_r` tab), both of which have `+` precedence.

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [September 27, 2019, 1:47am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/7 "2019-09-27T01:47:34Z")

</div>

Thank you.

I _think_ I’ve found where that stuff lives (julia-parser.scm) although I don’t find either \parallel or \doubleplus in that file. Is this somewhere in the docs?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 27, 2019, 2:08am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/8 "2019-09-27T02:08:58Z")

</div>

> [@klaff](#):
>
> although I don’t find either \parallel or \doubleplus in that file. Is this somewhere in the docs?

The tab completions are not part of the language or the parser, they are “just” a feature of the REPL (and many editors etcetera). All of the tab completions are [listed in the manual](https://docs.julialang.org/en/latest/manual/unicode-input/), and you can also get it from the REPL help:

```julia
help?> ⧺
"⧺" can be typed by \doubleplus<tab>

```

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [September 27, 2019, 2:14am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/9 "2019-09-27T02:14:24Z")

</div>

I’m sorry. I understand the \parallel followed by tab feature. What I was asking is where can I find information about infix operators and their precedences and categories (e.g. times, plus, comparison) in the docs.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [September 27, 2019, 2:15am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/10 "2019-09-27T02:15:54Z")

</div>

> [@klaff](#):
>
> What I was asking is where can I find information about infix operators and their precedences and categories (e.g. times, plus, comparison) in the docs.

Currently, the [manual just refers you `julia-parser.scm`](https://docs.julialang.org/en/latest/manual/mathematical-operations/#Operator-Precedence-and-Associativity-1). Both `⧺` and `∥` are indeed in that file.

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [September 27, 2019, 5:09am UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/11 "2019-09-27T05:09:32Z")

</div>

Well now they are! 🤔 I apparently did something wrong when searching for them earlier - sorry about that and thanks for the help!

---

<div class="post-metadata">

**Author:** ![christophE](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@christophE](https://discourse.julialang.org/u/christophE)\
**Post date:** [October 3, 2019, 11:53pm UTC](https://discourse.julialang.org/t/error-i-dont-understand-involving-infix-operator/29212/12 "2019-10-03T23:53:01Z")

</div>

Hi Klaff,  
I want to note that (10||10)||10 would not be the same as 10||10||10 . A binary operator for the 2nd expression which failed is not sufficient since it should evalutate to 1/(1/10 + 1/10 + 1/10) . You’d need a n-ary operator like the ‘+’ (n-ary operators are still rare in Julia AFAIK, there was a discussion about it on GitHub to use n-ariness with other operators). Besides the parallel-to operator there is another mathematics operator which I know is n-ary: the cartesian product. I don’t know if the cartesian product is defined as default in Julia but if then it could be worth considering n-ariness for it. It could allow to generate vectors with simple syntax.
