Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 85.8% → 99.6%
Time: 10.0s
Alternatives: 16
Speedup: 1.4×

Specification

?
\[\begin{array}{l} \\ \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}

Sampling outcomes in binary64 precision:

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 16 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: 85.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = ((j * (exp(l) - exp(-l))) * cos((k / 2.0d0))) + u
end function
public static double code(double J, double l, double K, double U) {
	return ((J * (Math.exp(l) - Math.exp(-l))) * Math.cos((K / 2.0))) + U;
}
def code(J, l, K, U):
	return ((J * (math.exp(l) - math.exp(-l))) * math.cos((K / 2.0))) + U
function code(J, l, K, U)
	return Float64(Float64(Float64(J * Float64(exp(l) - exp(Float64(-l)))) * cos(Float64(K / 2.0))) + U)
end
function tmp = code(J, l, K, U)
	tmp = ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
end
code[J_, l_, K_, U_] := N[(N[(N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\end{array}

Alternative 1: 99.6% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{-13}\right):\\ \;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 2e-13)))
     (+ (* (* t_0 J) (cos (/ K 2.0))) U)
     (+ U (* 2.0 (* J (* l (cos (* K 0.5)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 2e-13)) {
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	} else {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 2e-13)) {
		tmp = ((t_0 * J) * Math.cos((K / 2.0))) + U;
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 2e-13):
		tmp = ((t_0 * J) * math.cos((K / 2.0))) + U
	else:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 2e-13))
		tmp = Float64(Float64(Float64(t_0 * J) * cos(Float64(K / 2.0))) + U);
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = exp(l) - exp(-l);
	tmp = 0.0;
	if ((t_0 <= -Inf) || ~((t_0 <= 2e-13)))
		tmp = ((t_0 * J) * cos((K / 2.0))) + U;
	else
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, (-Infinity)], N[Not[LessEqual[t$95$0, 2e-13]], $MachinePrecision]], N[(N[(N[(t$95$0 * J), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t\_0 \leq -\infty \lor \neg \left(t\_0 \leq 2 \cdot 10^{-13}\right):\\
\;\;\;\;\left(t\_0 \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 2.0000000000000001e-13 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l)))

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing

    if -inf.0 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2.0000000000000001e-13

    1. Initial program 80.6%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification100.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;e^{\ell} - e^{-\ell} \leq -\infty \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-13}\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 95.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ t_1 := \cos \left(\frac{K}{2}\right)\\ \mathbf{if}\;\ell \leq -1.22 \cdot 10^{+92}:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -160:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 440:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+100}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (- (exp l) (exp (- l))) J)) (t_1 (cos (/ K 2.0))))
   (if (<= l -1.22e+92)
     (+ U (* t_1 (* J (* 0.3333333333333333 (pow l 3.0)))))
     (if (<= l -160.0)
       t_0
       (if (<= l 440.0)
         (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
         (if (<= l 1.65e+100)
           t_0
           (+
            U
            (*
             t_1
             (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = (exp(l) - exp(-l)) * J;
	double t_1 = cos((K / 2.0));
	double tmp;
	if (l <= -1.22e+92) {
		tmp = U + (t_1 * (J * (0.3333333333333333 * pow(l, 3.0))));
	} else if (l <= -160.0) {
		tmp = t_0;
	} else if (l <= 440.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 1.65e+100) {
		tmp = t_0;
	} else {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (exp(l) - exp(-l)) * j
    t_1 = cos((k / 2.0d0))
    if (l <= (-1.22d+92)) then
        tmp = u + (t_1 * (j * (0.3333333333333333d0 * (l ** 3.0d0))))
    else if (l <= (-160.0d0)) then
        tmp = t_0
    else if (l <= 440.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 1.65d+100) then
        tmp = t_0
    else
        tmp = u + (t_1 * (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0))))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = (Math.exp(l) - Math.exp(-l)) * J;
	double t_1 = Math.cos((K / 2.0));
	double tmp;
	if (l <= -1.22e+92) {
		tmp = U + (t_1 * (J * (0.3333333333333333 * Math.pow(l, 3.0))));
	} else if (l <= -160.0) {
		tmp = t_0;
	} else if (l <= 440.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 1.65e+100) {
		tmp = t_0;
	} else {
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = (math.exp(l) - math.exp(-l)) * J
	t_1 = math.cos((K / 2.0))
	tmp = 0
	if l <= -1.22e+92:
		tmp = U + (t_1 * (J * (0.3333333333333333 * math.pow(l, 3.0))))
	elif l <= -160.0:
		tmp = t_0
	elif l <= 440.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 1.65e+100:
		tmp = t_0
	else:
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(Float64(exp(l) - exp(Float64(-l))) * J)
	t_1 = cos(Float64(K / 2.0))
	tmp = 0.0
	if (l <= -1.22e+92)
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))));
	elseif (l <= -160.0)
		tmp = t_0;
	elseif (l <= 440.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 1.65e+100)
		tmp = t_0;
	else
		tmp = Float64(U + Float64(t_1 * Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = (exp(l) - exp(-l)) * J;
	t_1 = cos((K / 2.0));
	tmp = 0.0;
	if (l <= -1.22e+92)
		tmp = U + (t_1 * (J * (0.3333333333333333 * (l ^ 3.0))));
	elseif (l <= -160.0)
		tmp = t_0;
	elseif (l <= 440.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 1.65e+100)
		tmp = t_0;
	else
		tmp = U + (t_1 * (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0))))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]}, Block[{t$95$1 = N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[l, -1.22e+92], N[(U + N[(t$95$1 * N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -160.0], t$95$0, If[LessEqual[l, 440.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.65e+100], t$95$0, N[(U + N[(t$95$1 * N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
t_1 := \cos \left(\frac{K}{2}\right)\\
\mathbf{if}\;\ell \leq -1.22 \cdot 10^{+92}:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\

\mathbf{elif}\;\ell \leq -160:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 440:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+100}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;U + t\_1 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.22e92

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 97.9%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in l around inf 97.9%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Step-by-step derivation
      1. associate-*r*97.9%

        \[\leadsto \color{blue}{\left(\left(0.3333333333333333 \cdot J\right) \cdot {\ell}^{3}\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative97.9%

        \[\leadsto \left(\color{blue}{\left(J \cdot 0.3333333333333333\right)} \cdot {\ell}^{3}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. associate-*r*97.9%

        \[\leadsto \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Simplified97.9%

      \[\leadsto \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -1.22e92 < l < -160 or 440 < l < 1.6500000000000001e100

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 88.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 88.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} \]

    if -160 < l < 440

    1. Initial program 80.8%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]

    if 1.6500000000000001e100 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 97.7%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Recombined 4 regimes into one program.
  4. Final simplification96.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.22 \cdot 10^{+92}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -160:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 440:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+100}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 95.3% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{if}\;\ell \leq -1.22 \cdot 10^{+92}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -260:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq 150:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+100}:\\ \;\;\;\;t\_1\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+ U (* (cos (/ K 2.0)) (* J (* 0.3333333333333333 (pow l 3.0))))))
        (t_1 (* (- (exp l) (exp (- l))) J)))
   (if (<= l -1.22e+92)
     t_0
     (if (<= l -260.0)
       t_1
       (if (<= l 150.0)
         (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
         (if (<= l 1.65e+100) t_1 t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (cos((K / 2.0)) * (J * (0.3333333333333333 * pow(l, 3.0))));
	double t_1 = (exp(l) - exp(-l)) * J;
	double tmp;
	if (l <= -1.22e+92) {
		tmp = t_0;
	} else if (l <= -260.0) {
		tmp = t_1;
	} else if (l <= 150.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 1.65e+100) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = u + (cos((k / 2.0d0)) * (j * (0.3333333333333333d0 * (l ** 3.0d0))))
    t_1 = (exp(l) - exp(-l)) * j
    if (l <= (-1.22d+92)) then
        tmp = t_0
    else if (l <= (-260.0d0)) then
        tmp = t_1
    else if (l <= 150.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 1.65d+100) then
        tmp = t_1
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (Math.cos((K / 2.0)) * (J * (0.3333333333333333 * Math.pow(l, 3.0))));
	double t_1 = (Math.exp(l) - Math.exp(-l)) * J;
	double tmp;
	if (l <= -1.22e+92) {
		tmp = t_0;
	} else if (l <= -260.0) {
		tmp = t_1;
	} else if (l <= 150.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 1.65e+100) {
		tmp = t_1;
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (math.cos((K / 2.0)) * (J * (0.3333333333333333 * math.pow(l, 3.0))))
	t_1 = (math.exp(l) - math.exp(-l)) * J
	tmp = 0
	if l <= -1.22e+92:
		tmp = t_0
	elif l <= -260.0:
		tmp = t_1
	elif l <= 150.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 1.65e+100:
		tmp = t_1
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(J * Float64(0.3333333333333333 * (l ^ 3.0)))))
	t_1 = Float64(Float64(exp(l) - exp(Float64(-l))) * J)
	tmp = 0.0
	if (l <= -1.22e+92)
		tmp = t_0;
	elseif (l <= -260.0)
		tmp = t_1;
	elseif (l <= 150.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 1.65e+100)
		tmp = t_1;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (cos((K / 2.0)) * (J * (0.3333333333333333 * (l ^ 3.0))));
	t_1 = (exp(l) - exp(-l)) * J;
	tmp = 0.0;
	if (l <= -1.22e+92)
		tmp = t_0;
	elseif (l <= -260.0)
		tmp = t_1;
	elseif (l <= 150.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 1.65e+100)
		tmp = t_1;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(J * N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision]}, If[LessEqual[l, -1.22e+92], t$95$0, If[LessEqual[l, -260.0], t$95$1, If[LessEqual[l, 150.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.65e+100], t$95$1, t$95$0]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\
t_1 := \left(e^{\ell} - e^{-\ell}\right) \cdot J\\
\mathbf{if}\;\ell \leq -1.22 \cdot 10^{+92}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -260:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq 150:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+100}:\\
\;\;\;\;t\_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.22e92 or 1.6500000000000001e100 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 97.8%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in l around inf 97.8%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Step-by-step derivation
      1. associate-*r*97.8%

        \[\leadsto \color{blue}{\left(\left(0.3333333333333333 \cdot J\right) \cdot {\ell}^{3}\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
      2. *-commutative97.8%

        \[\leadsto \left(\color{blue}{\left(J \cdot 0.3333333333333333\right)} \cdot {\ell}^{3}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      3. associate-*r*97.8%

        \[\leadsto \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    6. Simplified97.8%

      \[\leadsto \color{blue}{\left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]

    if -1.22e92 < l < -260 or 150 < l < 1.6500000000000001e100

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 88.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 88.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} \]

    if -260 < l < 150

    1. Initial program 80.8%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification96.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.22 \cdot 10^{+92}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \mathbf{elif}\;\ell \leq -260:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{elif}\;\ell \leq 150:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+100}:\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 87.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -245 \lor \neg \left(\ell \leq 300\right):\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -245.0) (not (<= l 300.0)))
   (* (- (exp l) (exp (- l))) J)
   (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -245.0) || !(l <= 300.0)) {
		tmp = (exp(l) - exp(-l)) * J;
	} else {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-245.0d0)) .or. (.not. (l <= 300.0d0))) then
        tmp = (exp(l) - exp(-l)) * j
    else
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -245.0) || !(l <= 300.0)) {
		tmp = (Math.exp(l) - Math.exp(-l)) * J;
	} else {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -245.0) or not (l <= 300.0):
		tmp = (math.exp(l) - math.exp(-l)) * J
	else:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -245.0) || !(l <= 300.0))
		tmp = Float64(Float64(exp(l) - exp(Float64(-l))) * J);
	else
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -245.0) || ~((l <= 300.0)))
		tmp = (exp(l) - exp(-l)) * J;
	else
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -245.0], N[Not[LessEqual[l, 300.0]], $MachinePrecision]], N[(N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision] * J), $MachinePrecision], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -245 \lor \neg \left(\ell \leq 300\right):\\
\;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\

\mathbf{else}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -245 or 300 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 80.9%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in J around inf 80.9%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} \]

    if -245 < l < 300

    1. Initial program 80.8%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 99.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification89.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -245 \lor \neg \left(\ell \leq 300\right):\\ \;\;\;\;\left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 78.2% accurate, 2.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \mathbf{if}\;\ell \leq -3.2 \cdot 10^{+23}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 7.8 \cdot 10^{+85}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{\frac{68719476736}{{K}^{3}} + -0.5}{U}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))
   (if (<= l -3.2e+23)
     t_0
     (if (<= l 1.45e-11)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
       (if (<= l 7.8e+85)
         (* U (+ 1.0 (* J (/ (+ (/ 68719476736.0 (pow K 3.0)) -0.5) U))))
         t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	double tmp;
	if (l <= -3.2e+23) {
		tmp = t_0;
	} else if (l <= 1.45e-11) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 7.8e+85) {
		tmp = U * (1.0 + (J * (((68719476736.0 / pow(K, 3.0)) + -0.5) / U)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    if (l <= (-3.2d+23)) then
        tmp = t_0
    else if (l <= 1.45d-11) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 7.8d+85) then
        tmp = u * (1.0d0 + (j * (((68719476736.0d0 / (k ** 3.0d0)) + (-0.5d0)) / u)))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	double tmp;
	if (l <= -3.2e+23) {
		tmp = t_0;
	} else if (l <= 1.45e-11) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 7.8e+85) {
		tmp = U * (1.0 + (J * (((68719476736.0 / Math.pow(K, 3.0)) + -0.5) / U)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	tmp = 0
	if l <= -3.2e+23:
		tmp = t_0
	elif l <= 1.45e-11:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 7.8e+85:
		tmp = U * (1.0 + (J * (((68719476736.0 / math.pow(K, 3.0)) + -0.5) / U)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))))
	tmp = 0.0
	if (l <= -3.2e+23)
		tmp = t_0;
	elseif (l <= 1.45e-11)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 7.8e+85)
		tmp = Float64(U * Float64(1.0 + Float64(J * Float64(Float64(Float64(68719476736.0 / (K ^ 3.0)) + -0.5) / U))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	tmp = 0.0;
	if (l <= -3.2e+23)
		tmp = t_0;
	elseif (l <= 1.45e-11)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 7.8e+85)
		tmp = U * (1.0 + (J * (((68719476736.0 / (K ^ 3.0)) + -0.5) / U)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.2e+23], t$95$0, If[LessEqual[l, 1.45e-11], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 7.8e+85], N[(U * N[(1.0 + N[(J * N[(N[(N[(68719476736.0 / N[Power[K, 3.0], $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\
\mathbf{if}\;\ell \leq -3.2 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 7.8 \cdot 10^{+85}:\\
\;\;\;\;U \cdot \left(1 + J \cdot \frac{\frac{68719476736}{{K}^{3}} + -0.5}{U}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.2e23 or 7.80000000000000067e85 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 83.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 66.1%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]

    if -3.2e23 < l < 1.45e-11

    1. Initial program 80.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 98.3%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]

    if 1.45e-11 < l < 7.80000000000000067e85

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr5.2%

      \[\leadsto \left(J \cdot \color{blue}{-0.5}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 15.5%

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    5. Step-by-step derivation
      1. *-commutative15.5%

        \[\leadsto \left(\color{blue}{J \cdot -0.5} + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right) + U \]
      2. *-commutative15.5%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{\left(J \cdot {K}^{2}\right) \cdot 0.0625}\right) + U \]
      3. associate-*l*15.5%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{J \cdot \left({K}^{2} \cdot 0.0625\right)}\right) + U \]
      4. distribute-lft-out15.5%

        \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    6. Simplified15.5%

      \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    7. Applied egg-rr26.3%

      \[\leadsto J \cdot \left(-0.5 + \color{blue}{{\left(K \cdot 0.000244140625\right)}^{-3}}\right) + U \]
    8. Taylor expanded in U around inf 29.7%

      \[\leadsto \color{blue}{U \cdot \left(1 + \frac{J \cdot \left(68719476736 \cdot \frac{1}{{K}^{3}} - 0.5\right)}{U}\right)} \]
    9. Step-by-step derivation
      1. associate-/l*29.7%

        \[\leadsto U \cdot \left(1 + \color{blue}{J \cdot \frac{68719476736 \cdot \frac{1}{{K}^{3}} - 0.5}{U}}\right) \]
      2. sub-neg29.7%

        \[\leadsto U \cdot \left(1 + J \cdot \frac{\color{blue}{68719476736 \cdot \frac{1}{{K}^{3}} + \left(-0.5\right)}}{U}\right) \]
      3. associate-*r/29.7%

        \[\leadsto U \cdot \left(1 + J \cdot \frac{\color{blue}{\frac{68719476736 \cdot 1}{{K}^{3}}} + \left(-0.5\right)}{U}\right) \]
      4. metadata-eval29.7%

        \[\leadsto U \cdot \left(1 + J \cdot \frac{\frac{\color{blue}{68719476736}}{{K}^{3}} + \left(-0.5\right)}{U}\right) \]
      5. metadata-eval29.7%

        \[\leadsto U \cdot \left(1 + J \cdot \frac{\frac{68719476736}{{K}^{3}} + \color{blue}{-0.5}}{U}\right) \]
    10. Simplified29.7%

      \[\leadsto \color{blue}{U \cdot \left(1 + J \cdot \frac{\frac{68719476736}{{K}^{3}} + -0.5}{U}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification77.3%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.2 \cdot 10^{+23}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 7.8 \cdot 10^{+85}:\\ \;\;\;\;U \cdot \left(1 + J \cdot \frac{\frac{68719476736}{{K}^{3}} + -0.5}{U}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 77.9% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+23}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{+85}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))
   (if (<= l -7.5e+23)
     t_0
     (if (<= l 1.45e-11)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
       (if (<= l 8e+85)
         (+ U (* J (+ -0.5 (pow (* K 0.000244140625) -3.0))))
         t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	double tmp;
	if (l <= -7.5e+23) {
		tmp = t_0;
	} else if (l <= 1.45e-11) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 8e+85) {
		tmp = U + (J * (-0.5 + pow((K * 0.000244140625), -3.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    if (l <= (-7.5d+23)) then
        tmp = t_0
    else if (l <= 1.45d-11) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 8d+85) then
        tmp = u + (j * ((-0.5d0) + ((k * 0.000244140625d0) ** (-3.0d0))))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	double tmp;
	if (l <= -7.5e+23) {
		tmp = t_0;
	} else if (l <= 1.45e-11) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 8e+85) {
		tmp = U + (J * (-0.5 + Math.pow((K * 0.000244140625), -3.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	tmp = 0
	if l <= -7.5e+23:
		tmp = t_0
	elif l <= 1.45e-11:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 8e+85:
		tmp = U + (J * (-0.5 + math.pow((K * 0.000244140625), -3.0)))
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))))
	tmp = 0.0
	if (l <= -7.5e+23)
		tmp = t_0;
	elseif (l <= 1.45e-11)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 8e+85)
		tmp = Float64(U + Float64(J * Float64(-0.5 + (Float64(K * 0.000244140625) ^ -3.0))));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	tmp = 0.0;
	if (l <= -7.5e+23)
		tmp = t_0;
	elseif (l <= 1.45e-11)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 8e+85)
		tmp = U + (J * (-0.5 + ((K * 0.000244140625) ^ -3.0)));
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -7.5e+23], t$95$0, If[LessEqual[l, 1.45e-11], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 8e+85], N[(U + N[(J * N[(-0.5 + N[Power[N[(K * 0.000244140625), $MachinePrecision], -3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\
\mathbf{if}\;\ell \leq -7.5 \cdot 10^{+23}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\
\;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 8 \cdot 10^{+85}:\\
\;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -7.49999999999999987e23 or 8.0000000000000001e85 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 83.0%

      \[\leadsto \left(J \cdot \color{blue}{\left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 66.1%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)} + U \]

    if -7.49999999999999987e23 < l < 1.45e-11

    1. Initial program 80.9%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 98.3%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]

    if 1.45e-11 < l < 8.0000000000000001e85

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr5.2%

      \[\leadsto \left(J \cdot \color{blue}{-0.5}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 15.5%

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    5. Step-by-step derivation
      1. *-commutative15.5%

        \[\leadsto \left(\color{blue}{J \cdot -0.5} + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right) + U \]
      2. *-commutative15.5%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{\left(J \cdot {K}^{2}\right) \cdot 0.0625}\right) + U \]
      3. associate-*l*15.5%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{J \cdot \left({K}^{2} \cdot 0.0625\right)}\right) + U \]
      4. distribute-lft-out15.5%

        \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    6. Simplified15.5%

      \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    7. Applied egg-rr26.3%

      \[\leadsto J \cdot \left(-0.5 + \color{blue}{{\left(K \cdot 0.000244140625\right)}^{-3}}\right) + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification77.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -7.5 \cdot 10^{+23}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 8 \cdot 10^{+85}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 7: 61.5% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{if}\;\ell \leq -1.4 \cdot 10^{+98}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -1.28 \cdot 10^{+35}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;t\_0\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))))
   (if (<= l -1.4e+98)
     t_0
     (if (<= l -1.28e+35)
       (pow U -3.0)
       (if (<= l 1.45e-11)
         t_0
         (+ U (* J (+ -0.5 (pow (* K 0.000244140625) -3.0)))))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l * cos((K * 0.5)))));
	double tmp;
	if (l <= -1.4e+98) {
		tmp = t_0;
	} else if (l <= -1.28e+35) {
		tmp = pow(U, -3.0);
	} else if (l <= 1.45e-11) {
		tmp = t_0;
	} else {
		tmp = U + (J * (-0.5 + pow((K * 0.000244140625), -3.0)));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: tmp
    t_0 = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    if (l <= (-1.4d+98)) then
        tmp = t_0
    else if (l <= (-1.28d+35)) then
        tmp = u ** (-3.0d0)
    else if (l <= 1.45d-11) then
        tmp = t_0
    else
        tmp = u + (j * ((-0.5d0) + ((k * 0.000244140625d0) ** (-3.0d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	double tmp;
	if (l <= -1.4e+98) {
		tmp = t_0;
	} else if (l <= -1.28e+35) {
		tmp = Math.pow(U, -3.0);
	} else if (l <= 1.45e-11) {
		tmp = t_0;
	} else {
		tmp = U + (J * (-0.5 + Math.pow((K * 0.000244140625), -3.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	tmp = 0
	if l <= -1.4e+98:
		tmp = t_0
	elif l <= -1.28e+35:
		tmp = math.pow(U, -3.0)
	elif l <= 1.45e-11:
		tmp = t_0
	else:
		tmp = U + (J * (-0.5 + math.pow((K * 0.000244140625), -3.0)))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))))
	tmp = 0.0
	if (l <= -1.4e+98)
		tmp = t_0;
	elseif (l <= -1.28e+35)
		tmp = U ^ -3.0;
	elseif (l <= 1.45e-11)
		tmp = t_0;
	else
		tmp = Float64(U + Float64(J * Float64(-0.5 + (Float64(K * 0.000244140625) ^ -3.0))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + (2.0 * (J * (l * cos((K * 0.5)))));
	tmp = 0.0;
	if (l <= -1.4e+98)
		tmp = t_0;
	elseif (l <= -1.28e+35)
		tmp = U ^ -3.0;
	elseif (l <= 1.45e-11)
		tmp = t_0;
	else
		tmp = U + (J * (-0.5 + ((K * 0.000244140625) ^ -3.0)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.4e+98], t$95$0, If[LessEqual[l, -1.28e+35], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 1.45e-11], t$95$0, N[(U + N[(J * N[(-0.5 + N[Power[N[(K * 0.000244140625), $MachinePrecision], -3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\
\mathbf{if}\;\ell \leq -1.4 \cdot 10^{+98}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -1.28 \cdot 10^{+35}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\
\;\;\;\;t\_0\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.4e98 or -1.2799999999999999e35 < l < 1.45e-11

    1. Initial program 86.3%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in l around 0 78.9%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]

    if -1.4e98 < l < -1.2799999999999999e35

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr43.9%

      \[\leadsto \color{blue}{{U}^{-3}} \]

    if 1.45e-11 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr3.0%

      \[\leadsto \left(J \cdot \color{blue}{-0.5}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 17.3%

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    5. Step-by-step derivation
      1. *-commutative17.3%

        \[\leadsto \left(\color{blue}{J \cdot -0.5} + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right) + U \]
      2. *-commutative17.3%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{\left(J \cdot {K}^{2}\right) \cdot 0.0625}\right) + U \]
      3. associate-*l*16.1%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{J \cdot \left({K}^{2} \cdot 0.0625\right)}\right) + U \]
      4. distribute-lft-out16.1%

        \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    6. Simplified16.1%

      \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    7. Applied egg-rr20.4%

      \[\leadsto J \cdot \left(-0.5 + \color{blue}{{\left(K \cdot 0.000244140625\right)}^{-3}}\right) + U \]
  3. Recombined 3 regimes into one program.
  4. Final simplification60.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.4 \cdot 10^{+98}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -1.28 \cdot 10^{+35}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 8: 53.1% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.8 \cdot 10^{+104}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -2.7 \cdot 10^{+35}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1.8e+104)
   (+ U (* l (* J 2.0)))
   (if (<= l -2.7e+35)
     (pow U -3.0)
     (if (<= l 1.45e-11)
       (fma J (* l 2.0) U)
       (+ U (* J (+ -0.5 (pow (* K 0.000244140625) -3.0))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.8e+104) {
		tmp = U + (l * (J * 2.0));
	} else if (l <= -2.7e+35) {
		tmp = pow(U, -3.0);
	} else if (l <= 1.45e-11) {
		tmp = fma(J, (l * 2.0), U);
	} else {
		tmp = U + (J * (-0.5 + pow((K * 0.000244140625), -3.0)));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1.8e+104)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	elseif (l <= -2.7e+35)
		tmp = U ^ -3.0;
	elseif (l <= 1.45e-11)
		tmp = fma(J, Float64(l * 2.0), U);
	else
		tmp = Float64(U + Float64(J * Float64(-0.5 + (Float64(K * 0.000244140625) ^ -3.0))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.8e+104], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -2.7e+35], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 1.45e-11], N[(J * N[(l * 2.0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(-0.5 + N[Power[N[(K * 0.000244140625), $MachinePrecision], -3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.8 \cdot 10^{+104}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{elif}\;\ell \leq -2.7 \cdot 10^{+35}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.8e104

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 76.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 24.1%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    5. Step-by-step derivation
      1. associate-*r*24.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    6. Simplified24.1%

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]

    if -1.8e104 < l < -2.70000000000000003e35

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr43.9%

      \[\leadsto \color{blue}{{U}^{-3}} \]

    if -2.70000000000000003e35 < l < 1.45e-11

    1. Initial program 81.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 81.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 87.1%

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \ell\right)} \]
    5. Step-by-step derivation
      1. associate-*r*87.1%

        \[\leadsto U + \color{blue}{\left(2 \cdot J\right) \cdot \ell} \]
      2. +-commutative87.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell + U} \]
      3. associate-*r*87.1%

        \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
      4. *-commutative87.1%

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} + U \]
      5. associate-*l*87.1%

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + U \]
      6. fma-define87.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
    6. Simplified87.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]

    if 1.45e-11 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr3.0%

      \[\leadsto \left(J \cdot \color{blue}{-0.5}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 17.3%

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    5. Step-by-step derivation
      1. *-commutative17.3%

        \[\leadsto \left(\color{blue}{J \cdot -0.5} + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right) + U \]
      2. *-commutative17.3%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{\left(J \cdot {K}^{2}\right) \cdot 0.0625}\right) + U \]
      3. associate-*l*16.1%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{J \cdot \left({K}^{2} \cdot 0.0625\right)}\right) + U \]
      4. distribute-lft-out16.1%

        \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    6. Simplified16.1%

      \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    7. Applied egg-rr20.4%

      \[\leadsto J \cdot \left(-0.5 + \color{blue}{{\left(K \cdot 0.000244140625\right)}^{-3}}\right) + U \]
  3. Recombined 4 regimes into one program.
  4. Final simplification55.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.8 \cdot 10^{+104}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -2.7 \cdot 10^{+35}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(-0.5 + {\left(K \cdot 0.000244140625\right)}^{-3}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 53.0% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+103}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -6 \cdot 10^{+34}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \frac{68719476736}{{K}^{3}}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -4.2e+103)
   (+ U (* l (* J 2.0)))
   (if (<= l -6e+34)
     (pow U -3.0)
     (if (<= l 1.45e-11)
       (fma J (* l 2.0) U)
       (+ U (* J (/ 68719476736.0 (pow K 3.0))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -4.2e+103) {
		tmp = U + (l * (J * 2.0));
	} else if (l <= -6e+34) {
		tmp = pow(U, -3.0);
	} else if (l <= 1.45e-11) {
		tmp = fma(J, (l * 2.0), U);
	} else {
		tmp = U + (J * (68719476736.0 / pow(K, 3.0)));
	}
	return tmp;
}
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -4.2e+103)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	elseif (l <= -6e+34)
		tmp = U ^ -3.0;
	elseif (l <= 1.45e-11)
		tmp = fma(J, Float64(l * 2.0), U);
	else
		tmp = Float64(U + Float64(J * Float64(68719476736.0 / (K ^ 3.0))));
	end
	return tmp
end
code[J_, l_, K_, U_] := If[LessEqual[l, -4.2e+103], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, -6e+34], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 1.45e-11], N[(J * N[(l * 2.0), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(J * N[(68719476736.0 / N[Power[K, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -4.2 \cdot 10^{+103}:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{elif}\;\ell \leq -6 \cdot 10^{+34}:\\
\;\;\;\;{U}^{-3}\\

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \frac{68719476736}{{K}^{3}}\\


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -4.2000000000000003e103

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 76.2%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 24.1%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    5. Step-by-step derivation
      1. associate-*r*24.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
    6. Simplified24.1%

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]

    if -4.2000000000000003e103 < l < -6.00000000000000037e34

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr43.9%

      \[\leadsto \color{blue}{{U}^{-3}} \]

    if -6.00000000000000037e34 < l < 1.45e-11

    1. Initial program 81.7%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 81.4%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Taylor expanded in l around 0 87.1%

      \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \ell\right)} \]
    5. Step-by-step derivation
      1. associate-*r*87.1%

        \[\leadsto U + \color{blue}{\left(2 \cdot J\right) \cdot \ell} \]
      2. +-commutative87.1%

        \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell + U} \]
      3. associate-*r*87.1%

        \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
      4. *-commutative87.1%

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} + U \]
      5. associate-*l*87.1%

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + U \]
      6. fma-define87.1%

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
    6. Simplified87.1%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]

    if 1.45e-11 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr3.0%

      \[\leadsto \left(J \cdot \color{blue}{-0.5}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in K around 0 17.3%

      \[\leadsto \color{blue}{\left(-0.5 \cdot J + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
    5. Step-by-step derivation
      1. *-commutative17.3%

        \[\leadsto \left(\color{blue}{J \cdot -0.5} + 0.0625 \cdot \left(J \cdot {K}^{2}\right)\right) + U \]
      2. *-commutative17.3%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{\left(J \cdot {K}^{2}\right) \cdot 0.0625}\right) + U \]
      3. associate-*l*16.1%

        \[\leadsto \left(J \cdot -0.5 + \color{blue}{J \cdot \left({K}^{2} \cdot 0.0625\right)}\right) + U \]
      4. distribute-lft-out16.1%

        \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    6. Simplified16.1%

      \[\leadsto \color{blue}{J \cdot \left(-0.5 + {K}^{2} \cdot 0.0625\right)} + U \]
    7. Applied egg-rr20.4%

      \[\leadsto J \cdot \left(-0.5 + \color{blue}{{\left(K \cdot 0.000244140625\right)}^{-3}}\right) + U \]
    8. Taylor expanded in K around 0 19.0%

      \[\leadsto \color{blue}{68719476736 \cdot \frac{J}{{K}^{3}}} + U \]
    9. Step-by-step derivation
      1. associate-*r/19.0%

        \[\leadsto \color{blue}{\frac{68719476736 \cdot J}{{K}^{3}}} + U \]
      2. *-commutative19.0%

        \[\leadsto \frac{\color{blue}{J \cdot 68719476736}}{{K}^{3}} + U \]
      3. associate-/l*20.3%

        \[\leadsto \color{blue}{J \cdot \frac{68719476736}{{K}^{3}}} + U \]
    10. Simplified20.3%

      \[\leadsto \color{blue}{J \cdot \frac{68719476736}{{K}^{3}}} + U \]
  3. Recombined 4 regimes into one program.
  4. Final simplification55.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.2 \cdot 10^{+103}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq -6 \cdot 10^{+34}:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{-11}:\\ \;\;\;\;\mathsf{fma}\left(J, \ell \cdot 2, U\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \frac{68719476736}{{K}^{3}}\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 53.8% accurate, 3.0× speedup?

\[\begin{array}{l} \\ \mathsf{fma}\left(J, \ell \cdot 2, U\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (fma J (* l 2.0) U))
double code(double J, double l, double K, double U) {
	return fma(J, (l * 2.0), U);
}
function code(J, l, K, U)
	return fma(J, Float64(l * 2.0), U)
end
code[J_, l_, K_, U_] := N[(J * N[(l * 2.0), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
\mathsf{fma}\left(J, \ell \cdot 2, U\right)
\end{array}
Derivation
  1. Initial program 91.0%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in K around 0 80.7%

    \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  4. Taylor expanded in l around 0 52.5%

    \[\leadsto \color{blue}{U + 2 \cdot \left(J \cdot \ell\right)} \]
  5. Step-by-step derivation
    1. associate-*r*52.5%

      \[\leadsto U + \color{blue}{\left(2 \cdot J\right) \cdot \ell} \]
    2. +-commutative52.5%

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell + U} \]
    3. associate-*r*52.5%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
    4. *-commutative52.5%

      \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot 2} + U \]
    5. associate-*l*52.5%

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + U \]
    6. fma-define52.5%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
  6. Simplified52.5%

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
  7. Add Preprocessing

Alternative 11: 41.7% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.2 \cdot 10^{+45} \lor \neg \left(\ell \leq 160000\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -1.2e+45) (not (<= l 160000.0))) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.2e+45) || !(l <= 160000.0)) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if ((l <= (-1.2d+45)) .or. (.not. (l <= 160000.0d0))) then
        tmp = u * u
    else
        tmp = u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.2e+45) || !(l <= 160000.0)) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -1.2e+45) or not (l <= 160000.0):
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -1.2e+45) || !(l <= 160000.0))
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -1.2e+45) || ~((l <= 160000.0)))
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1.2e+45], N[Not[LessEqual[l, 160000.0]], $MachinePrecision]], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.2 \cdot 10^{+45} \lor \neg \left(\ell \leq 160000\right):\\
\;\;\;\;U \cdot U\\

\mathbf{else}:\\
\;\;\;\;U\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.19999999999999995e45 or 1.6e5 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr15.9%

      \[\leadsto \color{blue}{U \cdot U} \]

    if -1.19999999999999995e45 < l < 1.6e5

    1. Initial program 82.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in J around 0 73.1%

      \[\leadsto \color{blue}{U} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification45.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -1.2 \cdot 10^{+45} \lor \neg \left(\ell \leq 160000\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 12: 41.7% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.2 \cdot 10^{+45}:\\ \;\;\;\;U \cdot \left(U + -1\right)\\ \mathbf{elif}\;\ell \leq 1600000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -1.2e+45) (* U (+ U -1.0)) (if (<= l 1600000.0) U (* U U))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.2e+45) {
		tmp = U * (U + -1.0);
	} else if (l <= 1600000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= (-1.2d+45)) then
        tmp = u * (u + (-1.0d0))
    else if (l <= 1600000.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -1.2e+45) {
		tmp = U * (U + -1.0);
	} else if (l <= 1600000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -1.2e+45:
		tmp = U * (U + -1.0)
	elif l <= 1600000.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -1.2e+45)
		tmp = Float64(U * Float64(U + -1.0));
	elseif (l <= 1600000.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -1.2e+45)
		tmp = U * (U + -1.0);
	elseif (l <= 1600000.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -1.2e+45], N[(U * N[(U + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1600000.0], U, N[(U * U), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.2 \cdot 10^{+45}:\\
\;\;\;\;U \cdot \left(U + -1\right)\\

\mathbf{elif}\;\ell \leq 1600000:\\
\;\;\;\;U\\

\mathbf{else}:\\
\;\;\;\;U \cdot U\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -1.19999999999999995e45

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in K around 0 76.9%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
    4. Applied egg-rr18.9%

      \[\leadsto \color{blue}{\mathsf{fma}\left(U, U, -U\right)} \]
    5. Step-by-step derivation
      1. fma-undefine18.9%

        \[\leadsto \color{blue}{U \cdot U + \left(-U\right)} \]
      2. neg-mul-118.9%

        \[\leadsto U \cdot U + \color{blue}{-1 \cdot U} \]
      3. distribute-rgt-out18.9%

        \[\leadsto \color{blue}{U \cdot \left(U + -1\right)} \]
    6. Simplified18.9%

      \[\leadsto \color{blue}{U \cdot \left(U + -1\right)} \]

    if -1.19999999999999995e45 < l < 1.6e6

    1. Initial program 82.5%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Taylor expanded in J around 0 73.1%

      \[\leadsto \color{blue}{U} \]

    if 1.6e6 < l

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Add Preprocessing
    3. Applied egg-rr13.9%

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

Alternative 13: 53.7% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + \ell \cdot \left(J \cdot 2\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* l (* J 2.0))))
double code(double J, double l, double K, double U) {
	return U + (l * (J * 2.0));
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u + (l * (j * 2.0d0))
end function
public static double code(double J, double l, double K, double U) {
	return U + (l * (J * 2.0));
}
def code(J, l, K, U):
	return U + (l * (J * 2.0))
function code(J, l, K, U)
	return Float64(U + Float64(l * Float64(J * 2.0)))
end
function tmp = code(J, l, K, U)
	tmp = U + (l * (J * 2.0));
end
code[J_, l_, K_, U_] := N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + \ell \cdot \left(J \cdot 2\right)
\end{array}
Derivation
  1. Initial program 91.0%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in K around 0 80.7%

    \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  4. Taylor expanded in l around 0 52.5%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \ell\right)} + U \]
  5. Step-by-step derivation
    1. associate-*r*52.5%

      \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
  6. Simplified52.5%

    \[\leadsto \color{blue}{\left(2 \cdot J\right) \cdot \ell} + U \]
  7. Final simplification52.5%

    \[\leadsto U + \ell \cdot \left(J \cdot 2\right) \]
  8. Add Preprocessing

Alternative 14: 36.4% accurate, 312.0× speedup?

\[\begin{array}{l} \\ U \end{array} \]
(FPCore (J l K U) :precision binary64 U)
double code(double J, double l, double K, double U) {
	return U;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = u
end function
public static double code(double J, double l, double K, double U) {
	return U;
}
def code(J, l, K, U):
	return U
function code(J, l, K, U)
	return U
end
function tmp = code(J, l, K, U)
	tmp = U;
end
code[J_, l_, K_, U_] := U
\begin{array}{l}

\\
U
\end{array}
Derivation
  1. Initial program 91.0%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in J around 0 38.6%

    \[\leadsto \color{blue}{U} \]
  4. Add Preprocessing

Alternative 15: 2.7% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 1 \end{array} \]
(FPCore (J l K U) :precision binary64 1.0)
double code(double J, double l, double K, double U) {
	return 1.0;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = 1.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 1.0;
}
def code(J, l, K, U):
	return 1.0
function code(J, l, K, U)
	return 1.0
end
function tmp = code(J, l, K, U)
	tmp = 1.0;
end
code[J_, l_, K_, U_] := 1.0
\begin{array}{l}

\\
1
\end{array}
Derivation
  1. Initial program 91.0%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Applied egg-rr2.7%

    \[\leadsto \color{blue}{\frac{U}{U}} \]
  4. Step-by-step derivation
    1. *-inverses2.7%

      \[\leadsto \color{blue}{1} \]
  5. Simplified2.7%

    \[\leadsto \color{blue}{1} \]
  6. Add Preprocessing

Alternative 16: 2.4% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (J l K U) :precision binary64 0.0)
double code(double J, double l, double K, double U) {
	return 0.0;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    code = 0.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 0.0;
}
def code(J, l, K, U):
	return 0.0
function code(J, l, K, U)
	return 0.0
end
function tmp = code(J, l, K, U)
	tmp = 0.0;
end
code[J_, l_, K_, U_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 91.0%

    \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  2. Add Preprocessing
  3. Taylor expanded in K around 0 80.7%

    \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  4. Applied egg-rr2.2%

    \[\leadsto \color{blue}{U - U} \]
  5. Step-by-step derivation
    1. +-inverses2.2%

      \[\leadsto \color{blue}{0} \]
  6. Simplified2.2%

    \[\leadsto \color{blue}{0} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2024108 
(FPCore (J l K U)
  :name "Maksimov and Kolovsky, Equation (4)"
  :precision binary64
  (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))