
(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 (<= (* y 4.0) 2e-293)
(fma (* y 4.0) (- t (* z z)) (* x x))
(if (<= (* y 4.0) 5e-37)
(- (* x x) (+ (* -4.0 (* y t)) (* 4.0 (pow (* z (sqrt y)) 2.0))))
(fma x x (* (- (* z z) t) (* y -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y * 4.0) <= 2e-293) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else if ((y * 4.0) <= 5e-37) {
tmp = (x * x) - ((-4.0 * (y * t)) + (4.0 * pow((z * sqrt(y)), 2.0)));
} else {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(y * 4.0) <= 2e-293) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); elseif (Float64(y * 4.0) <= 5e-37) tmp = Float64(Float64(x * x) - Float64(Float64(-4.0 * Float64(y * t)) + Float64(4.0 * (Float64(z * sqrt(y)) ^ 2.0)))); else tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(y * 4.0), $MachinePrecision], 2e-293], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * 4.0), $MachinePrecision], 5e-37], 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], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot 4 \leq 2 \cdot 10^{-293}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{elif}\;y \cdot 4 \leq 5 \cdot 10^{-37}:\\
\;\;\;\;x \cdot x - \left(-4 \cdot \left(y \cdot t\right) + 4 \cdot {\left(z \cdot \sqrt{y}\right)}^{2}\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\end{array}
\end{array}
if (*.f64 y #s(literal 4 binary64)) < 2.0000000000000001e-293Initial program 95.0%
cancel-sign-sub-inv95.0%
distribute-lft-neg-out95.0%
+-commutative95.0%
distribute-lft-neg-out95.0%
distribute-lft-neg-in95.0%
distribute-rgt-neg-in95.0%
fma-define95.9%
sub-neg95.9%
+-commutative95.9%
distribute-neg-in95.9%
remove-double-neg95.9%
sub-neg95.9%
Simplified95.9%
if 2.0000000000000001e-293 < (*.f64 y #s(literal 4 binary64)) < 4.9999999999999997e-37Initial program 85.4%
Taylor expanded in z around 0 85.4%
pow285.4%
add-sqr-sqrt85.4%
pow285.4%
*-commutative85.4%
sqrt-prod85.4%
sqrt-prod59.5%
add-sqr-sqrt98.4%
Applied egg-rr98.4%
if 4.9999999999999997e-37 < (*.f64 y #s(literal 4 binary64)) Initial program 95.7%
fmm-def98.5%
distribute-lft-neg-in98.5%
*-commutative98.5%
distribute-rgt-neg-in98.5%
metadata-eval98.5%
Simplified98.5%
Final simplification97.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 92.5%
fmm-def93.7%
distribute-lft-neg-in93.7%
*-commutative93.7%
distribute-rgt-neg-in93.7%
metadata-eval93.7%
Simplified93.7%
(FPCore (x y z t) :precision binary64 (if (<= z 2.8e+95) (- (* x x) (* y (* t -4.0))) (* (* z z) (* y -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.8e+95) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z * z) * (y * -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 (z <= 2.8d+95) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (z * z) * (y * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.8e+95) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z * z) * (y * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 2.8e+95: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (z * z) * (y * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 2.8e+95) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(z * z) * Float64(y * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 2.8e+95) tmp = (x * x) - (y * (t * -4.0)); else tmp = (z * z) * (y * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 2.8e+95], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.8 \cdot 10^{+95}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 2.7999999999999998e95Initial program 95.4%
Taylor expanded in z around 0 72.5%
*-commutative72.5%
*-commutative72.5%
associate-*l*72.5%
Simplified72.5%
if 2.7999999999999998e95 < z Initial program 78.0%
fmm-def82.6%
distribute-lft-neg-in82.6%
*-commutative82.6%
distribute-rgt-neg-in82.6%
metadata-eval82.6%
Simplified82.6%
Taylor expanded in z around inf 80.4%
associate-*r*80.4%
*-commutative80.4%
*-commutative80.4%
Simplified80.4%
unpow280.4%
Applied egg-rr80.4%
(FPCore (x y z t) :precision binary64 (+ (* x x) (* (* y 4.0) (- t (* z z)))))
double code(double x, double y, double z, double t) {
return (x * x) + ((y * 4.0) * (t - (z * z)));
}
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) * (t - (z * z)))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) + ((y * 4.0) * (t - (z * z)));
}
def code(x, y, z, t): return (x * x) + ((y * 4.0) * (t - (z * z)))
function code(x, y, z, t) return Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))) end
function tmp = code(x, y, z, t) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)
\end{array}
Initial program 92.5%
Final simplification92.5%
(FPCore (x y z t) :precision binary64 (if (<= z 3.4e-19) (* 4.0 (* y t)) (* (* z z) (* y -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.4e-19) {
tmp = 4.0 * (y * t);
} else {
tmp = (z * z) * (y * -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 (z <= 3.4d-19) then
tmp = 4.0d0 * (y * t)
else
tmp = (z * z) * (y * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.4e-19) {
tmp = 4.0 * (y * t);
} else {
tmp = (z * z) * (y * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 3.4e-19: tmp = 4.0 * (y * t) else: tmp = (z * z) * (y * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 3.4e-19) tmp = Float64(4.0 * Float64(y * t)); else tmp = Float64(Float64(z * z) * Float64(y * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 3.4e-19) tmp = 4.0 * (y * t); else tmp = (z * z) * (y * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.4e-19], N[(4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.4 \cdot 10^{-19}:\\
\;\;\;\;4 \cdot \left(y \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 3.4000000000000002e-19Initial program 95.1%
fmm-def95.7%
distribute-lft-neg-in95.7%
*-commutative95.7%
distribute-rgt-neg-in95.7%
metadata-eval95.7%
Simplified95.7%
Taylor expanded in t around inf 34.6%
*-commutative34.6%
Simplified34.6%
if 3.4000000000000002e-19 < z Initial program 86.4%
fmm-def89.0%
distribute-lft-neg-in89.0%
*-commutative89.0%
distribute-rgt-neg-in89.0%
metadata-eval89.0%
Simplified89.0%
Taylor expanded in z around inf 64.4%
associate-*r*64.4%
*-commutative64.4%
*-commutative64.4%
Simplified64.4%
unpow264.4%
Applied egg-rr64.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 92.5%
fmm-def93.7%
distribute-lft-neg-in93.7%
*-commutative93.7%
distribute-rgt-neg-in93.7%
metadata-eval93.7%
Simplified93.7%
Taylor expanded in t around inf 26.8%
*-commutative26.8%
Simplified26.8%
(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 2024157
(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))))