Bulmash initializePoisson

Percentage Accurate: 100.0% → 100.0%
Time: 22.5s
Alternatives: 18
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (+
  (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
  (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    code = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	return (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))))
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT)))))
end
function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 18 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (+
  (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
  (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    code = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	return (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))))
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT)))))
end
function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}
\end{array}

Alternative 1: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (+
  (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
  (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    code = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	return (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))))
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT)))))
end
function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
  2. Add Preprocessing

Alternative 2: 81.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\ t_1 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ t_2 := \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + t\_1\\ t_3 := t\_0 + t\_1\\ \mathbf{if}\;t\_3 \leq -1 \cdot 10^{-232}:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;t\_3 \leq 0:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+21}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))))
        (t_1
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_2 (+ (/ NdChar (+ 1.0 (exp (/ mu KbT)))) t_1))
        (t_3 (+ t_0 t_1)))
   (if (<= t_3 -1e-232)
     t_2
     (if (<= t_3 0.0)
       (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
       (if (<= t_3 2e+21)
         t_2
         (+ t_0 (/ NaChar (+ 1.0 (exp (/ EAccept KbT))))))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_2 = (NdChar / (1.0 + exp((mu / KbT)))) + t_1;
	double t_3 = t_0 + t_1;
	double tmp;
	if (t_3 <= -1e-232) {
		tmp = t_2;
	} else if (t_3 <= 0.0) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else if (t_3 <= 2e+21) {
		tmp = t_2;
	} else {
		tmp = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))
    t_1 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_2 = (ndchar / (1.0d0 + exp((mu / kbt)))) + t_1
    t_3 = t_0 + t_1
    if (t_3 <= (-1d-232)) then
        tmp = t_2
    else if (t_3 <= 0.0d0) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else if (t_3 <= 2d+21) then
        tmp = t_2
    else
        tmp = t_0 + (nachar / (1.0d0 + exp((eaccept / kbt))))
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_2 = (NdChar / (1.0 + Math.exp((mu / KbT)))) + t_1;
	double t_3 = t_0 + t_1;
	double tmp;
	if (t_3 <= -1e-232) {
		tmp = t_2;
	} else if (t_3 <= 0.0) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else if (t_3 <= 2e+21) {
		tmp = t_2;
	} else {
		tmp = t_0 + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))
	t_1 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_2 = (NdChar / (1.0 + math.exp((mu / KbT)))) + t_1
	t_3 = t_0 + t_1
	tmp = 0
	if t_3 <= -1e-232:
		tmp = t_2
	elif t_3 <= 0.0:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	elif t_3 <= 2e+21:
		tmp = t_2
	else:
		tmp = t_0 + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT))))
	t_1 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT))))
	t_2 = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(mu / KbT)))) + t_1)
	t_3 = Float64(t_0 + t_1)
	tmp = 0.0
	if (t_3 <= -1e-232)
		tmp = t_2;
	elseif (t_3 <= 0.0)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	elseif (t_3 <= 2e+21)
		tmp = t_2;
	else
		tmp = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	t_1 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_2 = (NdChar / (1.0 + exp((mu / KbT)))) + t_1;
	t_3 = t_0 + t_1;
	tmp = 0.0;
	if (t_3 <= -1e-232)
		tmp = t_2;
	elseif (t_3 <= 0.0)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	elseif (t_3 <= 2e+21)
		tmp = t_2;
	else
		tmp = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(NdChar / N[(1.0 + N[Exp[N[(mu / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$0 + t$95$1), $MachinePrecision]}, If[LessEqual[t$95$3, -1e-232], t$95$2, If[LessEqual[t$95$3, 0.0], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2e+21], t$95$2, N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\
t_1 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
t_2 := \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + t\_1\\
t_3 := t\_0 + t\_1\\
\mathbf{if}\;t\_3 \leq -1 \cdot 10^{-232}:\\
\;\;\;\;t\_2\\

\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+21}:\\
\;\;\;\;t\_2\\

\mathbf{else}:\\
\;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1.00000000000000002e-232 or 0.0 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 2e21

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in mu around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites69.9%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]

    if -1.00000000000000002e-232 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 0.0

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if 2e21 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 3: 79.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\ t_1 := t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ t_2 := t\_0 + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ \mathbf{if}\;t\_2 \leq -5 \cdot 10^{+113}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq -1 \cdot 10^{-232}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(Ev + Vef\right) - mu}{KbT}}}\\ \mathbf{elif}\;t\_2 \leq 10^{-210}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))))
        (t_1 (+ t_0 (/ NaChar (+ 1.0 (exp (/ EAccept KbT))))))
        (t_2
         (+
          t_0
          (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))))
   (if (<= t_2 -5e+113)
     t_1
     (if (<= t_2 -1e-232)
       (+
        (/ NdChar (+ 1.0 (exp (/ mu KbT))))
        (/ NaChar (+ 1.0 (exp (/ (- (+ Ev Vef) mu) KbT)))))
       (if (<= t_2 1e-210)
         (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
         t_1)))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	double t_2 = t_0 + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_2 <= -5e+113) {
		tmp = t_1;
	} else if (t_2 <= -1e-232) {
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp((((Ev + Vef) - mu) / KbT))));
	} else if (t_2 <= 1e-210) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))
    t_1 = t_0 + (nachar / (1.0d0 + exp((eaccept / kbt))))
    t_2 = t_0 + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
    if (t_2 <= (-5d+113)) then
        tmp = t_1
    else if (t_2 <= (-1d-232)) then
        tmp = (ndchar / (1.0d0 + exp((mu / kbt)))) + (nachar / (1.0d0 + exp((((ev + vef) - mu) / kbt))))
    else if (t_2 <= 1d-210) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = t_0 + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	double t_2 = t_0 + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_2 <= -5e+113) {
		tmp = t_1;
	} else if (t_2 <= -1e-232) {
		tmp = (NdChar / (1.0 + Math.exp((mu / KbT)))) + (NaChar / (1.0 + Math.exp((((Ev + Vef) - mu) / KbT))));
	} else if (t_2 <= 1e-210) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))
	t_1 = t_0 + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	t_2 = t_0 + (NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))))
	tmp = 0
	if t_2 <= -5e+113:
		tmp = t_1
	elif t_2 <= -1e-232:
		tmp = (NdChar / (1.0 + math.exp((mu / KbT)))) + (NaChar / (1.0 + math.exp((((Ev + Vef) - mu) / KbT))))
	elif t_2 <= 1e-210:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = t_1
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT))))
	t_1 = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))))
	t_2 = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT)))))
	tmp = 0.0
	if (t_2 <= -5e+113)
		tmp = t_1;
	elseif (t_2 <= -1e-232)
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(mu / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Ev + Vef) - mu) / KbT)))));
	elseif (t_2 <= 1e-210)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	t_1 = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	t_2 = t_0 + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	tmp = 0.0;
	if (t_2 <= -5e+113)
		tmp = t_1;
	elseif (t_2 <= -1e-232)
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp((((Ev + Vef) - mu) / KbT))));
	elseif (t_2 <= 1e-210)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -5e+113], t$95$1, If[LessEqual[t$95$2, -1e-232], N[(N[(NdChar / N[(1.0 + N[Exp[N[(mu / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(Ev + Vef), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e-210], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\
t_1 := t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\
t_2 := t\_0 + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
\mathbf{if}\;t\_2 \leq -5 \cdot 10^{+113}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_2 \leq -1 \cdot 10^{-232}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(Ev + Vef\right) - mu}{KbT}}}\\

\mathbf{elif}\;t\_2 \leq 10^{-210}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{else}:\\
\;\;\;\;t\_1\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -5e113 or 1e-210 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]

    if -5e113 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1.00000000000000002e-232

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in mu around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites69.9%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    4. Taylor expanded in EAccept around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\color{blue}{\left(Ev + Vef\right) - mu}}{KbT}}} \]
    5. Applied rewrites64.7%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\color{blue}{\left(Ev + Vef\right) - mu}}{KbT}}} \]

    if -1.00000000000000002e-232 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1e-210

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 79.5% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\ t_1 := t\_0 + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ \mathbf{if}\;t\_1 \leq -1 \cdot 10^{-221}:\\ \;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\ \mathbf{elif}\;t\_1 \leq 10^{-210}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))))
        (t_1
         (+
          t_0
          (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))))
   (if (<= t_1 -1e-221)
     (+ t_0 (/ NaChar (+ 1.0 (exp (/ Ev KbT)))))
     (if (<= t_1 1e-210)
       (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
       (+ t_0 (/ NaChar (+ 1.0 (exp (/ EAccept KbT)))))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = t_0 + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -1e-221) {
		tmp = t_0 + (NaChar / (1.0 + exp((Ev / KbT))));
	} else if (t_1 <= 1e-210) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))
    t_1 = t_0 + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
    if (t_1 <= (-1d-221)) then
        tmp = t_0 + (nachar / (1.0d0 + exp((ev / kbt))))
    else if (t_1 <= 1d-210) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else
        tmp = t_0 + (nachar / (1.0d0 + exp((eaccept / kbt))))
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = t_0 + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -1e-221) {
		tmp = t_0 + (NaChar / (1.0 + Math.exp((Ev / KbT))));
	} else if (t_1 <= 1e-210) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = t_0 + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))
	t_1 = t_0 + (NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))))
	tmp = 0
	if t_1 <= -1e-221:
		tmp = t_0 + (NaChar / (1.0 + math.exp((Ev / KbT))))
	elif t_1 <= 1e-210:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = t_0 + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT))))
	t_1 = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT)))))
	tmp = 0.0
	if (t_1 <= -1e-221)
		tmp = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(Ev / KbT)))));
	elseif (t_1 <= 1e-210)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	else
		tmp = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	t_1 = t_0 + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	tmp = 0.0;
	if (t_1 <= -1e-221)
		tmp = t_0 + (NaChar / (1.0 + exp((Ev / KbT))));
	elseif (t_1 <= 1e-210)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-221], N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(Ev / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-210], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\
t_1 := t\_0 + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-221}:\\
\;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\

\mathbf{elif}\;t\_1 \leq 10^{-210}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{else}:\\
\;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1.00000000000000002e-221

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in Ev around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{Ev}{KbT}}}} \]
    3. Applied rewrites69.2%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{Ev}{KbT}}}} \]

    if -1.00000000000000002e-221 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1e-210

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if 1e-210 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 75.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(Ev + Vef\right) - mu}{KbT}}}\\ t_1 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\ t_2 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ t_3 := t\_1 + t\_2\\ \mathbf{if}\;t\_3 \leq -1 \cdot 10^{-232}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_3 \leq 2 \cdot 10^{-206}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+21}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+195}:\\ \;\;\;\;t\_1 + 0.5 \cdot NaChar\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot NdChar + t\_2\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0
         (+
          (/ NdChar (+ 1.0 (exp (/ mu KbT))))
          (/ NaChar (+ 1.0 (exp (/ (- (+ Ev Vef) mu) KbT))))))
        (t_1 (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))))
        (t_2
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_3 (+ t_1 t_2)))
   (if (<= t_3 -1e-232)
     t_0
     (if (<= t_3 2e-206)
       (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
       (if (<= t_3 2e+21)
         t_0
         (if (<= t_3 5e+195)
           (+ t_1 (* 0.5 NaChar))
           (+ (* 0.5 NdChar) t_2)))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp((((Ev + Vef) - mu) / KbT))));
	double t_1 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_2 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_3 = t_1 + t_2;
	double tmp;
	if (t_3 <= -1e-232) {
		tmp = t_0;
	} else if (t_3 <= 2e-206) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else if (t_3 <= 2e+21) {
		tmp = t_0;
	} else if (t_3 <= 5e+195) {
		tmp = t_1 + (0.5 * NaChar);
	} else {
		tmp = (0.5 * NdChar) + t_2;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: tmp
    t_0 = (ndchar / (1.0d0 + exp((mu / kbt)))) + (nachar / (1.0d0 + exp((((ev + vef) - mu) / kbt))))
    t_1 = ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))
    t_2 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_3 = t_1 + t_2
    if (t_3 <= (-1d-232)) then
        tmp = t_0
    else if (t_3 <= 2d-206) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else if (t_3 <= 2d+21) then
        tmp = t_0
    else if (t_3 <= 5d+195) then
        tmp = t_1 + (0.5d0 * nachar)
    else
        tmp = (0.5d0 * ndchar) + t_2
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = (NdChar / (1.0 + Math.exp((mu / KbT)))) + (NaChar / (1.0 + Math.exp((((Ev + Vef) - mu) / KbT))));
	double t_1 = NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_2 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_3 = t_1 + t_2;
	double tmp;
	if (t_3 <= -1e-232) {
		tmp = t_0;
	} else if (t_3 <= 2e-206) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else if (t_3 <= 2e+21) {
		tmp = t_0;
	} else if (t_3 <= 5e+195) {
		tmp = t_1 + (0.5 * NaChar);
	} else {
		tmp = (0.5 * NdChar) + t_2;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = (NdChar / (1.0 + math.exp((mu / KbT)))) + (NaChar / (1.0 + math.exp((((Ev + Vef) - mu) / KbT))))
	t_1 = NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))
	t_2 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_3 = t_1 + t_2
	tmp = 0
	if t_3 <= -1e-232:
		tmp = t_0
	elif t_3 <= 2e-206:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	elif t_3 <= 2e+21:
		tmp = t_0
	elif t_3 <= 5e+195:
		tmp = t_1 + (0.5 * NaChar)
	else:
		tmp = (0.5 * NdChar) + t_2
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(mu / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Ev + Vef) - mu) / KbT)))))
	t_1 = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT))))
	t_2 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT))))
	t_3 = Float64(t_1 + t_2)
	tmp = 0.0
	if (t_3 <= -1e-232)
		tmp = t_0;
	elseif (t_3 <= 2e-206)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	elseif (t_3 <= 2e+21)
		tmp = t_0;
	elseif (t_3 <= 5e+195)
		tmp = Float64(t_1 + Float64(0.5 * NaChar));
	else
		tmp = Float64(Float64(0.5 * NdChar) + t_2);
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp((((Ev + Vef) - mu) / KbT))));
	t_1 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	t_2 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_3 = t_1 + t_2;
	tmp = 0.0;
	if (t_3 <= -1e-232)
		tmp = t_0;
	elseif (t_3 <= 2e-206)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	elseif (t_3 <= 2e+21)
		tmp = t_0;
	elseif (t_3 <= 5e+195)
		tmp = t_1 + (0.5 * NaChar);
	else
		tmp = (0.5 * NdChar) + t_2;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(N[(NdChar / N[(1.0 + N[Exp[N[(mu / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(Ev + Vef), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(t$95$1 + t$95$2), $MachinePrecision]}, If[LessEqual[t$95$3, -1e-232], t$95$0, If[LessEqual[t$95$3, 2e-206], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$3, 2e+21], t$95$0, If[LessEqual[t$95$3, 5e+195], N[(t$95$1 + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * NdChar), $MachinePrecision] + t$95$2), $MachinePrecision]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(Ev + Vef\right) - mu}{KbT}}}\\
t_1 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\
t_2 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
t_3 := t\_1 + t\_2\\
\mathbf{if}\;t\_3 \leq -1 \cdot 10^{-232}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{-206}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{+21}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+195}:\\
\;\;\;\;t\_1 + 0.5 \cdot NaChar\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot NdChar + t\_2\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1.00000000000000002e-232 or 2.00000000000000006e-206 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 2e21

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in mu around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites69.9%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    4. Taylor expanded in EAccept around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\color{blue}{\left(Ev + Vef\right) - mu}}{KbT}}} \]
    5. Applied rewrites64.7%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\color{blue}{\left(Ev + Vef\right) - mu}}{KbT}}} \]

    if -1.00000000000000002e-232 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 2.00000000000000006e-206

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if 2e21 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 4.9999999999999998e195

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]

    if 4.9999999999999998e195 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites47.0%

      \[\leadsto \color{blue}{0.5 \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 6: 69.8% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ t_1 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + t\_0\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+240}:\\ \;\;\;\;0.5 \cdot NdChar + t\_0\\ \mathbf{elif}\;t\_1 \leq -2 \cdot 10^{-223}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{-1 \cdot \frac{mu}{KbT}}}\\ \mathbf{elif}\;t\_1 \leq 10^{-210}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_1
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
          t_0)))
   (if (<= t_1 -5e+240)
     (+ (* 0.5 NdChar) t_0)
     (if (<= t_1 -2e-223)
       (+
        (/ NdChar (+ 1.0 (exp (/ mu KbT))))
        (/ NaChar (+ 1.0 (exp (* -1.0 (/ mu KbT))))))
       (if (<= t_1 1e-210)
         (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
         (+
          (/ NdChar (+ 1.0 (exp (/ EDonor KbT))))
          (/ NaChar (+ 1.0 (exp (/ EAccept KbT))))))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0;
	double tmp;
	if (t_1 <= -5e+240) {
		tmp = (0.5 * NdChar) + t_0;
	} else if (t_1 <= -2e-223) {
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp((-1.0 * (mu / KbT)))));
	} else if (t_1 <= 1e-210) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (NaChar / (1.0 + exp((EAccept / KbT))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_1 = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + t_0
    if (t_1 <= (-5d+240)) then
        tmp = (0.5d0 * ndchar) + t_0
    else if (t_1 <= (-2d-223)) then
        tmp = (ndchar / (1.0d0 + exp((mu / kbt)))) + (nachar / (1.0d0 + exp(((-1.0d0) * (mu / kbt)))))
    else if (t_1 <= 1d-210) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else
        tmp = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (nachar / (1.0d0 + exp((eaccept / kbt))))
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_1 = (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0;
	double tmp;
	if (t_1 <= -5e+240) {
		tmp = (0.5 * NdChar) + t_0;
	} else if (t_1 <= -2e-223) {
		tmp = (NdChar / (1.0 + Math.exp((mu / KbT)))) + (NaChar / (1.0 + Math.exp((-1.0 * (mu / KbT)))));
	} else if (t_1 <= 1e-210) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_1 = (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0
	tmp = 0
	if t_1 <= -5e+240:
		tmp = (0.5 * NdChar) + t_0
	elif t_1 <= -2e-223:
		tmp = (NdChar / (1.0 + math.exp((mu / KbT)))) + (NaChar / (1.0 + math.exp((-1.0 * (mu / KbT)))))
	elif t_1 <= 1e-210:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT))))
	t_1 = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT)))) + t_0)
	tmp = 0.0
	if (t_1 <= -5e+240)
		tmp = Float64(Float64(0.5 * NdChar) + t_0);
	elseif (t_1 <= -2e-223)
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(mu / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(-1.0 * Float64(mu / KbT))))));
	elseif (t_1 <= 1e-210)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	else
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0;
	tmp = 0.0;
	if (t_1 <= -5e+240)
		tmp = (0.5 * NdChar) + t_0;
	elseif (t_1 <= -2e-223)
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp((-1.0 * (mu / KbT)))));
	elseif (t_1 <= 1e-210)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (NaChar / (1.0 + exp((EAccept / KbT))));
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+240], N[(N[(0.5 * NdChar), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[t$95$1, -2e-223], N[(N[(NdChar / N[(1.0 + N[Exp[N[(mu / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(-1.0 * N[(mu / KbT), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-210], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
t_1 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + t\_0\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+240}:\\
\;\;\;\;0.5 \cdot NdChar + t\_0\\

\mathbf{elif}\;t\_1 \leq -2 \cdot 10^{-223}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{-1 \cdot \frac{mu}{KbT}}}\\

\mathbf{elif}\;t\_1 \leq 10^{-210}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -5.0000000000000003e240

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites47.0%

      \[\leadsto \color{blue}{0.5 \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]

    if -5.0000000000000003e240 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1.9999999999999999e-223

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in mu around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites69.9%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    4. Taylor expanded in mu around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{-1 \cdot \frac{mu}{KbT}}}} \]
    5. Applied rewrites53.4%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{-1 \cdot \frac{mu}{KbT}}}} \]

    if -1.9999999999999999e-223 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1e-210

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if 1e-210 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    4. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    5. Applied rewrites50.8%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 7: 68.3% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ t_1 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + t\_0\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{+240}:\\ \;\;\;\;0.5 \cdot NdChar + t\_0\\ \mathbf{elif}\;t\_1 \leq -1 \cdot 10^{-232}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Vef - mu}{KbT}}}\\ \mathbf{elif}\;t\_1 \leq 10^{-210}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_1
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
          t_0)))
   (if (<= t_1 -5e+240)
     (+ (* 0.5 NdChar) t_0)
     (if (<= t_1 -1e-232)
       (+
        (/ NdChar (+ 1.0 (exp (/ mu KbT))))
        (/ NaChar (+ 1.0 (exp (/ (- Vef mu) KbT)))))
       (if (<= t_1 1e-210)
         (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
         (+
          (/ NdChar (+ 1.0 (exp (/ EDonor KbT))))
          (/ NaChar (+ 1.0 (exp (/ EAccept KbT))))))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0;
	double tmp;
	if (t_1 <= -5e+240) {
		tmp = (0.5 * NdChar) + t_0;
	} else if (t_1 <= -1e-232) {
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp(((Vef - mu) / KbT))));
	} else if (t_1 <= 1e-210) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (NaChar / (1.0 + exp((EAccept / KbT))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_1 = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + t_0
    if (t_1 <= (-5d+240)) then
        tmp = (0.5d0 * ndchar) + t_0
    else if (t_1 <= (-1d-232)) then
        tmp = (ndchar / (1.0d0 + exp((mu / kbt)))) + (nachar / (1.0d0 + exp(((vef - mu) / kbt))))
    else if (t_1 <= 1d-210) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else
        tmp = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (nachar / (1.0d0 + exp((eaccept / kbt))))
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_1 = (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0;
	double tmp;
	if (t_1 <= -5e+240) {
		tmp = (0.5 * NdChar) + t_0;
	} else if (t_1 <= -1e-232) {
		tmp = (NdChar / (1.0 + Math.exp((mu / KbT)))) + (NaChar / (1.0 + Math.exp(((Vef - mu) / KbT))));
	} else if (t_1 <= 1e-210) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_1 = (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0
	tmp = 0
	if t_1 <= -5e+240:
		tmp = (0.5 * NdChar) + t_0
	elif t_1 <= -1e-232:
		tmp = (NdChar / (1.0 + math.exp((mu / KbT)))) + (NaChar / (1.0 + math.exp(((Vef - mu) / KbT))))
	elif t_1 <= 1e-210:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT))))
	t_1 = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT)))) + t_0)
	tmp = 0.0
	if (t_1 <= -5e+240)
		tmp = Float64(Float64(0.5 * NdChar) + t_0);
	elseif (t_1 <= -1e-232)
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(mu / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Vef - mu) / KbT)))));
	elseif (t_1 <= 1e-210)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	else
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + t_0;
	tmp = 0.0;
	if (t_1 <= -5e+240)
		tmp = (0.5 * NdChar) + t_0;
	elseif (t_1 <= -1e-232)
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp(((Vef - mu) / KbT))));
	elseif (t_1 <= 1e-210)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (NaChar / (1.0 + exp((EAccept / KbT))));
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e+240], N[(N[(0.5 * NdChar), $MachinePrecision] + t$95$0), $MachinePrecision], If[LessEqual[t$95$1, -1e-232], N[(N[(NdChar / N[(1.0 + N[Exp[N[(mu / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(N[(Vef - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1e-210], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
t_1 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + t\_0\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{+240}:\\
\;\;\;\;0.5 \cdot NdChar + t\_0\\

\mathbf{elif}\;t\_1 \leq -1 \cdot 10^{-232}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Vef - mu}{KbT}}}\\

\mathbf{elif}\;t\_1 \leq 10^{-210}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -5.0000000000000003e240

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites47.0%

      \[\leadsto \color{blue}{0.5 \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]

    if -5.0000000000000003e240 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1.00000000000000002e-232

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in mu around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites69.9%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{mu}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    4. Taylor expanded in EAccept around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\color{blue}{\left(Ev + Vef\right) - mu}}{KbT}}} \]
    5. Applied rewrites64.7%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\color{blue}{\left(Ev + Vef\right) - mu}}{KbT}}} \]
    6. Taylor expanded in Ev around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Vef - \color{blue}{mu}}{KbT}}} \]
    7. Applied rewrites59.3%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Vef - \color{blue}{mu}}{KbT}}} \]

    if -1.00000000000000002e-232 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1e-210

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if 1e-210 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    4. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    5. Applied rewrites50.8%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 8: 67.7% accurate, 0.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\ t_1 := t\_0 + 0.5 \cdot NaChar\\ t_2 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ t_3 := 0.5 \cdot NdChar + t\_2\\ t_4 := t\_0 + t\_2\\ \mathbf{if}\;t\_4 \leq -2 \cdot 10^{+242}:\\ \;\;\;\;t\_3\\ \mathbf{elif}\;t\_4 \leq -1 \cdot 10^{-216}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_4 \leq 2 \cdot 10^{-124}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{elif}\;t\_4 \leq 5 \cdot 10^{+195}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_3\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))))
        (t_1 (+ t_0 (* 0.5 NaChar)))
        (t_2
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_3 (+ (* 0.5 NdChar) t_2))
        (t_4 (+ t_0 t_2)))
   (if (<= t_4 -2e+242)
     t_3
     (if (<= t_4 -1e-216)
       t_1
       (if (<= t_4 2e-124)
         (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
         (if (<= t_4 5e+195) t_1 t_3))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = t_0 + (0.5 * NaChar);
	double t_2 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_3 = (0.5 * NdChar) + t_2;
	double t_4 = t_0 + t_2;
	double tmp;
	if (t_4 <= -2e+242) {
		tmp = t_3;
	} else if (t_4 <= -1e-216) {
		tmp = t_1;
	} else if (t_4 <= 2e-124) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else if (t_4 <= 5e+195) {
		tmp = t_1;
	} else {
		tmp = t_3;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: t_3
    real(8) :: t_4
    real(8) :: tmp
    t_0 = ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))
    t_1 = t_0 + (0.5d0 * nachar)
    t_2 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_3 = (0.5d0 * ndchar) + t_2
    t_4 = t_0 + t_2
    if (t_4 <= (-2d+242)) then
        tmp = t_3
    else if (t_4 <= (-1d-216)) then
        tmp = t_1
    else if (t_4 <= 2d-124) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else if (t_4 <= 5d+195) then
        tmp = t_1
    else
        tmp = t_3
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = t_0 + (0.5 * NaChar);
	double t_2 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_3 = (0.5 * NdChar) + t_2;
	double t_4 = t_0 + t_2;
	double tmp;
	if (t_4 <= -2e+242) {
		tmp = t_3;
	} else if (t_4 <= -1e-216) {
		tmp = t_1;
	} else if (t_4 <= 2e-124) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else if (t_4 <= 5e+195) {
		tmp = t_1;
	} else {
		tmp = t_3;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))
	t_1 = t_0 + (0.5 * NaChar)
	t_2 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_3 = (0.5 * NdChar) + t_2
	t_4 = t_0 + t_2
	tmp = 0
	if t_4 <= -2e+242:
		tmp = t_3
	elif t_4 <= -1e-216:
		tmp = t_1
	elif t_4 <= 2e-124:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	elif t_4 <= 5e+195:
		tmp = t_1
	else:
		tmp = t_3
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT))))
	t_1 = Float64(t_0 + Float64(0.5 * NaChar))
	t_2 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT))))
	t_3 = Float64(Float64(0.5 * NdChar) + t_2)
	t_4 = Float64(t_0 + t_2)
	tmp = 0.0
	if (t_4 <= -2e+242)
		tmp = t_3;
	elseif (t_4 <= -1e-216)
		tmp = t_1;
	elseif (t_4 <= 2e-124)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	elseif (t_4 <= 5e+195)
		tmp = t_1;
	else
		tmp = t_3;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	t_1 = t_0 + (0.5 * NaChar);
	t_2 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_3 = (0.5 * NdChar) + t_2;
	t_4 = t_0 + t_2;
	tmp = 0.0;
	if (t_4 <= -2e+242)
		tmp = t_3;
	elseif (t_4 <= -1e-216)
		tmp = t_1;
	elseif (t_4 <= 2e-124)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	elseif (t_4 <= 5e+195)
		tmp = t_1;
	else
		tmp = t_3;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(N[(0.5 * NdChar), $MachinePrecision] + t$95$2), $MachinePrecision]}, Block[{t$95$4 = N[(t$95$0 + t$95$2), $MachinePrecision]}, If[LessEqual[t$95$4, -2e+242], t$95$3, If[LessEqual[t$95$4, -1e-216], t$95$1, If[LessEqual[t$95$4, 2e-124], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$4, 5e+195], t$95$1, t$95$3]]]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\
t_1 := t\_0 + 0.5 \cdot NaChar\\
t_2 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
t_3 := 0.5 \cdot NdChar + t\_2\\
t_4 := t\_0 + t\_2\\
\mathbf{if}\;t\_4 \leq -2 \cdot 10^{+242}:\\
\;\;\;\;t\_3\\

\mathbf{elif}\;t\_4 \leq -1 \cdot 10^{-216}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_4 \leq 2 \cdot 10^{-124}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{elif}\;t\_4 \leq 5 \cdot 10^{+195}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_3\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -2.0000000000000001e242 or 4.9999999999999998e195 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites47.0%

      \[\leadsto \color{blue}{0.5 \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]

    if -2.0000000000000001e242 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1e-216 or 1.99999999999999987e-124 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 4.9999999999999998e195

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]

    if -1e-216 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1.99999999999999987e-124

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 9: 66.4% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\ t_1 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ t_2 := t\_0 + t\_1\\ \mathbf{if}\;t\_2 \leq -2 \cdot 10^{+242}:\\ \;\;\;\;0.5 \cdot NdChar + t\_1\\ \mathbf{elif}\;t\_2 \leq -1 \cdot 10^{-216}:\\ \;\;\;\;t\_0 + 0.5 \cdot NaChar\\ \mathbf{elif}\;t\_2 \leq 10^{-210}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))))
        (t_1
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_2 (+ t_0 t_1)))
   (if (<= t_2 -2e+242)
     (+ (* 0.5 NdChar) t_1)
     (if (<= t_2 -1e-216)
       (+ t_0 (* 0.5 NaChar))
       (if (<= t_2 1e-210)
         (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
         (+
          (/ NdChar (+ 1.0 (exp (/ EDonor KbT))))
          (/ NaChar (+ 1.0 (exp (/ EAccept KbT))))))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_2 = t_0 + t_1;
	double tmp;
	if (t_2 <= -2e+242) {
		tmp = (0.5 * NdChar) + t_1;
	} else if (t_2 <= -1e-216) {
		tmp = t_0 + (0.5 * NaChar);
	} else if (t_2 <= 1e-210) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (NaChar / (1.0 + exp((EAccept / KbT))));
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_0 = ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))
    t_1 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_2 = t_0 + t_1
    if (t_2 <= (-2d+242)) then
        tmp = (0.5d0 * ndchar) + t_1
    else if (t_2 <= (-1d-216)) then
        tmp = t_0 + (0.5d0 * nachar)
    else if (t_2 <= 1d-210) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else
        tmp = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (nachar / (1.0d0 + exp((eaccept / kbt))))
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	double t_1 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_2 = t_0 + t_1;
	double tmp;
	if (t_2 <= -2e+242) {
		tmp = (0.5 * NdChar) + t_1;
	} else if (t_2 <= -1e-216) {
		tmp = t_0 + (0.5 * NaChar);
	} else if (t_2 <= 1e-210) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))
	t_1 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_2 = t_0 + t_1
	tmp = 0
	if t_2 <= -2e+242:
		tmp = (0.5 * NdChar) + t_1
	elif t_2 <= -1e-216:
		tmp = t_0 + (0.5 * NaChar)
	elif t_2 <= 1e-210:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT))))
	t_1 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT))))
	t_2 = Float64(t_0 + t_1)
	tmp = 0.0
	if (t_2 <= -2e+242)
		tmp = Float64(Float64(0.5 * NdChar) + t_1);
	elseif (t_2 <= -1e-216)
		tmp = Float64(t_0 + Float64(0.5 * NaChar));
	elseif (t_2 <= 1e-210)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	else
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)));
	t_1 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_2 = t_0 + t_1;
	tmp = 0.0;
	if (t_2 <= -2e+242)
		tmp = (0.5 * NdChar) + t_1;
	elseif (t_2 <= -1e-216)
		tmp = t_0 + (0.5 * NaChar);
	elseif (t_2 <= 1e-210)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (NaChar / (1.0 + exp((EAccept / KbT))));
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(t$95$0 + t$95$1), $MachinePrecision]}, If[LessEqual[t$95$2, -2e+242], N[(N[(0.5 * NdChar), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[t$95$2, -1e-216], N[(t$95$0 + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 1e-210], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}}\\
t_1 := \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\
t_2 := t\_0 + t\_1\\
\mathbf{if}\;t\_2 \leq -2 \cdot 10^{+242}:\\
\;\;\;\;0.5 \cdot NdChar + t\_1\\

\mathbf{elif}\;t\_2 \leq -1 \cdot 10^{-216}:\\
\;\;\;\;t\_0 + 0.5 \cdot NaChar\\

\mathbf{elif}\;t\_2 \leq 10^{-210}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -2.0000000000000001e242

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    3. Applied rewrites47.0%

      \[\leadsto \color{blue}{0.5 \cdot NdChar} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]

    if -2.0000000000000001e242 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < -1e-216

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]

    if -1e-216 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1e-210

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if 1e-210 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT)))))

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    4. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    5. Applied rewrites50.8%

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
  3. Recombined 4 regimes into one program.
  4. Add Preprocessing

Alternative 10: 63.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{if}\;NaChar \leq -1.6 \cdot 10^{-86}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + 0.5 \cdot NaChar\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))))
   (if (<= NaChar -1.6e-86)
     t_0
     (if (<= NaChar 6.2e+19)
       (+
        (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
        (* 0.5 NaChar))
       t_0))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double tmp;
	if (NaChar <= -1.6e-86) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (0.5 * NaChar);
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: tmp
    t_0 = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    if (nachar <= (-1.6d-86)) then
        tmp = t_0
    else if (nachar <= 6.2d+19) then
        tmp = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + (0.5d0 * nachar)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double tmp;
	if (NaChar <= -1.6e-86) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (0.5 * NaChar);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	tmp = 0
	if NaChar <= -1.6e-86:
		tmp = t_0
	elif NaChar <= 6.2e+19:
		tmp = (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (0.5 * NaChar)
	else:
		tmp = t_0
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))))
	tmp = 0.0
	if (NaChar <= -1.6e-86)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(-Float64(Float64(Float64(Ec - Vef) - EDonor) - mu)) / KbT)))) + Float64(0.5 * NaChar));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	tmp = 0.0;
	if (NaChar <= -1.6e-86)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (0.5 * NaChar);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[NaChar, -1.6e-86], t$95$0, If[LessEqual[NaChar, 6.2e+19], N[(N[(NdChar / N[(1.0 + N[Exp[N[((-N[(N[(N[(Ec - Vef), $MachinePrecision] - EDonor), $MachinePrecision] - mu), $MachinePrecision]) / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\
\mathbf{if}\;NaChar \leq -1.6 \cdot 10^{-86}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + 0.5 \cdot NaChar\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -1.60000000000000003e-86 or 6.2e19 < NaChar

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if -1.60000000000000003e-86 < NaChar < 6.2e19

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 11: 60.8% accurate, 1.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{if}\;NaChar \leq -4 \cdot 10^{-94}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + 0.5 \cdot NaChar\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))))
   (if (<= NaChar -4e-94)
     t_0
     (if (<= NaChar 6.2e+19)
       (+ (/ NdChar (+ 1.0 (exp (/ (- (+ Vef mu) Ec) KbT)))) (* 0.5 NaChar))
       t_0))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double tmp;
	if (NaChar <= -4e-94) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = (NdChar / (1.0 + exp((((Vef + mu) - Ec) / KbT)))) + (0.5 * NaChar);
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: tmp
    t_0 = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    if (nachar <= (-4d-94)) then
        tmp = t_0
    else if (nachar <= 6.2d+19) then
        tmp = (ndchar / (1.0d0 + exp((((vef + mu) - ec) / kbt)))) + (0.5d0 * nachar)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double tmp;
	if (NaChar <= -4e-94) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = (NdChar / (1.0 + Math.exp((((Vef + mu) - Ec) / KbT)))) + (0.5 * NaChar);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	tmp = 0
	if NaChar <= -4e-94:
		tmp = t_0
	elif NaChar <= 6.2e+19:
		tmp = (NdChar / (1.0 + math.exp((((Vef + mu) - Ec) / KbT)))) + (0.5 * NaChar)
	else:
		tmp = t_0
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))))
	tmp = 0.0
	if (NaChar <= -4e-94)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(Float64(Vef + mu) - Ec) / KbT)))) + Float64(0.5 * NaChar));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	tmp = 0.0;
	if (NaChar <= -4e-94)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = (NdChar / (1.0 + exp((((Vef + mu) - Ec) / KbT)))) + (0.5 * NaChar);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[NaChar, -4e-94], t$95$0, If[LessEqual[NaChar, 6.2e+19], N[(N[(NdChar / N[(1.0 + N[Exp[N[(N[(N[(Vef + mu), $MachinePrecision] - Ec), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\
\mathbf{if}\;NaChar \leq -4 \cdot 10^{-94}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + 0.5 \cdot NaChar\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -3.9999999999999998e-94 or 6.2e19 < NaChar

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if -3.9999999999999998e-94 < NaChar < 6.2e19

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]
    4. Taylor expanded in EDonor around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    5. Applied rewrites44.5%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + 0.5 \cdot NaChar \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 12: 58.3% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ t_1 := \frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar\\ \mathbf{if}\;NaChar \leq -1.7 \cdot 10^{-164}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 2.15 \cdot 10^{-284}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;NaChar \leq 1.7 \cdot 10^{-154}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT)))))
        (t_1 (+ (/ NdChar (+ 1.0 (exp (/ EDonor KbT)))) (* 0.5 NaChar))))
   (if (<= NaChar -1.7e-164)
     t_0
     (if (<= NaChar 2.15e-284)
       t_1
       (if (<= NaChar 1.7e-154) t_0 (if (<= NaChar 6.2e+19) t_1 t_0))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double t_1 = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
	double tmp;
	if (NaChar <= -1.7e-164) {
		tmp = t_0;
	} else if (NaChar <= 2.15e-284) {
		tmp = t_1;
	} else if (NaChar <= 1.7e-154) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    t_1 = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (0.5d0 * nachar)
    if (nachar <= (-1.7d-164)) then
        tmp = t_0
    else if (nachar <= 2.15d-284) then
        tmp = t_1
    else if (nachar <= 1.7d-154) then
        tmp = t_0
    else if (nachar <= 6.2d+19) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double t_1 = (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (0.5 * NaChar);
	double tmp;
	if (NaChar <= -1.7e-164) {
		tmp = t_0;
	} else if (NaChar <= 2.15e-284) {
		tmp = t_1;
	} else if (NaChar <= 1.7e-154) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	t_1 = (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (0.5 * NaChar)
	tmp = 0
	if NaChar <= -1.7e-164:
		tmp = t_0
	elif NaChar <= 2.15e-284:
		tmp = t_1
	elif NaChar <= 1.7e-154:
		tmp = t_0
	elif NaChar <= 6.2e+19:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))))
	t_1 = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(0.5 * NaChar))
	tmp = 0.0
	if (NaChar <= -1.7e-164)
		tmp = t_0;
	elseif (NaChar <= 2.15e-284)
		tmp = t_1;
	elseif (NaChar <= 1.7e-154)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	t_1 = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
	tmp = 0.0;
	if (NaChar <= -1.7e-164)
		tmp = t_0;
	elseif (NaChar <= 2.15e-284)
		tmp = t_1;
	elseif (NaChar <= 1.7e-154)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[NaChar, -1.7e-164], t$95$0, If[LessEqual[NaChar, 2.15e-284], t$95$1, If[LessEqual[NaChar, 1.7e-154], t$95$0, If[LessEqual[NaChar, 6.2e+19], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\
t_1 := \frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar\\
\mathbf{if}\;NaChar \leq -1.7 \cdot 10^{-164}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;NaChar \leq 2.15 \cdot 10^{-284}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;NaChar \leq 1.7 \cdot 10^{-154}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\
\;\;\;\;t\_1\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -1.7e-164 or 2.1500000000000001e-284 < NaChar < 1.6999999999999999e-154 or 6.2e19 < NaChar

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if -1.7e-164 < NaChar < 2.1500000000000001e-284 or 1.6999999999999999e-154 < NaChar < 6.2e19

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]
    4. Taylor expanded in EDonor around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    5. Applied rewrites44.5%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + 0.5 \cdot NaChar \]
    6. Taylor expanded in Vef around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu - Ec}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    7. Applied rewrites41.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu - Ec}{KbT}}} + 0.5 \cdot NaChar \]
    8. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{EDonor}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    9. Applied rewrites36.4%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{EDonor}}{KbT}}} + 0.5 \cdot NaChar \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 13: 57.1% accurate, 1.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{if}\;NaChar \leq -1.4 \cdot 10^{-94}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef - Ec}{KbT}}} + 0.5 \cdot NaChar\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))))
   (if (<= NaChar -1.4e-94)
     t_0
     (if (<= NaChar 6.2e+19)
       (+ (/ NdChar (+ 1.0 (exp (/ (- Vef Ec) KbT)))) (* 0.5 NaChar))
       t_0))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double tmp;
	if (NaChar <= -1.4e-94) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = (NdChar / (1.0 + exp(((Vef - Ec) / KbT)))) + (0.5 * NaChar);
	} else {
		tmp = t_0;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: t_0
    real(8) :: tmp
    t_0 = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    if (nachar <= (-1.4d-94)) then
        tmp = t_0
    else if (nachar <= 6.2d+19) then
        tmp = (ndchar / (1.0d0 + exp(((vef - ec) / kbt)))) + (0.5d0 * nachar)
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double t_0 = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	double tmp;
	if (NaChar <= -1.4e-94) {
		tmp = t_0;
	} else if (NaChar <= 6.2e+19) {
		tmp = (NdChar / (1.0 + Math.exp(((Vef - Ec) / KbT)))) + (0.5 * NaChar);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	tmp = 0
	if NaChar <= -1.4e-94:
		tmp = t_0
	elif NaChar <= 6.2e+19:
		tmp = (NdChar / (1.0 + math.exp(((Vef - Ec) / KbT)))) + (0.5 * NaChar)
	else:
		tmp = t_0
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))))
	tmp = 0.0
	if (NaChar <= -1.4e-94)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(Vef - Ec) / KbT)))) + Float64(0.5 * NaChar));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	tmp = 0.0;
	if (NaChar <= -1.4e-94)
		tmp = t_0;
	elseif (NaChar <= 6.2e+19)
		tmp = (NdChar / (1.0 + exp(((Vef - Ec) / KbT)))) + (0.5 * NaChar);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[NaChar, -1.4e-94], t$95$0, If[LessEqual[NaChar, 6.2e+19], N[(N[(NdChar / N[(1.0 + N[Exp[N[(N[(Vef - Ec), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\
\mathbf{if}\;NaChar \leq -1.4 \cdot 10^{-94}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;NaChar \leq 6.2 \cdot 10^{+19}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef - Ec}{KbT}}} + 0.5 \cdot NaChar\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -1.3999999999999999e-94 or 6.2e19 < NaChar

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Applied rewrites59.5%

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]

    if -1.3999999999999999e-94 < NaChar < 6.2e19

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]
    4. Taylor expanded in EDonor around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    5. Applied rewrites44.5%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + 0.5 \cdot NaChar \]
    6. Taylor expanded in mu around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef - \color{blue}{Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    7. Applied rewrites40.6%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef - \color{blue}{Ec}}{KbT}}} + 0.5 \cdot NaChar \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 14: 36.4% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;KbT \leq 8.2 \cdot 10^{-262}:\\ \;\;\;\;\frac{NdChar}{2} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (if (<= KbT 8.2e-262)
   (+ (/ NdChar 2.0) (/ NaChar (+ 1.0 (exp (/ EAccept KbT)))))
   (+ (/ NdChar (+ 1.0 (exp (/ EDonor KbT)))) (* 0.5 NaChar))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double tmp;
	if (KbT <= 8.2e-262) {
		tmp = (NdChar / 2.0) + (NaChar / (1.0 + exp((EAccept / KbT))));
	} else {
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: tmp
    if (kbt <= 8.2d-262) then
        tmp = (ndchar / 2.0d0) + (nachar / (1.0d0 + exp((eaccept / kbt))))
    else
        tmp = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (0.5d0 * nachar)
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double tmp;
	if (KbT <= 8.2e-262) {
		tmp = (NdChar / 2.0) + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	} else {
		tmp = (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (0.5 * NaChar);
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	tmp = 0
	if KbT <= 8.2e-262:
		tmp = (NdChar / 2.0) + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	else:
		tmp = (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (0.5 * NaChar)
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0
	if (KbT <= 8.2e-262)
		tmp = Float64(Float64(NdChar / 2.0) + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	else
		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(0.5 * NaChar));
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0;
	if (KbT <= 8.2e-262)
		tmp = (NdChar / 2.0) + (NaChar / (1.0 + exp((EAccept / KbT))));
	else
		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[KbT, 8.2e-262], N[(N[(NdChar / 2.0), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;KbT \leq 8.2 \cdot 10^{-262}:\\
\;\;\;\;\frac{NdChar}{2} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if KbT < 8.20000000000000052e-262

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in EAccept around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    3. Applied rewrites69.8%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\color{blue}{\frac{EAccept}{KbT}}}} \]
    4. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{\color{blue}{2}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    5. Applied rewrites36.0%

      \[\leadsto \frac{NdChar}{\color{blue}{2}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]

    if 8.20000000000000052e-262 < KbT

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Applied rewrites48.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]
    4. Taylor expanded in EDonor around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    5. Applied rewrites44.5%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + 0.5 \cdot NaChar \]
    6. Taylor expanded in Vef around 0

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu - Ec}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    7. Applied rewrites41.0%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{mu - Ec}{KbT}}} + 0.5 \cdot NaChar \]
    8. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{EDonor}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
    9. Applied rewrites36.4%

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{EDonor}}{KbT}}} + 0.5 \cdot NaChar \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 15: 36.3% accurate, 2.3× speedup?

\[\begin{array}{l} \\ \frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (+ (/ NdChar (+ 1.0 (exp (/ EDonor KbT)))) (* 0.5 NaChar)))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    code = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (0.5d0 * nachar)
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (0.5 * NaChar);
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	return (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (0.5 * NaChar)
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(0.5 * NaChar))
end
function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
  2. Taylor expanded in KbT around inf

    \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
  3. Applied rewrites48.0%

    \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{0.5 \cdot NaChar} \]
  4. Taylor expanded in EDonor around 0

    \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
  5. Applied rewrites44.5%

    \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{\left(Vef + mu\right) - Ec}}{KbT}}} + 0.5 \cdot NaChar \]
  6. Taylor expanded in Vef around 0

    \[\leadsto \frac{NdChar}{1 + e^{\frac{mu - Ec}{KbT}}} + \frac{1}{2} \cdot NaChar \]
  7. Applied rewrites41.0%

    \[\leadsto \frac{NdChar}{1 + e^{\frac{mu - Ec}{KbT}}} + 0.5 \cdot NaChar \]
  8. Taylor expanded in EDonor around inf

    \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{EDonor}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
  9. Applied rewrites36.4%

    \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{EDonor}}{KbT}}} + 0.5 \cdot NaChar \]
  10. Add Preprocessing

Alternative 16: 28.2% accurate, 9.1× speedup?

\[\begin{array}{l} \\ \left(NaChar + NdChar\right) \cdot 0.5 \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (* (+ NaChar NdChar) 0.5))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NaChar + NdChar) * 0.5;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    code = (nachar + ndchar) * 0.5d0
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return (NaChar + NdChar) * 0.5;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	return (NaChar + NdChar) * 0.5
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return Float64(Float64(NaChar + NdChar) * 0.5)
end
function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = (NaChar + NdChar) * 0.5;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(N[(NaChar + NdChar), $MachinePrecision] * 0.5), $MachinePrecision]
\begin{array}{l}

\\
\left(NaChar + NdChar\right) \cdot 0.5
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
  2. Taylor expanded in KbT around inf

    \[\leadsto \color{blue}{\frac{1}{2} \cdot NaChar + \frac{1}{2} \cdot NdChar} \]
  3. Applied rewrites28.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]
  4. Applied rewrites28.2%

    \[\leadsto \color{blue}{\left(NaChar + NdChar\right) \cdot 0.5} \]
  5. Add Preprocessing

Alternative 17: 22.8% accurate, 5.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;NaChar \leq -3.8 \cdot 10^{-85}:\\ \;\;\;\;0.5 \cdot NaChar\\ \mathbf{elif}\;NaChar \leq 5.2 \cdot 10^{+88}:\\ \;\;\;\;NdChar \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot NaChar\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (if (<= NaChar -3.8e-85)
   (* 0.5 NaChar)
   (if (<= NaChar 5.2e+88) (* NdChar 0.5) (* 0.5 NaChar))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double tmp;
	if (NaChar <= -3.8e-85) {
		tmp = 0.5 * NaChar;
	} else if (NaChar <= 5.2e+88) {
		tmp = NdChar * 0.5;
	} else {
		tmp = 0.5 * NaChar;
	}
	return tmp;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    real(8) :: tmp
    if (nachar <= (-3.8d-85)) then
        tmp = 0.5d0 * nachar
    else if (nachar <= 5.2d+88) then
        tmp = ndchar * 0.5d0
    else
        tmp = 0.5d0 * nachar
    end if
    code = tmp
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double tmp;
	if (NaChar <= -3.8e-85) {
		tmp = 0.5 * NaChar;
	} else if (NaChar <= 5.2e+88) {
		tmp = NdChar * 0.5;
	} else {
		tmp = 0.5 * NaChar;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	tmp = 0
	if NaChar <= -3.8e-85:
		tmp = 0.5 * NaChar
	elif NaChar <= 5.2e+88:
		tmp = NdChar * 0.5
	else:
		tmp = 0.5 * NaChar
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0
	if (NaChar <= -3.8e-85)
		tmp = Float64(0.5 * NaChar);
	elseif (NaChar <= 5.2e+88)
		tmp = Float64(NdChar * 0.5);
	else
		tmp = Float64(0.5 * NaChar);
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0;
	if (NaChar <= -3.8e-85)
		tmp = 0.5 * NaChar;
	elseif (NaChar <= 5.2e+88)
		tmp = NdChar * 0.5;
	else
		tmp = 0.5 * NaChar;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[NaChar, -3.8e-85], N[(0.5 * NaChar), $MachinePrecision], If[LessEqual[NaChar, 5.2e+88], N[(NdChar * 0.5), $MachinePrecision], N[(0.5 * NaChar), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;NaChar \leq -3.8 \cdot 10^{-85}:\\
\;\;\;\;0.5 \cdot NaChar\\

\mathbf{elif}\;NaChar \leq 5.2 \cdot 10^{+88}:\\
\;\;\;\;NdChar \cdot 0.5\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot NaChar\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -3.7999999999999999e-85 or 5.2000000000000001e88 < NaChar

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NaChar + \frac{1}{2} \cdot NdChar} \]
    3. Applied rewrites28.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]
    4. Taylor expanded in NdChar around 0

      \[\leadsto \frac{1}{2} \cdot \color{blue}{NaChar} \]
    5. Applied rewrites18.6%

      \[\leadsto 0.5 \cdot \color{blue}{NaChar} \]

    if -3.7999999999999999e-85 < NaChar < 5.2000000000000001e88

    1. Initial program 100.0%

      \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
    2. Taylor expanded in KbT around inf

      \[\leadsto \color{blue}{\frac{1}{2} \cdot NaChar + \frac{1}{2} \cdot NdChar} \]
    3. Applied rewrites28.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]
    4. Taylor expanded in NdChar around inf

      \[\leadsto NdChar \cdot \color{blue}{\left(\frac{1}{2} + \frac{1}{2} \cdot \frac{NaChar}{NdChar}\right)} \]
    5. Applied rewrites25.3%

      \[\leadsto NdChar \cdot \color{blue}{\left(0.5 + 0.5 \cdot \frac{NaChar}{NdChar}\right)} \]
    6. Taylor expanded in NdChar around inf

      \[\leadsto NdChar \cdot \frac{1}{2} \]
    7. Applied rewrites18.4%

      \[\leadsto NdChar \cdot 0.5 \]
  3. Recombined 2 regimes into one program.
  4. Add Preprocessing

Alternative 18: 18.6% accurate, 15.4× speedup?

\[\begin{array}{l} \\ 0.5 \cdot NaChar \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (* 0.5 NaChar))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return 0.5 * NaChar;
}
module fmin_fmax_functions
    implicit none
    private
    public fmax
    public fmin

    interface fmax
        module procedure fmax88
        module procedure fmax44
        module procedure fmax84
        module procedure fmax48
    end interface
    interface fmin
        module procedure fmin88
        module procedure fmin44
        module procedure fmin84
        module procedure fmin48
    end interface
contains
    real(8) function fmax88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(4) function fmax44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, max(x, y), y /= y), x /= x)
    end function
    real(8) function fmax84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmax48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
    end function
    real(8) function fmin88(x, y) result (res)
        real(8), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(4) function fmin44(x, y) result (res)
        real(4), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(y, merge(x, min(x, y), y /= y), x /= x)
    end function
    real(8) function fmin84(x, y) result(res)
        real(8), intent (in) :: x
        real(4), intent (in) :: y
        res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
    end function
    real(8) function fmin48(x, y) result(res)
        real(4), intent (in) :: x
        real(8), intent (in) :: y
        res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
    end function
end module

real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
use fmin_fmax_functions
    real(8), intent (in) :: ndchar
    real(8), intent (in) :: ec
    real(8), intent (in) :: vef
    real(8), intent (in) :: edonor
    real(8), intent (in) :: mu
    real(8), intent (in) :: kbt
    real(8), intent (in) :: nachar
    real(8), intent (in) :: ev
    real(8), intent (in) :: eaccept
    code = 0.5d0 * nachar
end function
public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return 0.5 * NaChar;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	return 0.5 * NaChar
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return Float64(0.5 * NaChar)
end
function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.5 * NaChar;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(0.5 * NaChar), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot NaChar
\end{array}
Derivation
  1. Initial program 100.0%

    \[\frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
  2. Taylor expanded in KbT around inf

    \[\leadsto \color{blue}{\frac{1}{2} \cdot NaChar + \frac{1}{2} \cdot NdChar} \]
  3. Applied rewrites28.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]
  4. Taylor expanded in NdChar around 0

    \[\leadsto \frac{1}{2} \cdot \color{blue}{NaChar} \]
  5. Applied rewrites18.6%

    \[\leadsto 0.5 \cdot \color{blue}{NaChar} \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025153 
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
  :name "Bulmash initializePoisson"
  :precision binary64
  (+ (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT)))) (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT))))))