Average Error: 17.6 → 0.1
Time: 14.2s
Precision: binary64
Cost: 19776
\[\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
\[\mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(0.5 \cdot K\right), U\right) \]
(FPCore (J l K U)
 :precision binary64
 (+ (* (* J (- (exp l) (exp (- l)))) (cos (/ K 2.0))) U))
(FPCore (J l K U)
 :precision binary64
 (fma J (* (* 2.0 (sinh l)) (cos (* 0.5 K))) U))
double code(double J, double l, double K, double U) {
	return ((J * (exp(l) - exp(-l))) * cos((K / 2.0))) + U;
}
double code(double J, double l, double K, double U) {
	return fma(J, ((2.0 * sinh(l)) * cos((0.5 * K))), 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 code(J, l, K, U)
	return fma(J, Float64(Float64(2.0 * sinh(l)) * cos(Float64(0.5 * K))), 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]
code[J_, l_, K_, U_] := N[(J * N[(N[(2.0 * N[Sinh[l], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(0.5 * K), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] + U), $MachinePrecision]
\left(J \cdot \left(e^{\ell} - e^{-\ell}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U
\mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(0.5 \cdot K\right), U\right)

Error

Derivation

  1. Initial program 17.6

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

    \[\leadsto \left(J \cdot \color{blue}{\left(\sqrt{2 \cdot \sinh \ell} \cdot \sqrt{2 \cdot \sinh \ell}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
  3. Applied egg-rr44.0

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\mathsf{fma}\left(J, 2 \cdot \left(\sinh \ell \cdot \cos \left(K \cdot 0.5\right)\right), U\right)\right)} - 1} \]
  4. Simplified0.1

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

    [Start]44.0

    \[ e^{\mathsf{log1p}\left(\mathsf{fma}\left(J, 2 \cdot \left(\sinh \ell \cdot \cos \left(K \cdot 0.5\right)\right), U\right)\right)} - 1 \]

    expm1-def [=>]22.3

    \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{fma}\left(J, 2 \cdot \left(\sinh \ell \cdot \cos \left(K \cdot 0.5\right)\right), U\right)\right)\right)} \]

    expm1-log1p [=>]0.1

    \[ \color{blue}{\mathsf{fma}\left(J, 2 \cdot \left(\sinh \ell \cdot \cos \left(K \cdot 0.5\right)\right), U\right)} \]

    associate-*r* [=>]0.1

    \[ \mathsf{fma}\left(J, \color{blue}{\left(2 \cdot \sinh \ell\right) \cdot \cos \left(K \cdot 0.5\right)}, U\right) \]

    *-commutative [<=]0.1

    \[ \mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \color{blue}{\left(0.5 \cdot K\right)}, U\right) \]
  5. Final simplification0.1

    \[\leadsto \mathsf{fma}\left(J, \left(2 \cdot \sinh \ell\right) \cdot \cos \left(0.5 \cdot K\right), U\right) \]

Alternatives

Alternative 1
Error0.1
Cost13504
\[U + 2 \cdot \left(J \cdot \left(\sinh \ell \cdot \cos \left(0.5 \cdot K\right)\right)\right) \]
Alternative 2
Error0.7
Cost13376
\[\mathsf{fma}\left(\cos \left(0.5 \cdot K\right) \cdot \left(2 \cdot \ell\right), J, U\right) \]
Alternative 3
Error8.9
Cost7240
\[\begin{array}{l} \mathbf{if}\;U \leq -4.7 \cdot 10^{-265}:\\ \;\;\;\;U + \sinh \ell \cdot \left(J \cdot 2\right)\\ \mathbf{elif}\;U \leq 6.5 \cdot 10^{-256}:\\ \;\;\;\;2 \cdot \left(J \cdot \left(\ell \cdot \cos \left(0.5 \cdot K\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(2 \cdot \ell\right)\\ \end{array} \]
Alternative 4
Error0.7
Cost7104
\[U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(0.5 \cdot K\right)\right)\right) \]
Alternative 5
Error0.7
Cost7104
\[U + J \cdot \left(\cos \left(0.5 \cdot K\right) \cdot \left(2 \cdot \ell\right)\right) \]
Alternative 6
Error9.2
Cost6848
\[U + \sinh \ell \cdot \left(J \cdot 2\right) \]
Alternative 7
Error19.1
Cost849
\[\begin{array}{l} \mathbf{if}\;U \leq -3.8 \cdot 10^{-158}:\\ \;\;\;\;U\\ \mathbf{elif}\;U \leq -6.6 \cdot 10^{-201} \lor \neg \left(U \leq 5.6 \cdot 10^{-274}\right) \land U \leq 2.6 \cdot 10^{-236}:\\ \;\;\;\;\ell \cdot \left(J \cdot 2\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 8
Error9.5
Cost448
\[U + J \cdot \left(2 \cdot \ell\right) \]
Alternative 9
Error18.8
Cost64
\[U \]

Error

Reproduce

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