Formula for E

I'm sure this is common knowledge and I feel dumb asking this question but my googlefu is only bringing up how to calibrate extrusion. I am wanting to write my own G code for simple objects for testing various changes such as pressure advance and non linear extrusion. What is the proper formula based on filament diameter, nozzle diameter, layer height, and segment length to calculate the G1 E value?

@alexandermundy The quick and easy way is to create something like a 100mm cube and slice it. Then look at one 100mm long X or Y move and note the E value.
Of course you are relying on the slicer doing it right, but hey are generally pretty close.

I did that already but wanted the actual basic calculation given no pressure advance etc.

E=mc^2?
(Sorry, I couldn't resist.)

You think in volumes. In theory, what goes in should go out. I assume that there are some differences from plastic left in the extruder from teeth biting in the filament or temperature expansion in the nozzle (both plastic and the water steaming in it).

Best I can tell from this page on how Slic3r calculates it:
Given in mm:
Fd = filament diameter
Ew = extrusion width
Eh = extrusion height
Sl = segment lengthE = (Sl * (EwEh) * Eh + π * (Eh/2)^2) / (π * (Fd/2)^2)
Which is independent of nozzle size, which makes sense because (ignoring pressure changes, viscosity, etc) it would be based on the amount of filament going into the extruder. I'm sure there is some additional math for the items ignored since the formula above gives a slightly lower value than my slicer did.