5
(*can compiled*)
Compile[{}, Table[Boole[a == b == c], {a, 3}, {b, 3}, {c, 3}],
  CompilationTarget -> "C"][]

(*can compiled*)
Compile[{}, Table[Boole[a != b != c], {a, 3}, {b, 3}, {c, 3}]][]

(*can't compiled*)
Compile[{}, Table[Boole[a != b != c], {a, 3}, {b, 3}, {c, 3}],
  CompilationTarget -> "C"][]

enter image description here

Why doesn't the third snippet code compile when I set CompilationTarget -> "C"?

expression
  • 5,642
  • 1
  • 19
  • 46

1 Answers1

4

I confirm it with Mathematica 9.0.1 and Linux. It seems that double inequalities is not yet implemented for CompilationTarget -> "C".

You can manually expand a != b != c to b != a && c != a && c != b.

LogicalExpand can also be helpful

With[{neq = LogicalExpand[a != b != c]}, 
 Compile[{}, Table[Boole[neq], {a, 3}, {b, 3}, {c, 3}], 
  CompilationTarget -> "C"]]

no errors

ybeltukov
  • 43,673
  • 5
  • 108
  • 212