
(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 8 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) t) 1e+290) (fma x x (* y (* (fma z z (- t)) -4.0))) (fma x x (* z (* y (* z -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (((z * z) - t) <= 1e+290) {
tmp = fma(x, x, (y * (fma(z, z, -t) * -4.0)));
} else {
tmp = fma(x, x, (z * (y * (z * -4.0))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(z * z) - t) <= 1e+290) tmp = fma(x, x, Float64(y * Float64(fma(z, z, Float64(-t)) * -4.0))); else tmp = fma(x, x, Float64(z * Float64(y * Float64(z * -4.0)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision], 1e+290], N[(x * x + N[(y * N[(N[(z * z + (-t)), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(z * N[(y * N[(z * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z - t \leq 10^{+290}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(\mathsf{fma}\left(z, z, -t\right) \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, z \cdot \left(y \cdot \left(z \cdot -4\right)\right)\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 z z) t) < 1.00000000000000006e290Initial program 97.7%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-neg.f64N/A
metadata-eval98.3
Applied rewrites98.3%
if 1.00000000000000006e290 < (-.f64 (*.f64 z z) t) Initial program 54.9%
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
*-commutativeN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lift--.f64N/A
sub-negN/A
lift-*.f64N/A
lower-fma.f64N/A
lower-neg.f64N/A
metadata-eval65.1
Applied rewrites65.1%
Applied rewrites83.4%
Taylor expanded in z around inf
unpow2N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f6494.8
Applied rewrites94.8%
Final simplification97.2%
(FPCore (x y z t)
:precision binary64
(if (<= (* z z) 1e+64)
(fma y (* t 4.0) (* x x))
(if (<= (* z z) 2e+301)
(fma y (* (* z z) -4.0) (* x x))
(* z (* z (* y -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+64) {
tmp = fma(y, (t * 4.0), (x * x));
} else if ((z * z) <= 2e+301) {
tmp = fma(y, ((z * z) * -4.0), (x * x));
} else {
tmp = z * (z * (y * -4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+64) tmp = fma(y, Float64(t * 4.0), Float64(x * x)); elseif (Float64(z * z) <= 2e+301) tmp = fma(y, Float64(Float64(z * z) * -4.0), Float64(x * x)); else tmp = Float64(z * Float64(z * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+64], N[(y * N[(t * 4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * z), $MachinePrecision], 2e+301], N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(z * N[(z * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+64}:\\
\;\;\;\;\mathsf{fma}\left(y, t \cdot 4, x \cdot x\right)\\
\mathbf{elif}\;z \cdot z \leq 2 \cdot 10^{+301}:\\
\;\;\;\;\mathsf{fma}\left(y, \left(z \cdot z\right) \cdot -4, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(z \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.00000000000000002e64Initial program 98.4%
Taylor expanded in z around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f6492.3
Applied rewrites92.3%
if 1.00000000000000002e64 < (*.f64 z z) < 2.00000000000000011e301Initial program 96.3%
Taylor expanded in t around 0
cancel-sign-sub-invN/A
metadata-evalN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6487.2
Applied rewrites87.2%
if 2.00000000000000011e301 < (*.f64 z z) Initial program 71.5%
Taylor expanded in z around inf
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6476.7
Applied rewrites76.7%
Applied rewrites88.5%
Final simplification90.3%
(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 2024223
(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))))