11 votes
Accepted

Metaprogramming: creating compiled functions from inter-dependent code blocks

To compose code from blocks you could use simple quoting mechanism like following: ...
jkuczm's user avatar
  • 15.1k
9 votes

Generate FORTRAN77 code from Mathematica

Warning: as @george points out in the comments, something is wrong with the output of this package. It produced incorrect d0d0. I don't have time to investigate at the moment, so making it community ...
9 votes
Accepted

Converting Piecewise function to C code

-10 < x < 0 // LogicalExpand // CForm (* -10 < x && x < 0 *)
xzczd's user avatar
  • 66k
8 votes

Automatically add debug contents to a program

In your example, a message is issued at the problem. You want to find out where the message comes from. The debugger is pretty good at this. Just enable the debugger, then enable Break at Messages, ...
Szabolcs's user avatar
  • 235k
8 votes
Accepted

Compute Hessian of function symbolically

I think this should be fine, the full form doesn't look neat with x$123 etc but that doesn't matter: ...
Kuba's user avatar
  • 137k
7 votes
Accepted

Easy code help about matrix. How to change the elements in a given matrix?

Have a look at ReplacePart[] A[1, 1] = {1, 2, 3, 4}; ReplacePart[A[1, 1], 2 -> 5] {1, 5, 3, 4}
infinitezero's user avatar
  • 1,419
6 votes

Christmas fun with Mathematica

Nothing groundbreaking, but a quick composure of some graphics objects: ...
ktm's user avatar
  • 4,242
6 votes

Metaprogramming: creating compiled functions from inter-dependent code blocks

You already have a very good and general answer for your question. Just for completeness I wanted to show you an alternative which is much less general but shows that there is actually not too much ...
Albert Retey's user avatar
  • 23.6k
6 votes

Compute Hessian of function symbolically

Is this not a good place to use Formal Symbols? A number of built-ins do that.(1) ...
Mr.Wizard's user avatar
  • 271k
6 votes
Accepted

How to get a peek at the source code for demonstrations if there is no source code provided

One method that I think works is to highlight the demonstration, copy it to a new Mathematica notebook, and then click "Convert to Input Form" on the cell.
MassDefect's user avatar
  • 10.1k
6 votes
Accepted

Understanding code generated by MicrocontrollerEmbedCode

The value 84.38063590995105=-26.8592*π is a residue that pops up if the equilibrium value is not set correctly. There are a few things that need to be changed to ...
Suba Thomas's user avatar
  • 8,741
6 votes

How to generate input cells whose code is determined dynamically?

You should just use With instead of Module, as Carl Woll suggests in the comments: ...
Alexey Popkov's user avatar
5 votes

OEIS A144311 Generating function

This function calculates the maximum fails for the given list upto n. It also shows the numbers which give these gaps. ...
Hubble07's user avatar
  • 3,614
5 votes
Accepted

Is it possible to automate definitions given with TagSetDelayed?

You mean something like: ...
Sjoerd Smit's user avatar
  • 23.5k
5 votes
Accepted

How to convert any string of code to an input cell?

TLDR: FrontEnd will happily accept an input form string wrapped with BoxData: ...
Kuba's user avatar
  • 137k
4 votes

SymbolicC`CSwitch basically broken?

The documentation for CSwitch looks like it was written by somebody who didn't understand what the SymbolicC package or, for ...
m_goldberg's user avatar
  • 108k
4 votes

Write Power in CForm[] as multiplication instead

You can override the default CForm handling of Power as follows: ...
Carl Woll's user avatar
  • 131k
4 votes

NDSolveValue solutions differ based on number of equations

General reasons for a difference There are (at least) two differences why solving independent systems with one call might result in different solution than solving them separately: Independent vs. ...
Michael E2's user avatar
  • 236k
4 votes
Accepted

Turn definitions into rules

How about: ...
xzczd's user avatar
  • 66k
4 votes

How to programmatically modify a function definition

This is my first time wading into metaprogramming in Mathematica, so take this with a pinch of salt. I can get the DownValues of ...
flinty's user avatar
  • 25.3k
4 votes
Accepted

How to programmatically modify a function definition

To operate on notebooks Let nb be the notebook you want to alter obtained with NotebookGet[]. For instance, it could be ...
Michael E2's user avatar
  • 236k
4 votes

How to generate input cells whose code is determined dynamically?

This required a bit more trickery than I would like: ...
4 votes

Stepped Infinite Square Well

Having solved the problem with writing the potential, you may use "Eigensystem" to solve this problem (with arbitrary numerical values): ...
Daniel Huber's user avatar
  • 51.5k
3 votes

Applying And to a list inside a Function

For the exact expansion that you show: Replace[And[1, 3, 7, 9, 13, 27] &, x_ :> PrimeQ[# + x], {2}] ...
Mr.Wizard's user avatar
  • 271k
3 votes

Write Power in CForm[] as multiplication instead

If the symbol you are using is known in advance, you can useTagSetDelayed and associate an UpValue with that symbol inside the <...
Stitch's user avatar
  • 4,225
3 votes

Metaprogramming: creating compiled functions from inter-dependent code blocks

I came up with my own way of dealing with this. I'm not sure if it's the simplest way. I was careful to make sure I dealt with all possible namespace issues, as well as possible recursive calls ...
Ben Niehoff's user avatar
3 votes

OptimizeExpression to C code

So since I need it, I wrote the function myself. It is a little bit hackish approach, but it solves my problem. So any comment and suggestions for improvement are welcome. ...
tom's user avatar
  • 295
3 votes
Accepted

Generate assignment code to symbols from string

Since you referenced How do I evaluate only one step of an expression? I might use: ...
Mr.Wizard's user avatar
  • 271k
3 votes

Automatically add debug contents to a program

Actually form C.E.'s comment. Make a custom function for this ...
yode's user avatar
  • 26.7k
3 votes

SymbolicC namespace?

Have you looked at the builtin documentation? SymbolicC User Guide The introduction – C++ section clearly states: At present, SymbolicC only supports C syntax. That is, it does not support C++. ...
Szabolcs's user avatar
  • 235k

Only top scored, non community-wiki answers of a minimum length are eligible