Maksimov and Kolovsky, Equation (4)

?

Percentage Accurate: 86.4% → 99.7%
Time: 18.3s
Precision: binary64
Cost: 47049

?

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

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


\end{array}

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.

Herbie found 19 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Split input into 2 regimes
  2. if (-.f64 (exp.f64 l) (exp.f64 (neg.f64 l))) < -inf.0 or 1.00000000000000004e-10 < (-.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 \]

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

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

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

      \[\leadsto \left(J \cdot \color{blue}{\mathsf{fma}\left(2, \ell, \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 0.016666666666666666 \cdot {\ell}^{5}\right)\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
      Step-by-step derivation

      [Start]99.9%

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

      associate-+r+ [=>]99.9%

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

      +-commutative [=>]99.9%

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

      fma-def [=>]99.9%

      \[ \left(J \cdot \color{blue}{\mathsf{fma}\left(2, \ell, 0.3333333333333333 \cdot {\ell}^{3} + 0.016666666666666666 \cdot {\ell}^{5}\right)}\right) \cdot \cos \left(\frac{K}{2}\right) + U \]

      fma-def [=>]99.9%

      \[ \left(J \cdot \mathsf{fma}\left(2, \ell, \color{blue}{\mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, 0.016666666666666666 \cdot {\ell}^{5}\right)}\right)\right) \cdot \cos \left(\frac{K}{2}\right) + U \]
    4. Taylor expanded in l around 0 99.9%

      \[\leadsto \color{blue}{\left(2 \cdot \left(\ell \cdot J\right) + \left(0.3333333333333333 \cdot \left({\ell}^{3} \cdot J\right) + 0.016666666666666666 \cdot \left({\ell}^{5} \cdot J\right)\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 10^{-10}\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(2 \cdot \left(\ell \cdot J\right) + \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)\right)\right)\\ \end{array} \]

Alternatives

Alternative 1
Accuracy99.7%
Cost47049
\[\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{-10}\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(2 \cdot \left(\ell \cdot J\right) + \left(0.3333333333333333 \cdot \left(J \cdot {\ell}^{3}\right) + 0.016666666666666666 \cdot \left(J \cdot {\ell}^{5}\right)\right)\right)\\ \end{array} \]
Alternative 2
Accuracy99.7%
Cost46793
\[\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -\infty \lor \neg \left(t_1 \leq 10^{-10}\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \left(0.016666666666666666 \cdot {\ell}^{5} + \ell \cdot 2\right)\right)\right)\\ \end{array} \]
Alternative 3
Accuracy99.8%
Cost46345
\[\begin{array}{l} t_0 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_0 \leq -0.002 \lor \neg \left(t_0 \leq 10^{-10}\right):\\ \;\;\;\;\cos \left(\frac{K}{2}\right) \cdot \left(t_0 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(\cos \left(K \cdot 0.5\right) \cdot \mathsf{fma}\left(0.3333333333333333, {\ell}^{3}, \ell \cdot 2\right)\right)\\ \end{array} \]
Alternative 4
Accuracy99.8%
Cost46217
\[\begin{array}{l} t_0 := \cos \left(\frac{K}{2}\right)\\ t_1 := e^{\ell} - e^{-\ell}\\ \mathbf{if}\;t_1 \leq -0.002 \lor \neg \left(t_1 \leq 10^{-10}\right):\\ \;\;\;\;t_0 \cdot \left(t_1 \cdot J\right) + U\\ \mathbf{else}:\\ \;\;\;\;U + t_0 \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \end{array} \]
Alternative 5
Accuracy95.2%
Cost14220
\[\begin{array}{l} t_0 := U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;\ell \leq -5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 3.3:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 4.2 \cdot 10^{+61}:\\ \;\;\;\;U + \left(-0.125 \cdot \left(K \cdot K\right) + 1\right) \cdot \left(\left(e^{\ell} - e^{-\ell}\right) \cdot J\right)\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 6
Accuracy95.1%
Cost14088
\[\begin{array}{l} t_0 := U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot \cos \left(K \cdot 0.5\right)\right)\\ \mathbf{if}\;\ell \leq -5:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq 0.21:\\ \;\;\;\;U + \cos \left(\frac{K}{2}\right) \cdot \left(J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+53}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 7
Accuracy94.9%
Cost13964
\[\begin{array}{l} t_0 := \cos \left(K \cdot 0.5\right)\\ t_1 := U + \left(J \cdot {\ell}^{5}\right) \cdot \left(0.016666666666666666 \cdot t_0\right)\\ \mathbf{if}\;\ell \leq -3.3:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\ell \leq 0.00039:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot t_0\right)\right)\\ \mathbf{elif}\;\ell \leq 1.65 \cdot 10^{+53}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Accuracy78.8%
Cost13828
\[\begin{array}{l} \mathbf{if}\;\cos \left(\frac{K}{2}\right) \leq 0.235:\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + J \cdot \left(0.3333333333333333 \cdot {\ell}^{3} + \ell \cdot 2\right)\\ \end{array} \]
Alternative 9
Accuracy81.1%
Cost13577
\[\begin{array}{l} \mathbf{if}\;J \leq -2.2 \cdot 10^{+107} \lor \neg \left(J \leq 3250000\right):\\ \;\;\;\;U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right)\\ \mathbf{else}:\\ \;\;\;\;U + \left(e^{\ell} - e^{-\ell}\right) \cdot J\\ \end{array} \]
Alternative 10
Accuracy47.3%
Cost7308
\[\begin{array}{l} t_0 := U + {K}^{4} \cdot \left(J \cdot -0.0013020833333333333\right)\\ \mathbf{if}\;\ell \leq -1.7 \cdot 10^{+271}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -650:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 420:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 11
Accuracy64.4%
Cost7104
\[U + 2 \cdot \left(\ell \cdot \left(J \cdot \cos \left(K \cdot 0.5\right)\right)\right) \]
Alternative 12
Accuracy64.4%
Cost7104
\[U + J \cdot \left(2 \cdot \left(\ell \cdot \cos \left(K \cdot 0.5\right)\right)\right) \]
Alternative 13
Accuracy46.0%
Cost6792
\[\begin{array}{l} t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{if}\;\ell \leq -1.45 \cdot 10^{+269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -510:\\ \;\;\;\;{U}^{-8}\\ \mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 14
Accuracy45.2%
Cost1100
\[\begin{array}{l} t_0 := U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{if}\;\ell \leq -1.3 \cdot 10^{+269}:\\ \;\;\;\;t_0\\ \mathbf{elif}\;\ell \leq -1850000000000:\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot 0.0625 + -0.5\right)\\ \mathbf{elif}\;\ell \leq 7.4 \cdot 10^{-19}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;t_0\\ \end{array} \]
Alternative 15
Accuracy44.3%
Cost969
\[\begin{array}{l} \mathbf{if}\;\ell \leq -120000000 \lor \neg \left(\ell \leq 7.4 \cdot 10^{-19}\right):\\ \;\;\;\;U + J \cdot \left(\left(K \cdot K\right) \cdot -64 + 512\right)\\ \mathbf{else}:\\ \;\;\;\;U\\ \end{array} \]
Alternative 16
Accuracy42.3%
Cost456
\[\begin{array}{l} \mathbf{if}\;\ell \leq -135000000:\\ \;\;\;\;U \cdot U\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-11}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]
Alternative 17
Accuracy42.2%
Cost456
\[\begin{array}{l} \mathbf{if}\;\ell \leq -8.6 \cdot 10^{+15}:\\ \;\;\;\;U \cdot \left(U - -8\right)\\ \mathbf{elif}\;\ell \leq 2.6 \cdot 10^{-11}:\\ \;\;\;\;U\\ \mathbf{else}:\\ \;\;\;\;U \cdot U\\ \end{array} \]
Alternative 18
Accuracy2.7%
Cost64
\[1 \]
Alternative 19
Accuracy37.1%
Cost64
\[U \]

Reproduce?

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