?

Average Error: 30.79% → 24.55%
Time: 28.8s
Precision: binary64
Cost: 40648

?

\[\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 := t \cdot \left(z \cdot 0.3333333333333333\right)\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+43}:\\ \;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{\frac{a}{b}}{3}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+177}:\\ \;\;\;\;2 \cdot \left(\sqrt{x} \cdot \left(\sin y \cdot \sin t_1\right) + \sqrt{x} \cdot \left(\cos y \cdot \cos t_1\right)\right) - \frac{a}{b \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{a}{b} \cdot -0.3333333333333333\right)\\ \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 (* z 0.3333333333333333))))
   (if (<= (* z t) -5e+43)
     (- (* (* 2.0 (sqrt x)) (cos y)) (/ (/ a b) 3.0))
     (if (<= (* z t) 2e+177)
       (-
        (*
         2.0
         (+
          (* (sqrt x) (* (sin y) (sin t_1)))
          (* (sqrt x) (* (cos y) (cos t_1)))))
        (/ a (* b 3.0)))
       (fma 2.0 (* (sqrt x) (cos y)) (* (/ a b) -0.3333333333333333))))))
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 * (z * 0.3333333333333333);
	double tmp;
	if ((z * t) <= -5e+43) {
		tmp = ((2.0 * sqrt(x)) * cos(y)) - ((a / b) / 3.0);
	} else if ((z * t) <= 2e+177) {
		tmp = (2.0 * ((sqrt(x) * (sin(y) * sin(t_1))) + (sqrt(x) * (cos(y) * cos(t_1))))) - (a / (b * 3.0));
	} else {
		tmp = fma(2.0, (sqrt(x) * cos(y)), ((a / b) * -0.3333333333333333));
	}
	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(z * 0.3333333333333333))
	tmp = 0.0
	if (Float64(z * t) <= -5e+43)
		tmp = Float64(Float64(Float64(2.0 * sqrt(x)) * cos(y)) - Float64(Float64(a / b) / 3.0));
	elseif (Float64(z * t) <= 2e+177)
		tmp = Float64(Float64(2.0 * Float64(Float64(sqrt(x) * Float64(sin(y) * sin(t_1))) + Float64(sqrt(x) * Float64(cos(y) * cos(t_1))))) - Float64(a / Float64(b * 3.0)));
	else
		tmp = fma(2.0, Float64(sqrt(x) * cos(y)), Float64(Float64(a / b) * -0.3333333333333333));
	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[(z * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -5e+43], N[(N[(N[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[(a / b), $MachinePrecision] / 3.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 2e+177], N[(N[(2.0 * N[(N[(N[Sqrt[x], $MachinePrecision] * N[(N[Sin[y], $MachinePrecision] * N[Sin[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[Sqrt[x], $MachinePrecision] * N[(N[Cos[y], $MachinePrecision] * N[Cos[t$95$1], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[(b * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(N[Sqrt[x], $MachinePrecision] * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(N[(a / b), $MachinePrecision] * -0.3333333333333333), $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 := t \cdot \left(z \cdot 0.3333333333333333\right)\\
\mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+43}:\\
\;\;\;\;\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{\frac{a}{b}}{3}\\

\mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+177}:\\
\;\;\;\;2 \cdot \left(\sqrt{x} \cdot \left(\sin y \cdot \sin t_1\right) + \sqrt{x} \cdot \left(\cos y \cdot \cos t_1\right)\right) - \frac{a}{b \cdot 3}\\

\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{a}{b} \cdot -0.3333333333333333\right)\\


\end{array}

Error?

Target

Original30.79%
Target28.26%
Herbie24.55%
\[\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) < -5.0000000000000004e43

    1. Initial program 65.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 51.23

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

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

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

    if -5.0000000000000004e43 < (*.f64 z t) < 2e177

    1. Initial program 12.24

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

      \[\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]12.24

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

      associate-*l* [=>]12.24

      \[ \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* [=>]12.26

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

      *-commutative [=>]12.26

      \[ 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-rr11.2

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

    if 2e177 < (*.f64 z t)

    1. Initial program 72.6

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

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

      [Start]72.6

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

      associate-*l* [=>]72.6

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

      fma-neg [=>]72.6

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

      associate-*l/ [<=]72.47

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

      *-commutative [=>]72.47

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

      distribute-neg-frac [=>]72.47

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

      *-commutative [=>]72.47

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

      neg-mul-1 [=>]72.47

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

      times-frac [=>]72.73

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

      metadata-eval [=>]72.73

      \[ \mathsf{fma}\left(2, \sqrt{x} \cdot \cos \left(y - t \cdot \frac{z}{3}\right), \color{blue}{-0.3333333333333333} \cdot \frac{a}{b}\right) \]
    3. Taylor expanded in t around 0 51.86

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

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

Alternatives

Alternative 1
Error24.53%
Cost34120
\[\begin{array}{l} t_1 := z \cdot \left(t \cdot 0.3333333333333333\right)\\ t_2 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+43}:\\ \;\;\;\;t_2 \cdot \cos y - \frac{\frac{a}{b}}{3}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+177}:\\ \;\;\;\;t_2 \cdot \left(\sin y \cdot \sin t_1 + \cos y \cdot \cos t_1\right) - \frac{a}{b \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{a}{b} \cdot -0.3333333333333333\right)\\ \end{array} \]
Alternative 2
Error24.54%
Cost34120
\[\begin{array}{l} t_1 := t \cdot \left(z \cdot -0.3333333333333333\right)\\ t_2 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -5 \cdot 10^{+43}:\\ \;\;\;\;t_2 \cdot \cos y - \frac{\frac{a}{b}}{3}\\ \mathbf{elif}\;z \cdot t \leq 2 \cdot 10^{+177}:\\ \;\;\;\;t_2 \cdot \left(\cos y \cdot \cos t_1 - \sin y \cdot \sin t_1\right) - \frac{a}{b \cdot 3}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{a}{b} \cdot -0.3333333333333333\right)\\ \end{array} \]
Alternative 3
Error25.69%
Cost19776
\[\mathsf{fma}\left(2, \sqrt{x} \cdot \cos y, \frac{\frac{a}{-3}}{b}\right) \]
Alternative 4
Error32.77%
Cost14024
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-131}:\\ \;\;\;\;2 \cdot \sqrt{x} + \frac{a}{3} \cdot \frac{-1}{b}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{-11}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(2, \sqrt{x}, \frac{\frac{a}{-3}}{b}\right)\\ \end{array} \]
Alternative 5
Error32.8%
Cost13897
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ \mathbf{if}\;t_1 \leq -5 \cdot 10^{-131} \lor \neg \left(t_1 \leq 2 \cdot 10^{-11}\right):\\ \;\;\;\;2 \cdot \sqrt{x} + \frac{a}{3} \cdot \frac{-1}{b}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \end{array} \]
Alternative 6
Error25.77%
Cost13632
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y + \frac{a}{3} \cdot \frac{-1}{b} \]
Alternative 7
Error25.78%
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y + a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 8
Error25.7%
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{a}{b \cdot 3} \]
Alternative 9
Error38.73%
Cost7104
\[2 \cdot \sqrt{x} + \frac{a}{3} \cdot \frac{-1}{b} \]
Alternative 10
Error38.66%
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{b \cdot 3} \]
Alternative 11
Error56.42%
Cost320
\[\frac{a}{b} \cdot -0.3333333333333333 \]
Alternative 12
Error56.39%
Cost320
\[a \cdot \frac{-0.3333333333333333}{b} \]
Alternative 13
Error56.37%
Cost320
\[\frac{a}{\frac{b}{-0.3333333333333333}} \]
Alternative 14
Error56.3%
Cost320
\[\frac{\frac{a}{-3}}{b} \]

Error

Reproduce?

herbie shell --seed 2023102 
(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))))