Maksimov and Kolovsky, Equation (4)

Percentage Accurate: 86.6% → 99.8%
Time: 11.8s
Alternatives: 14
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 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.6% 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.8% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{-7}\right):\\ \;\;\;\;J \cdot \left(t_0 \cdot \cos \left(0.5 \cdot K\right)\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (- (exp l) (exp (- l)))))
   (if (or (<= t_0 (- INFINITY)) (not (<= t_0 5e-7)))
     (+ (* J (* t_0 (cos (* 0.5 K)))) U)
     (+
      U
      (*
       (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))
       (cos (/ K 2.0)))))))
double code(double J, double l, double K, double U) {
	double t_0 = exp(l) - exp(-l);
	double tmp;
	if ((t_0 <= -((double) INFINITY)) || !(t_0 <= 5e-7)) {
		tmp = (J * (t_0 * cos((0.5 * K)))) + U;
	} else {
		tmp = U + ((J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) * cos((K / 2.0)));
	}
	return tmp;
}
public static double code(double J, double l, double K, double U) {
	double t_0 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if ((t_0 <= -Double.POSITIVE_INFINITY) || !(t_0 <= 5e-7)) {
		tmp = (J * (t_0 * Math.cos((0.5 * K)))) + U;
	} else {
		tmp = U + ((J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))) * Math.cos((K / 2.0)));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = math.exp(l) - math.exp(-l)
	tmp = 0
	if (t_0 <= -math.inf) or not (t_0 <= 5e-7):
		tmp = (J * (t_0 * math.cos((0.5 * K)))) + U
	else:
		tmp = U + ((J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) * math.cos((K / 2.0)))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if ((t_0 <= Float64(-Inf)) || !(t_0 <= 5e-7))
		tmp = Float64(Float64(J * Float64(t_0 * cos(Float64(0.5 * K)))) + U);
	else
		tmp = Float64(U + Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) * cos(Float64(K / 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 <= -Inf) || ~((t_0 <= 5e-7)))
		tmp = (J * (t_0 * cos((0.5 * K)))) + U;
	else
		tmp = U + ((J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))) * cos((K / 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, (-Infinity)], N[Not[LessEqual[t$95$0, 5e-7]], $MachinePrecision]], N[(N[(J * N[(t$95$0 * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision], N[(U + N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{-7}\right):\\
\;\;\;\;J \cdot \left(t_0 \cdot \cos \left(0.5 \cdot K\right)\right) + U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 4.99999999999999977e-7 < (-.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. Taylor expanded in J around 0 100.0%

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

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

    1. Initial program 73.9%

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

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

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

Alternative 2: 87.4% accurate, 0.5× speedup?

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

\\
\begin{array}{l}
t_0 := e^{\ell} - e^{-\ell}\\
\mathbf{if}\;t_0 \leq -\infty \lor \neg \left(t_0 \leq 5 \cdot 10^{-7}\right):\\
\;\;\;\;U + t_0 \cdot J\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 4.99999999999999977e-7 < (-.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. Taylor expanded in K around 0 72.1%

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

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

    1. Initial program 73.9%

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. 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-*l*99.9%

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

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

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

Alternative 3: 94.4% accurate, 1.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := U + \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+76}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -350:\\ \;\;\;\;U + t_1 \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 0.21 \lor \neg \left(\ell \leq 4.5 \cdot 10^{+68}\right):\\ \;\;\;\;t_0\\ \mathbf{else}:\\ \;\;\;\;U + t_1 \cdot J\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0
         (+
          U
          (*
           (* J (+ (* 0.3333333333333333 (pow l 3.0)) (* l 2.0)))
           (cos (/ K 2.0)))))
        (t_1 (- (exp l) (exp (- l)))))
   (if (<= l -4.5e+76)
     t_0
     (if (<= l -350.0)
       (+ U (* t_1 (+ J (* J (* K (* K -0.125))))))
       (if (or (<= l 0.21) (not (<= l 4.5e+68))) t_0 (+ U (* t_1 J)))))))
double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * ((0.3333333333333333 * pow(l, 3.0)) + (l * 2.0))) * cos((K / 2.0)));
	double t_1 = exp(l) - exp(-l);
	double tmp;
	if (l <= -4.5e+76) {
		tmp = t_0;
	} else if (l <= -350.0) {
		tmp = U + (t_1 * (J + (J * (K * (K * -0.125)))));
	} else if ((l <= 0.21) || !(l <= 4.5e+68)) {
		tmp = t_0;
	} else {
		tmp = U + (t_1 * 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) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = u + ((j * ((0.3333333333333333d0 * (l ** 3.0d0)) + (l * 2.0d0))) * cos((k / 2.0d0)))
    t_1 = exp(l) - exp(-l)
    if (l <= (-4.5d+76)) then
        tmp = t_0
    else if (l <= (-350.0d0)) then
        tmp = u + (t_1 * (j + (j * (k * (k * (-0.125d0))))))
    else if ((l <= 0.21d0) .or. (.not. (l <= 4.5d+68))) then
        tmp = t_0
    else
        tmp = u + (t_1 * j)
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = U + ((J * ((0.3333333333333333 * Math.pow(l, 3.0)) + (l * 2.0))) * Math.cos((K / 2.0)));
	double t_1 = Math.exp(l) - Math.exp(-l);
	double tmp;
	if (l <= -4.5e+76) {
		tmp = t_0;
	} else if (l <= -350.0) {
		tmp = U + (t_1 * (J + (J * (K * (K * -0.125)))));
	} else if ((l <= 0.21) || !(l <= 4.5e+68)) {
		tmp = t_0;
	} else {
		tmp = U + (t_1 * J);
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = U + ((J * ((0.3333333333333333 * math.pow(l, 3.0)) + (l * 2.0))) * math.cos((K / 2.0)))
	t_1 = math.exp(l) - math.exp(-l)
	tmp = 0
	if l <= -4.5e+76:
		tmp = t_0
	elif l <= -350.0:
		tmp = U + (t_1 * (J + (J * (K * (K * -0.125)))))
	elif (l <= 0.21) or not (l <= 4.5e+68):
		tmp = t_0
	else:
		tmp = U + (t_1 * J)
	return tmp
function code(J, l, K, U)
	t_0 = Float64(U + Float64(Float64(J * Float64(Float64(0.3333333333333333 * (l ^ 3.0)) + Float64(l * 2.0))) * cos(Float64(K / 2.0))))
	t_1 = Float64(exp(l) - exp(Float64(-l)))
	tmp = 0.0
	if (l <= -4.5e+76)
		tmp = t_0;
	elseif (l <= -350.0)
		tmp = Float64(U + Float64(t_1 * Float64(J + Float64(J * Float64(K * Float64(K * -0.125))))));
	elseif ((l <= 0.21) || !(l <= 4.5e+68))
		tmp = t_0;
	else
		tmp = Float64(U + Float64(t_1 * J));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = U + ((J * ((0.3333333333333333 * (l ^ 3.0)) + (l * 2.0))) * cos((K / 2.0)));
	t_1 = exp(l) - exp(-l);
	tmp = 0.0;
	if (l <= -4.5e+76)
		tmp = t_0;
	elseif (l <= -350.0)
		tmp = U + (t_1 * (J + (J * (K * (K * -0.125)))));
	elseif ((l <= 0.21) || ~((l <= 4.5e+68)))
		tmp = t_0;
	else
		tmp = U + (t_1 * J);
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(U + N[(N[(J * N[(N[(0.3333333333333333 * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision] + N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Cos[N[(K / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Exp[l], $MachinePrecision] - N[Exp[(-l)], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -4.5e+76], t$95$0, If[LessEqual[l, -350.0], N[(U + N[(t$95$1 * N[(J + N[(J * N[(K * N[(K * -0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 0.21], N[Not[LessEqual[l, 4.5e+68]], $MachinePrecision]], t$95$0, N[(U + N[(t$95$1 * J), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

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

\mathbf{elif}\;\ell \leq -350:\\
\;\;\;\;U + t_1 \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\

\mathbf{elif}\;\ell \leq 0.21 \lor \neg \left(\ell \leq 4.5 \cdot 10^{+68}\right):\\
\;\;\;\;t_0\\

\mathbf{else}:\\
\;\;\;\;U + t_1 \cdot J\\


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -4.4999999999999997e76 or -350 < l < 0.209999999999999992 or 4.5000000000000003e68 < l

    1. Initial program 84.5%

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

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

    if -4.4999999999999997e76 < l < -350

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\left(-0.125 \cdot \left(J \cdot \left({K}^{2} \cdot \left(e^{\ell} - e^{-\ell}\right)\right)\right) + J \cdot \left(e^{\ell} - e^{-\ell}\right)\right)} + U \]
    3. Step-by-step derivation
      1. +-commutative0.0%

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

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

        \[\leadsto \left(J \cdot \left(e^{\ell} - e^{-\ell}\right) + \color{blue}{\left(-0.125 \cdot \left(J \cdot {K}^{2}\right)\right) \cdot \left(e^{\ell} - e^{-\ell}\right)}\right) + U \]
      4. distribute-rgt-out85.7%

        \[\leadsto \color{blue}{\left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + -0.125 \cdot \left(J \cdot {K}^{2}\right)\right)} + U \]
      5. associate-*r*85.7%

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + \color{blue}{\left(-0.125 \cdot J\right) \cdot {K}^{2}}\right) + U \]
      6. *-commutative85.7%

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

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

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \color{blue}{\left({K}^{2} \cdot -0.125\right)}\right) + U \]
      9. unpow285.7%

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(\color{blue}{\left(K \cdot K\right)} \cdot -0.125\right)\right) + U \]
      10. associate-*l*85.7%

        \[\leadsto \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \color{blue}{\left(K \cdot \left(K \cdot -0.125\right)\right)}\right) + U \]
    4. Simplified85.7%

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

    if 0.209999999999999992 < l < 4.5000000000000003e68

    1. Initial program 99.9%

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -4.5 \cdot 10^{+76}:\\ \;\;\;\;U + \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{elif}\;\ell \leq -350:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot \left(J + J \cdot \left(K \cdot \left(K \cdot -0.125\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 0.21 \lor \neg \left(\ell \leq 4.5 \cdot 10^{+68}\right):\\ \;\;\;\;U + \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \end{array} \]

Alternative 4: 79.3% accurate, 1.4× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (cos.f64 (/.f64 K 2)) < -2e-3

    1. Initial program 86.4%

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

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

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

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

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

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

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

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

    if -2e-3 < (cos.f64 (/.f64 K 2))

    1. Initial program 86.2%

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

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

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

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

Alternative 5: 88.2% accurate, 1.4× speedup?

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

\\
U + \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right) \cdot \cos \left(\frac{K}{2}\right)
\end{array}
Derivation
  1. Initial program 86.2%

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

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

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

Alternative 6: 78.5% accurate, 2.7× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.8 \cdot 10^{+44} \lor \neg \left(\ell \leq 9 \cdot 10^{+50}\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.8000000000000001e44 or 9.00000000000000027e50 < 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. Taylor expanded in l around 0 87.1%

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

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

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

    if -2.8000000000000001e44 < l < 9.00000000000000027e50

    1. Initial program 76.8%

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

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

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 2} + U \]
      2. *-commutative89.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*89.9%

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.8 \cdot 10^{+44} \lor \neg \left(\ell \leq 9 \cdot 10^{+50}\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(2 \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \end{array} \]

Alternative 7: 72.2% accurate, 2.8× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq -340 \lor \neg \left(\ell \leq 2.5\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (if (or (<= l -340.0) (not (<= l 2.5)))
   (+ U (* 0.3333333333333333 (* J (pow l 3.0))))
   (+ U (* l (* J 2.0)))))
double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -340.0) || !(l <= 2.5)) {
		tmp = U + (0.3333333333333333 * (J * pow(l, 3.0)));
	} else {
		tmp = U + (l * (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) :: tmp
    if ((l <= (-340.0d0)) .or. (.not. (l <= 2.5d0))) then
        tmp = u + (0.3333333333333333d0 * (j * (l ** 3.0d0)))
    else
        tmp = u + (l * (j * 2.0d0))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if ((l <= -340.0) || !(l <= 2.5)) {
		tmp = U + (0.3333333333333333 * (J * Math.pow(l, 3.0)));
	} else {
		tmp = U + (l * (J * 2.0));
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if (l <= -340.0) or not (l <= 2.5):
		tmp = U + (0.3333333333333333 * (J * math.pow(l, 3.0)))
	else:
		tmp = U + (l * (J * 2.0))
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if ((l <= -340.0) || !(l <= 2.5))
		tmp = Float64(U + Float64(0.3333333333333333 * Float64(J * (l ^ 3.0))));
	else
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if ((l <= -340.0) || ~((l <= 2.5)))
		tmp = U + (0.3333333333333333 * (J * (l ^ 3.0)));
	else
		tmp = U + (l * (J * 2.0));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[Or[LessEqual[l, -340.0], N[Not[LessEqual[l, 2.5]], $MachinePrecision]], N[(U + N[(0.3333333333333333 * N[(J * N[Power[l, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -340 \lor \neg \left(\ell \leq 2.5\right):\\
\;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -340 or 2.5 < 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. Taylor expanded in l around 0 78.0%

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

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

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

    if -340 < l < 2.5

    1. Initial program 73.9%

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

      \[\leadsto \color{blue}{2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)} + U \]
    3. 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-*l*99.9%

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -340 \lor \neg \left(\ell \leq 2.5\right):\\ \;\;\;\;U + 0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \]

Alternative 8: 60.4% accurate, 6.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := K \cdot \left(\ell \cdot \left(K \cdot -0.25\right)\right)\\ t_1 := U + J \cdot \left(\ell \cdot \left(2 + K \cdot \left(K \cdot -0.25\right)\right)\right)\\ \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 200:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 7 \cdot 10^{+153} \lor \neg \left(\ell \leq 4.6 \cdot 10^{+238}\right):\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \frac{t_0 \cdot t_0 - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{t_0 - \ell \cdot 2}\\ \end{array} \end{array} \]
(FPCore (J l K U)
 :precision binary64
 (let* ((t_0 (* K (* l (* K -0.25))))
        (t_1 (+ U (* J (* l (+ 2.0 (* K (* K -0.25))))))))
   (if (<= l -2.2e+34)
     t_1
     (if (<= l 200.0)
       (+ U (* l (* J 2.0)))
       (if (or (<= l 7e+153) (not (<= l 4.6e+238)))
         t_1
         (+
          U
          (*
           J
           (/ (- (* t_0 t_0) (* (* l 2.0) (* l 2.0))) (- t_0 (* l 2.0))))))))))
double code(double J, double l, double K, double U) {
	double t_0 = K * (l * (K * -0.25));
	double t_1 = U + (J * (l * (2.0 + (K * (K * -0.25)))));
	double tmp;
	if (l <= -2.2e+34) {
		tmp = t_1;
	} else if (l <= 200.0) {
		tmp = U + (l * (J * 2.0));
	} else if ((l <= 7e+153) || !(l <= 4.6e+238)) {
		tmp = t_1;
	} else {
		tmp = U + (J * (((t_0 * t_0) - ((l * 2.0) * (l * 2.0))) / (t_0 - (l * 2.0))));
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = k * (l * (k * (-0.25d0)))
    t_1 = u + (j * (l * (2.0d0 + (k * (k * (-0.25d0))))))
    if (l <= (-2.2d+34)) then
        tmp = t_1
    else if (l <= 200.0d0) then
        tmp = u + (l * (j * 2.0d0))
    else if ((l <= 7d+153) .or. (.not. (l <= 4.6d+238))) then
        tmp = t_1
    else
        tmp = u + (j * (((t_0 * t_0) - ((l * 2.0d0) * (l * 2.0d0))) / (t_0 - (l * 2.0d0))))
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double t_0 = K * (l * (K * -0.25));
	double t_1 = U + (J * (l * (2.0 + (K * (K * -0.25)))));
	double tmp;
	if (l <= -2.2e+34) {
		tmp = t_1;
	} else if (l <= 200.0) {
		tmp = U + (l * (J * 2.0));
	} else if ((l <= 7e+153) || !(l <= 4.6e+238)) {
		tmp = t_1;
	} else {
		tmp = U + (J * (((t_0 * t_0) - ((l * 2.0) * (l * 2.0))) / (t_0 - (l * 2.0))));
	}
	return tmp;
}
def code(J, l, K, U):
	t_0 = K * (l * (K * -0.25))
	t_1 = U + (J * (l * (2.0 + (K * (K * -0.25)))))
	tmp = 0
	if l <= -2.2e+34:
		tmp = t_1
	elif l <= 200.0:
		tmp = U + (l * (J * 2.0))
	elif (l <= 7e+153) or not (l <= 4.6e+238):
		tmp = t_1
	else:
		tmp = U + (J * (((t_0 * t_0) - ((l * 2.0) * (l * 2.0))) / (t_0 - (l * 2.0))))
	return tmp
function code(J, l, K, U)
	t_0 = Float64(K * Float64(l * Float64(K * -0.25)))
	t_1 = Float64(U + Float64(J * Float64(l * Float64(2.0 + Float64(K * Float64(K * -0.25))))))
	tmp = 0.0
	if (l <= -2.2e+34)
		tmp = t_1;
	elseif (l <= 200.0)
		tmp = Float64(U + Float64(l * Float64(J * 2.0)));
	elseif ((l <= 7e+153) || !(l <= 4.6e+238))
		tmp = t_1;
	else
		tmp = Float64(U + Float64(J * Float64(Float64(Float64(t_0 * t_0) - Float64(Float64(l * 2.0) * Float64(l * 2.0))) / Float64(t_0 - Float64(l * 2.0)))));
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	t_0 = K * (l * (K * -0.25));
	t_1 = U + (J * (l * (2.0 + (K * (K * -0.25)))));
	tmp = 0.0;
	if (l <= -2.2e+34)
		tmp = t_1;
	elseif (l <= 200.0)
		tmp = U + (l * (J * 2.0));
	elseif ((l <= 7e+153) || ~((l <= 4.6e+238)))
		tmp = t_1;
	else
		tmp = U + (J * (((t_0 * t_0) - ((l * 2.0) * (l * 2.0))) / (t_0 - (l * 2.0))));
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := Block[{t$95$0 = N[(K * N[(l * N[(K * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(U + N[(J * N[(l * N[(2.0 + N[(K * N[(K * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[l, -2.2e+34], t$95$1, If[LessEqual[l, 200.0], N[(U + N[(l * N[(J * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[l, 7e+153], N[Not[LessEqual[l, 4.6e+238]], $MachinePrecision]], t$95$1, N[(U + N[(J * N[(N[(N[(t$95$0 * t$95$0), $MachinePrecision] - N[(N[(l * 2.0), $MachinePrecision] * N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 - N[(l * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := K \cdot \left(\ell \cdot \left(K \cdot -0.25\right)\right)\\
t_1 := U + J \cdot \left(\ell \cdot \left(2 + K \cdot \left(K \cdot -0.25\right)\right)\right)\\
\mathbf{if}\;\ell \leq -2.2 \cdot 10^{+34}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;\ell \leq 200:\\
\;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\

\mathbf{elif}\;\ell \leq 7 \cdot 10^{+153} \lor \neg \left(\ell \leq 4.6 \cdot 10^{+238}\right):\\
\;\;\;\;t_1\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 3 regimes
  2. if l < -2.2000000000000002e34 or 200 < l < 6.9999999999999998e153 or 4.60000000000000005e238 < 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. Taylor expanded in l around 0 25.7%

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

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 2} + U \]
      2. *-commutative25.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*25.7%

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

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2\right)} + U \]
    5. Taylor expanded in K around 0 26.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 \]
    6. Taylor expanded in J around 0 39.9%

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

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

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

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

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

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

    if -2.2000000000000002e34 < l < 200

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

    if 6.9999999999999998e153 < l < 4.60000000000000005e238

    1. Initial program 100.0%

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

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

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

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

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

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

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

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

      \[\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 \]
    6. Taylor expanded in J around 0 32.8%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto J \cdot \frac{\left(K \cdot \left(\left(-0.25 \cdot K\right) \cdot \ell\right)\right) \cdot \left(K \cdot \left(\left(-0.25 \cdot K\right) \cdot \ell\right)\right) - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{\color{blue}{K \cdot \left(\left(-0.25 \cdot K\right) \cdot \ell\right)} - \ell \cdot 2} + U \]
    10. Applied egg-rr58.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+34}:\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + K \cdot \left(K \cdot -0.25\right)\right)\right)\\ \mathbf{elif}\;\ell \leq 200:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;\ell \leq 7 \cdot 10^{+153} \lor \neg \left(\ell \leq 4.6 \cdot 10^{+238}\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + K \cdot \left(K \cdot -0.25\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \frac{\left(K \cdot \left(\ell \cdot \left(K \cdot -0.25\right)\right)\right) \cdot \left(K \cdot \left(\ell \cdot \left(K \cdot -0.25\right)\right)\right) - \left(\ell \cdot 2\right) \cdot \left(\ell \cdot 2\right)}{K \cdot \left(\ell \cdot \left(K \cdot -0.25\right)\right) - \ell \cdot 2}\\ \end{array} \]

Alternative 9: 60.1% accurate, 18.2× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq -2.2 \cdot 10^{+34} \lor \neg \left(\ell \leq 490\right):\\
\;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + K \cdot \left(K \cdot -0.25\right)\right)\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < -2.2000000000000002e34 or 490 < 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. Taylor expanded in l around 0 25.9%

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

        \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 2} + U \]
      2. *-commutative25.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*25.9%

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

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

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

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

      \[\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 \]
    6. Taylor expanded in J around 0 38.9%

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

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

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

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

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

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

    if -2.2000000000000002e34 < l < 490

    1. Initial program 74.8%

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

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

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

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

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

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

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

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq -2.2 \cdot 10^{+34} \lor \neg \left(\ell \leq 490\right):\\ \;\;\;\;U + J \cdot \left(\ell \cdot \left(2 + K \cdot \left(K \cdot -0.25\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \end{array} \]

Alternative 10: 52.2% accurate, 23.9× speedup?

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

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

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if U < 3.6e182

    1. Initial program 84.6%

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

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

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

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

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

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

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

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

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

    if 3.6e182 < U

    1. Initial program 100.0%

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\ell \cdot \left(\left(J \cdot \cos \left(0.5 \cdot K\right)\right) \cdot 2\right)} + U \]
    5. Taylor expanded in K around 0 59.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 \]
    6. Taylor expanded in K around inf 71.1%

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

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

        \[\leadsto -0.25 \cdot \left(J \cdot \left(\ell \cdot \color{blue}{\left(K \cdot K\right)}\right)\right) + U \]
    8. Simplified71.1%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;U \leq 3.6 \cdot 10^{+182}:\\ \;\;\;\;U + \ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U + -0.25 \cdot \left(J \cdot \left(\ell \cdot \left(K \cdot K\right)\right)\right)\\ \end{array} \]

Alternative 11: 53.7% accurate, 44.6× speedup?

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

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

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

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

      \[\leadsto \color{blue}{\left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \cdot 2} + U \]
    2. *-commutative64.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*64.9%

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

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

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

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

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

    \[\leadsto U + \ell \cdot \left(J \cdot 2\right) \]

Alternative 12: 40.1% accurate, 61.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\ell \leq 280000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \end{array} \]
(FPCore (J l K U) :precision binary64 (if (<= l 280000.0) U (* U U)))
double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 280000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
real(8) function code(j, l, k, u)
    real(8), intent (in) :: j
    real(8), intent (in) :: l
    real(8), intent (in) :: k
    real(8), intent (in) :: u
    real(8) :: tmp
    if (l <= 280000.0d0) then
        tmp = u
    else
        tmp = u * u
    end if
    code = tmp
end function
public static double code(double J, double l, double K, double U) {
	double tmp;
	if (l <= 280000.0) {
		tmp = U;
	} else {
		tmp = U * U;
	}
	return tmp;
}
def code(J, l, K, U):
	tmp = 0
	if l <= 280000.0:
		tmp = U
	else:
		tmp = U * U
	return tmp
function code(J, l, K, U)
	tmp = 0.0
	if (l <= 280000.0)
		tmp = U;
	else
		tmp = Float64(U * U);
	end
	return tmp
end
function tmp_2 = code(J, l, K, U)
	tmp = 0.0;
	if (l <= 280000.0)
		tmp = U;
	else
		tmp = U * U;
	end
	tmp_2 = tmp;
end
code[J_, l_, K_, U_] := If[LessEqual[l, 280000.0], U, N[(U * U), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\ell \leq 280000:\\
\;\;\;\;U\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if l < 2.8e5

    1. Initial program 82.4%

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

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

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
    4. Taylor expanded in J around 0 49.8%

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

    if 2.8e5 < 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. 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-def100.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. Applied egg-rr15.7%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\ell \leq 280000:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]

Alternative 13: 2.8% 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 86.2%

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

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

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

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

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

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

    \[\leadsto \color{blue}{1} \]
  7. Final simplification2.8%

    \[\leadsto 1 \]

Alternative 14: 37.0% 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 86.2%

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

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

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

    \[\leadsto \color{blue}{\mathsf{fma}\left(J, \left(e^{\ell} - e^{-\ell}\right) \cdot \cos \left(\frac{K}{2}\right), U\right)} \]
  4. Taylor expanded in J around 0 39.5%

    \[\leadsto \color{blue}{U} \]
  5. Final simplification39.5%

    \[\leadsto U \]

Reproduce

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