
(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 11 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 (<= (* 4.0 y) 2e-18) (fma (* z (* -4.0 y)) z (fma (* (- -4.0) t) y (* x x))) (fma x x (* (* (fma z z (- t)) y) -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if ((4.0 * y) <= 2e-18) {
tmp = fma((z * (-4.0 * y)), z, fma((-(-4.0) * t), y, (x * x)));
} else {
tmp = fma(x, x, ((fma(z, z, -t) * y) * -4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(4.0 * y) <= 2e-18) tmp = fma(Float64(z * Float64(-4.0 * y)), z, fma(Float64(Float64(-(-4.0)) * t), y, Float64(x * x))); else tmp = fma(x, x, Float64(Float64(fma(z, z, Float64(-t)) * y) * -4.0)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(4.0 * y), $MachinePrecision], 2e-18], N[(N[(z * N[(-4.0 * y), $MachinePrecision]), $MachinePrecision] * z + N[(N[((--4.0) * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(N[(N[(z * z + (-t)), $MachinePrecision] * y), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;4 \cdot y \leq 2 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(z \cdot \left(-4 \cdot y\right), z, \mathsf{fma}\left(\left(--4\right) \cdot t, y, x \cdot x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(\mathsf{fma}\left(z, z, -t\right) \cdot y\right) \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 y #s(literal 4 binary64)) < 2.0000000000000001e-18Initial program 91.8%
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
lift--.f64N/A
sub-negN/A
distribute-lft-inN/A
associate-+l+N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lift-*.f64N/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
metadata-evalN/A
Applied rewrites99.4%
if 2.0000000000000001e-18 < (*.f64 y #s(literal 4 binary64)) Initial program 83.9%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-neg.f64N/A
metadata-eval95.6
Applied rewrites95.6%
Final simplification98.4%
(FPCore (x y z t)
:precision binary64
(if (<= (* z z) 1e+14)
(fma (* t 4.0) y (* x x))
(if (<= (* z z) 1e+275)
(fma (* (* z z) -4.0) y (* x x))
(* (* (* z y) -4.0) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+14) {
tmp = fma((t * 4.0), y, (x * x));
} else if ((z * z) <= 1e+275) {
tmp = fma(((z * z) * -4.0), y, (x * x));
} else {
tmp = ((z * y) * -4.0) * z;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+14) tmp = fma(Float64(t * 4.0), y, Float64(x * x)); elseif (Float64(z * z) <= 1e+275) tmp = fma(Float64(Float64(z * z) * -4.0), y, Float64(x * x)); else tmp = Float64(Float64(Float64(z * y) * -4.0) * z); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+14], N[(N[(t * 4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 1e+275], N[(N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] * -4.0), $MachinePrecision] * z), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+14}:\\
\;\;\;\;\mathsf{fma}\left(t \cdot 4, y, x \cdot x\right)\\
\mathbf{elif}\;z \cdot z \leq 10^{+275}:\\
\;\;\;\;\mathsf{fma}\left(\left(z \cdot z\right) \cdot -4, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(z \cdot y\right) \cdot -4\right) \cdot z\\
\end{array}
\end{array}
if (*.f64 z z) < 1e14Initial program 98.6%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6494.5
Applied rewrites94.5%
if 1e14 < (*.f64 z z) < 9.9999999999999996e274Initial program 96.6%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6483.4
Applied rewrites83.4%
if 9.9999999999999996e274 < (*.f64 z z) Initial program 72.6%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6421.9
Applied rewrites21.9%
Taylor expanded in z around inf
unpow2N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6488.9
Applied rewrites88.9%
Final simplification90.6%
(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 2024230
(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))))