?

Average Error: 20.5 → 16.6
Time: 18.0s
Precision: binary64
Cost: 14408

?

\[ \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 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+82}:\\ \;\;\;\;t_1 - \frac{0.3333333333333333}{\frac{b}{a}}\\ \mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+118}:\\ \;\;\;\;t_1 \cdot \cos \left(y - t \cdot \frac{z}{3}\right) - \frac{a}{3 \cdot b}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot \cos y - \frac{a}{b \cdot 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 (* 2.0 (sqrt x))))
   (if (<= (* z t) -1e+82)
     (- t_1 (/ 0.3333333333333333 (/ b a)))
     (if (<= (* z t) 5e+118)
       (- (* t_1 (cos (- y (* t (/ z 3.0))))) (/ a (* 3.0 b)))
       (- (* t_1 (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 = 2.0 * sqrt(x);
	double tmp;
	if ((z * t) <= -1e+82) {
		tmp = t_1 - (0.3333333333333333 / (b / a));
	} else if ((z * t) <= 5e+118) {
		tmp = (t_1 * cos((y - (t * (z / 3.0))))) - (a / (3.0 * b));
	} else {
		tmp = (t_1 * cos(y)) - (a / (b * 3.0));
	}
	return tmp;
}
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    code = ((2.0d0 * sqrt(x)) * cos((y - ((z * t) / 3.0d0)))) - (a / (b * 3.0d0))
end function
real(8) function code(x, y, z, t, a, b)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8), intent (in) :: b
    real(8) :: t_1
    real(8) :: tmp
    t_1 = 2.0d0 * sqrt(x)
    if ((z * t) <= (-1d+82)) then
        tmp = t_1 - (0.3333333333333333d0 / (b / a))
    else if ((z * t) <= 5d+118) then
        tmp = (t_1 * cos((y - (t * (z / 3.0d0))))) - (a / (3.0d0 * b))
    else
        tmp = (t_1 * cos(y)) - (a / (b * 3.0d0))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a, double b) {
	return ((2.0 * Math.sqrt(x)) * Math.cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
}
public static double code(double x, double y, double z, double t, double a, double b) {
	double t_1 = 2.0 * Math.sqrt(x);
	double tmp;
	if ((z * t) <= -1e+82) {
		tmp = t_1 - (0.3333333333333333 / (b / a));
	} else if ((z * t) <= 5e+118) {
		tmp = (t_1 * Math.cos((y - (t * (z / 3.0))))) - (a / (3.0 * b));
	} else {
		tmp = (t_1 * Math.cos(y)) - (a / (b * 3.0));
	}
	return tmp;
}
def code(x, y, z, t, a, b):
	return ((2.0 * math.sqrt(x)) * math.cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0))
def code(x, y, z, t, a, b):
	t_1 = 2.0 * math.sqrt(x)
	tmp = 0
	if (z * t) <= -1e+82:
		tmp = t_1 - (0.3333333333333333 / (b / a))
	elif (z * t) <= 5e+118:
		tmp = (t_1 * math.cos((y - (t * (z / 3.0))))) - (a / (3.0 * b))
	else:
		tmp = (t_1 * math.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(2.0 * sqrt(x))
	tmp = 0.0
	if (Float64(z * t) <= -1e+82)
		tmp = Float64(t_1 - Float64(0.3333333333333333 / Float64(b / a)));
	elseif (Float64(z * t) <= 5e+118)
		tmp = Float64(Float64(t_1 * cos(Float64(y - Float64(t * Float64(z / 3.0))))) - Float64(a / Float64(3.0 * b)));
	else
		tmp = Float64(Float64(t_1 * cos(y)) - Float64(a / Float64(b * 3.0)));
	end
	return tmp
end
function tmp = code(x, y, z, t, a, b)
	tmp = ((2.0 * sqrt(x)) * cos((y - ((z * t) / 3.0)))) - (a / (b * 3.0));
end
function tmp_2 = code(x, y, z, t, a, b)
	t_1 = 2.0 * sqrt(x);
	tmp = 0.0;
	if ((z * t) <= -1e+82)
		tmp = t_1 - (0.3333333333333333 / (b / a));
	elseif ((z * t) <= 5e+118)
		tmp = (t_1 * cos((y - (t * (z / 3.0))))) - (a / (3.0 * b));
	else
		tmp = (t_1 * cos(y)) - (a / (b * 3.0));
	end
	tmp_2 = 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[(2.0 * N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * t), $MachinePrecision], -1e+82], N[(t$95$1 - N[(0.3333333333333333 / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * t), $MachinePrecision], 5e+118], N[(N[(t$95$1 * N[Cos[N[(y - N[(t * N[(z / 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - N[(a / N[(3.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(a / N[(b * 3.0), $MachinePrecision]), $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 := 2 \cdot \sqrt{x}\\
\mathbf{if}\;z \cdot t \leq -1 \cdot 10^{+82}:\\
\;\;\;\;t_1 - \frac{0.3333333333333333}{\frac{b}{a}}\\

\mathbf{elif}\;z \cdot t \leq 5 \cdot 10^{+118}:\\
\;\;\;\;t_1 \cdot \cos \left(y - t \cdot \frac{z}{3}\right) - \frac{a}{3 \cdot b}\\

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original20.5
Target18.7
Herbie16.6
\[\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) < -9.9999999999999996e81

    1. Initial program 42.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 32.4

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

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \cos y - \color{blue}{\frac{0.3333333333333333}{b} \cdot a} \]
    4. Applied egg-rr32.5

      \[\leadsto \left(2 \cdot \sqrt{x}\right) \cdot \cos y - \color{blue}{\frac{0.3333333333333333}{\frac{b}{a}}} \]
    5. Taylor expanded in y around 0 32.5

      \[\leadsto \color{blue}{2 \cdot \sqrt{x}} - \frac{0.3333333333333333}{\frac{b}{a}} \]

    if -9.9999999999999996e81 < (*.f64 z t) < 4.99999999999999972e118

    1. Initial program 7.9

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

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

      [Start]7.9

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

    if 4.99999999999999972e118 < (*.f64 z t)

    1. Initial program 45.9

      \[\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.8

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

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

Alternatives

Alternative 1
Error21.0
Cost13896
\[\begin{array}{l} t_1 := \frac{a}{b \cdot 3}\\ t_2 := 2 \cdot \sqrt{x}\\ \mathbf{if}\;t_1 \leq -4 \cdot 10^{-121}:\\ \;\;\;\;t_2 - \frac{0.3333333333333333}{\frac{b}{a}}\\ \mathbf{elif}\;t_1 \leq 500:\\ \;\;\;\;\sqrt{x} \cdot \left(2 \cdot \cos y\right)\\ \mathbf{else}:\\ \;\;\;\;\left(t_2 + \left(1 - \frac{a}{3 \cdot b}\right)\right) + -1\\ \end{array} \]
Alternative 2
Error16.9
Cost13504
\[2 \cdot \left(\sqrt{x} \cdot \cos y\right) - \frac{\frac{a}{3}}{b} \]
Alternative 3
Error17.0
Cost13504
\[\left(2 \cdot \sqrt{x}\right) \cdot \cos y - \frac{a}{b \cdot 3} \]
Alternative 4
Error25.5
Cost6976
\[2 \cdot \sqrt{x} - \frac{0.3333333333333333}{b} \cdot a \]
Alternative 5
Error25.5
Cost6976
\[2 \cdot \sqrt{x} - \frac{0.3333333333333333}{\frac{b}{a}} \]
Alternative 6
Error25.5
Cost6976
\[2 \cdot \sqrt{x} - \frac{a}{b \cdot 3} \]
Alternative 7
Error36.4
Cost320
\[-0.3333333333333333 \cdot \frac{a}{b} \]

Error

Reproduce?

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