Average Error: 5.7 → 0.1
Time: 16.1s
Precision: binary64
Cost: 1092
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+308}:\\ \;\;\;\;x \cdot x - \left(y \cdot -4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= (* z z) 1e+308)
   (- (* x x) (* (* y -4.0) (- t (* z z))))
   (+ (* x x) (* z (* (* y -4.0) z)))))
double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((z * z) <= 1e+308) {
		tmp = (x * x) - ((y * -4.0) * (t - (z * z)));
	} else {
		tmp = (x * x) + (z * ((y * -4.0) * z));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x * x) - ((y * 4.0d0) * ((z * z) - t))
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: tmp
    if ((z * z) <= 1d+308) then
        tmp = (x * x) - ((y * (-4.0d0)) * (t - (z * z)))
    else
        tmp = (x * x) + (z * ((y * (-4.0d0)) * z))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return (x * x) - ((y * 4.0) * ((z * z) - t));
}
public static double code(double x, double y, double z, double t) {
	double tmp;
	if ((z * z) <= 1e+308) {
		tmp = (x * x) - ((y * -4.0) * (t - (z * z)));
	} else {
		tmp = (x * x) + (z * ((y * -4.0) * z));
	}
	return tmp;
}
def code(x, y, z, t):
	return (x * x) - ((y * 4.0) * ((z * z) - t))
def code(x, y, z, t):
	tmp = 0
	if (z * z) <= 1e+308:
		tmp = (x * x) - ((y * -4.0) * (t - (z * z)))
	else:
		tmp = (x * x) + (z * ((y * -4.0) * z))
	return tmp
function code(x, y, z, t)
	return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t)))
end
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(z * z) <= 1e+308)
		tmp = Float64(Float64(x * x) - Float64(Float64(y * -4.0) * Float64(t - Float64(z * z))));
	else
		tmp = Float64(Float64(x * x) + Float64(z * Float64(Float64(y * -4.0) * z)));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = (x * x) - ((y * 4.0) * ((z * z) - t));
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if ((z * z) <= 1e+308)
		tmp = (x * x) - ((y * -4.0) * (t - (z * z)));
	else
		tmp = (x * x) + (z * ((y * -4.0) * z));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+308], N[(N[(x * x), $MachinePrecision] - N[(N[(y * -4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] + N[(z * N[(N[(y * -4.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+308}:\\
\;\;\;\;x \cdot x - \left(y \cdot -4\right) \cdot \left(t - z \cdot z\right)\\

\mathbf{else}:\\
\;\;\;\;x \cdot x + z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original5.7
Target5.7
Herbie0.1
\[x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right) \]

Derivation

  1. Split input into 2 regimes
  2. if (*.f64 z z) < 1e308

    1. Initial program 0.1

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]

    if 1e308 < (*.f64 z z)

    1. Initial program 63.9

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Applied egg-rr64.0

      \[\leadsto x \cdot x - \color{blue}{e^{\log \left(4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)\right)}} \]
    3. Taylor expanded in z around inf 63.9

      \[\leadsto x \cdot x - \color{blue}{4 \cdot \left(y \cdot {z}^{2}\right)} \]
    4. Simplified0.2

      \[\leadsto x \cdot x - \color{blue}{z \cdot \left(z \cdot \left(y \cdot 4\right)\right)} \]
      Proof
      (*.f64 z (*.f64 z (*.f64 y 4))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (*.f64 z (Rewrite<= *-commutative_binary64 (*.f64 4 y)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (*.f64 4 y))): 46 points increase in error, 29 points decrease in error
      (*.f64 (Rewrite<= unpow2_binary64 (pow.f64 z 2)) (*.f64 4 y)): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 (*.f64 4 y) (pow.f64 z 2))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*r*_binary64 (*.f64 4 (*.f64 y (pow.f64 z 2)))): 3 points increase in error, 0 points decrease in error
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot z \leq 10^{+308}:\\ \;\;\;\;x \cdot x - \left(y \cdot -4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.1
Cost7360
\[x \cdot x - \mathsf{fma}\left(t, y \cdot -4, z \cdot \left(\left(y \cdot 4\right) \cdot z\right)\right) \]
Alternative 2
Error27.7
Cost1372
\[\begin{array}{l} t_1 := t \cdot \left(y \cdot 4\right)\\ t_2 := z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\ \mathbf{if}\;z \leq -7.18487229094804 \cdot 10^{-10}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.6735081816373794 \cdot 10^{-169}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq -5.248800862034127 \cdot 10^{-261}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 6.639253109185855 \cdot 10^{-130}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 4.3712480282106345 \cdot 10^{-75}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;z \leq 4.180596071835353 \cdot 10^{-20}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 7.182813924607119 \cdot 10^{+20}:\\ \;\;\;\;x \cdot x\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error0.1
Cost1088
\[\left(x \cdot x + z \cdot \left(y \cdot \left(z \cdot -4\right)\right)\right) + y \cdot \left(t \cdot 4\right) \]
Alternative 4
Error6.0
Cost968
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\ \mathbf{if}\;z \leq -7.18487229094804 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.08064050857052041:\\ \;\;\;\;x \cdot x + y \cdot \left(t \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 5
Error10.1
Cost840
\[\begin{array}{l} t_1 := z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\ \mathbf{if}\;z \leq -716197483952.5151:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+57}:\\ \;\;\;\;x \cdot x + 4 \cdot \left(t \cdot y\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error10.1
Cost840
\[\begin{array}{l} t_1 := z \cdot \left(\left(y \cdot -4\right) \cdot z\right)\\ \mathbf{if}\;z \leq -716197483952.5151:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 2.7 \cdot 10^{+57}:\\ \;\;\;\;x \cdot x + y \cdot \left(t \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error25.8
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -8.394689161373312 \cdot 10^{+23}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 0.00018207125022657775:\\ \;\;\;\;t \cdot \left(y \cdot 4\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 8
Error41.5
Cost192
\[x \cdot x \]

Error

Reproduce

herbie shell --seed 2022291 
(FPCore (x y z t)
  :name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
  :precision binary64

  :herbie-target
  (- (* x x) (* 4.0 (* y (- (* z z) t))))

  (- (* x x) (* (* y 4.0) (- (* z z) t))))