
(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 (or (<= (* y 4.0) -2e-298) (not (<= (* y 4.0) 4e-73))) (fma x x (* (- (* z z) t) (* y -4.0))) (- (* x x) (+ (* -4.0 (* y t)) (* 4.0 (pow (* z (sqrt y)) 2.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (((y * 4.0) <= -2e-298) || !((y * 4.0) <= 4e-73)) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x * x) - ((-4.0 * (y * t)) + (4.0 * pow((z * sqrt(y)), 2.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if ((Float64(y * 4.0) <= -2e-298) || !(Float64(y * 4.0) <= 4e-73)) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x * x) - Float64(Float64(-4.0 * Float64(y * t)) + Float64(4.0 * (Float64(z * sqrt(y)) ^ 2.0)))); end return tmp end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(y * 4.0), $MachinePrecision], -2e-298], N[Not[LessEqual[N[(y * 4.0), $MachinePrecision], 4e-73]], $MachinePrecision]], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(-4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[Power[N[(z * N[Sqrt[y], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot 4 \leq -2 \cdot 10^{-298} \lor \neg \left(y \cdot 4 \leq 4 \cdot 10^{-73}\right):\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(-4 \cdot \left(y \cdot t\right) + 4 \cdot {\left(z \cdot \sqrt{y}\right)}^{2}\right)\\
\end{array}
\end{array}
if (*.f64 y 4) < -1.99999999999999982e-298 or 3.99999999999999999e-73 < (*.f64 y 4) Initial program 90.1%
fma-neg93.2%
distribute-lft-neg-in93.2%
*-commutative93.2%
distribute-rgt-neg-in93.2%
metadata-eval93.2%
Simplified93.2%
if -1.99999999999999982e-298 < (*.f64 y 4) < 3.99999999999999999e-73Initial program 82.6%
Taylor expanded in z around 0 82.6%
add-sqr-sqrt82.6%
pow282.6%
*-commutative82.6%
sqrt-prod82.6%
unpow282.6%
sqrt-prod44.9%
add-sqr-sqrt98.1%
Applied egg-rr98.1%
Final simplification94.3%
(FPCore (x y z t) :precision binary64 (fma x x (* (- (* z z) t) (* y -4.0))))
double code(double x, double y, double z, double t) {
return fma(x, x, (((z * z) - t) * (y * -4.0)));
}
function code(x, y, z, t) return fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))) end
code[x_, y_, z_, t_] := N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)
\end{array}
Initial program 88.4%
fma-neg90.7%
distribute-lft-neg-in90.7%
*-commutative90.7%
distribute-rgt-neg-in90.7%
metadata-eval90.7%
Simplified90.7%
Final simplification90.7%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 4e+268) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (pow x 2.0)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 4e+268) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = pow(x, 2.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) <= 4d+268) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = x ** 2.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 4e+268) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = Math.pow(x, 2.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 4e+268: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = math.pow(x, 2.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 4e+268) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = x ^ 2.0; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 4e+268) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = x ^ 2.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 4e+268], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x, 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4 \cdot 10^{+268}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2}\\
\end{array}
\end{array}
if (*.f64 x x) < 3.9999999999999999e268Initial program 91.7%
if 3.9999999999999999e268 < (*.f64 x x) Initial program 78.8%
Taylor expanded in x around inf 89.6%
Final simplification91.1%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 5e+306) (+ (* 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) <= 5e+306) {
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) <= 5d+306) 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) <= 5e+306) {
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) <= 5e+306: 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) <= 5e+306) 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) <= 5e+306) 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], 5e+306], 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 5 \cdot 10^{+306}:\\
\;\;\;\;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) < 4.99999999999999993e306Initial program 91.6%
if 4.99999999999999993e306 < (*.f64 x x) Initial program 77.2%
Taylor expanded in z around 0 86.0%
*-commutative86.0%
*-commutative86.0%
associate-*l*86.0%
Simplified86.0%
Final simplification90.3%
(FPCore (x y z t) :precision binary64 (- (* x x) (* y (* t -4.0))))
double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
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 * (t * (-4.0d0)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (y * (t * -4.0));
}
def code(x, y, z, t): return (x * x) - (y * (t * -4.0))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (y * (t * -4.0)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 88.4%
Taylor expanded in z around 0 61.4%
*-commutative61.4%
*-commutative61.4%
associate-*l*61.4%
Simplified61.4%
Final simplification61.4%
(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 88.4%
Taylor expanded in t around inf 33.4%
*-commutative33.4%
Simplified33.4%
Final simplification33.4%
(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 2024020
(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))))