I have tried to reproduce your commands in Imagemagick, but I am not sure of the result or about whether T and M should be in range 0 to 1 or 0 to Quantumrange (0 to 65535 for Q16 HDRI IM compile). I tested on the Imagemagick logo: image using Imagemagick 7.0.7.21 Q16 HDRI.

T="65000"
sigma=5
magick logo: I.mpc
magick I.mpc -blur 0x$sigma G.mpc
magick I.mpc G.mpc +swap -compose minus -composite G.mpc +swap -compose divide -composite D.mpc
M=`magick D.mpc D.mpc -compose multiply -composite -evaluate pow 0.5 -evaluate multiply $T -format "%[fx:maxima]" info:`
M2=`magick xc: -format "%[fx:2*$M]" info:`
magick D.mpc -evaluate add $M -evaluate divide $M2 -evaluate multiply $T output.png
Line 1: Set T=65000 (range 0 to 65355)
Line 2: Set gaussian blur sigma to 5
Line 3: Read the input into I.mpc
Line 4: Apply gaussian blur to I.mpc to create G.mpc
Line 5: Create D=(I-G)/G (requires HDRI IM 7 compile to keep negative values)
Line 6: Compute M=T*Max(sqrt(D*D)) as a single number variable in the range 0 to 65535 (Quantumrange for 16-bit IM compile)
Line 7: Compute 2*M as variable M2
Line 8: Compute output O = T * (D + M) / (2 * M)

If this is not correct (does not match your python, etc, approach, then please post and input and output example and then I might be able to correct any false assumptions or mistakes and make it work the same.
If wanting to use Imagemagick 6, then one would have to compile or get a version that is Q16 HDRI compiled. Then in the above commands, just change magick to convert.