Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
(*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"?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

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

share|improve this answer
    
Confirmed with 9.01 and Win8x64 –  Hector Oct 15 '13 at 15:59
1  
Label is not implemented either: Compile[{}, Label[1]; Goto[1], CompilationTarget -> "C"]. Both of these should be considered bugs in the CCompilerDriver` package, IMO. –  Oleksandr R. Oct 15 '13 at 17:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.