Average Error: 6.2 → 0.3
Time: 6.0s
Precision: binary64
Cost: 1096
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -6.8 \cdot 10^{+104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.2 \cdot 10^{+154}:\\ \;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (+ (* x x) (* z (* z (* y -4.0))))))
   (if (<= z -6.8e+104)
     t_1
     (if (<= z 1.2e+154) (+ (* x x) (* (- (* z z) t) (* y -4.0))) t_1))))
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 t_1 = (x * x) + (z * (z * (y * -4.0)));
	double tmp;
	if (z <= -6.8e+104) {
		tmp = t_1;
	} else if (z <= 1.2e+154) {
		tmp = (x * x) + (((z * z) - t) * (y * -4.0));
	} else {
		tmp = t_1;
	}
	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) :: t_1
    real(8) :: tmp
    t_1 = (x * x) + (z * (z * (y * (-4.0d0))))
    if (z <= (-6.8d+104)) then
        tmp = t_1
    else if (z <= 1.2d+154) then
        tmp = (x * x) + (((z * z) - t) * (y * (-4.0d0)))
    else
        tmp = t_1
    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 t_1 = (x * x) + (z * (z * (y * -4.0)));
	double tmp;
	if (z <= -6.8e+104) {
		tmp = t_1;
	} else if (z <= 1.2e+154) {
		tmp = (x * x) + (((z * z) - t) * (y * -4.0));
	} else {
		tmp = t_1;
	}
	return tmp;
}
def code(x, y, z, t):
	return (x * x) - ((y * 4.0) * ((z * z) - t))
def code(x, y, z, t):
	t_1 = (x * x) + (z * (z * (y * -4.0)))
	tmp = 0
	if z <= -6.8e+104:
		tmp = t_1
	elif z <= 1.2e+154:
		tmp = (x * x) + (((z * z) - t) * (y * -4.0))
	else:
		tmp = t_1
	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)
	t_1 = Float64(Float64(x * x) + Float64(z * Float64(z * Float64(y * -4.0))))
	tmp = 0.0
	if (z <= -6.8e+104)
		tmp = t_1;
	elseif (z <= 1.2e+154)
		tmp = Float64(Float64(x * x) + Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0)));
	else
		tmp = t_1;
	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)
	t_1 = (x * x) + (z * (z * (y * -4.0)));
	tmp = 0.0;
	if (z <= -6.8e+104)
		tmp = t_1;
	elseif (z <= 1.2e+154)
		tmp = (x * x) + (((z * z) - t) * (y * -4.0));
	else
		tmp = t_1;
	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_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.8e+104], t$95$1, If[LessEqual[z, 1.2e+154], N[(N[(x * x), $MachinePrecision] + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\begin{array}{l}
t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\mathbf{if}\;z \leq -6.8 \cdot 10^{+104}:\\
\;\;\;\;t_1\\

\mathbf{elif}\;z \leq 1.2 \cdot 10^{+154}:\\
\;\;\;\;x \cdot x + \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\\

\mathbf{else}:\\
\;\;\;\;t_1\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.2
Target6.2
Herbie0.3
\[x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right) \]

Derivation

  1. Split input into 2 regimes
  2. if z < -6.7999999999999994e104 or 1.20000000000000007e154 < z

    1. Initial program 45.7

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
    2. Taylor expanded in z around inf 47.1

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

      \[\leadsto x \cdot x - \color{blue}{z \cdot \left(z \cdot \left(4 \cdot y\right)\right)} \]
      Proof
      (*.f64 z (*.f64 z (*.f64 4 y))): 0 points increase in error, 0 points decrease in error
      (*.f64 z (*.f64 z (Rewrite<= *-commutative_binary64 (*.f64 y 4)))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-*l*_binary64 (*.f64 (*.f64 z z) (*.f64 y 4))): 71 points increase in error, 26 points decrease in error
      (Rewrite=> associate-*r*_binary64 (*.f64 (*.f64 (*.f64 z z) y) 4)): 1 points increase in error, 1 points decrease in error
      (*.f64 (Rewrite<= *-commutative_binary64 (*.f64 y (*.f64 z z))) 4): 0 points increase in error, 0 points decrease in error
      (*.f64 (*.f64 y (Rewrite<= unpow2_binary64 (pow.f64 z 2))) 4): 0 points increase in error, 0 points decrease in error
      (Rewrite<= *-commutative_binary64 (*.f64 4 (*.f64 y (pow.f64 z 2)))): 0 points increase in error, 0 points decrease in error

    if -6.7999999999999994e104 < z < 1.20000000000000007e154

    1. Initial program 0.1

      \[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.3

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

Alternatives

Alternative 1
Error12.6
Cost1224
\[\begin{array}{l} t_1 := x \cdot x + \left(4 \cdot y\right) \cdot t\\ \mathbf{if}\;z \cdot z \leq 2.8 \cdot 10^{-21}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot z \leq 1.26 \cdot 10^{+280}:\\ \;\;\;\;x \cdot x - y \cdot \left(4 \cdot \left(z \cdot z\right)\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error6.4
Cost968
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\ \mathbf{if}\;z \leq -2.12 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 125000000000:\\ \;\;\;\;x \cdot x + \left(4 \cdot y\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error18.0
Cost576
\[x \cdot x + \left(4 \cdot y\right) \cdot t \]

Error

Reproduce

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