Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.1% → 99.5%
Time: 12.8s
Alternatives: 17
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 17 alternatives:

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

Initial Program: 86.1% 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.5% accurate, 1.0× speedup?

\[\begin{array}{l} \\ 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (+ (* 2.0 (* J (log1p (expm1 (* l (cos (* K 0.5))))))) U))
double code(double J, double l, double K, double U) {
	return (2.0 * (J * log1p(expm1((l * cos((K * 0.5))))))) + U;
}
public static double code(double J, double l, double K, double U) {
	return (2.0 * (J * Math.log1p(Math.expm1((l * Math.cos((K * 0.5))))))) + U;
}
def code(J, l, K, U):
	return (2.0 * (J * math.log1p(math.expm1((l * math.cos((K * 0.5))))))) + U
function code(J, l, K, U)
	return Float64(Float64(2.0 * Float64(J * log1p(expm1(Float64(l * cos(Float64(K * 0.5))))))) + U)
end
code[J_, l_, K_, U_] := N[(N[(2.0 * N[(J * N[Log[1 + N[(Exp[N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\begin{array}{l}

\\
2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\right) + U
\end{array}
Derivation
  1. Initial program 82.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 l around 0 65.8%

    \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
  4. Step-by-step derivation
    1. log1p-expm1-u98.7%

      \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)}\right) + U \]
    2. *-commutative98.7%

      \[\leadsto 2 \cdot \left(J \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \color{blue}{\left(K \cdot 0.5\right)}\right)\right)\right) + U \]
  5. Applied egg-rr98.7%

    \[\leadsto 2 \cdot \left(J \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)}\right) + U \]
  6. Add Preprocessing

Alternative 2: 95.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -6.8 \cdot 10^{+84} \lor \neg \left(\ell \leq -0.0126 \lor \neg \left(\ell \leq 2\right) \land \ell \leq 9.8 \cdot 10^{+89}\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -6.8e+84)
         (not (or (<= l -0.0126) (and (not (<= l 2.0)) (<= l 9.8e+89)))))
   (+
    U
    (* J (* l (* (cos (* K 0.5)) (+ 2.0 (* 0.3333333333333333 (pow l 2.0)))))))
   (+ U (* J (- (exp l) (exp (- l)))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -6.8e+84) || !((l <= -0.0126) || (!(l <= 2.0) && (l <= 9.8e+89)))) {
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + (0.3333333333333333 * pow(l, 2.0))))));
	} else {
		tmp = U + (J * (exp(l) - exp(-l)));
	}
	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 <= (-6.8d+84)) .or. (.not. (l <= (-0.0126d0)) .or. (.not. (l <= 2.0d0)) .and. (l <= 9.8d+89))) then
        tmp = u + (j * (l * (cos((k * 0.5d0)) * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0))))))
    else
        tmp = u + (j * (exp(l) - exp(-l)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -6.8e+84) || !((l <= -0.0126) || (!(l <= 2.0) && (l <= 9.8e+89)))) {
		tmp = U + (J * (l * (Math.cos((K * 0.5)) * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0))))));
	} else {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -6.8e+84) or not ((l <= -0.0126) or (not (l <= 2.0) and (l <= 9.8e+89))):
		tmp = U + (J * (l * (math.cos((K * 0.5)) * (2.0 + (0.3333333333333333 * math.pow(l, 2.0))))))
	else:
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -6.8e+84) || !((l <= -0.0126) || (!(l <= 2.0) && (l <= 9.8e+89))))
		tmp = Float64(U + Float64(J * Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))))));
	else
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -6.8e+84) || ~(((l <= -0.0126) || (~((l <= 2.0)) && (l <= 9.8e+89)))))
		tmp = U + (J * (l * (cos((K * 0.5)) * (2.0 + (0.3333333333333333 * (l ^ 2.0))))));
	else
		tmp = U + (J * (exp(l) - exp(-l)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -6.8e+84], N[Not[Or[LessEqual[l, -0.0126], And[N[Not[LessEqual[l, 2.0]], $MachinePrecision], LessEqual[l, 9.8e+89]]]], $MachinePrecision]], N[(U + N[(J * N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -6.8 \cdot 10^{+84} \lor \neg \left(\ell \leq -0.0126 \lor \neg \left(\ell \leq 2\right) \land \ell \leq 9.8 \cdot 10^{+89}\right):\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\

\mathbf{else}:\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.7999999999999996e84 or -0.0126 < l < 2 or 9.79999999999999992e89 < l

    1. Initial program 79.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 l around 0 98.3%

      \[\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 J around 0 98.2%

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

    if -6.7999999999999996e84 < l < -0.0126 or 2 < l < 9.79999999999999992e89

    1. Initial program 99.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 K around 0 82.9%

      \[\leadsto \color{blue}{J \cdot \left(e^{\ell} - e^{-\ell}\right)} + U \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.8 \cdot 10^{+84} \lor \neg \left(\ell \leq -0.0126 \lor \neg \left(\ell \leq 2\right) \land \ell \leq 9.8 \cdot 10^{+89}\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 95.0% accurate, 1.3× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := 2 + 0.3333333333333333 \cdot {\ell}^{2}\\ t_1 := U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot t\_0\right)\right)\\ t_2 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{if}\;\ell \leq -6.8 \cdot 10^{+84}:\\ \;\;\;\;t\_1\\ \mathbf{elif}\;\ell \leq -0.05:\\ \;\;\;\;t\_2\\ \mathbf{elif}\;\ell \leq 2:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot t\_0\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq 8.5 \cdot 10^{+89}:\\ \;\;\;\;t\_2\\ \mathbf{else}:\\ \;\;\;\;t\_1\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))
        (t_1 (+ U (* J (* l (* (cos (* K 0.5)) t_0)))))
        (t_2 (+ U (* J (- (exp l) (exp (- l)))))))
   (if (<= l -6.8e+84)
     t_1
     (if (<= l -0.05)
       t_2
       (if (<= l 2.0)
         (+ U (* (* J (* l t_0)) (cos (/ K 2.0))))
         (if (<= l 8.5e+89) t_2 t_1))))))
double code(double J, double l, double K, double U) {
	double t_0 = 2.0 + (0.3333333333333333 * pow(l, 2.0));
	double t_1 = U + (J * (l * (cos((K * 0.5)) * t_0)));
	double t_2 = U + (J * (exp(l) - exp(-l)));
	double tmp;
	if (l <= -6.8e+84) {
		tmp = t_1;
	} else if (l <= -0.05) {
		tmp = t_2;
	} else if (l <= 2.0) {
		tmp = U + ((J * (l * t_0)) * cos((K / 2.0)));
	} else if (l <= 8.5e+89) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	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) :: t_2
    real(8) :: tmp
    t_0 = 2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0))
    t_1 = u + (j * (l * (cos((k * 0.5d0)) * t_0)))
    t_2 = u + (j * (exp(l) - exp(-l)))
    if (l <= (-6.8d+84)) then
        tmp = t_1
    else if (l <= (-0.05d0)) then
        tmp = t_2
    else if (l <= 2.0d0) then
        tmp = u + ((j * (l * t_0)) * cos((k / 2.0d0)))
    else if (l <= 8.5d+89) then
        tmp = t_2
    else
        tmp = t_1
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = 2.0 + (0.3333333333333333 * Math.pow(l, 2.0));
	double t_1 = U + (J * (l * (Math.cos((K * 0.5)) * t_0)));
	double t_2 = U + (J * (Math.exp(l) - Math.exp(-l)));
	double tmp;
	if (l <= -6.8e+84) {
		tmp = t_1;
	} else if (l <= -0.05) {
		tmp = t_2;
	} else if (l <= 2.0) {
		tmp = U + ((J * (l * t_0)) * Math.cos((K / 2.0)));
	} else if (l <= 8.5e+89) {
		tmp = t_2;
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = 2.0 + (0.3333333333333333 * math.pow(l, 2.0))
	t_1 = U + (J * (l * (math.cos((K * 0.5)) * t_0)))
	t_2 = U + (J * (math.exp(l) - math.exp(-l)))
	tmp = 0
	if l <= -6.8e+84:
		tmp = t_1
	elif l <= -0.05:
		tmp = t_2
	elif l <= 2.0:
		tmp = U + ((J * (l * t_0)) * math.cos((K / 2.0)))
	elif l <= 8.5e+89:
		tmp = t_2
	else:
		tmp = t_1
	return tmp
function code(J, l, K, U)
	t_0 = Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0)))
	t_1 = Float64(U + Float64(J * Float64(l * Float64(cos(Float64(K * 0.5)) * t_0))))
	t_2 = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))))
	tmp = 0.0
	if (l <= -6.8e+84)
		tmp = t_1;
	elseif (l <= -0.05)
		tmp = t_2;
	elseif (l <= 2.0)
		tmp = Float64(U + Float64(Float64(J * Float64(l * t_0)) * cos(Float64(K / 2.0))));
	elseif (l <= 8.5e+89)
		tmp = t_2;
	else
		tmp = t_1;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = 2.0 + (0.3333333333333333 * (l ^ 2.0));
	t_1 = U + (J * (l * (cos((K * 0.5)) * t_0)));
	t_2 = U + (J * (exp(l) - exp(-l)));
	tmp = 0.0;
	if (l <= -6.8e+84)
		tmp = t_1;
	elseif (l <= -0.05)
		tmp = t_2;
	elseif (l <= 2.0)
		tmp = U + ((J * (l * t_0)) * cos((K / 2.0)));
	elseif (l <= 8.5e+89)
		tmp = t_2;
	else
		tmp = t_1;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(J * N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6.8e+84], t$95$1, If[LessEqual[l, -0.05], t$95$2, If[LessEqual[l, 2.0], N[(U + N[(N[(J * N[(l * t$95$0), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 8.5e+89], t$95$2, t$95$1]]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := 2 + 0.3333333333333333 \cdot {\ell}^{2}\\
t_1 := U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot t\_0\right)\right)\\
t_2 := U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\
\mathbf{if}\;\ell \leq -6.8 \cdot 10^{+84}:\\
\;\;\;\;t\_1\\

\mathbf{elif}\;\ell \leq -0.05:\\
\;\;\;\;t\_2\\

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

\mathbf{elif}\;\ell \leq 8.5 \cdot 10^{+89}:\\
\;\;\;\;t\_2\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.7999999999999996e84 or 8.50000000000000045e89 < 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.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 J around 0 97.0%

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

    if -6.7999999999999996e84 < l < -0.050000000000000003 or 2 < l < 8.50000000000000045e89

    1. Initial program 99.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 K around 0 82.9%

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

    if -0.050000000000000003 < l < 2

    1. Initial program 63.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 l around 0 99.3%

      \[\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 3 regimes into one program.
  4. Final simplification95.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.8 \cdot 10^{+84}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \mathbf{elif}\;\ell \leq -0.05:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{elif}\;\ell \leq 2:\\ \;\;\;\;U + \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq 8.5 \cdot 10^{+89}:\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 76.6% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.997:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (cos (/ K 2.0)) 0.997)
   (+ U (* l (* J (* 2.0 (cos (* K 0.5))))))
   (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if (cos((K / 2.0)) <= 0.997) {
		tmp = U + (l * (J * (2.0 * cos((K * 0.5)))));
	} else {
		tmp = U + (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) :: tmp
    if (cos((k / 2.0d0)) <= 0.997d0) then
        tmp = u + (l * (j * (2.0d0 * cos((k * 0.5d0)))))
    else
        tmp = u + (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 tmp;
	if (Math.cos((K / 2.0)) <= 0.997) {
		tmp = U + (l * (J * (2.0 * Math.cos((K * 0.5)))));
	} else {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if math.cos((K / 2.0)) <= 0.997:
		tmp = U + (l * (J * (2.0 * math.cos((K * 0.5)))))
	else:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (cos(Float64(K / 2.0)) <= 0.997)
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 * cos(Float64(K * 0.5))))));
	else
		tmp = Float64(U + 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)
	tmp = 0.0;
	if (cos((K / 2.0)) <= 0.997)
		tmp = U + (l * (J * (2.0 * cos((K * 0.5)))));
	else
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision], 0.997], N[(U + N[(l * N[(J * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.997:\\
\;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K #s(literal 2 binary64))) < 0.996999999999999997

    1. Initial program 79.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 65.4%

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative65.4%

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

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

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

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

        \[\leadsto \ell \cdot \color{blue}{\left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2\right)} + U \]
      6. associate-*l*65.5%

        \[\leadsto \ell \cdot \color{blue}{\left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot 2\right)\right)} + U \]
      7. *-commutative65.5%

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

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

    if 0.996999999999999997 < (cos.f64 (/.f64 K #s(literal 2 binary64)))

    1. Initial program 85.2%

      \[\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 84.2%

      \[\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 84.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.997:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 87.1% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -0.0007 \lor \neg \left(\ell \leq 1.9 \cdot 10^{-6}\right):\\ \;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -0.0007) (not (<= l 1.9e-6)))
   (+ U (* J (- (exp l) (exp (- l)))))
   (+ U (* (cos (/ K 2.0)) (* l (* 2.0 J))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -0.0007) || !(l <= 1.9e-6)) {
		tmp = U + (J * (exp(l) - exp(-l)));
	} else {
		tmp = U + (cos((K / 2.0)) * (l * (2.0 * J)));
	}
	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 <= (-0.0007d0)) .or. (.not. (l <= 1.9d-6))) then
        tmp = u + (j * (exp(l) - exp(-l)))
    else
        tmp = u + (cos((k / 2.0d0)) * (l * (2.0d0 * j)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -0.0007) || !(l <= 1.9e-6)) {
		tmp = U + (J * (Math.exp(l) - Math.exp(-l)));
	} else {
		tmp = U + (Math.cos((K / 2.0)) * (l * (2.0 * J)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -0.0007) or not (l <= 1.9e-6):
		tmp = U + (J * (math.exp(l) - math.exp(-l)))
	else:
		tmp = U + (math.cos((K / 2.0)) * (l * (2.0 * J)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -0.0007) || !(l <= 1.9e-6))
		tmp = Float64(U + Float64(J * Float64(exp(l) - exp(Float64(-l)))));
	else
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(2.0 * J))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -0.0007) || ~((l <= 1.9e-6)))
		tmp = U + (J * (exp(l) - exp(-l)));
	else
		tmp = U + (cos((K / 2.0)) * (l * (2.0 * J)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -0.0007], N[Not[LessEqual[l, 1.9e-6]], $MachinePrecision]], N[(U + N[(J * N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(2.0 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -0.0007 \lor \neg \left(\ell \leq 1.9 \cdot 10^{-6}\right):\\
\;\;\;\;U + J \cdot \left(e^{\ell} - e^{-\ell}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -6.99999999999999993e-4 or 1.9e-6 < l

    1. Initial program 99.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 K around 0 72.5%

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

    if -6.99999999999999993e-4 < l < 1.9e-6

    1. Initial program 62.4%

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

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

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified99.7%

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

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

Alternative 6: 71.9% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -1.7 \cdot 10^{+70}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -1.1 \cdot 10^{+24}:\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \mathbf{elif}\;\ell \leq 1900000000:\\ \;\;\;\;\mathsf{fma}\left(J, 2 \cdot \ell, U\right)\\ \mathbf{elif}\;\ell \leq 8.4 \cdot 10^{+82}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (pow l 3.0) (* J 0.3333333333333333))))
   (if (<= l -1.7e+70)
     t_0
     (if (<= l -1.1e+24)
       (* U (- U -4.0))
       (if (<= l 1900000000.0)
         (fma J (* 2.0 l) U)
         (if (<= l 8.4e+82) (pow U -4.0) t_0))))))
double code(double J, double l, double K, double U) {
	double t_0 = pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -1.7e+70) {
		tmp = t_0;
	} else if (l <= -1.1e+24) {
		tmp = U * (U - -4.0);
	} else if (l <= 1900000000.0) {
		tmp = fma(J, (2.0 * l), U);
	} else if (l <= 8.4e+82) {
		tmp = pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
function code(J, l, K, U)
	t_0 = Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))
	tmp = 0.0
	if (l <= -1.7e+70)
		tmp = t_0;
	elseif (l <= -1.1e+24)
		tmp = Float64(U * Float64(U - -4.0));
	elseif (l <= 1900000000.0)
		tmp = fma(J, Float64(2.0 * l), U);
	elseif (l <= 8.4e+82)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -1.7e+70], t$95$0, If[LessEqual[l, -1.1e+24], N[(U * N[(U - -4.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1900000000.0], N[(J * N[(2.0 * l), $MachinePrecision] + U), $MachinePrecision], If[LessEqual[l, 8.4e+82], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\
\mathbf{if}\;\ell \leq -1.7 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -1.1 \cdot 10^{+24}:\\
\;\;\;\;U \cdot \left(U - -4\right)\\

\mathbf{elif}\;\ell \leq 1900000000:\\
\;\;\;\;\mathsf{fma}\left(J, 2 \cdot \ell, U\right)\\

\mathbf{elif}\;\ell \leq 8.4 \cdot 10^{+82}:\\
\;\;\;\;{U}^{-4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 4 regimes
  2. if l < -1.7e70 or 8.4000000000000001e82 < 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 94.2%

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

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    6. Step-by-step derivation
      1. *-commutative66.5%

        \[\leadsto \color{blue}{\left(J \cdot {\ell}^{3}\right) \cdot 0.3333333333333333} \]
      2. *-commutative66.5%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot J\right)} \cdot 0.3333333333333333 \]
      3. associate-*r*66.5%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)} \]
    7. Simplified66.5%

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

    if -1.7e70 < l < -1.10000000000000001e24

    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.0%

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

    if -1.10000000000000001e24 < l < 1.9e9

    1. Initial program 66.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 92.2%

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

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

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

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

        \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + U \]
      4. fma-define75.3%

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
      5. *-commutative75.3%

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

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

    if 1.9e9 < l < 8.4000000000000001e82

    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-rr44.6%

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

Alternative 7: 75.2% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{K}{2} \leq 5 \cdot 10^{-5}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot {\ell}^{2}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U \cdot \left(1 + 2 \cdot \frac{\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot \ell\right)}{U}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= (/ K 2.0) 5e-5)
   (+ U (* J (* l (+ 2.0 (* 0.3333333333333333 (pow l 2.0))))))
   (* U (+ 1.0 (* 2.0 (/ (* (cos (* K 0.5)) (* J l)) U))))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-5) {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * pow(l, 2.0)))));
	} else {
		tmp = U * (1.0 + (2.0 * ((cos((K * 0.5)) * (J * l)) / 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 ((k / 2.0d0) <= 5d-5) then
        tmp = u + (j * (l * (2.0d0 + (0.3333333333333333d0 * (l ** 2.0d0)))))
    else
        tmp = u * (1.0d0 + (2.0d0 * ((cos((k * 0.5d0)) * (j * l)) / u)))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((K / 2.0) <= 5e-5) {
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * Math.pow(l, 2.0)))));
	} else {
		tmp = U * (1.0 + (2.0 * ((Math.cos((K * 0.5)) * (J * l)) / U)));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (K / 2.0) <= 5e-5:
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * math.pow(l, 2.0)))))
	else:
		tmp = U * (1.0 + (2.0 * ((math.cos((K * 0.5)) * (J * l)) / U)))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (Float64(K / 2.0) <= 5e-5)
		tmp = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(0.3333333333333333 * (l ^ 2.0))))));
	else
		tmp = Float64(U * Float64(1.0 + Float64(2.0 * Float64(Float64(cos(Float64(K * 0.5)) * Float64(J * l)) / U))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((K / 2.0) <= 5e-5)
		tmp = U + (J * (l * (2.0 + (0.3333333333333333 * (l ^ 2.0)))));
	else
		tmp = U * (1.0 + (2.0 * ((cos((K * 0.5)) * (J * l)) / U)));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[N[(K / 2.0), $MachinePrecision], 5e-5], N[(U + N[(J * N[(l * N[(2.0 + N[(0.3333333333333333 * N[Power[l, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U * N[(1.0 + N[(2.0 * N[(N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * l), $MachinePrecision]), $MachinePrecision] / U), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 K #s(literal 2 binary64)) < 5.00000000000000024e-5

    1. Initial program 83.4%

      \[\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 84.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 72.0%

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

    if 5.00000000000000024e-5 < (/.f64 K #s(literal 2 binary64))

    1. Initial program 80.4%

      \[\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 64.2%

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

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

        \[\leadsto U \cdot \left(1 + 2 \cdot \frac{\color{blue}{\left(J \cdot \ell\right) \cdot \cos \left(0.5 \cdot K\right)}}{U}\right) \]
    6. Simplified65.9%

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

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

Alternative 8: 77.8% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -6 \cdot 10^{+94}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 1900000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+76}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (pow l 3.0) (* J 0.3333333333333333))))
   (if (<= l -6e+94)
     t_0
     (if (<= l 1900000000.0)
       (+ U (* (cos (/ K 2.0)) (* l (* 2.0 J))))
       (if (<= l 9.5e+76) (pow U -4.0) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -6e+94) {
		tmp = t_0;
	} else if (l <= 1900000000.0) {
		tmp = U + (cos((K / 2.0)) * (l * (2.0 * J)));
	} else if (l <= 9.5e+76) {
		tmp = pow(U, -4.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 = (l ** 3.0d0) * (j * 0.3333333333333333d0)
    if (l <= (-6d+94)) then
        tmp = t_0
    else if (l <= 1900000000.0d0) then
        tmp = u + (cos((k / 2.0d0)) * (l * (2.0d0 * j)))
    else if (l <= 9.5d+76) then
        tmp = u ** (-4.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 = Math.pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -6e+94) {
		tmp = t_0;
	} else if (l <= 1900000000.0) {
		tmp = U + (Math.cos((K / 2.0)) * (l * (2.0 * J)));
	} else if (l <= 9.5e+76) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.pow(l, 3.0) * (J * 0.3333333333333333)
	tmp = 0
	if l <= -6e+94:
		tmp = t_0
	elif l <= 1900000000.0:
		tmp = U + (math.cos((K / 2.0)) * (l * (2.0 * J)))
	elif l <= 9.5e+76:
		tmp = math.pow(U, -4.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))
	tmp = 0.0
	if (l <= -6e+94)
		tmp = t_0;
	elseif (l <= 1900000000.0)
		tmp = Float64(U + Float64(cos(Float64(K / 2.0)) * Float64(l * Float64(2.0 * J))));
	elseif (l <= 9.5e+76)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = (l ^ 3.0) * (J * 0.3333333333333333);
	tmp = 0.0;
	if (l <= -6e+94)
		tmp = t_0;
	elseif (l <= 1900000000.0)
		tmp = U + (cos((K / 2.0)) * (l * (2.0 * J)));
	elseif (l <= 9.5e+76)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6e+94], t$95$0, If[LessEqual[l, 1900000000.0], N[(U + N[(N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision] * N[(l * N[(2.0 * J), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 9.5e+76], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\
\mathbf{if}\;\ell \leq -6 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+76}:\\
\;\;\;\;{U}^{-4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.0000000000000001e94 or 9.5000000000000003e76 < 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 96.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 K around 0 68.6%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    6. Step-by-step derivation
      1. *-commutative68.5%

        \[\leadsto \color{blue}{\left(J \cdot {\ell}^{3}\right) \cdot 0.3333333333333333} \]
      2. *-commutative68.5%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot J\right)} \cdot 0.3333333333333333 \]
      3. associate-*r*68.5%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)} \]
    7. Simplified68.5%

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

    if -6.0000000000000001e94 < l < 1.9e9

    1. Initial program 70.1%

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

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

        \[\leadsto \color{blue}{\left(\left(2 \cdot J\right) \cdot \ell\right)} \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Simplified83.5%

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

    if 1.9e9 < l < 9.5000000000000003e76

    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-rr44.6%

      \[\leadsto \color{blue}{{U}^{-4}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+94}:\\ \;\;\;\;{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 1900000000:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(\ell \cdot \left(2 \cdot J\right)\right)\\ \mathbf{elif}\;\ell \leq 9.5 \cdot 10^{+76}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 77.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -6.6 \cdot 10^{+94}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 3900000000:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{+77}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (pow l 3.0) (* J 0.3333333333333333))))
   (if (<= l -6.6e+94)
     t_0
     (if (<= l 3900000000.0)
       (+ U (* l (* J (* 2.0 (cos (* K 0.5))))))
       (if (<= l 1.45e+77) (pow U -4.0) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -6.6e+94) {
		tmp = t_0;
	} else if (l <= 3900000000.0) {
		tmp = U + (l * (J * (2.0 * cos((K * 0.5)))));
	} else if (l <= 1.45e+77) {
		tmp = pow(U, -4.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 = (l ** 3.0d0) * (j * 0.3333333333333333d0)
    if (l <= (-6.6d+94)) then
        tmp = t_0
    else if (l <= 3900000000.0d0) then
        tmp = u + (l * (j * (2.0d0 * cos((k * 0.5d0)))))
    else if (l <= 1.45d+77) then
        tmp = u ** (-4.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 = Math.pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -6.6e+94) {
		tmp = t_0;
	} else if (l <= 3900000000.0) {
		tmp = U + (l * (J * (2.0 * Math.cos((K * 0.5)))));
	} else if (l <= 1.45e+77) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.pow(l, 3.0) * (J * 0.3333333333333333)
	tmp = 0
	if l <= -6.6e+94:
		tmp = t_0
	elif l <= 3900000000.0:
		tmp = U + (l * (J * (2.0 * math.cos((K * 0.5)))))
	elif l <= 1.45e+77:
		tmp = math.pow(U, -4.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))
	tmp = 0.0
	if (l <= -6.6e+94)
		tmp = t_0;
	elseif (l <= 3900000000.0)
		tmp = Float64(U + Float64(l * Float64(J * Float64(2.0 * cos(Float64(K * 0.5))))));
	elseif (l <= 1.45e+77)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = (l ^ 3.0) * (J * 0.3333333333333333);
	tmp = 0.0;
	if (l <= -6.6e+94)
		tmp = t_0;
	elseif (l <= 3900000000.0)
		tmp = U + (l * (J * (2.0 * cos((K * 0.5)))));
	elseif (l <= 1.45e+77)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6.6e+94], t$95$0, If[LessEqual[l, 3900000000.0], N[(U + N[(l * N[(J * N[(2.0 * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[l, 1.45e+77], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\
\mathbf{if}\;\ell \leq -6.6 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.45 \cdot 10^{+77}:\\
\;\;\;\;{U}^{-4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.6e94 or 1.4500000000000001e77 < 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 96.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 K around 0 68.6%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    6. Step-by-step derivation
      1. *-commutative68.5%

        \[\leadsto \color{blue}{\left(J \cdot {\ell}^{3}\right) \cdot 0.3333333333333333} \]
      2. *-commutative68.5%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot J\right)} \cdot 0.3333333333333333 \]
      3. associate-*r*68.5%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)} \]
    7. Simplified68.5%

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

    if -6.6e94 < l < 3.9e9

    1. Initial program 70.1%

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    4. Step-by-step derivation
      1. *-commutative83.4%

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

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

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

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

        \[\leadsto \ell \cdot \color{blue}{\left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2\right)} + U \]
      6. associate-*l*83.5%

        \[\leadsto \ell \cdot \color{blue}{\left(J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot 2\right)\right)} + U \]
      7. *-commutative83.5%

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

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

    if 3.9e9 < l < 1.4500000000000001e77

    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-rr44.6%

      \[\leadsto \color{blue}{{U}^{-4}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6.6 \cdot 10^{+94}:\\ \;\;\;\;{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 3900000000:\\ \;\;\;\;U + \ell \cdot \left(J \cdot \left(2 \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.45 \cdot 10^{+77}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 10: 77.9% accurate, 2.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{if}\;\ell \leq -6 \cdot 10^{+94}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq 1900000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+76}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* (pow l 3.0) (* J 0.3333333333333333))))
   (if (<= l -6e+94)
     t_0
     (if (<= l 1900000000.0)
       (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
       (if (<= l 1.25e+76) (pow U -4.0) t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -6e+94) {
		tmp = t_0;
	} else if (l <= 1900000000.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} else if (l <= 1.25e+76) {
		tmp = pow(U, -4.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 = (l ** 3.0d0) * (j * 0.3333333333333333d0)
    if (l <= (-6d+94)) then
        tmp = t_0
    else if (l <= 1900000000.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    else if (l <= 1.25d+76) then
        tmp = u ** (-4.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 = Math.pow(l, 3.0) * (J * 0.3333333333333333);
	double tmp;
	if (l <= -6e+94) {
		tmp = t_0;
	} else if (l <= 1900000000.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else if (l <= 1.25e+76) {
		tmp = Math.pow(U, -4.0);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.pow(l, 3.0) * (J * 0.3333333333333333)
	tmp = 0
	if l <= -6e+94:
		tmp = t_0
	elif l <= 1900000000.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	elif l <= 1.25e+76:
		tmp = math.pow(U, -4.0)
	else:
		tmp = t_0
	return tmp
function code(J, l, K, U)
	t_0 = Float64((l ^ 3.0) * Float64(J * 0.3333333333333333))
	tmp = 0.0
	if (l <= -6e+94)
		tmp = t_0;
	elseif (l <= 1900000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	elseif (l <= 1.25e+76)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = (l ^ 3.0) * (J * 0.3333333333333333);
	tmp = 0.0;
	if (l <= -6e+94)
		tmp = t_0;
	elseif (l <= 1900000000.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	elseif (l <= 1.25e+76)
		tmp = U ^ -4.0;
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(N[Power[l, 3.0], $MachinePrecision] * N[(J * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -6e+94], t$95$0, If[LessEqual[l, 1900000000.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.25e+76], N[Power[U, -4.0], $MachinePrecision], t$95$0]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\
\mathbf{if}\;\ell \leq -6 \cdot 10^{+94}:\\
\;\;\;\;t\_0\\

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

\mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+76}:\\
\;\;\;\;{U}^{-4}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -6.0000000000000001e94 or 1.24999999999999998e76 < 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 96.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 K around 0 68.6%

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

      \[\leadsto \color{blue}{0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)} \]
    6. Step-by-step derivation
      1. *-commutative68.5%

        \[\leadsto \color{blue}{\left(J \cdot {\ell}^{3}\right) \cdot 0.3333333333333333} \]
      2. *-commutative68.5%

        \[\leadsto \color{blue}{\left({\ell}^{3} \cdot J\right)} \cdot 0.3333333333333333 \]
      3. associate-*r*68.5%

        \[\leadsto \color{blue}{{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)} \]
    7. Simplified68.5%

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

    if -6.0000000000000001e94 < l < 1.9e9

    1. Initial program 70.1%

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

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

    if 1.9e9 < l < 1.24999999999999998e76

    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-rr44.6%

      \[\leadsto \color{blue}{{U}^{-4}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification75.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -6 \cdot 10^{+94}:\\ \;\;\;\;{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \mathbf{elif}\;\ell \leq 1900000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 1.25 \cdot 10^{+76}:\\ \;\;\;\;{U}^{-4}\\ \mathbf{else}:\\ \;\;\;\;{\ell}^{3} \cdot \left(J \cdot 0.3333333333333333\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 11: 54.8% accurate, 3.0× speedup?

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

\\
\mathsf{fma}\left(J, 2 \cdot \ell, U\right)
\end{array}
Derivation
  1. Initial program 82.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 l around 0 65.8%

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

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

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

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

      \[\leadsto \color{blue}{J \cdot \left(\ell \cdot 2\right)} + U \]
    4. fma-define53.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \ell \cdot 2, U\right)} \]
    5. *-commutative53.0%

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

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

Alternative 12: 42.6% accurate, 15.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -3.9 \cdot 10^{+151}:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq -7.8 \cdot 10^{+23} \lor \neg \left(\ell \leq 1.95\right):\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (<= l -3.9e+151)
   (- -4.0 (* U U))
   (if (or (<= l -7.8e+23) (not (<= l 1.95))) (* U (- U -4.0)) U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= -3.9e+151) {
		tmp = -4.0 - (U * U);
	} else if ((l <= -7.8e+23) || !(l <= 1.95)) {
		tmp = U * (U - -4.0);
	} 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 <= (-3.9d+151)) then
        tmp = (-4.0d0) - (u * u)
    else if ((l <= (-7.8d+23)) .or. (.not. (l <= 1.95d0))) then
        tmp = u * (u - (-4.0d0))
    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 <= -3.9e+151) {
		tmp = -4.0 - (U * U);
	} else if ((l <= -7.8e+23) || !(l <= 1.95)) {
		tmp = U * (U - -4.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= -3.9e+151:
		tmp = -4.0 - (U * U)
	elif (l <= -7.8e+23) or not (l <= 1.95):
		tmp = U * (U - -4.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= -3.9e+151)
		tmp = Float64(-4.0 - Float64(U * U));
	elseif ((l <= -7.8e+23) || !(l <= 1.95))
		tmp = Float64(U * Float64(U - -4.0));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= -3.9e+151)
		tmp = -4.0 - (U * U);
	elseif ((l <= -7.8e+23) || ~((l <= 1.95)))
		tmp = U * (U - -4.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, -3.9e+151], N[(-4.0 - N[(U * U), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, -7.8e+23], N[Not[LessEqual[l, 1.95]], $MachinePrecision]], N[(U * N[(U - -4.0), $MachinePrecision]), $MachinePrecision], U]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -3.9 \cdot 10^{+151}:\\
\;\;\;\;-4 - U \cdot U\\

\mathbf{elif}\;\ell \leq -7.8 \cdot 10^{+23} \lor \neg \left(\ell \leq 1.95\right):\\
\;\;\;\;U \cdot \left(U - -4\right)\\

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


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

    1. Initial program 100.0%

      \[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    2. Step-by-step derivation
      1. associate-*l*100.0%

        \[\leadsto \color{blue}{J \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right)\right)} + U \]
      2. fma-define100.0%

        \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    3. Simplified100.0%

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Add Preprocessing
    5. Applied egg-rr22.4%

      \[\leadsto \color{blue}{-4 + \left(-U\right) \cdot U} \]
    6. Step-by-step derivation
      1. cancel-sign-sub-inv22.4%

        \[\leadsto \color{blue}{-4 - U \cdot U} \]
    7. Simplified22.4%

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

    if -3.89999999999999976e151 < l < -7.8000000000000001e23 or 1.94999999999999996 < 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-rr22.2%

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

    if -7.8000000000000001e23 < l < 1.94999999999999996

    1. Initial program 65.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 57.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -3.9 \cdot 10^{+151}:\\ \;\;\;\;-4 - U \cdot U\\ \mathbf{elif}\;\ell \leq -7.8 \cdot 10^{+23} \lor \neg \left(\ell \leq 1.95\right):\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
  5. Add Preprocessing

Alternative 13: 42.6% accurate, 20.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -1.85 \cdot 10^{+24} \lor \neg \left(\ell \leq 1.95\right):\\ \;\;\;\;U \cdot \left(U - -4\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -1.85e+24) (not (<= l 1.95))) (* U (- U -4.0)) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -1.85e+24) || !(l <= 1.95)) {
		tmp = U * (U - -4.0);
	} 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.85d+24)) .or. (.not. (l <= 1.95d0))) then
        tmp = u * (u - (-4.0d0))
    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.85e+24) || !(l <= 1.95)) {
		tmp = U * (U - -4.0);
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -1.85e+24) or not (l <= 1.95):
		tmp = U * (U - -4.0)
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -1.85e+24) || !(l <= 1.95))
		tmp = Float64(U * Float64(U - -4.0));
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -1.85e+24) || ~((l <= 1.95)))
		tmp = U * (U - -4.0);
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -1.85e+24], N[Not[LessEqual[l, 1.95]], $MachinePrecision]], N[(U * N[(U - -4.0), $MachinePrecision]), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -1.85 \cdot 10^{+24} \lor \neg \left(\ell \leq 1.95\right):\\
\;\;\;\;U \cdot \left(U - -4\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -1.85e24 or 1.94999999999999996 < 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-rr19.1%

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

    if -1.85e24 < l < 1.94999999999999996

    1. Initial program 65.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 57.7%

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

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

Alternative 14: 42.3% accurate, 23.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -9.1 \cdot 10^{-7} \lor \neg \left(\ell \leq 1.95\right):\\ \;\;\;\;U \cdot U\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -9.1e-7) (not (<= l 1.95))) (* U U) U))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -9.1e-7) || !(l <= 1.95)) {
		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 <= (-9.1d-7)) .or. (.not. (l <= 1.95d0))) 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 <= -9.1e-7) || !(l <= 1.95)) {
		tmp = U * U;
	} else {
		tmp = U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -9.1e-7) or not (l <= 1.95):
		tmp = U * U
	else:
		tmp = U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -9.1e-7) || !(l <= 1.95))
		tmp = Float64(U * U);
	else
		tmp = U;
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -9.1e-7) || ~((l <= 1.95)))
		tmp = U * U;
	else
		tmp = U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -9.1e-7], N[Not[LessEqual[l, 1.95]], $MachinePrecision]], N[(U * U), $MachinePrecision], U]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -9.1 \cdot 10^{-7} \lor \neg \left(\ell \leq 1.95\right):\\
\;\;\;\;U \cdot U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -9.0999999999999997e-7 or 1.94999999999999996 < l

    1. Initial program 99.8%

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

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

    if -9.0999999999999997e-7 < l < 1.94999999999999996

    1. Initial program 63.1%

      \[\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 61.0%

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

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

Alternative 15: 54.8% accurate, 44.6× speedup?

\[\begin{array}{l} \\ U + J \cdot \left(2 \cdot \ell\right) \end{array} \]
(FPCore (J l K U) :precision binary64 (+ U (* J (* 2.0 l))))
double code(double J, double l, double K, double U) {
	return U + (J * (2.0 * l));
}
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 + (j * (2.0d0 * l))
end function
public static double code(double J, double l, double K, double U) {
	return U + (J * (2.0 * l));
}
def code(J, l, K, U):
	return U + (J * (2.0 * l))
function code(J, l, K, U)
	return Float64(U + Float64(J * Float64(2.0 * l)))
end
function tmp = code(J, l, K, U)
	tmp = U + (J * (2.0 * l));
end
code[J_, l_, K_, U_] := N[(U + N[(J * N[(2.0 * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
U + J \cdot \left(2 \cdot \ell\right)
\end{array}
Derivation
  1. Initial program 82.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 l around 0 65.8%

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

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

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

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

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

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

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

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

Alternative 16: 37.2% 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 82.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 J around 0 29.6%

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

Alternative 17: 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 82.7%

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

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

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

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

Reproduce

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