4
$\begingroup$

The documentation of SymbolicC, more specifically of COperator, states that Parentheses are added as necessary together with the following example:

In[1]:= Needs["SymbolicC`"]

In[2]:= COperator[Times, {COperator[Plus, {a, b}], c}] // ToCCodeString

Out[2]= "(a + b) * c"

I expected the same result, when I used CExpression to create the a+b-part of the expression:

In[3]:= COperator[Times, {CExpression[a + b], c}] // ToCCodeString

Out[3]= "a + b * c"

However, the required parentheses were not added. They may be added explicitly using CParentheses:

In[4]:= COperator[Times, {CParentheses@CExpression[a + b], c}] // ToCCodeString

Out[4]= "(a + b) * c"

This feels wrong to me. I expected all of Out[2], Out[3] and Out[4] to be the same.

Is this a bug?

$\endgroup$
  • $\begingroup$ By the way, this has been tested with Mathematica 10.1.0.0 on Linux x64. $\endgroup$ – Sunday Oct 16 '15 at 13:28
  • $\begingroup$ I suspect that COperator doesn't "see" within the expression generated by CExpression, so it doesn't realized that it needs to be wrapped in parentheses. $\endgroup$ – MarcoB Oct 16 '15 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.