Render 3 dimensional scalar field
Bender uses python for the user interface and it can also automate many tasks that manipulate blenders data. However when you want to customise a material python isn't much help.

If you want to use blender internal render engine you will find that there is some support for external voxel data.

For cycles, I think your best option would be an OSL shader.

I made a quick sample script as a starting point for you -

float myFunc(float x, float y, float z)
{
    return 1.5;
}

shader MyVolShader(
    color   BaseColour = color(1.0,0.0,0.0),
    output closure color Volume = 0)
{
    // P is the current point
    // P[0] == x
    // P[1] == y
    // P[2] == z
    Volume = (BaseColour * myFunc(P[0], P[1], P[2])) * absorption();
}


You then fillin myFunc using your algorithm, and the final colour as desired.

If you want volume scattering, swap absorption() with henyey_greenstein(0.0) in the final calculation (or add them together).

The OSL Language reference should be helpful.

I have a collection of OSL scripts here but none that use volume yet.