?

Average Error: 20.4 → 16.2
Time: 25.3s
Precision: binary64
Cost: 40392

?

\[ \begin{array}{c}[z, t] = \mathsf{sort}([z, t])\\ \end{array} \]
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
\[\begin{array}{l} t_1 := \frac{t}{\frac{3}{z}}\\ t_2 := \frac{a}{b \cdot 3}\\ t_3 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+98}:\\ \;\;\;\;e^{\log t_3} - t_2\\ \mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+71}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \mathsf{fma}\left(\cos t_1, \cos y, \sin y \cdot \sin t_1\right)\right) - t_2\\ \mathbf{else}:\\ \;\;\;\;t_3 \cdot \cos y + \frac{\frac{a}{b}}{-3}\\ \end{array} \]
(FPCore (x y z t a b)
 :precision binary64
 (- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))
(FPCore (x y z t a b)
 :precision binary64
 (let* ((t_1 (/ t (/ 3.0 z))) (t_2 (/ a (* b 3.0))) (t_3 (* 2.0 (sqrt x))))
   (if (<= (* z t) -2e+98)
     (- (exp (log t_3)) t_2)
     (if (<= (* z t) 4e+71)
       (-
        (* 2.0 (* (sqrt x) (fma (cos t_1) (cos y) (* (sin y) (sin t_1)))))
        t_2)
       (+ (* t_3 (cos y)) (/ (/ a b) -3.0))))))
double code(double x, double y, double z, double t, double a, double b) {
	return ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = t / (3.0 / z);
	double t_2 = a / (b * 3.0);
	double t_3 = 2.0 * sqrt(x);
	double tmp;
	if ((z * t) <= -2e+98) {
		tmp = exp(log(t_3)) - t_2;
	} else if ((z * t) <= 4e+71) {
		tmp = (2.0 * (sqrt(x) * fma(cos(t_1), cos(y), (sin(y) * sin(t_1))))) - t_2;
	} else {
		tmp = (t_3 * cos(y)) + ((a / b) / -3.0);
	}
	return tmp;
}
function code(x, y, z, t, a, b)
	return Float64(Float64(Float64(2.0 * sqrt(x)) * cos(Float64(y - Float64(Float64(z * t) / 3.0)))) - Float64(a / Float64(b * 3.0)))
end
function code(x, y, z, t, a, b)
	t_1 = Float64(t / Float64(3.0 / z))
	t_2 = Float64(a / Float64(b * 3.0))
	t_3 = Float64(2.0 * sqrt(x))
	tmp = 0.0
	if (Float64(z * t) <= -2e+98)
		tmp = Float64(exp(log(t_3)) - t_2);
	elseif (Float64(z * t) <= 4e+71)
		tmp = Float64(Float64(2.0 * Float64(sqrt(x) * fma(cos(t_1), cos(y), Float64(sin(y) * sin(t_1))))) - t_2);
	else
		tmp = Float64(Float64(t_3 * cos(y)) + Float64(Float64(a / b) / -3.0));
	end
	return tmp
end
code[x_, y_, z_, t_, a_, b_] := N[(N[(N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[Cos[N[(y - N[(N[(z * t), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_, b_] := Block[{t$95$1 = N[(t / N[(3.0 / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -2e+98], N[(N[Exp[N[Log[t$95$3], $MachinePrecision]], $MachinePrecision] - t$95$2), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 4e+71], N[(N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[(N[Cos[t$95$1], $MachinePrecision] * N[Cos[y], $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - t$95$2), $MachinePrecision], N[(N[(t$95$3 * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(N[(a / b), $MachinePrecision] / -3.0), $MachinePrecision]), $MachinePrecision]]]]]]
\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3}
\begin{array}{l}
t_1 := \frac{t}{\frac{3}{z}}\\
t_2 := \frac{a}{b \cdot 3}\\
t_3 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+98}:\\
\;\;\;\;e^{\log t_3} - t_2\\

\mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+71}:\\
\;\;\;\;2 \cdot \left(\sqrt{x} \cdot \mathsf{fma}\left(\cos t_1, \cos y, \sin y \cdot \sin t_1\right)\right) - t_2\\

\mathbf{else}:\\
\;\;\;\;t_3 \cdot \cos y + \frac{\frac{a}{b}}{-3}\\


\end{array}

Error?

Target

Original20.4
Target18.5
Herbie16.2
\[\begin{array}{l} \mathbf{if}\;z < -1.3793337487235141 \cdot 10^{+129}:\\ \;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(\frac{1}{y} - \frac{\frac{0.3333333333333333}{z}}{t}\right) - \frac{\frac{a}{3}}{b}\\ \mathbf{elif}\;z < 3.516290613555987 \cdot 10^{+106}:\\ \;\;\;\;\left(\sqrt{x} \cdot 2\right) \cdot \cos \left(y - \frac{t}{3} \cdot z\right) - \frac{\frac{a}{3}}{b}\\ \mathbf{else}:\\ \;\;\;\;\cos \left(y - \frac{\frac{0.3333333333333333}{z}}{t}\right) \cdot \left(2 \cdot \sqrt{x}\right) - \frac{\frac{a}{b}}{3}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if (*.f64 z t) < -2e98

    1. Initial program 45.6

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Taylor expanded in z around 0 34.8

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos y} - \frac{a}{b \cdot 3} \]
    3. Applied egg-rr41.6

      \[\leadsto \color{blue}{e^{\log \left(2 \cdot \left(\sqrt{x} \cdot \cos y\right)\right)}} - \frac{a}{b \cdot 3} \]
    4. Taylor expanded in y around 0 34.8

      \[\leadsto e^{\color{blue}{\log \left(2 \cdot \sqrt{x}\right)}} - \frac{a}{b \cdot 3} \]

    if -2e98 < (*.f64 z t) < 4.0000000000000002e71

    1. Initial program 6.6

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Simplified6.6

      \[\leadsto \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z}{\frac{3}{t}}\right)\right) - \frac{a}{3 \cdot b}} \]
      Proof

      [Start]6.6

      \[ \left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]

      associate-*l* [=>]6.6

      \[ \color{blue}{2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z \cdot t}{3}\right)\right)} - \frac{a}{b \cdot 3} \]

      associate-/l* [=>]6.6

      \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \color{blue}{\frac{z}{\frac{3}{t}}}\right)\right) - \frac{a}{b \cdot 3} \]

      *-commutative [=>]6.6

      \[ 2 \cdot \left(\sqrt{x} \cdot \cos \left(y - \frac{z}{\frac{3}{t}}\right)\right) - \frac{a}{\color{blue}{3 \cdot b}} \]
    3. Applied egg-rr6.0

      \[\leadsto 2 \cdot \left(\sqrt{x} \cdot \color{blue}{\left(\cos y \cdot \cos \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right) + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)}\right) - \frac{a}{3 \cdot b} \]
    4. Simplified6.0

      \[\leadsto 2 \cdot \left(\sqrt{x} \cdot \color{blue}{\mathsf{fma}\left(\cos \left(\frac{t}{\frac{3}{z}}\right), \cos y, \sin y \cdot \sin \left(\frac{t}{\frac{3}{z}}\right)\right)}\right) - \frac{a}{3 \cdot b} \]
      Proof

      [Start]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos y \cdot \cos \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right) + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      *-commutative [=>]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\color{blue}{\cos \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right) \cdot \cos y} + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      cos-neg [<=]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\color{blue}{\cos \left(-t \cdot \left(z \cdot 0.3333333333333333\right)\right)} \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      distribute-lft-neg-in [=>]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \color{blue}{\left(\left(-t\right) \cdot \left(z \cdot 0.3333333333333333\right)\right)} \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      *-commutative [=>]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\left(-t\right) \cdot \color{blue}{\left(0.3333333333333333 \cdot z\right)}\right) \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      associate-*l* [<=]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \color{blue}{\left(\left(\left(-t\right) \cdot 0.3333333333333333\right) \cdot z\right)} \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      distribute-lft-neg-in [<=]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(\color{blue}{\left(-t \cdot 0.3333333333333333\right)} \cdot z\right) \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      distribute-lft-neg-in [<=]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \color{blue}{\left(-\left(t \cdot 0.3333333333333333\right) \cdot z\right)} \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      *-commutative [=>]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(-\color{blue}{\left(0.3333333333333333 \cdot t\right)} \cdot z\right) \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      associate-*r* [<=]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \left(\cos \left(-\color{blue}{0.3333333333333333 \cdot \left(t \cdot z\right)}\right) \cdot \cos y + \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)\right) - \frac{a}{3 \cdot b} \]

      fma-def [=>]6.0

      \[ 2 \cdot \left(\sqrt{x} \cdot \color{blue}{\mathsf{fma}\left(\cos \left(-0.3333333333333333 \cdot \left(t \cdot z\right)\right), \cos y, \sin y \cdot \sin \left(t \cdot \left(z \cdot 0.3333333333333333\right)\right)\right)}\right) - \frac{a}{3 \cdot b} \]

    if 4.0000000000000002e71 < (*.f64 z t)

    1. Initial program 43.5

      \[\left(2 \cdot \sqrt{x}\right) \cdot \cos \left(y - \frac{z \cdot t}{3}\right) - \frac{a}{b \cdot 3} \]
    2. Taylor expanded in z around 0 33.0

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \color{blue}{\cos y} - \frac{a}{b \cdot 3} \]
    3. Applied egg-rr33.1

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \cos y - \color{blue}{\left(-\frac{\frac{a}{b}}{-3}\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification16.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+98}:\\ \;\;\;\;e^{\log \left(2 \cdot \sqrt{x}\right)} - \frac{a}{b \cdot 3}\\ \mathbf{elif}\;z \cdot t \leq 4 \cdot 10^{+71}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \mathsf{fma}\left(\cos \left(\frac{t}{\frac{3}{z}}\right), \cos y, \sin y \cdot \sin \left(\frac{t}{\frac{3}{z}}\right)\right)\right) - \frac{a}{b \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \cos y + \frac{\frac{a}{b}}{-3}\\ \end{array} \]

Alternatives

Alternative 1
Error16.1
Cost34120
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ t_2 := t \cdot \frac{z}{-3}\\ \mathbf{if}\;z \cdot t \leq -2 \cdot 10^{+98}:\\ \;\;\;\;e^{\log \left(2 \cdot \sqrt{x}\right)} - t_1\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+60}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \left(\cos y \cdot \cos t_2 - \sin y \cdot \sin t_2\right)\right) - t_1\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x}, \frac{\frac{a}{-3}}{b}\right)\\ \end{array} \]
Alternative 2
Error16.9
Cost19776
\[\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{\frac{a}{-3}}{b}\right) \]
Alternative 3
Error20.1
Cost14025
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-84} \lor \neg \left(t_1 \leq 5 \cdot 10^{-73}\right):\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x}, \frac{\frac{a}{-3}}{b}\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \end{array} \]
Alternative 4
Error20.1
Cost13897
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-84} \lor \neg \left(t_1 \leq 5 \cdot 10^{-73}\right):\\ \;\;\;\;2 \cdot \sqrt{x} - t_1\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \end{array} \]
Alternative 5
Error17.0
Cost13504
\[\frac{-0.3333333333333333}{\frac{b}{a}} + 2 \cdot \left(\sqrt{x} \cdot \cos y\right) \]
Alternative 6
Error17.0
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y + a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 7
Error16.9
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{a}{b \cdot 3} \]
Alternative 8
Error25.2
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{b \cdot 3} \]
Alternative 9
Error36.3
Cost320
\[\frac{a}{b} \cdot -0.3333333333333333 \]
Alternative 10
Error36.3
Cost320
\[a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 11
Error36.3
Cost320
\[\frac{a \cdot -0.3333333333333333}{b} \]
Alternative 12
Error36.3
Cost320
\[\frac{\frac{a}{-3}}{b} \]

Error

Reproduce?

herbie shell --seed 2023046 
(FPCore (x y z t a b)
  :name "Diagrams.Solve.Polynomial:cubForm  from diagrams-solve-0.1, K"
  :precision binary64

  :herbie-target
  (if (< z -1.3793337487235141e+129) (- (* (* 2.0 (sqrt x)) (cos (- (/ 1.0 y) (/ (/ 0.3333333333333333 z) t)))) (/ (/ a 3.0) b)) (if (< z 3.516290613555987e+106) (- (* (* (sqrt x) 2.0) (cos (- y (* (/ t 3.0) z)))) (/ (/ a 3.0) b)) (- (* (cos (- y (/ (/ 0.3333333333333333 z) t))) (* 2.0 (sqrt x))) (/ (/ a b) 3.0))))

  (- (* (* 2.0 (sqrt x)) (cos (- y (/ (* z t) 3.0)))) (/ a (* b 3.0))))