Bulmash initializePoisson

Percentage Accurate: 100.0% → 100.0%
Time: 9.0s
Alternatives: 17
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 17 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: 93.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}}\\ \mathbf{if}\;mu \leq -2.4 \cdot 10^{+139}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;mu \leq 1.75 \cdot 10^{+143}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{EAccept + \left(Ev + Vef\right)}{KbT}}} + \frac{NdChar}{1 + e^{\frac{\left(EDonor + Vef\right) - Ec}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \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) EAccept) (- mu)) KbT)))))))
   (if (<= mu -2.4e+139)
     t_0
     (if (<= mu 1.75e+143)
       (+
        (/ NaChar (+ 1.0 (exp (/ (+ EAccept (+ Ev Vef)) KbT))))
        (/ NdChar (+ 1.0 (exp (/ (- (+ EDonor Vef) Ec) KbT)))))
       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 = (NdChar / (1.0 + exp((mu / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (mu <= -2.4e+139) {
		tmp = t_0;
	} else if (mu <= 1.75e+143) {
		tmp = (NaChar / (1.0 + exp(((EAccept + (Ev + Vef)) / KbT)))) + (NdChar / (1.0 + exp((((EDonor + Vef) - Ec) / KbT))));
	} 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 = (ndchar / (1.0d0 + exp((mu / kbt)))) + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
    if (mu <= (-2.4d+139)) then
        tmp = t_0
    else if (mu <= 1.75d+143) then
        tmp = (nachar / (1.0d0 + exp(((eaccept + (ev + vef)) / kbt)))) + (ndchar / (1.0d0 + exp((((edonor + vef) - ec) / kbt))))
    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 = (NdChar / (1.0 + Math.exp((mu / KbT)))) + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (mu <= -2.4e+139) {
		tmp = t_0;
	} else if (mu <= 1.75e+143) {
		tmp = (NaChar / (1.0 + Math.exp(((EAccept + (Ev + Vef)) / KbT)))) + (NdChar / (1.0 + Math.exp((((EDonor + Vef) - Ec) / KbT))));
	} else {
		tmp = t_0;
	}
	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) + EAccept) + -mu) / KbT))))
	tmp = 0
	if mu <= -2.4e+139:
		tmp = t_0
	elif mu <= 1.75e+143:
		tmp = (NaChar / (1.0 + math.exp(((EAccept + (Ev + Vef)) / KbT)))) + (NdChar / (1.0 + math.exp((((EDonor + Vef) - Ec) / KbT))))
	else:
		tmp = t_0
	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(Float64(Ev + Vef) + EAccept) + Float64(-mu)) / KbT)))))
	tmp = 0.0
	if (mu <= -2.4e+139)
		tmp = t_0;
	elseif (mu <= 1.75e+143)
		tmp = Float64(Float64(NaChar / Float64(1.0 + exp(Float64(Float64(EAccept + Float64(Ev + Vef)) / KbT)))) + Float64(NdChar / Float64(1.0 + exp(Float64(Float64(Float64(EDonor + Vef) - Ec) / KbT)))));
	else
		tmp = t_0;
	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) + EAccept) + -mu) / KbT))));
	tmp = 0.0;
	if (mu <= -2.4e+139)
		tmp = t_0;
	elseif (mu <= 1.75e+143)
		tmp = (NaChar / (1.0 + exp(((EAccept + (Ev + Vef)) / KbT)))) + (NdChar / (1.0 + exp((((EDonor + Vef) - Ec) / KbT))));
	else
		tmp = t_0;
	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[(N[(Ev + Vef), $MachinePrecision] + EAccept), $MachinePrecision] + (-mu)), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[mu, -2.4e+139], t$95$0, If[LessEqual[mu, 1.75e+143], N[(N[(NaChar / N[(1.0 + N[Exp[N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NdChar / N[(1.0 + N[Exp[N[(N[(N[(EDonor + Vef), $MachinePrecision] - Ec), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

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

\mathbf{elif}\;mu \leq 1.75 \cdot 10^{+143}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{EAccept + \left(Ev + Vef\right)}{KbT}}} + \frac{NdChar}{1 + e^{\frac{\left(EDonor + Vef\right) - Ec}{KbT}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if mu < -2.40000000000000008e139 or 1.75000000000000004e143 < mu

    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. Step-by-step derivation
      1. lower-/.f6468.8

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

      \[\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 -2.40000000000000008e139 < mu < 1.75000000000000004e143

    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 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{EAccept + \left(Ev + Vef\right)}{KbT}}} + \frac{NdChar}{1 + e^{\frac{\left(EDonor + Vef\right) - Ec}{KbT}}}} \]
    3. Step-by-step derivation
      1. lower-+.f64N/A

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

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

Alternative 3: 80.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^{-170}:\\ \;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \mathbf{elif}\;t\_2 \leq 0:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + 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
         (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))
        (t_2 (+ t_0 t_1)))
   (if (<= t_2 -2e-170)
     (+ t_0 (/ NaChar (+ 1.0 (exp (/ EAccept KbT)))))
     (if (<= t_2 0.0)
       (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
       (+ (/ NdChar (+ 1.0 (exp (/ 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 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_2 = t_0 + t_1;
	double tmp;
	if (t_2 <= -2e-170) {
		tmp = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	} else if (t_2 <= 0.0) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + 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 = nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt)))
    t_2 = t_0 + t_1
    if (t_2 <= (-2d-170)) then
        tmp = t_0 + (nachar / (1.0d0 + exp((eaccept / kbt))))
    else if (t_2 <= 0.0d0) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    else
        tmp = (ndchar / (1.0d0 + exp((mu / kbt)))) + 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 = NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	double t_2 = t_0 + t_1;
	double tmp;
	if (t_2 <= -2e-170) {
		tmp = t_0 + (NaChar / (1.0 + Math.exp((EAccept / KbT))));
	} else if (t_2 <= 0.0) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = (NdChar / (1.0 + Math.exp((mu / KbT)))) + 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 = NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT)))
	t_2 = t_0 + t_1
	tmp = 0
	if t_2 <= -2e-170:
		tmp = t_0 + (NaChar / (1.0 + math.exp((EAccept / KbT))))
	elif t_2 <= 0.0:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = (NdChar / (1.0 + math.exp((mu / KbT)))) + 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(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-170)
		tmp = Float64(t_0 + Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT)))));
	elseif (t_2 <= 0.0)
		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(mu / KbT)))) + 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 = NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT)));
	t_2 = t_0 + t_1;
	tmp = 0.0;
	if (t_2 <= -2e-170)
		tmp = t_0 + (NaChar / (1.0 + exp((EAccept / KbT))));
	elseif (t_2 <= 0.0)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = (NdChar / (1.0 + exp((mu / KbT)))) + 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[(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-170], N[(t$95$0 + N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 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], N[(N[(NdChar / N[(1.0 + N[Exp[N[(mu / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$1), $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^{-170}:\\
\;\;\;\;t\_0 + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\

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

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + 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))))) < -1.99999999999999997e-170

    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. Step-by-step derivation
      1. lower-/.f6468.3

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

      \[\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 -1.99999999999999997e-170 < (+.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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

    if 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)))))

    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. Step-by-step derivation
      1. lower-/.f6468.8

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

      \[\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. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 4: 77.8% 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 -2 \cdot 10^{-170}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-150}:\\ \;\;\;\;\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 -2e-170)
     t_1
     (if (<= t_2 5e-150)
       (/ 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 <= -2e-170) {
		tmp = t_1;
	} else if (t_2 <= 5e-150) {
		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 <= (-2d-170)) then
        tmp = t_1
    else if (t_2 <= 5d-150) 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 <= -2e-170) {
		tmp = t_1;
	} else if (t_2 <= 5e-150) {
		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 <= -2e-170:
		tmp = t_1
	elif t_2 <= 5e-150:
		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 <= -2e-170)
		tmp = t_1;
	elseif (t_2 <= 5e-150)
		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 <= -2e-170)
		tmp = t_1;
	elseif (t_2 <= 5e-150)
		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, -2e-170], t$95$1, If[LessEqual[t$95$2, 5e-150], 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 -2 \cdot 10^{-170}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{-150}:\\
\;\;\;\;\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 2 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.99999999999999997e-170 or 4.9999999999999999e-150 < (+.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. Step-by-step derivation
      1. lower-/.f6468.3

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

      \[\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 -1.99999999999999997e-170 < (+.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.9999999999999999e-150

    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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

Alternative 5: 73.9% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\ t_1 := \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}}}\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-168}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (+ Vef mu) Ec) KbT))))
          (/ NaChar (+ 1.0 (exp (/ Ev KbT))))))
        (t_1
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
          (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))))
   (if (<= t_1 -5e-168)
     t_0
     (if (<= t_1 0.0)
       (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))
       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 = (NdChar / (1.0 + exp((((Vef + mu) - Ec) / KbT)))) + (NaChar / (1.0 + exp((Ev / KbT))));
	double t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -5e-168) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} 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 = (ndchar / (1.0d0 + exp((((vef + mu) - ec) / kbt)))) + (nachar / (1.0d0 + exp((ev / kbt))))
    t_1 = (ndchar / (1.0d0 + exp((-(((ec - vef) - edonor) - mu) / kbt)))) + (nachar / (1.0d0 + exp(((((ev + vef) + eaccept) + -mu) / kbt))))
    if (t_1 <= (-5d-168)) then
        tmp = t_0
    else if (t_1 <= 0.0d0) then
        tmp = nachar / (1.0d0 + exp((((eaccept + (ev + vef)) - mu) / kbt)))
    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 = (NdChar / (1.0 + Math.exp((((Vef + mu) - Ec) / KbT)))) + (NaChar / (1.0 + Math.exp((Ev / KbT))));
	double t_1 = (NdChar / (1.0 + Math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + Math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -5e-168) {
		tmp = t_0;
	} else if (t_1 <= 0.0) {
		tmp = NaChar / (1.0 + Math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	t_0 = (NdChar / (1.0 + math.exp((((Vef + mu) - Ec) / KbT)))) + (NaChar / (1.0 + math.exp((Ev / KbT))))
	t_1 = (NdChar / (1.0 + math.exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + math.exp(((((Ev + Vef) + EAccept) + -mu) / KbT))))
	tmp = 0
	if t_1 <= -5e-168:
		tmp = t_0
	elif t_1 <= 0.0:
		tmp = NaChar / (1.0 + math.exp((((EAccept + (Ev + Vef)) - mu) / KbT)))
	else:
		tmp = t_0
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Float64(Float64(Vef + mu) - Ec) / KbT)))) + Float64(NaChar / Float64(1.0 + exp(Float64(Ev / KbT)))))
	t_1 = 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)))))
	tmp = 0.0
	if (t_1 <= -5e-168)
		tmp = t_0;
	elseif (t_1 <= 0.0)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = (NdChar / (1.0 + exp((((Vef + mu) - Ec) / KbT)))) + (NaChar / (1.0 + exp((Ev / KbT))));
	t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	tmp = 0.0;
	if (t_1 <= -5e-168)
		tmp = t_0;
	elseif (t_1 <= 0.0)
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	else
		tmp = t_0;
	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[(N[(N[(Vef + mu), $MachinePrecision] - Ec), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(NaChar / N[(1.0 + N[Exp[N[(Ev / KbT), $MachinePrecision]], $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] + 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, -5e-168], t$95$0, If[LessEqual[t$95$1, 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], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\
t_1 := \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}}}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-168}:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 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.00000000000000001e-168 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)))))

    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. Step-by-step derivation
      1. lower-/.f6468.2

        \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{\color{blue}{KbT}}}} \]
    4. Applied rewrites68.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}}}} \]
    5. Taylor expanded in EDonor around 0

      \[\leadsto \color{blue}{\frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{NdChar}{\color{blue}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
      2. lower-+.f64N/A

        \[\leadsto \frac{NdChar}{1 + \color{blue}{e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
      6. lift-+.f6461.8

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(Vef + mu\right) - Ec}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
    7. Applied rewrites61.8%

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

    if -5.00000000000000001e-168 < (+.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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

Alternative 6: 70.9% 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 -2800000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 2.3 \cdot 10^{-48}:\\ \;\;\;\;NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}}\\ \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 -2800000.0)
     t_0
     (if (<= NaChar 2.3e-48)
       (* NdChar (/ 1.0 (+ 1.0 (exp (/ (- (+ EDonor (+ Vef mu)) Ec) KbT)))))
       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 <= -2800000.0) {
		tmp = t_0;
	} else if (NaChar <= 2.3e-48) {
		tmp = NdChar * (1.0 / (1.0 + exp((((EDonor + (Vef + mu)) - Ec) / KbT))));
	} 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 <= (-2800000.0d0)) then
        tmp = t_0
    else if (nachar <= 2.3d-48) then
        tmp = ndchar * (1.0d0 / (1.0d0 + exp((((edonor + (vef + mu)) - ec) / kbt))))
    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 <= -2800000.0) {
		tmp = t_0;
	} else if (NaChar <= 2.3e-48) {
		tmp = NdChar * (1.0 / (1.0 + Math.exp((((EDonor + (Vef + mu)) - Ec) / KbT))));
	} 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 <= -2800000.0:
		tmp = t_0
	elif NaChar <= 2.3e-48:
		tmp = NdChar * (1.0 / (1.0 + math.exp((((EDonor + (Vef + mu)) - Ec) / KbT))))
	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 <= -2800000.0)
		tmp = t_0;
	elseif (NaChar <= 2.3e-48)
		tmp = Float64(NdChar * Float64(1.0 / Float64(1.0 + exp(Float64(Float64(Float64(EDonor + Float64(Vef + mu)) - Ec) / KbT)))));
	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 <= -2800000.0)
		tmp = t_0;
	elseif (NaChar <= 2.3e-48)
		tmp = NdChar * (1.0 / (1.0 + exp((((EDonor + (Vef + mu)) - Ec) / KbT))));
	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, -2800000.0], t$95$0, If[LessEqual[NaChar, 2.3e-48], N[(NdChar * N[(1.0 / N[(1.0 + N[Exp[N[(N[(N[(EDonor + N[(Vef + mu), $MachinePrecision]), $MachinePrecision] - Ec), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $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 -2800000:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -2.8e6 or 2.3000000000000001e-48 < 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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

    if -2.8e6 < NaChar < 2.3000000000000001e-48

    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 inf

      \[\leadsto \color{blue}{NdChar \cdot \left(\frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} + \frac{NaChar}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto NdChar \cdot \color{blue}{\left(\frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} + \frac{NaChar}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}\right)} \]
      2. lower-+.f64N/A

        \[\leadsto NdChar \cdot \left(\frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} + \color{blue}{\frac{NaChar}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}}\right) \]
    4. Applied rewrites90.6%

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

      \[\leadsto NdChar \cdot \frac{1}{\color{blue}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}}} \]
    6. Step-by-step derivation
      1. lift-+.f64N/A

        \[\leadsto NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      2. lift-+.f64N/A

        \[\leadsto NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      3. lift--.f64N/A

        \[\leadsto NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      4. lift-/.f64N/A

        \[\leadsto NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      5. lift-exp.f64N/A

        \[\leadsto NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      6. lift-+.f64N/A

        \[\leadsto NdChar \cdot \frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      7. lift-/.f6460.3

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

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

Alternative 7: 70.9% 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 -2800000:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 2.3 \cdot 10^{-48}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}}\\ \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 -2800000.0)
     t_0
     (if (<= NaChar 2.3e-48)
       (/ NdChar (+ 1.0 (exp (/ (- (+ EDonor (+ Vef mu)) Ec) KbT))))
       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 <= -2800000.0) {
		tmp = t_0;
	} else if (NaChar <= 2.3e-48) {
		tmp = NdChar / (1.0 + exp((((EDonor + (Vef + mu)) - Ec) / KbT)));
	} 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 <= (-2800000.0d0)) then
        tmp = t_0
    else if (nachar <= 2.3d-48) then
        tmp = ndchar / (1.0d0 + exp((((edonor + (vef + mu)) - ec) / kbt)))
    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 <= -2800000.0) {
		tmp = t_0;
	} else if (NaChar <= 2.3e-48) {
		tmp = NdChar / (1.0 + Math.exp((((EDonor + (Vef + mu)) - Ec) / KbT)));
	} 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 <= -2800000.0:
		tmp = t_0
	elif NaChar <= 2.3e-48:
		tmp = NdChar / (1.0 + math.exp((((EDonor + (Vef + mu)) - Ec) / KbT)))
	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 <= -2800000.0)
		tmp = t_0;
	elseif (NaChar <= 2.3e-48)
		tmp = Float64(NdChar / Float64(1.0 + exp(Float64(Float64(Float64(EDonor + Float64(Vef + mu)) - Ec) / KbT))));
	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 <= -2800000.0)
		tmp = t_0;
	elseif (NaChar <= 2.3e-48)
		tmp = NdChar / (1.0 + exp((((EDonor + (Vef + mu)) - Ec) / KbT)));
	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, -2800000.0], t$95$0, If[LessEqual[NaChar, 2.3e-48], N[(NdChar / N[(1.0 + N[Exp[N[(N[(N[(EDonor + N[(Vef + mu), $MachinePrecision]), $MachinePrecision] - Ec), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $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 -2800000:\\
\;\;\;\;t\_0\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -2.8e6 or 2.3000000000000001e-48 < 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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

    if -2.8e6 < NaChar < 2.3000000000000001e-48

    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 inf

      \[\leadsto \color{blue}{NdChar \cdot \left(\frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} + \frac{NaChar}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}\right)} \]
    3. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto NdChar \cdot \color{blue}{\left(\frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} + \frac{NaChar}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}\right)} \]
      2. lower-+.f64N/A

        \[\leadsto NdChar \cdot \left(\frac{1}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} + \color{blue}{\frac{NaChar}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}}\right) \]
    4. Applied rewrites90.6%

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

      \[\leadsto NdChar \cdot \left(NaChar \cdot \color{blue}{\left(\frac{1}{NaChar \cdot \left(1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}\right)} + \frac{1}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}\right)}\right) \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto NdChar \cdot \left(NaChar \cdot \left(\frac{1}{NaChar \cdot \left(1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}\right)} + \color{blue}{\frac{1}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}}\right)\right) \]
      2. lower-+.f64N/A

        \[\leadsto NdChar \cdot \left(NaChar \cdot \left(\frac{1}{NaChar \cdot \left(1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}\right)} + \frac{1}{\color{blue}{NdChar \cdot \left(1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}\right)}}\right)\right) \]
    7. Applied rewrites90.4%

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

      \[\leadsto \color{blue}{\frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}}} \]
    9. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{NdChar}{\color{blue}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}}} \]
      2. lift-+.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      4. lift--.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      5. lift-/.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      6. lift-exp.f64N/A

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\left(EDonor + \left(Vef + mu\right)\right) - Ec}{KbT}}} \]
      7. lift-+.f6460.3

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

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

Alternative 8: 61.3% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;KbT \leq -9 \cdot 10^{+120}:\\ \;\;\;\;\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (if (<= KbT -9e+120)
   (fma 0.5 NaChar (* 0.5 NdChar))
   (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept (+ Ev Vef)) mu) KbT))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double tmp;
	if (KbT <= -9e+120) {
		tmp = fma(0.5, NaChar, (0.5 * NdChar));
	} else {
		tmp = NaChar / (1.0 + exp((((EAccept + (Ev + Vef)) - mu) / KbT)));
	}
	return tmp;
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0
	if (KbT <= -9e+120)
		tmp = fma(0.5, NaChar, Float64(0.5 * NdChar));
	else
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Float64(Ev + Vef)) - mu) / KbT))));
	end
	return tmp
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[KbT, -9e+120], N[(0.5 * NaChar + N[(0.5 * NdChar), $MachinePrecision]), $MachinePrecision], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + N[(Ev + Vef), $MachinePrecision]), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;KbT \leq -9 \cdot 10^{+120}:\\
\;\;\;\;\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if KbT < -8.99999999999999953e120

    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. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]

    if -8.99999999999999953e120 < 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 NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

Alternative 9: 55.3% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;KbT \leq -9 \cdot 10^{+120}:\\ \;\;\;\;\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + Vef\right) - mu}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (if (<= KbT -9e+120)
   (fma 0.5 NaChar (* 0.5 NdChar))
   (/ NaChar (+ 1.0 (exp (/ (- (+ EAccept Vef) mu) KbT))))))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	double tmp;
	if (KbT <= -9e+120) {
		tmp = fma(0.5, NaChar, (0.5 * NdChar));
	} else {
		tmp = NaChar / (1.0 + exp((((EAccept + Vef) - mu) / KbT)));
	}
	return tmp;
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0
	if (KbT <= -9e+120)
		tmp = fma(0.5, NaChar, Float64(0.5 * NdChar));
	else
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Float64(Float64(EAccept + Vef) - mu) / KbT))));
	end
	return tmp
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[KbT, -9e+120], N[(0.5 * NaChar + N[(0.5 * NdChar), $MachinePrecision]), $MachinePrecision], N[(NaChar / N[(1.0 + N[Exp[N[(N[(N[(EAccept + Vef), $MachinePrecision] - mu), $MachinePrecision] / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;KbT \leq -9 \cdot 10^{+120}:\\
\;\;\;\;\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{\left(EAccept + Vef\right) - mu}{KbT}}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if KbT < -8.99999999999999953e120

    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. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]

    if -8.99999999999999953e120 < 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 NdChar around 0

      \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
    3. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

      \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + Vef\right) - mu}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-+.f6454.6

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + Vef\right) - mu}{KbT}}} \]
    7. Applied rewrites54.6%

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

Alternative 10: 41.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;EAccept \leq 5.5 \cdot 10^{+36}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (if (<= EAccept 5.5e+36)
   (/ NaChar (+ 1.0 (exp (/ Ev 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 tmp;
	if (EAccept <= 5.5e+36) {
		tmp = NaChar / (1.0 + exp((Ev / KbT)));
	} else {
		tmp = 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) :: tmp
    if (eaccept <= 5.5d+36) then
        tmp = nachar / (1.0d0 + exp((ev / kbt)))
    else
        tmp = 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 tmp;
	if (EAccept <= 5.5e+36) {
		tmp = NaChar / (1.0 + Math.exp((Ev / KbT)));
	} else {
		tmp = NaChar / (1.0 + Math.exp((EAccept / KbT)));
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	tmp = 0
	if EAccept <= 5.5e+36:
		tmp = NaChar / (1.0 + math.exp((Ev / KbT)))
	else:
		tmp = NaChar / (1.0 + math.exp((EAccept / KbT)))
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0
	if (EAccept <= 5.5e+36)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(Ev / KbT))));
	else
		tmp = 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)
	tmp = 0.0;
	if (EAccept <= 5.5e+36)
		tmp = NaChar / (1.0 + exp((Ev / KbT)));
	else
		tmp = NaChar / (1.0 + exp((EAccept / KbT)));
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[EAccept, 5.5e+36], N[(NaChar / N[(1.0 + N[Exp[N[(Ev / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;EAccept \leq 5.5 \cdot 10^{+36}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if EAccept < 5.5000000000000002e36

    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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

      \[\leadsto \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f6434.9

        \[\leadsto \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
    7. Applied rewrites34.9%

      \[\leadsto \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]

    if 5.5000000000000002e36 < EAccept

    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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

      \[\leadsto \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f6435.4

        \[\leadsto \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    7. Applied rewrites35.4%

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

Alternative 11: 38.1% accurate, 2.2× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\ \mathbf{if}\;KbT \leq -6.5 \cdot 10^{+120}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;KbT \leq 2.7 \cdot 10^{+188}:\\ \;\;\;\;\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (fma 0.5 NaChar (* 0.5 NdChar))))
   (if (<= KbT -6.5e+120)
     t_0
     (if (<= KbT 2.7e+188) (/ NaChar (+ 1.0 (exp (/ EAccept KbT)))) 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 = fma(0.5, NaChar, (0.5 * NdChar));
	double tmp;
	if (KbT <= -6.5e+120) {
		tmp = t_0;
	} else if (KbT <= 2.7e+188) {
		tmp = NaChar / (1.0 + exp((EAccept / KbT)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = fma(0.5, NaChar, Float64(0.5 * NdChar))
	tmp = 0.0
	if (KbT <= -6.5e+120)
		tmp = t_0;
	elseif (KbT <= 2.7e+188)
		tmp = Float64(NaChar / Float64(1.0 + exp(Float64(EAccept / KbT))));
	else
		tmp = t_0;
	end
	return tmp
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(0.5 * NaChar + N[(0.5 * NdChar), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[KbT, -6.5e+120], t$95$0, If[LessEqual[KbT, 2.7e+188], N[(NaChar / N[(1.0 + N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\
\mathbf{if}\;KbT \leq -6.5 \cdot 10^{+120}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;KbT \leq 2.7 \cdot 10^{+188}:\\
\;\;\;\;\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if KbT < -6.4999999999999997e120 or 2.7e188 < 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 NaChar + \frac{1}{2} \cdot NdChar} \]
    3. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]

    if -6.4999999999999997e120 < KbT < 2.7e188

    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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

      \[\leadsto \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f6435.4

        \[\leadsto \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    7. Applied rewrites35.4%

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

Alternative 12: 35.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\ t_1 := \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}}}\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-184}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-178}:\\ \;\;\;\;\frac{NaChar}{\left(2 + \frac{EAccept + Vef}{KbT}\right) - \frac{mu}{KbT}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (fma 0.5 NaChar (* 0.5 NdChar)))
        (t_1
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
          (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))))
   (if (<= t_1 -5e-184)
     t_0
     (if (<= t_1 5e-178)
       (/ NaChar (- (+ 2.0 (/ (+ EAccept Vef) KbT)) (/ mu KbT)))
       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 = fma(0.5, NaChar, (0.5 * NdChar));
	double t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -5e-184) {
		tmp = t_0;
	} else if (t_1 <= 5e-178) {
		tmp = NaChar / ((2.0 + ((EAccept + Vef) / KbT)) - (mu / KbT));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = fma(0.5, NaChar, Float64(0.5 * NdChar))
	t_1 = 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)))))
	tmp = 0.0
	if (t_1 <= -5e-184)
		tmp = t_0;
	elseif (t_1 <= 5e-178)
		tmp = Float64(NaChar / Float64(Float64(2.0 + Float64(Float64(EAccept + Vef) / KbT)) - Float64(mu / KbT)));
	else
		tmp = t_0;
	end
	return tmp
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(0.5 * NaChar + N[(0.5 * NdChar), $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] + 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, -5e-184], t$95$0, If[LessEqual[t$95$1, 5e-178], N[(NaChar / N[(N[(2.0 + N[(N[(EAccept + Vef), $MachinePrecision] / KbT), $MachinePrecision]), $MachinePrecision] - N[(mu / KbT), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\
t_1 := \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}}}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-184}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-178}:\\
\;\;\;\;\frac{NaChar}{\left(2 + \frac{EAccept + Vef}{KbT}\right) - \frac{mu}{KbT}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 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.00000000000000003e-184 or 4.99999999999999976e-178 < (+.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 NaChar + \frac{1}{2} \cdot NdChar} \]
    3. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]

    if -5.00000000000000003e-184 < (+.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.99999999999999976e-178

    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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

      \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \left(\frac{Ev}{KbT} + \frac{Vef}{KbT}\right)\right)\right) - \color{blue}{\frac{mu}{KbT}}} \]
    6. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \left(\frac{Ev}{KbT} + \frac{Vef}{KbT}\right)\right)\right) - \frac{mu}{\color{blue}{KbT}}} \]
      2. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \left(\frac{Ev}{KbT} + \frac{Vef}{KbT}\right)\right)\right) - \frac{mu}{KbT}} \]
      3. div-add-revN/A

        \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \frac{Ev + Vef}{KbT}\right)\right) - \frac{mu}{KbT}} \]
      4. div-addN/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      6. lift-+.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      7. lift-+.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      8. lower-/.f6422.5

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
    7. Applied rewrites22.5%

      \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \color{blue}{\frac{mu}{KbT}}} \]
    8. Taylor expanded in Ev around 0

      \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + Vef}{KbT}\right) - \frac{mu}{KbT}} \]
    9. Step-by-step derivation
      1. lower-+.f6422.0

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + Vef}{KbT}\right) - \frac{mu}{KbT}} \]
    10. Applied rewrites22.0%

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

Alternative 13: 35.7% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\ t_1 := \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}}}\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-212}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-178}:\\ \;\;\;\;\frac{NaChar}{\left(2 + \frac{Ev + Vef}{KbT}\right) - \frac{mu}{KbT}}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (fma 0.5 NaChar (* 0.5 NdChar)))
        (t_1
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
          (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))))
   (if (<= t_1 -5e-212)
     t_0
     (if (<= t_1 5e-178)
       (/ NaChar (- (+ 2.0 (/ (+ Ev Vef) KbT)) (/ mu KbT)))
       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 = fma(0.5, NaChar, (0.5 * NdChar));
	double t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -5e-212) {
		tmp = t_0;
	} else if (t_1 <= 5e-178) {
		tmp = NaChar / ((2.0 + ((Ev + Vef) / KbT)) - (mu / KbT));
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = fma(0.5, NaChar, Float64(0.5 * NdChar))
	t_1 = 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)))))
	tmp = 0.0
	if (t_1 <= -5e-212)
		tmp = t_0;
	elseif (t_1 <= 5e-178)
		tmp = Float64(NaChar / Float64(Float64(2.0 + Float64(Float64(Ev + Vef) / KbT)) - Float64(mu / KbT)));
	else
		tmp = t_0;
	end
	return tmp
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(0.5 * NaChar + N[(0.5 * NdChar), $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] + 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, -5e-212], t$95$0, If[LessEqual[t$95$1, 5e-178], N[(NaChar / N[(N[(2.0 + N[(N[(Ev + Vef), $MachinePrecision] / KbT), $MachinePrecision]), $MachinePrecision] - N[(mu / KbT), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\
t_1 := \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}}}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-212}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq 5 \cdot 10^{-178}:\\
\;\;\;\;\frac{NaChar}{\left(2 + \frac{Ev + Vef}{KbT}\right) - \frac{mu}{KbT}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 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.00000000000000043e-212 or 4.99999999999999976e-178 < (+.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 NaChar + \frac{1}{2} \cdot NdChar} \]
    3. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]

    if -5.00000000000000043e-212 < (+.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.99999999999999976e-178

    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. Step-by-step derivation
      1. lower-/.f64N/A

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

        \[\leadsto \frac{NaChar}{1 + \color{blue}{e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}}} \]
      3. lower-exp.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      4. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      5. lower--.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      6. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
      7. lift-+.f6461.1

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) - mu}{KbT}}} \]
    4. Applied rewrites61.1%

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

      \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \left(\frac{Ev}{KbT} + \frac{Vef}{KbT}\right)\right)\right) - \color{blue}{\frac{mu}{KbT}}} \]
    6. Step-by-step derivation
      1. lower--.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \left(\frac{Ev}{KbT} + \frac{Vef}{KbT}\right)\right)\right) - \frac{mu}{\color{blue}{KbT}}} \]
      2. lower-+.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \left(\frac{Ev}{KbT} + \frac{Vef}{KbT}\right)\right)\right) - \frac{mu}{KbT}} \]
      3. div-add-revN/A

        \[\leadsto \frac{NaChar}{\left(2 + \left(\frac{EAccept}{KbT} + \frac{Ev + Vef}{KbT}\right)\right) - \frac{mu}{KbT}} \]
      4. div-addN/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      5. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      6. lift-+.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      7. lift-+.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
      8. lower-/.f6422.5

        \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \frac{mu}{KbT}} \]
    7. Applied rewrites22.5%

      \[\leadsto \frac{NaChar}{\left(2 + \frac{EAccept + \left(Ev + Vef\right)}{KbT}\right) - \color{blue}{\frac{mu}{KbT}}} \]
    8. Taylor expanded in EAccept around 0

      \[\leadsto \frac{NaChar}{\left(2 + \frac{Ev + Vef}{KbT}\right) - \frac{mu}{KbT}} \]
    9. Step-by-step derivation
      1. lower-/.f64N/A

        \[\leadsto \frac{NaChar}{\left(2 + \frac{Ev + Vef}{KbT}\right) - \frac{mu}{KbT}} \]
      2. lift-+.f6421.9

        \[\leadsto \frac{NaChar}{\left(2 + \frac{Ev + Vef}{KbT}\right) - \frac{mu}{KbT}} \]
    10. Applied rewrites21.9%

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

Alternative 14: 30.1% accurate, 0.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\ t_1 := \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}}}\\ \mathbf{if}\;t\_1 \leq -5 \cdot 10^{-168}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;t\_1 \leq -4 \cdot 10^{-297}:\\ \;\;\;\;0.5 \cdot NaChar\\ \mathbf{elif}\;t\_1 \leq 0:\\ \;\;\;\;-0.25 \cdot \frac{Ev \cdot NaChar}{KbT}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (let* ((t_0 (fma 0.5 NaChar (* 0.5 NdChar)))
        (t_1
         (+
          (/ NdChar (+ 1.0 (exp (/ (- (- (- (- Ec Vef) EDonor) mu)) KbT))))
          (/ NaChar (+ 1.0 (exp (/ (+ (+ (+ Ev Vef) EAccept) (- mu)) KbT)))))))
   (if (<= t_1 -5e-168)
     t_0
     (if (<= t_1 -4e-297)
       (* 0.5 NaChar)
       (if (<= t_1 0.0) (* -0.25 (/ (* Ev NaChar) KbT)) 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 = fma(0.5, NaChar, (0.5 * NdChar));
	double t_1 = (NdChar / (1.0 + exp((-(((Ec - Vef) - EDonor) - mu) / KbT)))) + (NaChar / (1.0 + exp(((((Ev + Vef) + EAccept) + -mu) / KbT))));
	double tmp;
	if (t_1 <= -5e-168) {
		tmp = t_0;
	} else if (t_1 <= -4e-297) {
		tmp = 0.5 * NaChar;
	} else if (t_1 <= 0.0) {
		tmp = -0.25 * ((Ev * NaChar) / KbT);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	t_0 = fma(0.5, NaChar, Float64(0.5 * NdChar))
	t_1 = 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)))))
	tmp = 0.0
	if (t_1 <= -5e-168)
		tmp = t_0;
	elseif (t_1 <= -4e-297)
		tmp = Float64(0.5 * NaChar);
	elseif (t_1 <= 0.0)
		tmp = Float64(-0.25 * Float64(Float64(Ev * NaChar) / KbT));
	else
		tmp = t_0;
	end
	return tmp
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(0.5 * NaChar + N[(0.5 * NdChar), $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] + 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, -5e-168], t$95$0, If[LessEqual[t$95$1, -4e-297], N[(0.5 * NaChar), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(-0.25 * N[(N[(Ev * NaChar), $MachinePrecision] / KbT), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\\
t_1 := \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}}}\\
\mathbf{if}\;t\_1 \leq -5 \cdot 10^{-168}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;t\_1 \leq -4 \cdot 10^{-297}:\\
\;\;\;\;0.5 \cdot NaChar\\

\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;-0.25 \cdot \frac{Ev \cdot NaChar}{KbT}\\

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


\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))))) < -5.00000000000000001e-168 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)))))

    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. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

      \[\leadsto \color{blue}{\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)} \]

    if -5.00000000000000001e-168 < (+.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.00000000000000016e-297

    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. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{NaChar} \]
    6. Step-by-step derivation
      1. lift-*.f6417.7

        \[\leadsto 0.5 \cdot NaChar \]
    7. Applied rewrites17.7%

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

    if -4.00000000000000016e-297 < (+.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 KbT around inf

      \[\leadsto \color{blue}{-1 \cdot \frac{\frac{1}{4} \cdot \left(NaChar \cdot \left(\left(EAccept + \left(Ev + Vef\right)\right) - mu\right)\right) + \frac{1}{4} \cdot \left(NdChar \cdot \left(\left(EDonor + \left(Vef + mu\right)\right) - Ec\right)\right)}{KbT} + \left(\frac{1}{2} \cdot NaChar + \frac{1}{2} \cdot NdChar\right)} \]
    3. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(-1, \color{blue}{\frac{\frac{1}{4} \cdot \left(NaChar \cdot \left(\left(EAccept + \left(Ev + Vef\right)\right) - mu\right)\right) + \frac{1}{4} \cdot \left(NdChar \cdot \left(\left(EDonor + \left(Vef + mu\right)\right) - Ec\right)\right)}{KbT}}, \frac{1}{2} \cdot NaChar + \frac{1}{2} \cdot NdChar\right) \]
    4. Applied rewrites14.2%

      \[\leadsto \color{blue}{\mathsf{fma}\left(-1, \frac{\mathsf{fma}\left(0.25, NaChar \cdot \left(\left(EAccept + \left(Ev + Vef\right)\right) - mu\right), 0.25 \cdot \left(NdChar \cdot \left(\left(EDonor + \left(Vef + mu\right)\right) - Ec\right)\right)\right)}{KbT}, \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)\right)} \]
    5. Taylor expanded in Ev around inf

      \[\leadsto \frac{-1}{4} \cdot \color{blue}{\frac{Ev \cdot NaChar}{KbT}} \]
    6. Step-by-step derivation
      1. lower-*.f64N/A

        \[\leadsto \frac{-1}{4} \cdot \frac{Ev \cdot NaChar}{\color{blue}{KbT}} \]
      2. lower-/.f64N/A

        \[\leadsto \frac{-1}{4} \cdot \frac{Ev \cdot NaChar}{KbT} \]
      3. lower-*.f646.4

        \[\leadsto -0.25 \cdot \frac{Ev \cdot NaChar}{KbT} \]
    7. Applied rewrites6.4%

      \[\leadsto -0.25 \cdot \color{blue}{\frac{Ev \cdot NaChar}{KbT}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 15: 26.8% accurate, 6.8× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (fma 0.5 NaChar (* 0.5 NdChar)))
double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
	return fma(0.5, NaChar, (0.5 * NdChar));
}
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	return fma(0.5, NaChar, Float64(0.5 * NdChar))
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(0.5 * NaChar + N[(0.5 * NdChar), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right)
\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. Step-by-step derivation
    1. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
    2. lower-*.f6426.8

      \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
  4. Applied rewrites26.8%

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

Alternative 16: 22.4% accurate, 5.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;NaChar \leq -960000:\\ \;\;\;\;0.5 \cdot NaChar\\ \mathbf{elif}\;NaChar \leq 4.9 \cdot 10^{-123}:\\ \;\;\;\;0.5 \cdot NdChar\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot NaChar\\ \end{array} \end{array} \]
(FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
 :precision binary64
 (if (<= NaChar -960000.0)
   (* 0.5 NaChar)
   (if (<= NaChar 4.9e-123) (* 0.5 NdChar) (* 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 <= -960000.0) {
		tmp = 0.5 * NaChar;
	} else if (NaChar <= 4.9e-123) {
		tmp = 0.5 * NdChar;
	} 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 <= (-960000.0d0)) then
        tmp = 0.5d0 * nachar
    else if (nachar <= 4.9d-123) then
        tmp = 0.5d0 * ndchar
    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 <= -960000.0) {
		tmp = 0.5 * NaChar;
	} else if (NaChar <= 4.9e-123) {
		tmp = 0.5 * NdChar;
	} else {
		tmp = 0.5 * NaChar;
	}
	return tmp;
}
def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
	tmp = 0
	if NaChar <= -960000.0:
		tmp = 0.5 * NaChar
	elif NaChar <= 4.9e-123:
		tmp = 0.5 * NdChar
	else:
		tmp = 0.5 * NaChar
	return tmp
function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
	tmp = 0.0
	if (NaChar <= -960000.0)
		tmp = Float64(0.5 * NaChar);
	elseif (NaChar <= 4.9e-123)
		tmp = Float64(0.5 * NdChar);
	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 <= -960000.0)
		tmp = 0.5 * NaChar;
	elseif (NaChar <= 4.9e-123)
		tmp = 0.5 * NdChar;
	else
		tmp = 0.5 * NaChar;
	end
	tmp_2 = tmp;
end
code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[NaChar, -960000.0], N[(0.5 * NaChar), $MachinePrecision], If[LessEqual[NaChar, 4.9e-123], N[(0.5 * NdChar), $MachinePrecision], N[(0.5 * NaChar), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;NaChar \leq -960000:\\
\;\;\;\;0.5 \cdot NaChar\\

\mathbf{elif}\;NaChar \leq 4.9 \cdot 10^{-123}:\\
\;\;\;\;0.5 \cdot NdChar\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if NaChar < -9.6e5 or 4.8999999999999998e-123 < 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. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{NaChar} \]
    6. Step-by-step derivation
      1. lift-*.f6417.7

        \[\leadsto 0.5 \cdot NaChar \]
    7. Applied rewrites17.7%

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

    if -9.6e5 < NaChar < 4.8999999999999998e-123

    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. Step-by-step derivation
      1. lower-fma.f64N/A

        \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
      2. lower-*.f6426.8

        \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
    4. Applied rewrites26.8%

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

      \[\leadsto \frac{1}{2} \cdot \color{blue}{NaChar} \]
    6. Step-by-step derivation
      1. lift-*.f6417.7

        \[\leadsto 0.5 \cdot NaChar \]
    7. Applied rewrites17.7%

      \[\leadsto 0.5 \cdot \color{blue}{NaChar} \]
    8. Taylor expanded in NdChar around inf

      \[\leadsto \frac{1}{2} \cdot \color{blue}{NdChar} \]
    9. Step-by-step derivation
      1. lower-*.f6418.1

        \[\leadsto 0.5 \cdot NdChar \]
    10. Applied rewrites18.1%

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

Alternative 17: 17.7% 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. Step-by-step derivation
    1. lower-fma.f64N/A

      \[\leadsto \mathsf{fma}\left(\frac{1}{2}, \color{blue}{NaChar}, \frac{1}{2} \cdot NdChar\right) \]
    2. lower-*.f6426.8

      \[\leadsto \mathsf{fma}\left(0.5, NaChar, 0.5 \cdot NdChar\right) \]
  4. Applied rewrites26.8%

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

    \[\leadsto \frac{1}{2} \cdot \color{blue}{NaChar} \]
  6. Step-by-step derivation
    1. lift-*.f6417.7

      \[\leadsto 0.5 \cdot NaChar \]
  7. Applied rewrites17.7%

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

Reproduce

?
herbie shell --seed 2025140 
(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))))))