
(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 7 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 (<= (* z z) 1e+199) (fma x x (* -4.0 (* y (- (* z z) t)))) (fma (* (* -4.0 y) z) z (fma (* (- t) y) -4.0 (* x x)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+199) {
tmp = fma(x, x, (-4.0 * (y * ((z * z) - t))));
} else {
tmp = fma(((-4.0 * y) * z), z, fma((-t * y), -4.0, (x * x)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+199) tmp = fma(x, x, Float64(-4.0 * Float64(y * Float64(Float64(z * z) - t)))); else tmp = fma(Float64(Float64(-4.0 * y) * z), z, fma(Float64(Float64(-t) * y), -4.0, Float64(x * x))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+199], N[(x * x + N[(-4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-4.0 * y), $MachinePrecision] * z), $MachinePrecision] * z + N[(N[((-t) * y), $MachinePrecision] * -4.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+199}:\\
\;\;\;\;\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(-4 \cdot y\right) \cdot z, z, \mathsf{fma}\left(\left(-t\right) \cdot y, -4, x \cdot x\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e199Initial program 96.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
metadata-eval99.3
Applied rewrites99.3%
if 1.0000000000000001e199 < (*.f64 z z) Initial program 75.2%
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 rewrites94.5%
Final simplification97.6%
(FPCore (x y z t)
:precision binary64
(if (<= (* z z) 5e-112)
(fma (* 4.0 t) y (* x x))
(if (<= (* z z) 5e+291)
(fma x x (* (* y (* z z)) -4.0))
(* (* -4.0 z) (* y z)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e-112) {
tmp = fma((4.0 * t), y, (x * x));
} else if ((z * z) <= 5e+291) {
tmp = fma(x, x, ((y * (z * z)) * -4.0));
} else {
tmp = (-4.0 * z) * (y * z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e-112) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); elseif (Float64(z * z) <= 5e+291) tmp = fma(x, x, Float64(Float64(y * Float64(z * z)) * -4.0)); else tmp = Float64(Float64(-4.0 * z) * Float64(y * z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e-112], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 5e+291], N[(x * x + N[(N[(y * N[(z * z), $MachinePrecision]), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * z), $MachinePrecision] * N[(y * z), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-112}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{elif}\;z \cdot z \leq 5 \cdot 10^{+291}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(y \cdot \left(z \cdot z\right)\right) \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-4 \cdot z\right) \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.00000000000000044e-112Initial program 97.4%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6451.2
Applied rewrites51.2%
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-*.f6495.7
Applied rewrites95.7%
if 5.00000000000000044e-112 < (*.f64 z z) < 5.0000000000000001e291Initial program 96.9%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6489.3
Applied rewrites89.3%
Applied rewrites90.8%
if 5.0000000000000001e291 < (*.f64 z z) Initial program 68.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6470.2
Applied rewrites70.2%
Applied rewrites85.5%
Final simplification91.5%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 2e+212) (fma x x (* -4.0 (* y (- (* z z) t)))) (fma (* (* y z) z) -4.0 (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+212) {
tmp = fma(x, x, (-4.0 * (y * ((z * z) - t))));
} else {
tmp = fma(((y * z) * z), -4.0, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+212) tmp = fma(x, x, Float64(-4.0 * Float64(y * Float64(Float64(z * z) - t)))); else tmp = fma(Float64(Float64(y * z) * z), -4.0, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+212], N[(x * x + N[(-4.0 * N[(y * N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision] * -4.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+212}:\\
\;\;\;\;\mathsf{fma}\left(x, x, -4 \cdot \left(y \cdot \left(z \cdot z - t\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(y \cdot z\right) \cdot z, -4, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.9999999999999998e212Initial program 97.0%
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
metadata-eval99.3
Applied rewrites99.3%
if 1.9999999999999998e212 < (*.f64 z z) Initial program 73.8%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6473.8
Applied rewrites73.8%
Applied rewrites94.2%
Final simplification97.6%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e-112) (fma (* 4.0 t) y (* x x)) (fma (* (* y z) z) -4.0 (* x x))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e-112) {
tmp = fma((4.0 * t), y, (x * x));
} else {
tmp = fma(((y * z) * z), -4.0, (x * x));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e-112) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); else tmp = fma(Float64(Float64(y * z) * z), -4.0, Float64(x * x)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e-112], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(N[(y * z), $MachinePrecision] * z), $MachinePrecision] * -4.0 + N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{-112}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(y \cdot z\right) \cdot z, -4, x \cdot x\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.00000000000000044e-112Initial program 97.4%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6451.2
Applied rewrites51.2%
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-*.f6495.7
Applied rewrites95.7%
if 5.00000000000000044e-112 < (*.f64 z z) Initial program 82.3%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6478.7
Applied rewrites78.7%
Applied rewrites91.3%
Final simplification93.3%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e-8) (* (* 4.0 t) y) (* (* -4.0 z) (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e-8) {
tmp = (4.0 * t) * y;
} else {
tmp = (-4.0 * z) * (y * 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 * z) <= 1d-8) then
tmp = (4.0d0 * t) * y
else
tmp = ((-4.0d0) * z) * (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e-8) {
tmp = (4.0 * t) * y;
} else {
tmp = (-4.0 * z) * (y * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 1e-8: tmp = (4.0 * t) * y else: tmp = (-4.0 * z) * (y * z) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e-8) tmp = Float64(Float64(4.0 * t) * y); else tmp = Float64(Float64(-4.0 * z) * Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 1e-8) tmp = (4.0 * t) * y; else tmp = (-4.0 * z) * (y * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e-8], N[(N[(4.0 * t), $MachinePrecision] * y), $MachinePrecision], N[(N[(-4.0 * z), $MachinePrecision] * N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{-8}:\\
\;\;\;\;\left(4 \cdot t\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(-4 \cdot z\right) \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1e-8Initial program 97.6%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6449.3
Applied rewrites49.3%
Applied rewrites49.3%
if 1e-8 < (*.f64 z z) Initial program 80.5%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6460.8
Applied rewrites60.8%
Applied rewrites69.5%
Final simplification59.5%
(FPCore (x y z t) :precision binary64 (if (<= z 1.9e+81) (fma (* 4.0 t) y (* x x)) (* (* -4.0 z) (* y z))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1.9e+81) {
tmp = fma((4.0 * t), y, (x * x));
} else {
tmp = (-4.0 * z) * (y * z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 1.9e+81) tmp = fma(Float64(4.0 * t), y, Float64(x * x)); else tmp = Float64(Float64(-4.0 * z) * Float64(y * z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 1.9e+81], N[(N[(4.0 * t), $MachinePrecision] * y + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(-4.0 * z), $MachinePrecision] * N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 1.9 \cdot 10^{+81}:\\
\;\;\;\;\mathsf{fma}\left(4 \cdot t, y, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-4 \cdot z\right) \cdot \left(y \cdot z\right)\\
\end{array}
\end{array}
if z < 1.9e81Initial program 91.1%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6433.8
Applied rewrites33.8%
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-*.f6474.5
Applied rewrites74.5%
if 1.9e81 < z Initial program 79.9%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6469.7
Applied rewrites69.7%
Applied rewrites75.6%
Final simplification74.7%
(FPCore (x y z t) :precision binary64 (* (* 4.0 t) y))
double code(double x, double y, double z, double t) {
return (4.0 * t) * y;
}
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 * t) * y
end function
public static double code(double x, double y, double z, double t) {
return (4.0 * t) * y;
}
def code(x, y, z, t): return (4.0 * t) * y
function code(x, y, z, t) return Float64(Float64(4.0 * t) * y) end
function tmp = code(x, y, z, t) tmp = (4.0 * t) * y; end
code[x_, y_, z_, t_] := N[(N[(4.0 * t), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\left(4 \cdot t\right) \cdot y
\end{array}
Initial program 89.0%
Taylor expanded in t around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6429.0
Applied rewrites29.0%
Applied rewrites29.0%
Final simplification29.0%
(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 2024327
(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))))