Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.1% → 99.6%
Time: 8.6s
Alternatives: 14
Speedup: 2.7×

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 14 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.6% accurate, 0.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -0.5 or 2e-16 < (-.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 -0.5 < (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < 2e-16

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(J \cdot 2\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 -0.5 \lor \neg \left(e^{\ell} - e^{-\ell} \leq 2 \cdot 10^{-16}\right):\\ \;\;\;\;\left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) \cdot \cos \left(\frac{K}{2}\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\right)\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 93.5% accurate, 0.7× speedup?

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

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

\mathbf{else}:\\
\;\;\;\;U + t\_0 \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\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

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

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

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

    1. Initial program 85.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 95.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. Step-by-step derivation
      1. unpow295.3%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr95.3%

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

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

Alternative 3: 76.5% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 88.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 51.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. *-commutative51.5%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(-0.25 \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right) + 2 \cdot \left(J \cdot \ell\right)\right)} + U \]
    10. Step-by-step derivation
      1. +-commutative50.8%

        \[\leadsto \color{blue}{\left(2 \cdot \left(J \cdot \ell\right) + -0.25 \cdot \left(J \cdot \left({K}^{2} \cdot \ell\right)\right)\right)} + U \]
      2. *-commutative50.8%

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

        \[\leadsto \left(2 \cdot \left(J \cdot \ell\right) + -0.25 \cdot \color{blue}{\left(\left(J \cdot \ell\right) \cdot {K}^{2}\right)}\right) + U \]
      4. associate-*l*49.1%

        \[\leadsto \left(2 \cdot \left(J \cdot \ell\right) + \color{blue}{\left(-0.25 \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}}\right) + U \]
      5. *-commutative49.1%

        \[\leadsto \left(\color{blue}{\left(J \cdot \ell\right) \cdot 2} + \left(-0.25 \cdot \left(J \cdot \ell\right)\right) \cdot {K}^{2}\right) + U \]
      6. *-commutative49.1%

        \[\leadsto \left(\left(J \cdot \ell\right) \cdot 2 + \color{blue}{\left(\left(J \cdot \ell\right) \cdot -0.25\right)} \cdot {K}^{2}\right) + U \]
      7. associate-*l*49.1%

        \[\leadsto \left(\left(J \cdot \ell\right) \cdot 2 + \color{blue}{\left(J \cdot \ell\right) \cdot \left(-0.25 \cdot {K}^{2}\right)}\right) + U \]
      8. distribute-lft-out57.8%

        \[\leadsto \color{blue}{\left(J \cdot \ell\right) \cdot \left(2 + -0.25 \cdot {K}^{2}\right)} + U \]
      9. *-commutative57.8%

        \[\leadsto \color{blue}{\left(\ell \cdot J\right)} \cdot \left(2 + -0.25 \cdot {K}^{2}\right) + U \]
    11. Simplified57.8%

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

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

    1. Initial program 89.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 89.6%

      \[\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. Step-by-step derivation
      1. unpow289.6%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr89.6%

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

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

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

Alternative 4: 91.1% accurate, 1.4× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.75 \cdot 10^{+81} \lor \neg \left(\ell \leq -0.0265\right):\\
\;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.7500000000000002e81 or -0.0264999999999999993 < l

    1. Initial program 88.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 95.5%

      \[\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. Step-by-step derivation
      1. unpow295.5%

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

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

    if -2.7500000000000002e81 < l < -0.0264999999999999993

    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 68.1%

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

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

Alternative 5: 79.6% accurate, 1.4× speedup?

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

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

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


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

    1. Initial program 88.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 51.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. *-commutative51.5%

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

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

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

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

    1. Initial program 89.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 89.6%

      \[\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. Step-by-step derivation
      1. unpow289.6%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr89.6%

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

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

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

Alternative 6: 78.8% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\ \mathbf{if}\;\ell \leq -2.35 \cdot 10^{+89}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -940:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 240000000:\\ \;\;\;\;U + \ell \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \left(J \cdot 2\right)\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 (* l l))))))))
   (if (<= l -2.35e+89)
     t_0
     (if (<= l -940.0)
       (pow U -3.0)
       (if (<= l 240000000.0)
         (+ U (* l (* (cos (* K 0.5)) (* J 2.0))))
         t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
	double tmp;
	if (l <= -2.35e+89) {
		tmp = t_0;
	} else if (l <= -940.0) {
		tmp = pow(U, -3.0);
	} else if (l <= 240000000.0) {
		tmp = U + (l * (cos((K * 0.5)) * (J * 2.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 * l)))))
    if (l <= (-2.35d+89)) then
        tmp = t_0
    else if (l <= (-940.0d0)) then
        tmp = u ** (-3.0d0)
    else if (l <= 240000000.0d0) then
        tmp = u + (l * (cos((k * 0.5d0)) * (j * 2.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 * (l * l)))));
	double tmp;
	if (l <= -2.35e+89) {
		tmp = t_0;
	} else if (l <= -940.0) {
		tmp = Math.pow(U, -3.0);
	} else if (l <= 240000000.0) {
		tmp = U + (l * (Math.cos((K * 0.5)) * (J * 2.0)));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))
	tmp = 0
	if l <= -2.35e+89:
		tmp = t_0
	elif l <= -940.0:
		tmp = math.pow(U, -3.0)
	elif l <= 240000000.0:
		tmp = U + (l * (math.cos((K * 0.5)) * (J * 2.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 * Float64(l * l))))))
	tmp = 0.0
	if (l <= -2.35e+89)
		tmp = t_0;
	elseif (l <= -940.0)
		tmp = U ^ -3.0;
	elseif (l <= 240000000.0)
		tmp = Float64(U + Float64(l * Float64(cos(Float64(K * 0.5)) * Float64(J * 2.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 * l)))));
	tmp = 0.0;
	if (l <= -2.35e+89)
		tmp = t_0;
	elseif (l <= -940.0)
		tmp = U ^ -3.0;
	elseif (l <= 240000000.0)
		tmp = U + (l * (cos((K * 0.5)) * (J * 2.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[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.35e+89], t$95$0, If[LessEqual[l, -940.0], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 240000000.0], N[(U + N[(l * N[(N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision] * N[(J * 2.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 \left(\ell \cdot \ell\right)\right)\right)\\
\mathbf{if}\;\ell \leq -2.35 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -940:\\
\;\;\;\;{U}^{-3}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.35000000000000011e89 or 2.4e8 < 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 90.1%

      \[\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. Step-by-step derivation
      1. unpow290.1%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr90.1%

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

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

    if -2.35000000000000011e89 < l < -940

    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-rr35.8%

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

    if -940 < l < 2.4e8

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

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

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

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

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

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

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

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

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

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

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

Alternative 7: 78.8% accurate, 2.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\\ \mathbf{if}\;\ell \leq -3.1 \cdot 10^{+89}:\\ \;\;\;\;t\_0\\ \mathbf{elif}\;\ell \leq -1200:\\ \;\;\;\;{U}^{-3}\\ \mathbf{elif}\;\ell \leq 950000000:\\ \;\;\;\;U + 2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\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 (* l l))))))))
   (if (<= l -3.1e+89)
     t_0
     (if (<= l -1200.0)
       (pow U -3.0)
       (if (<= l 950000000.0)
         (+ U (* 2.0 (* J (* l (cos (* K 0.5))))))
         t_0)))))
double code(double J, double l, double K, double U) {
	double t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))));
	double tmp;
	if (l <= -3.1e+89) {
		tmp = t_0;
	} else if (l <= -1200.0) {
		tmp = pow(U, -3.0);
	} else if (l <= 950000000.0) {
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	} 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 * l)))))
    if (l <= (-3.1d+89)) then
        tmp = t_0
    else if (l <= (-1200.0d0)) then
        tmp = u ** (-3.0d0)
    else if (l <= 950000000.0d0) then
        tmp = u + (2.0d0 * (j * (l * cos((k * 0.5d0)))))
    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 * (l * l)))));
	double tmp;
	if (l <= -3.1e+89) {
		tmp = t_0;
	} else if (l <= -1200.0) {
		tmp = Math.pow(U, -3.0);
	} else if (l <= 950000000.0) {
		tmp = U + (2.0 * (J * (l * Math.cos((K * 0.5)))));
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + (J * (l * (2.0 + (0.3333333333333333 * (l * l)))))
	tmp = 0
	if l <= -3.1e+89:
		tmp = t_0
	elif l <= -1200.0:
		tmp = math.pow(U, -3.0)
	elif l <= 950000000.0:
		tmp = U + (2.0 * (J * (l * math.cos((K * 0.5)))))
	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 * Float64(l * l))))))
	tmp = 0.0
	if (l <= -3.1e+89)
		tmp = t_0;
	elseif (l <= -1200.0)
		tmp = U ^ -3.0;
	elseif (l <= 950000000.0)
		tmp = Float64(U + Float64(2.0 * Float64(J * Float64(l * cos(Float64(K * 0.5))))));
	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 * l)))));
	tmp = 0.0;
	if (l <= -3.1e+89)
		tmp = t_0;
	elseif (l <= -1200.0)
		tmp = U ^ -3.0;
	elseif (l <= 950000000.0)
		tmp = U + (2.0 * (J * (l * cos((K * 0.5)))));
	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[(l * l), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -3.1e+89], t$95$0, If[LessEqual[l, -1200.0], N[Power[U, -3.0], $MachinePrecision], If[LessEqual[l, 950000000.0], N[(U + N[(2.0 * N[(J * N[(l * N[Cos[N[(K * 0.5), $MachinePrecision]], $MachinePrecision]), $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 \left(\ell \cdot \ell\right)\right)\right)\\
\mathbf{if}\;\ell \leq -3.1 \cdot 10^{+89}:\\
\;\;\;\;t\_0\\

\mathbf{elif}\;\ell \leq -1200:\\
\;\;\;\;{U}^{-3}\\

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -3.1e89 or 9.5e8 < 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 90.1%

      \[\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. Step-by-step derivation
      1. unpow290.1%

        \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \color{blue}{\left(\ell \cdot \ell\right)}\right)\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    5. Applied egg-rr90.1%

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

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

    if -3.1e89 < l < -1200

    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-rr35.8%

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

    if -1200 < l < 9.5e8

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

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

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

Alternative 8: 87.9% accurate, 2.7× speedup?

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

\\
U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right)
\end{array}
Derivation
  1. Initial program 89.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 88.5%

    \[\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. Step-by-step derivation
    1. unpow288.5%

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

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

    \[\leadsto U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \]
  7. Add Preprocessing

Alternative 9: 41.9% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -8.4999999999999998e79 or 850 < 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-rr16.7%

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

    if -8.4999999999999998e79 < l < 850

    1. Initial program 82.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 J around 0 68.2%

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

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

Alternative 10: 72.6% accurate, 24.0× speedup?

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

\\
U + J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)
\end{array}
Derivation
  1. Initial program 89.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 88.5%

    \[\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. Step-by-step derivation
    1. unpow288.5%

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

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

    \[\leadsto \left(J \cdot \left(\ell \cdot \left(2 + 0.3333333333333333 \cdot \left(\ell \cdot \ell\right)\right)\right)\right) \cdot \color{blue}{1} + U \]
  7. Final simplification73.3%

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

Alternative 11: 54.8% accurate, 44.6× speedup?

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

\\
U + 2 \cdot \left(\ell \cdot J\right)
\end{array}
Derivation
  1. Initial program 89.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 64.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. *-commutative64.7%

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

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

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

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

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

Alternative 12: 36.7% 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 89.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 J around 0 42.4%

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

Alternative 13: 2.8% accurate, 312.0× speedup?

\[\begin{array}{l} \\ 16 \end{array} \]
(FPCore (J l K U) :precision binary64 16.0)
double code(double J, double l, double K, double U) {
	return 16.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 = 16.0d0
end function
public static double code(double J, double l, double K, double U) {
	return 16.0;
}
def code(J, l, K, U):
	return 16.0
function code(J, l, K, U)
	return 16.0
end
function tmp = code(J, l, K, U)
	tmp = 16.0;
end
code[J_, l_, K_, U_] := 16.0
\begin{array}{l}

\\
16
\end{array}
Derivation
  1. Initial program 89.2%

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

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

      \[\leadsto \color{blue}{-4 \cdot -4 + U} \]
    2. +-commutative28.6%

      \[\leadsto \color{blue}{U + -4 \cdot -4} \]
    3. metadata-eval28.6%

      \[\leadsto U + \color{blue}{16} \]
  5. Simplified28.6%

    \[\leadsto \color{blue}{U + 16} \]
  6. Taylor expanded in U around 0 2.8%

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

Alternative 14: 2.7% accurate, 312.0× speedup?

\[\begin{array}{l} \\ -4 \end{array} \]
(FPCore (J l K U) :precision binary64 -4.0)
double code(double J, double l, double K, double U) {
	return -4.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 = -4.0d0
end function
public static double code(double J, double l, double K, double U) {
	return -4.0;
}
def code(J, l, K, U):
	return -4.0
function code(J, l, K, U)
	return -4.0
end
function tmp = code(J, l, K, U)
	tmp = -4.0;
end
code[J_, l_, K_, U_] := -4.0
\begin{array}{l}

\\
-4
\end{array}
Derivation
  1. Initial program 89.2%

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

    \[\leadsto \color{blue}{-4 - U} \]
  4. Taylor expanded in U around 0 2.6%

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

Reproduce

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