
(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) 1.25e+308) (fma (* y 4.0) (- t (* z z)) (* x x)) (pow (* (* (pow (cbrt z) 2.0) (cbrt y)) (cbrt -4.0)) 3.0)))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1.25e+308) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = pow(((pow(cbrt(z), 2.0) * cbrt(y)) * cbrt(-4.0)), 3.0);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1.25e+308) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(Float64((cbrt(z) ^ 2.0) * cbrt(y)) * cbrt(-4.0)) ^ 3.0; end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1.25e+308], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[Power[N[(N[(N[Power[N[Power[z, 1/3], $MachinePrecision], 2.0], $MachinePrecision] * N[Power[y, 1/3], $MachinePrecision]), $MachinePrecision] * N[Power[-4.0, 1/3], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 1.25 \cdot 10^{+308}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left({\left(\sqrt[3]{z}\right)}^{2} \cdot \sqrt[3]{y}\right) \cdot \sqrt[3]{-4}\right)}^{3}\\
\end{array}
\end{array}
if (*.f64 z z) < 1.25e308Initial program 98.4%
cancel-sign-sub-inv98.4%
distribute-lft-neg-out98.4%
+-commutative98.4%
associate-*l*97.9%
distribute-lft-neg-in97.9%
associate-*l*98.4%
distribute-rgt-neg-in98.4%
fma-define99.4%
sub-neg99.4%
+-commutative99.4%
distribute-neg-in99.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
if 1.25e308 < (*.f64 z z) Initial program 66.2%
fma-neg74.6%
*-commutative74.6%
distribute-rgt-neg-in74.6%
distribute-rgt-neg-in74.6%
metadata-eval74.6%
add-cube-cbrt74.6%
pow374.6%
Applied egg-rr74.6%
Taylor expanded in z around inf 74.6%
*-commutative74.6%
cbrt-prod74.6%
unpow274.6%
cbrt-prod89.6%
pow289.6%
Applied egg-rr89.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (* (* y -4.0) (pow z 2.0)))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (y * -4.0) * pow(z, 2.0);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (y * -4.0) * Math.pow(z, 2.0);
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * x) + ((y * 4.0) * (t - (z * z))) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (y * -4.0) * math.pow(z, 2.0) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(y * -4.0) * (z ^ 2.0)); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * x) + ((y * 4.0) * (t - (z * z))); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (y * -4.0) * (z ^ 2.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(y * -4.0), $MachinePrecision] * N[Power[z, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\left(y \cdot -4\right) \cdot {z}^{2}\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 95.0%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
Taylor expanded in z around inf 54.5%
associate-*r*54.5%
*-commutative54.5%
*-commutative54.5%
Simplified54.5%
Final simplification93.3%
(FPCore (x y z t) :precision binary64 (if (<= x 6.6e+153) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (fma x x (* y (* t (- -4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 6.6e+153) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = fma(x, x, (y * (t * -(-4.0))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= 6.6e+153) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = fma(x, x, Float64(y * Float64(t * Float64(-(-4.0))))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, 6.6e+153], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * x + N[(y * N[(t * (--4.0)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 6.6 \cdot 10^{+153}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(t \cdot \left(--4\right)\right)\right)\\
\end{array}
\end{array}
if x < 6.59999999999999989e153Initial program 91.9%
if 6.59999999999999989e153 < x Initial program 84.4%
Taylor expanded in z around 0 90.6%
*-commutative90.6%
*-commutative90.6%
associate-*l*90.6%
Simplified90.6%
cancel-sign-sub-inv90.6%
fma-define93.8%
Applied egg-rr93.8%
Final simplification92.1%
(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 91.0%
fma-neg93.3%
distribute-lft-neg-in93.3%
*-commutative93.3%
distribute-rgt-neg-in93.3%
metadata-eval93.3%
Simplified93.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (- (* x x) (* y (* t -4.0))))))
double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= ((double) INFINITY)) {
tmp = t_1;
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
double t_1 = (x * x) + ((y * 4.0) * (t - (z * z)));
double tmp;
if (t_1 <= Double.POSITIVE_INFINITY) {
tmp = t_1;
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
def code(x, y, z, t): t_1 = (x * x) + ((y * 4.0) * (t - (z * z))) tmp = 0 if t_1 <= math.inf: tmp = t_1 else: tmp = (x * x) - (y * (t * -4.0)) return tmp
function code(x, y, z, t) t_1 = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))) tmp = 0.0 if (t_1 <= Inf) tmp = t_1; else tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (x * x) + ((y * 4.0) * (t - (z * z))); tmp = 0.0; if (t_1 <= Inf) tmp = t_1; else tmp = (x * x) - (y * (t * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, Infinity], t$95$1, N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{if}\;t\_1 \leq \infty:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 95.0%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
Taylor expanded in z around 0 45.5%
*-commutative45.5%
*-commutative45.5%
associate-*l*45.5%
Simplified45.5%
Final simplification92.9%
(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 91.0%
Taylor expanded in z around 0 69.2%
*-commutative69.2%
*-commutative69.2%
associate-*l*69.2%
Simplified69.2%
(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 91.0%
Taylor expanded in t around inf 30.1%
*-commutative30.1%
Simplified30.1%
(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 2024089
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))