Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to generate C code for some functions, which I do not post in full because they are a few hundred lines long. The functions do nothing too fancy: a bunch of dot products, powers and roots.

Still, when compiling to C code Mathematica sticks in some unwanted dependency on its own libraries, which is not acceptable for the use case in question. The functions I am trying to compile have 5 arguments, 4 of which are 3-dimensional vectors.

The compile printout of one of them can be found here. As you can see, there are 3 Mathematica functions being pulled in: DotVV, Power and Internal`ReciprocalSqrt. Is there any way I can get rid of these without modifying the code manually?

Edit: here is the code I am using to compile the function

Compile[{{pos, _Real, 1} , {a, _Real, 1}, {v, _Real, 1}, {ba, _Real, 
    1} , {V, _Real}} , 
  xSol, CompilationTarget -> "C"];
share|improve this question

closed as off-topic by Kuba, Öskå, LLlAMnYP, m_goldberg, blochwave Dec 12 '15 at 23:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Kuba, Öskå, LLlAMnYP, m_goldberg, blochwave
If this question can be reworded to fit the rules in the help center, please edit the question.

    
Can you whittle down your code and output to something that will fit in the Q? That would make it self-contained and easier to work with. – Yves Klett Jul 4 '14 at 5:33
    
Thanks for your comment. Unfortunately how I get to xSol is quite complicated and requires some lengthy evaluations. As for the compiled code, I would not know how to shrink it. I have, however, included the call I am making to Compile, hoping that it helps. – em70 Jul 4 '14 at 5:47
    
The outlook of reverse-engineering compiled code may not get you many takers. Providing code (e.g. in a linked notebook) would make the task easier, e.g. by identification of functions that do not compile, see. eg. List of compilable functions. – Yves Klett Jul 4 '14 at 6:01
    
I do not expect anybody to reverse-engineer the code. That is just posted for reference. The point is that I have a huge expression which is, at its essence, just a large sum of the values of applications of the functions I listed in my question. Moreover, all of those are compilable, hence the question. I wonder if the fact that there is no size constraint on the vectors is the issue (how could Mathematica know that they are 3d otherwise?) – em70 Jul 4 '14 at 6:10
2  
@emaster70 I meant: this is an example that produces DotVV. As your question is posed, we'd need to come up with code that produces Internal`ReciprocalSqrt, DotVV and Power when compiled, solve the problem, then report to you. You could help by providing an example of problematic code. This is what I have been trying to hint at, but... – acl Jul 4 '14 at 14:14