ignoring a portion of elemental resistance in dmg formula?

Let's say I want to create a skill that ignores 50% of the target's resistance to a particular element.

Is there a way to achieve this through the damage formula? If so, what would the formula look like?
Damage is calculated before element rate is applied...

One option: precalculate the damage resisted due to element rate, then add half that to the result? I.e. more damage for higher resistance, maybe something like this (untested):
JavaScript:
var dmg = a.atk * 4 - b.def * 2; var res = dmg * Math.max(0, 1 - b.elementRate(5)); dmg + res/2
(OK I'm going to sleep now, hopefully that's at least vaguely correct. 😴)

Original thread: https://forums.rpgmakerweb.com/threads/ignoring-a-portion-of-elemental-resistance-in-dmg-formula.130198/