Average Error: 5.9 → 0.1
Time: 10.9s
Precision: binary64
Cost: 7360
\[x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right) \]
\[x \cdot x - \mathsf{fma}\left(z \cdot \left(y \cdot 4\right), z, \left(y \cdot -4\right) \cdot t\right) \]
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
(FPCore (x y z t)
 :precision binary64
 (- (* x x) (fma (* z (* y 4.0)) z (* (* y -4.0) t))))
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) {
	return (x * x) - fma((z * (y * 4.0)), z, ((y * -4.0) * t));
}
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)
	return Float64(Float64(x * x) - fma(Float64(z * Float64(y * 4.0)), z, Float64(Float64(y * -4.0) * t)))
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_] := N[(N[(x * x), $MachinePrecision] - N[(N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision] * z + N[(N[(y * -4.0), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
x \cdot x - \mathsf{fma}\left(z \cdot \left(y \cdot 4\right), z, \left(y \cdot -4\right) \cdot t\right)

Error

Target

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

Derivation

  1. Initial program 5.9

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

    \[\leadsto x \cdot x - \color{blue}{\left(\left(z \cdot z\right) \cdot \left(y \cdot 4\right) + \left(-t\right) \cdot \left(y \cdot 4\right)\right)} \]
  3. Applied egg-rr0.1

    \[\leadsto x \cdot x - \color{blue}{\mathsf{fma}\left(z \cdot \left(y \cdot 4\right), z, \left(-y \cdot 4\right) \cdot t\right)} \]
  4. Final simplification0.1

    \[\leadsto x \cdot x - \mathsf{fma}\left(z \cdot \left(y \cdot 4\right), z, \left(y \cdot -4\right) \cdot t\right) \]

Alternatives

Alternative 1
Error0.1
Cost7360
\[\mathsf{fma}\left(y \cdot 4, t, x \cdot x + z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\right) \]
Alternative 2
Error26.4
Cost2008
\[\begin{array}{l} t_1 := -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ t_2 := \left(y \cdot 4\right) \cdot t\\ \mathbf{if}\;x \cdot x \leq 4.3 \cdot 10^{-229}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 7 \cdot 10^{-171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 2.3 \cdot 10^{-130}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \cdot x \leq 6 \cdot 10^{-81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 6.2 \cdot 10^{-60}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \cdot x \leq 7 \cdot 10^{-38}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 3
Error15.5
Cost1356
\[\begin{array}{l} t_1 := y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\ \mathbf{if}\;x \cdot x \leq 1.95 \cdot 10^{-41}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \cdot x \leq 1.7 \cdot 10^{+24}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \cdot x \leq 6.2 \cdot 10^{+65}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 4
Error8.1
Cost1232
\[\begin{array}{l} t_1 := 4 \cdot \left(y \cdot t - y \cdot \left(z \cdot z\right)\right)\\ t_2 := -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -4.5 \cdot 10^{+151}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.25 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.026:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot t\\ \mathbf{elif}\;z \leq 1.32 \cdot 10^{+154}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 5
Error8.1
Cost1104
\[\begin{array}{l} t_1 := y \cdot \left(4 \cdot \left(t - z \cdot z\right)\right)\\ t_2 := -4 \cdot \left(z \cdot \left(z \cdot y\right)\right)\\ \mathbf{if}\;z \leq -1 \cdot 10^{+151}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;z \leq -2.2 \cdot 10^{-33}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 0.039:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot t\\ \mathbf{elif}\;z \leq 6 \cdot 10^{+153}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error0.1
Cost1092
\[\begin{array}{l} \mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+285}:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\ \end{array} \]
Alternative 7
Error0.1
Cost1088
\[x \cdot x + \left(y \cdot \left(4 \cdot t\right) - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\right) \]
Alternative 8
Error6.6
Cost968
\[\begin{array}{l} t_1 := x \cdot x + z \cdot \left(\left(z \cdot y\right) \cdot -4\right)\\ \mathbf{if}\;z \leq -6.5 \cdot 10^{-34}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1350000000:\\ \;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error26.1
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{+22}:\\ \;\;\;\;x \cdot x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{-61}:\\ \;\;\;\;\left(y \cdot 4\right) \cdot t\\ \mathbf{else}:\\ \;\;\;\;x \cdot x\\ \end{array} \]
Alternative 10
Error41.5
Cost192
\[x \cdot x \]

Error

Reproduce

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