The way it calculates is as following:
1. Check if life/max_life is below 0.4 or above 0.4
2. If above, then block runs [Math 1]
3. If below, else block runs [Math 2]
[Math 1]
R = ability level/4*0.2*attribute + 2*level
Translate to description:
Level 1: 1/4*0.2*attribute + 2*1 = 0.25*0.2*attribute + 2 = 0.05*attribute + 2
Level 2: 2/4*0.2*attribute + 2*2 = 0.5*0.2*attribute + 4 = 0.10*attribute + 4
[Math 2]
Works exactly like math 1, but the times 3 the original (0.2 changed into 0.6). So, for level 1 it is 0.05*3*attribute + 2 = 0.15*attribute + 2 and so on.
If you want to simplify the math for the current values, I recommend the following:
For then block: I2R(d.lvl)*0.05*stat + 2*d.lvl
For else block: I2R(d.lvl)*0.15*stat + 2*d.lvl
(I personally think I2R is not needed either, but just to be safe)
Easier to read for you that way.