
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
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
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - 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]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (- (* x x) (* (* y 4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
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
public static double code(double x, double y, double z, double t) {
return (x * x) - ((y * 4.0) * ((z * z) - t));
}
def code(x, y, z, t): return (x * x) - ((y * 4.0) * ((z * z) - t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(Float64(y * 4.0) * Float64(Float64(z * z) - t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - ((y * 4.0) * ((z * z) - 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]
\begin{array}{l}
\\
x \cdot x - \left(y \cdot 4\right) \cdot \left(z \cdot z - t\right)
\end{array}
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 2e+289) (- (* x x) (* (* y 4.0) (fma z z (- t)))) (* (* x x) (+ (* (* y -4.0) (pow (/ z x) 2.0)) 1.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 2e+289) {
tmp = (x * x) - ((y * 4.0) * fma(z, z, -t));
} else {
tmp = (x * x) * (((y * -4.0) * pow((z / x), 2.0)) + 1.0);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 2e+289) tmp = Float64(Float64(x * x) - Float64(Float64(y * 4.0) * fma(z, z, Float64(-t)))); else tmp = Float64(Float64(x * x) * Float64(Float64(Float64(y * -4.0) * (Float64(z / x) ^ 2.0)) + 1.0)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 2e+289], N[(N[(x * x), $MachinePrecision] - N[(N[(y * 4.0), $MachinePrecision] * N[(z * z + (-t)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(N[(N[(y * -4.0), $MachinePrecision] * N[Power[N[(z / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 2 \cdot 10^{+289}:\\
\;\;\;\;x \cdot x - \left(y \cdot 4\right) \cdot \mathsf{fma}\left(z, z, -t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \left(\left(y \cdot -4\right) \cdot {\left(\frac{z}{x}\right)}^{2} + 1\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 2.0000000000000001e289Initial program 93.0%
fma-neg93.1%
Applied egg-rr93.1%
if 2.0000000000000001e289 < (*.f64 x x) Initial program 87.5%
fma-neg92.2%
distribute-lft-neg-in92.2%
*-commutative92.2%
distribute-rgt-neg-in92.2%
metadata-eval92.2%
Simplified92.2%
Taylor expanded in x around inf 62.5%
associate-/l*73.4%
Simplified73.4%
Applied egg-rr62.5%
associate-/l*73.4%
neg-mul-173.4%
times-frac73.4%
metadata-eval73.4%
rem-square-sqrt48.4%
fma-undefine48.4%
rem-square-sqrt35.9%
hypot-undefine35.9%
fma-undefine35.9%
rem-square-sqrt35.9%
hypot-undefine35.9%
unpow235.9%
times-frac45.3%
unpow245.3%
associate-*r*45.3%
Simplified45.3%
Taylor expanded in z around inf 98.4%
pow298.4%
Applied egg-rr98.4%
Final simplification94.4%
(FPCore (x y z t) :precision binary64 (fma x x (* (* y -4.0) (- (* z z) t))))
double code(double x, double y, double z, double t) {
return fma(x, x, ((y * -4.0) * ((z * z) - t)));
}
function code(x, y, z, t) return fma(x, x, Float64(Float64(y * -4.0) * Float64(Float64(z * z) - t))) end
code[x_, y_, z_, t_] := N[(x * x + N[(N[(y * -4.0), $MachinePrecision] * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, \left(y \cdot -4\right) \cdot \left(z \cdot z - t\right)\right)
\end{array}
Initial program 91.7%
fma-neg92.8%
distribute-lft-neg-in92.8%
*-commutative92.8%
distribute-rgt-neg-in92.8%
metadata-eval92.8%
Simplified92.8%
Final simplification92.8%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 8.5e+291) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* y (* t -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 8.5e+291) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (y * (t * -4.0));
}
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
real(8) :: tmp
if ((x * x) <= 8.5d+291) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (y * (t * (-4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 8.5e+291) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 8.5e+291: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (y * (t * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 8.5e+291) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 8.5e+291) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (y * (t * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 8.5e+291], 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[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 8.5 \cdot 10^{+291}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 8.5000000000000003e291Initial program 93.1%
if 8.5000000000000003e291 < (*.f64 x x) Initial program 87.3%
Taylor expanded in z around 0 93.9%
*-commutative93.9%
*-commutative93.9%
associate-*l*93.9%
Simplified93.9%
Final simplification93.3%
(FPCore (x y z t) :precision binary64 (if (<= z 3.7e+65) (- (* x x) (* y (* t -4.0))) (* (* y -4.0) (* z z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.7e+65) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (y * -4.0) * (z * 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
real(8) :: tmp
if (z <= 3.7d+65) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (y * (-4.0d0)) * (z * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.7e+65) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (y * -4.0) * (z * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 3.7e+65: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (y * -4.0) * (z * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 3.7e+65) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(y * -4.0) * Float64(z * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 3.7e+65) tmp = (x * x) - (y * (t * -4.0)); else tmp = (y * -4.0) * (z * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.7e+65], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * -4.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.7 \cdot 10^{+65}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if z < 3.69999999999999995e65Initial program 94.0%
Taylor expanded in z around 0 72.8%
*-commutative72.8%
*-commutative72.8%
associate-*l*72.8%
Simplified72.8%
if 3.69999999999999995e65 < z Initial program 81.0%
fma-neg83.2%
distribute-lft-neg-in83.2%
*-commutative83.2%
distribute-rgt-neg-in83.2%
metadata-eval83.2%
Simplified83.2%
Taylor expanded in z around inf 72.3%
associate-*r*72.3%
*-commutative72.3%
*-commutative72.3%
Simplified72.3%
pow272.3%
Applied egg-rr72.3%
Final simplification72.7%
(FPCore (x y z t) :precision binary64 (if (<= z 2100000.0) (* 4.0 (* y t)) (* (* y -4.0) (* z z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2100000.0) {
tmp = 4.0 * (y * t);
} else {
tmp = (y * -4.0) * (z * 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
real(8) :: tmp
if (z <= 2100000.0d0) then
tmp = 4.0d0 * (y * t)
else
tmp = (y * (-4.0d0)) * (z * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2100000.0) {
tmp = 4.0 * (y * t);
} else {
tmp = (y * -4.0) * (z * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 2100000.0: tmp = 4.0 * (y * t) else: tmp = (y * -4.0) * (z * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 2100000.0) tmp = Float64(4.0 * Float64(y * t)); else tmp = Float64(Float64(y * -4.0) * Float64(z * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 2100000.0) tmp = 4.0 * (y * t); else tmp = (y * -4.0) * (z * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 2100000.0], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(N[(y * -4.0), $MachinePrecision] * N[(z * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2100000:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -4\right) \cdot \left(z \cdot z\right)\\
\end{array}
\end{array}
if z < 2.1e6Initial program 93.7%
fma-neg94.7%
distribute-lft-neg-in94.7%
*-commutative94.7%
distribute-rgt-neg-in94.7%
metadata-eval94.7%
Simplified94.7%
Taylor expanded in t around inf 35.2%
*-commutative35.2%
Simplified35.2%
if 2.1e6 < z Initial program 84.6%
fma-neg86.4%
distribute-lft-neg-in86.4%
*-commutative86.4%
distribute-rgt-neg-in86.4%
metadata-eval86.4%
Simplified86.4%
Taylor expanded in z around inf 63.8%
associate-*r*63.8%
*-commutative63.8%
*-commutative63.8%
Simplified63.8%
pow263.8%
Applied egg-rr63.8%
Final simplification41.5%
(FPCore (x y z t) :precision binary64 (* 4.0 (* y t)))
double code(double x, double y, double z, double t) {
return 4.0 * (y * t);
}
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 = 4.0d0 * (y * t)
end function
public static double code(double x, double y, double z, double t) {
return 4.0 * (y * t);
}
def code(x, y, z, t): return 4.0 * (y * t)
function code(x, y, z, t) return Float64(4.0 * Float64(y * t)) end
function tmp = code(x, y, z, t) tmp = 4.0 * (y * t); end
code[x_, y_, z_, t_] := N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(y \cdot t\right)
\end{array}
Initial program 91.7%
fma-neg92.8%
distribute-lft-neg-in92.8%
*-commutative92.8%
distribute-rgt-neg-in92.8%
metadata-eval92.8%
Simplified92.8%
Taylor expanded in t around inf 31.7%
*-commutative31.7%
Simplified31.7%
(FPCore (x y z t) :precision binary64 (- (* x x) (* 4.0 (* y (- (* z z) t)))))
double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
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) - (4.0d0 * (y * ((z * z) - t)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (4.0 * (y * ((z * z) - t)));
}
def code(x, y, z, t): return (x * x) - (4.0 * (y * ((z * z) - t)))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(4.0 * Float64(y * Float64(Float64(z * z) - t)))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (4.0 * (y * ((z * z) - t))); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - 4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)
\end{array}
herbie shell --seed 2024146
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))