Bulmash initializePoisson

Percentage Accurate: 100.0% → 100.0%
Time: 6.6s
Alternatives: 20
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 20 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: 80.7% accurate, 0.3× speedup?

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

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

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

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

\mathbf{elif}\;t\_3 \leq 2 \cdot 10^{-178}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{-Ec}{KbT}}} + t\_2\\


\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.0000000000000001e-264

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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 -5.0000000000000001e-264 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1.9999999999999999e-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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

    if 1.9999999999999999e-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 Ec around inf

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\mathsf{neg}\left(Ec\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
      2. lower-neg.f6469.0

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

      \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{-Ec}}{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 3: 79.3% accurate, 0.3× speedup?

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

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

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

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

\mathbf{elif}\;t\_3 \leq 0:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{mu}{KbT}}} + t\_2\\


\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.0000000000000001e-264

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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 -5.0000000000000001e-264 < (+.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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

    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-/.f6469.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 rewrites69.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: 79.2% accurate, 0.3× speedup?

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

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

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

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

\mathbf{elif}\;t\_2 \leq 9.5 \cdot 10^{-257}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

\mathbf{else}:\\
\;\;\;\;t\_1 + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\


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

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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 -5.0000000000000001e-264 < (+.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))))) < 9.49999999999999941e-257

    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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

    if 9.49999999999999941e-257 < (+.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-/.f6469.3

        \[\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 rewrites69.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{Ev}{KbT}}}} \]
  3. Recombined 3 regimes into one program.
  4. Add Preprocessing

Alternative 5: 77.1% accurate, 0.3× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-178}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{-Ec}{KbT}}} + \frac{NaChar}{e^{\frac{\left(Ev + Vef\right) - mu}{KbT}} + 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))))) < -5.0000000000000001e-264

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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 -5.0000000000000001e-264 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1.9999999999999999e-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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

    if 1.9999999999999999e-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 Ec around inf

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\mathsf{neg}\left(Ec\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
      2. lower-neg.f6469.0

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

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

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

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

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

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

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

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

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

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

Alternative 6: 75.3% accurate, 0.3× speedup?

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

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

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

\mathbf{elif}\;t\_2 \leq 2 \cdot 10^{-178}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

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


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

    1. Initial program 100.0%

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

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

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

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

    if -2.00000000000000007e154 < (+.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.99999999999999984e-226

    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-/.f6469.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 rewrites69.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}}} \]
    5. Taylor expanded in Ev around 0

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

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

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

    if -1.99999999999999984e-226 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1.9999999999999999e-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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

    if 1.9999999999999999e-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 Ec around inf

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\mathsf{neg}\left(Ec\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
      2. lower-neg.f6469.0

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

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

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

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

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

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

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

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

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

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

Alternative 7: 70.4% accurate, 0.3× speedup?

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

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

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

\mathbf{else}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{-Ec}{KbT}}} + \frac{NaChar}{e^{\frac{\left(Ev + Vef\right) - mu}{KbT}} + 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))))) < -2e-131

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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}}}} \]
    5. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f6450.6

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

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

    if -2e-131 < (+.f64 (/.f64 NdChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (neg.f64 (-.f64 (-.f64 (-.f64 Ec Vef) EDonor) mu)) KbT)))) (/.f64 NaChar (+.f64 #s(literal 1 binary64) (exp.f64 (/.f64 (+.f64 (+.f64 (+.f64 Ev Vef) EAccept) (neg.f64 mu)) KbT))))) < 1.9999999999999999e-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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

    if 1.9999999999999999e-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 Ec around inf

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\mathsf{neg}\left(Ec\right)}{KbT}}} + \frac{NaChar}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}}} \]
      2. lower-neg.f6469.0

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

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

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

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

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

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

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

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

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

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

Alternative 8: 66.9% accurate, 1.1× speedup?

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

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

\mathbf{elif}\;NdChar \leq -4.3 \cdot 10^{+26}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef}{KbT}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}}\\

\mathbf{elif}\;NdChar \leq 8 \cdot 10^{+117}:\\
\;\;\;\;\frac{NaChar}{e^{t\_0} + 1}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if NdChar < -1.02000000000000007e98 or 8.0000000000000004e117 < NdChar

    1. Initial program 100.0%

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

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

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{2 + \left(\left(\frac{EAccept}{KbT} + \frac{Ev + Vef}{KbT}\right) - \frac{mu}{KbT}\right)} \]
      3. div-addN/A

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

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{2 + \frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}} \]
      6. +-commutativeN/A

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

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

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

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

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \frac{NaChar}{2 + \frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(-mu\right)}{KbT}} \]
      12. lift-/.f6460.1

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

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

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

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

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

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

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

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

        \[\leadsto \frac{NdChar}{e^{\frac{\left(mu + Vef\right) - Ec}{KbT}} + 1} + \frac{NaChar}{2 + \frac{\left(\left(Ev + Vef\right) + EAccept\right) - mu}{KbT}} \]
      7. lower-+.f6454.6

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

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

    if -1.02000000000000007e98 < NdChar < -4.2999999999999998e26

    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-/.f6469.3

        \[\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 rewrites69.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{Ev}{KbT}}}} \]
    5. Taylor expanded in Vef around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{Vef}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f6449.1

        \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef}{\color{blue}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{Ev}{KbT}}} \]
    7. Applied rewrites49.1%

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

    if -4.2999999999999998e26 < NdChar < 8.0000000000000004e117

    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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

Alternative 9: 66.7% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 10^{+15}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot NdChar + 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))))) < -2e-131

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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}}}} \]
    5. Taylor expanded in EDonor around inf

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    6. Step-by-step derivation
      1. lower-/.f6450.6

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

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

    if -2e-131 < (+.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))))) < 1e15

    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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

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

    1. Initial program 100.0%

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

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

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

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

Alternative 10: 65.9% accurate, 0.4× speedup?

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

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

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

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

\mathbf{elif}\;t\_3 \leq 10^{+15}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

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


\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.00000000000000006e63

    1. Initial program 100.0%

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

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

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

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

    if -1.00000000000000006e63 < (+.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))))) < 1e15

    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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

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

    1. Initial program 100.0%

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

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

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

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

Alternative 11: 64.6% accurate, 0.4× speedup?

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

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

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

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

\mathbf{elif}\;t\_3 \leq 5 \cdot 10^{+171}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

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


\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.00000000000000006e63 or 5.0000000000000004e171 < (+.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 \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Step-by-step derivation
      1. lower-*.f6447.8

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

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

    if -1.00000000000000006e63 < (+.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.0000000000000004e171

    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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

Alternative 12: 64.1% accurate, 0.4× speedup?

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

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

\mathbf{elif}\;t\_2 \leq 5 \cdot 10^{+171}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 1}\\

\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.00000000000000006e63 or 5.0000000000000004e171 < (+.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 \frac{NdChar}{1 + e^{\frac{-\left(\left(\left(Ec - Vef\right) - EDonor\right) - mu\right)}{KbT}}} + \color{blue}{\frac{1}{2} \cdot NaChar} \]
    3. Step-by-step derivation
      1. lower-*.f6447.8

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

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

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

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

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

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

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

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

        \[\leadsto \frac{NdChar}{e^{\frac{\left(mu + Vef\right) - Ec}{KbT}} + 1} + \frac{1}{2} \cdot NaChar \]
      7. lower-+.f6444.0

        \[\leadsto \frac{NdChar}{e^{\frac{\left(mu + Vef\right) - Ec}{KbT}} + 1} + 0.5 \cdot NaChar \]
    7. Applied rewrites44.0%

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

    if -1.00000000000000006e63 < (+.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.0000000000000004e171

    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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

Alternative 13: 59.6% accurate, 0.7× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{t\_0 - mu}{KbT}} + 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.00000000000000006e63

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{Vef}{KbT}}}} + \frac{1}{2} \cdot NaChar \]
    6. Step-by-step derivation
      1. lower-/.f6435.2

        \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef}{\color{blue}{KbT}}}} + 0.5 \cdot NaChar \]
    7. Applied rewrites35.2%

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

    if -1.00000000000000006e63 < (+.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 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. sub-flipN/A

        \[\leadsto \frac{NaChar}{1 + e^{\frac{\left(EAccept + \left(Ev + Vef\right)\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}} \]
      2. +-commutativeN/A

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

        \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{\left(\left(Ev + Vef\right) + EAccept\right) + \left(\mathsf{neg}\left(mu\right)\right)}{KbT}}}} \]
      4. +-commutativeN/A

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

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

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

Alternative 14: 39.8% accurate, 1.7× speedup?

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

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

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

\\
\begin{array}{l}
\mathbf{if}\;NdChar \leq -3.5 \cdot 10^{-36}:\\
\;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef}{KbT}}} + 0.5 \cdot NaChar\\

\mathbf{elif}\;NdChar \leq 1.65 \cdot 10^{+23}:\\
\;\;\;\;\frac{NaChar}{e^{\frac{EAccept}{KbT}} + 1} + \frac{NdChar}{2}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if NdChar < -3.5e-36

    1. Initial program 100.0%

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

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

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

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

      \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{Vef}{KbT}}}} + \frac{1}{2} \cdot NaChar \]
    6. Step-by-step derivation
      1. lower-/.f6435.2

        \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef}{\color{blue}{KbT}}}} + 0.5 \cdot NaChar \]
    7. Applied rewrites35.2%

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

    if -3.5e-36 < NdChar < 1.65000000000000015e23

    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-/.f6469.5

        \[\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 rewrites69.5%

      \[\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}}}} \]
    5. Taylor expanded in KbT around inf

      \[\leadsto \frac{NdChar}{\color{blue}{2}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
    6. Step-by-step derivation
      1. Applied rewrites36.1%

        \[\leadsto \frac{NdChar}{\color{blue}{2}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
      2. Step-by-step derivation
        1. lift-+.f64N/A

          \[\leadsto \color{blue}{\frac{NdChar}{2} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}} \]
        2. +-commutativeN/A

          \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} + \frac{NdChar}{2}} \]
        3. lower-+.f6436.1

          \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} + \frac{NdChar}{2}} \]
        4. lift-+.f64N/A

          \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{EAccept}{KbT}}}} + \frac{NdChar}{2} \]
        5. +-commutativeN/A

          \[\leadsto \frac{NaChar}{\color{blue}{e^{\frac{EAccept}{KbT}} + 1}} + \frac{NdChar}{2} \]
        6. lower-+.f6436.1

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

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

      if 1.65000000000000015e23 < NdChar

      1. Initial program 100.0%

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

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

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

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

        \[\leadsto \frac{NdChar}{1 + e^{\frac{\color{blue}{-1 \cdot Ec}}{KbT}}} + \frac{1}{2} \cdot NaChar \]
      6. Step-by-step derivation
        1. mul-1-negN/A

          \[\leadsto \frac{NdChar}{1 + e^{\frac{\mathsf{neg}\left(Ec\right)}{KbT}}} + \frac{1}{2} \cdot NaChar \]
        2. lower-neg.f6436.5

          \[\leadsto \frac{NdChar}{1 + e^{\frac{-Ec}{KbT}}} + 0.5 \cdot NaChar \]
      7. Applied rewrites36.5%

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

    Alternative 15: 39.5% accurate, 1.8× speedup?

    \[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{NaChar}{e^{\frac{EAccept}{KbT}} + 1} + \frac{NdChar}{2}\\ \mathbf{if}\;NaChar \leq -5.8 \cdot 10^{-22}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;NaChar \leq 2.1 \cdot 10^{+53}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef}{KbT}}} + 0.5 \cdot NaChar\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
    (FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
     :precision binary64
     (let* ((t_0 (+ (/ NaChar (+ (exp (/ EAccept KbT)) 1.0)) (/ NdChar 2.0))))
       (if (<= NaChar -5.8e-22)
         t_0
         (if (<= NaChar 2.1e+53)
           (+ (/ NdChar (+ 1.0 (exp (/ Vef KbT)))) (* 0.5 NaChar))
           t_0))))
    double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
    	double t_0 = (NaChar / (exp((EAccept / KbT)) + 1.0)) + (NdChar / 2.0);
    	double tmp;
    	if (NaChar <= -5.8e-22) {
    		tmp = t_0;
    	} else if (NaChar <= 2.1e+53) {
    		tmp = (NdChar / (1.0 + exp((Vef / KbT)))) + (0.5 * NaChar);
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    module fmin_fmax_functions
        implicit none
        private
        public fmax
        public fmin
    
        interface fmax
            module procedure fmax88
            module procedure fmax44
            module procedure fmax84
            module procedure fmax48
        end interface
        interface fmin
            module procedure fmin88
            module procedure fmin44
            module procedure fmin84
            module procedure fmin48
        end interface
    contains
        real(8) function fmax88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(4) function fmax44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, max(x, y), y /= y), x /= x)
        end function
        real(8) function fmax84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmax48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
        end function
        real(8) function fmin88(x, y) result (res)
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(4) function fmin44(x, y) result (res)
            real(4), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(y, merge(x, min(x, y), y /= y), x /= x)
        end function
        real(8) function fmin84(x, y) result(res)
            real(8), intent (in) :: x
            real(4), intent (in) :: y
            res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
        end function
        real(8) function fmin48(x, y) result(res)
            real(4), intent (in) :: x
            real(8), intent (in) :: y
            res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
        end function
    end module
    
    real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
    use fmin_fmax_functions
        real(8), intent (in) :: ndchar
        real(8), intent (in) :: ec
        real(8), intent (in) :: vef
        real(8), intent (in) :: edonor
        real(8), intent (in) :: mu
        real(8), intent (in) :: kbt
        real(8), intent (in) :: nachar
        real(8), intent (in) :: ev
        real(8), intent (in) :: eaccept
        real(8) :: t_0
        real(8) :: tmp
        t_0 = (nachar / (exp((eaccept / kbt)) + 1.0d0)) + (ndchar / 2.0d0)
        if (nachar <= (-5.8d-22)) then
            tmp = t_0
        else if (nachar <= 2.1d+53) then
            tmp = (ndchar / (1.0d0 + exp((vef / kbt)))) + (0.5d0 * nachar)
        else
            tmp = t_0
        end if
        code = tmp
    end function
    
    public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
    	double t_0 = (NaChar / (Math.exp((EAccept / KbT)) + 1.0)) + (NdChar / 2.0);
    	double tmp;
    	if (NaChar <= -5.8e-22) {
    		tmp = t_0;
    	} else if (NaChar <= 2.1e+53) {
    		tmp = (NdChar / (1.0 + Math.exp((Vef / KbT)))) + (0.5 * NaChar);
    	} else {
    		tmp = t_0;
    	}
    	return tmp;
    }
    
    def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
    	t_0 = (NaChar / (math.exp((EAccept / KbT)) + 1.0)) + (NdChar / 2.0)
    	tmp = 0
    	if NaChar <= -5.8e-22:
    		tmp = t_0
    	elif NaChar <= 2.1e+53:
    		tmp = (NdChar / (1.0 + math.exp((Vef / KbT)))) + (0.5 * NaChar)
    	else:
    		tmp = t_0
    	return tmp
    
    function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
    	t_0 = Float64(Float64(NaChar / Float64(exp(Float64(EAccept / KbT)) + 1.0)) + Float64(NdChar / 2.0))
    	tmp = 0.0
    	if (NaChar <= -5.8e-22)
    		tmp = t_0;
    	elseif (NaChar <= 2.1e+53)
    		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Vef / KbT)))) + Float64(0.5 * NaChar));
    	else
    		tmp = t_0;
    	end
    	return tmp
    end
    
    function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
    	t_0 = (NaChar / (exp((EAccept / KbT)) + 1.0)) + (NdChar / 2.0);
    	tmp = 0.0;
    	if (NaChar <= -5.8e-22)
    		tmp = t_0;
    	elseif (NaChar <= 2.1e+53)
    		tmp = (NdChar / (1.0 + exp((Vef / KbT)))) + (0.5 * NaChar);
    	else
    		tmp = t_0;
    	end
    	tmp_2 = tmp;
    end
    
    code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := Block[{t$95$0 = N[(N[(NaChar / N[(N[Exp[N[(EAccept / KbT), $MachinePrecision]], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] + N[(NdChar / 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[NaChar, -5.8e-22], t$95$0, If[LessEqual[NaChar, 2.1e+53], N[(N[(NdChar / N[(1.0 + N[Exp[N[(Vef / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], t$95$0]]]
    
    \begin{array}{l}
    
    \\
    \begin{array}{l}
    t_0 := \frac{NaChar}{e^{\frac{EAccept}{KbT}} + 1} + \frac{NdChar}{2}\\
    \mathbf{if}\;NaChar \leq -5.8 \cdot 10^{-22}:\\
    \;\;\;\;t\_0\\
    
    \mathbf{elif}\;NaChar \leq 2.1 \cdot 10^{+53}:\\
    \;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef}{KbT}}} + 0.5 \cdot NaChar\\
    
    \mathbf{else}:\\
    \;\;\;\;t\_0\\
    
    
    \end{array}
    \end{array}
    
    Derivation
    1. Split input into 2 regimes
    2. if NaChar < -5.8000000000000003e-22 or 2.1000000000000002e53 < 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 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-/.f6469.5

          \[\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 rewrites69.5%

        \[\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}}}} \]
      5. Taylor expanded in KbT around inf

        \[\leadsto \frac{NdChar}{\color{blue}{2}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
      6. Step-by-step derivation
        1. Applied rewrites36.1%

          \[\leadsto \frac{NdChar}{\color{blue}{2}} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} \]
        2. Step-by-step derivation
          1. lift-+.f64N/A

            \[\leadsto \color{blue}{\frac{NdChar}{2} + \frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}}} \]
          2. +-commutativeN/A

            \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} + \frac{NdChar}{2}} \]
          3. lower-+.f6436.1

            \[\leadsto \color{blue}{\frac{NaChar}{1 + e^{\frac{EAccept}{KbT}}} + \frac{NdChar}{2}} \]
          4. lift-+.f64N/A

            \[\leadsto \frac{NaChar}{\color{blue}{1 + e^{\frac{EAccept}{KbT}}}} + \frac{NdChar}{2} \]
          5. +-commutativeN/A

            \[\leadsto \frac{NaChar}{\color{blue}{e^{\frac{EAccept}{KbT}} + 1}} + \frac{NdChar}{2} \]
          6. lower-+.f6436.1

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

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

        if -5.8000000000000003e-22 < NaChar < 2.1000000000000002e53

        1. Initial program 100.0%

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

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

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

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

          \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{Vef}{KbT}}}} + \frac{1}{2} \cdot NaChar \]
        6. Step-by-step derivation
          1. lower-/.f6435.2

            \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef}{\color{blue}{KbT}}}} + 0.5 \cdot NaChar \]
        7. Applied rewrites35.2%

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

      Alternative 16: 37.1% accurate, 2.0× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;EDonor \leq -2.6 \cdot 10^{+74}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar\\ \mathbf{else}:\\ \;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef}{KbT}}} + 0.5 \cdot NaChar\\ \end{array} \end{array} \]
      (FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
       :precision binary64
       (if (<= EDonor -2.6e+74)
         (+ (/ NdChar (+ 1.0 (exp (/ EDonor KbT)))) (* 0.5 NaChar))
         (+ (/ NdChar (+ 1.0 (exp (/ Vef KbT)))) (* 0.5 NaChar))))
      double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
      	double tmp;
      	if (EDonor <= -2.6e+74) {
      		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
      	} else {
      		tmp = (NdChar / (1.0 + exp((Vef / KbT)))) + (0.5 * NaChar);
      	}
      	return tmp;
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
      use fmin_fmax_functions
          real(8), intent (in) :: ndchar
          real(8), intent (in) :: ec
          real(8), intent (in) :: vef
          real(8), intent (in) :: edonor
          real(8), intent (in) :: mu
          real(8), intent (in) :: kbt
          real(8), intent (in) :: nachar
          real(8), intent (in) :: ev
          real(8), intent (in) :: eaccept
          real(8) :: tmp
          if (edonor <= (-2.6d+74)) then
              tmp = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (0.5d0 * nachar)
          else
              tmp = (ndchar / (1.0d0 + exp((vef / kbt)))) + (0.5d0 * nachar)
          end if
          code = tmp
      end function
      
      public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
      	double tmp;
      	if (EDonor <= -2.6e+74) {
      		tmp = (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (0.5 * NaChar);
      	} else {
      		tmp = (NdChar / (1.0 + Math.exp((Vef / KbT)))) + (0.5 * NaChar);
      	}
      	return tmp;
      }
      
      def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
      	tmp = 0
      	if EDonor <= -2.6e+74:
      		tmp = (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (0.5 * NaChar)
      	else:
      		tmp = (NdChar / (1.0 + math.exp((Vef / KbT)))) + (0.5 * NaChar)
      	return tmp
      
      function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
      	tmp = 0.0
      	if (EDonor <= -2.6e+74)
      		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(0.5 * NaChar));
      	else
      		tmp = Float64(Float64(NdChar / Float64(1.0 + exp(Float64(Vef / KbT)))) + Float64(0.5 * NaChar));
      	end
      	return tmp
      end
      
      function tmp_2 = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
      	tmp = 0.0;
      	if (EDonor <= -2.6e+74)
      		tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
      	else
      		tmp = (NdChar / (1.0 + exp((Vef / KbT)))) + (0.5 * NaChar);
      	end
      	tmp_2 = tmp;
      end
      
      code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := If[LessEqual[EDonor, -2.6e+74], N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision], N[(N[(NdChar / N[(1.0 + N[Exp[N[(Vef / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;EDonor \leq -2.6 \cdot 10^{+74}:\\
      \;\;\;\;\frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar\\
      
      \mathbf{else}:\\
      \;\;\;\;\frac{NdChar}{1 + e^{\frac{Vef}{KbT}}} + 0.5 \cdot NaChar\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if EDonor < -2.6000000000000001e74

        1. Initial program 100.0%

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

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

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

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

          \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{1}{2} \cdot NaChar \]
        6. Step-by-step derivation
          1. lower-/.f6436.4

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

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

        if -2.6000000000000001e74 < EDonor

        1. Initial program 100.0%

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

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

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

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

          \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{Vef}{KbT}}}} + \frac{1}{2} \cdot NaChar \]
        6. Step-by-step derivation
          1. lower-/.f6435.2

            \[\leadsto \frac{NdChar}{1 + e^{\frac{Vef}{\color{blue}{KbT}}}} + 0.5 \cdot NaChar \]
        7. Applied rewrites35.2%

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

      Alternative 17: 36.4% accurate, 2.3× speedup?

      \[\begin{array}{l} \\ \frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar \end{array} \]
      (FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
       :precision binary64
       (+ (/ NdChar (+ 1.0 (exp (/ EDonor KbT)))) (* 0.5 NaChar)))
      double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
      	return (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
      }
      
      module fmin_fmax_functions
          implicit none
          private
          public fmax
          public fmin
      
          interface fmax
              module procedure fmax88
              module procedure fmax44
              module procedure fmax84
              module procedure fmax48
          end interface
          interface fmin
              module procedure fmin88
              module procedure fmin44
              module procedure fmin84
              module procedure fmin48
          end interface
      contains
          real(8) function fmax88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(4) function fmax44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, max(x, y), y /= y), x /= x)
          end function
          real(8) function fmax84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmax48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
          end function
          real(8) function fmin88(x, y) result (res)
              real(8), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(4) function fmin44(x, y) result (res)
              real(4), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(y, merge(x, min(x, y), y /= y), x /= x)
          end function
          real(8) function fmin84(x, y) result(res)
              real(8), intent (in) :: x
              real(4), intent (in) :: y
              res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
          end function
          real(8) function fmin48(x, y) result(res)
              real(4), intent (in) :: x
              real(8), intent (in) :: y
              res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
          end function
      end module
      
      real(8) function code(ndchar, ec, vef, edonor, mu, kbt, nachar, ev, eaccept)
      use fmin_fmax_functions
          real(8), intent (in) :: ndchar
          real(8), intent (in) :: ec
          real(8), intent (in) :: vef
          real(8), intent (in) :: edonor
          real(8), intent (in) :: mu
          real(8), intent (in) :: kbt
          real(8), intent (in) :: nachar
          real(8), intent (in) :: ev
          real(8), intent (in) :: eaccept
          code = (ndchar / (1.0d0 + exp((edonor / kbt)))) + (0.5d0 * nachar)
      end function
      
      public static double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
      	return (NdChar / (1.0 + Math.exp((EDonor / KbT)))) + (0.5 * NaChar);
      }
      
      def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
      	return (NdChar / (1.0 + math.exp((EDonor / KbT)))) + (0.5 * NaChar)
      
      function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
      	return Float64(Float64(NdChar / Float64(1.0 + exp(Float64(EDonor / KbT)))) + Float64(0.5 * NaChar))
      end
      
      function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
      	tmp = (NdChar / (1.0 + exp((EDonor / KbT)))) + (0.5 * NaChar);
      end
      
      code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(N[(NdChar / N[(1.0 + N[Exp[N[(EDonor / KbT), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.5 * NaChar), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      \frac{NdChar}{1 + e^{\frac{EDonor}{KbT}}} + 0.5 \cdot NaChar
      \end{array}
      
      Derivation
      1. Initial program 100.0%

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

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

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

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

        \[\leadsto \frac{NdChar}{1 + e^{\color{blue}{\frac{EDonor}{KbT}}}} + \frac{1}{2} \cdot NaChar \]
      6. Step-by-step derivation
        1. lower-/.f6436.4

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

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

      Alternative 18: 28.3% accurate, 9.1× speedup?

      \[\begin{array}{l} \\ 0.5 \cdot \left(NaChar + NdChar\right) \end{array} \]
      (FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
       :precision binary64
       (* 0.5 (+ NaChar NdChar)))
      double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
      	return 0.5 * (NaChar + NdChar);
      }
      
      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 + ndchar)
      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 + NdChar);
      }
      
      def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
      	return 0.5 * (NaChar + NdChar)
      
      function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
      	return Float64(0.5 * Float64(NaChar + NdChar))
      end
      
      function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
      	tmp = 0.5 * (NaChar + NdChar);
      end
      
      code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(0.5 * N[(NaChar + NdChar), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      0.5 \cdot \left(NaChar + 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. distribute-lft-outN/A

          \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
        2. lower-*.f64N/A

          \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
        3. lower-+.f6428.3

          \[\leadsto 0.5 \cdot \left(NaChar + \color{blue}{NdChar}\right) \]
      4. Applied rewrites28.3%

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

      Alternative 19: 20.8% accurate, 7.9× speedup?

      \[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;NdChar \leq -1.15 \cdot 10^{+30}:\\ \;\;\;\;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 (<= NdChar -1.15e+30) (* 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 (NdChar <= -1.15e+30) {
      		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 (ndchar <= (-1.15d+30)) 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 (NdChar <= -1.15e+30) {
      		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 NdChar <= -1.15e+30:
      		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 (NdChar <= -1.15e+30)
      		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 (NdChar <= -1.15e+30)
      		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[NdChar, -1.15e+30], N[(0.5 * NdChar), $MachinePrecision], N[(0.5 * NaChar), $MachinePrecision]]
      
      \begin{array}{l}
      
      \\
      \begin{array}{l}
      \mathbf{if}\;NdChar \leq -1.15 \cdot 10^{+30}:\\
      \;\;\;\;0.5 \cdot NdChar\\
      
      \mathbf{else}:\\
      \;\;\;\;0.5 \cdot NaChar\\
      
      
      \end{array}
      \end{array}
      
      Derivation
      1. Split input into 2 regimes
      2. if NdChar < -1.15e30

        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. distribute-lft-outN/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
          2. lower-*.f64N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
          3. lower-+.f6428.3

            \[\leadsto 0.5 \cdot \left(NaChar + \color{blue}{NdChar}\right) \]
        4. Applied rewrites28.3%

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

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

            \[\leadsto 0.5 \cdot NdChar \]
        7. Applied rewrites19.0%

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

        if -1.15e30 < NdChar

        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. distribute-lft-outN/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
          2. lower-*.f64N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
          3. lower-+.f6428.3

            \[\leadsto 0.5 \cdot \left(NaChar + \color{blue}{NdChar}\right) \]
        4. Applied rewrites28.3%

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

          \[\leadsto \frac{1}{2} \cdot NaChar \]
        6. Step-by-step derivation
          1. Applied rewrites18.4%

            \[\leadsto 0.5 \cdot NaChar \]
        7. Recombined 2 regimes into one program.
        8. Add Preprocessing

        Alternative 20: 19.0% accurate, 15.4× speedup?

        \[\begin{array}{l} \\ 0.5 \cdot NdChar \end{array} \]
        (FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept)
         :precision binary64
         (* 0.5 NdChar))
        double code(double NdChar, double Ec, double Vef, double EDonor, double mu, double KbT, double NaChar, double Ev, double EAccept) {
        	return 0.5 * NdChar;
        }
        
        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 * ndchar
        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 * NdChar;
        }
        
        def code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept):
        	return 0.5 * NdChar
        
        function code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
        	return Float64(0.5 * NdChar)
        end
        
        function tmp = code(NdChar, Ec, Vef, EDonor, mu, KbT, NaChar, Ev, EAccept)
        	tmp = 0.5 * NdChar;
        end
        
        code[NdChar_, Ec_, Vef_, EDonor_, mu_, KbT_, NaChar_, Ev_, EAccept_] := N[(0.5 * NdChar), $MachinePrecision]
        
        \begin{array}{l}
        
        \\
        0.5 \cdot NdChar
        \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. distribute-lft-outN/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
          2. lower-*.f64N/A

            \[\leadsto \frac{1}{2} \cdot \color{blue}{\left(NaChar + NdChar\right)} \]
          3. lower-+.f6428.3

            \[\leadsto 0.5 \cdot \left(NaChar + \color{blue}{NdChar}\right) \]
        4. Applied rewrites28.3%

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

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

            \[\leadsto 0.5 \cdot NdChar \]
        7. Applied rewrites19.0%

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

        Reproduce

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