Custom cycles math function
No

Unfortunately there's currently no Eval / Custom math node for Cycles as described in the question. Unless it's an OSL definition it has to be pre-compiled. Look through the OSL examples, you might find that it is capable of doing at least some of what you want.

See the specs: https://github.com/imageworks/OpenShadingLanguage/blob/master/src/doc/osl-languagespec.pdf

And suggested reading: Understanding the Cycles &#39;Script&#39; node

But..

Node trees can be scripted and groups can too. I imagine it is possible, with sufficient willpower, to write a script or addon that translates a (Python like) expression with variables into a node-group with inputs and outputs. Perhaps something like:

# {materialname: material.001, groupname: NodeGroup}
sockets = {inputs: [var1, var2, var3], outputs: [var4]}
theta = var1 / 300
gamma = sin(theta * var2)
var4 = gamma * var3




and to the outside world that would look like a single node.



To make a useful implementation is not a trivial thing, but it could move away from pure python syntax to a more domain specific syntax to provide more convenience for specifying the types of inputs and outputs (Vector, Color, numeric..).