
(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) 5e+242) (fma (* y 4.0) (fma z (- z) t) (* x x)) (- (* x x) (* (* z y) (* z 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+242) {
tmp = fma((y * 4.0), fma(z, -z, t), (x * x));
} else {
tmp = (x * x) - ((z * y) * (z * 4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+242) tmp = fma(Float64(y * 4.0), fma(z, Float64(-z), t), Float64(x * x)); else tmp = Float64(Float64(x * x) - Float64(Float64(z * y) * Float64(z * 4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+242], N[(N[(y * 4.0), $MachinePrecision] * N[(z * (-z) + t), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+242}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, \mathsf{fma}\left(z, -z, t\right), x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(z \cdot y\right) \cdot \left(z \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000004e242Initial program 98.8%
cancel-sign-sub-inv98.8%
distribute-lft-neg-out98.8%
+-commutative98.8%
associate-*l*98.8%
distribute-lft-neg-in98.8%
associate-*l*98.8%
distribute-rgt-neg-in98.8%
fma-define99.4%
sub-neg99.4%
distribute-neg-in99.4%
distribute-rgt-neg-out99.4%
remove-double-neg99.4%
fma-define99.4%
Simplified99.4%
if 5.0000000000000004e242 < (*.f64 z z) Initial program 73.1%
fma-neg73.1%
Applied egg-rr73.1%
fma-undefine73.1%
unpow273.1%
flip-+9.7%
pow-prod-up9.7%
metadata-eval9.7%
clear-num9.7%
un-div-inv9.7%
clear-num9.7%
metadata-eval9.7%
pow-sqr9.7%
flip-+73.1%
unpow273.1%
fma-undefine73.1%
add-sqr-sqrt35.1%
sqrt-prod73.1%
Applied egg-rr73.1%
Taylor expanded in z around inf 73.1%
add-sqr-sqrt73.1%
times-frac73.1%
sqrt-div73.1%
metadata-eval73.1%
sqrt-pow137.5%
metadata-eval37.5%
pow137.5%
sqrt-div37.5%
metadata-eval37.5%
sqrt-pow195.8%
metadata-eval95.8%
pow195.8%
Applied egg-rr95.8%
associate-/r/95.8%
/-rgt-identity95.8%
associate-/r/95.8%
metadata-eval95.8%
Simplified95.8%
Final simplification98.4%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+242) (fma x x (* (- (* z z) t) (* y -4.0))) (- (* x x) (* (* z y) (* z 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+242) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x * x) - ((z * y) * (z * 4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+242) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x * x) - Float64(Float64(z * y) * Float64(z * 4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+242], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+242}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(z \cdot y\right) \cdot \left(z \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000004e242Initial program 98.8%
fma-neg99.4%
distribute-lft-neg-in99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
if 5.0000000000000004e242 < (*.f64 z z) Initial program 73.1%
fma-neg73.1%
Applied egg-rr73.1%
fma-undefine73.1%
unpow273.1%
flip-+9.7%
pow-prod-up9.7%
metadata-eval9.7%
clear-num9.7%
un-div-inv9.7%
clear-num9.7%
metadata-eval9.7%
pow-sqr9.7%
flip-+73.1%
unpow273.1%
fma-undefine73.1%
add-sqr-sqrt35.1%
sqrt-prod73.1%
Applied egg-rr73.1%
Taylor expanded in z around inf 73.1%
add-sqr-sqrt73.1%
times-frac73.1%
sqrt-div73.1%
metadata-eval73.1%
sqrt-pow137.5%
metadata-eval37.5%
pow137.5%
sqrt-div37.5%
metadata-eval37.5%
sqrt-pow195.8%
metadata-eval95.8%
pow195.8%
Applied egg-rr95.8%
associate-/r/95.8%
/-rgt-identity95.8%
associate-/r/95.8%
metadata-eval95.8%
Simplified95.8%
Final simplification98.3%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+242) (fma (* y 4.0) (- t (* z z)) (* x x)) (- (* x x) (* (* z y) (* z 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+242) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = (x * x) - ((z * y) * (z * 4.0));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+242) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(Float64(x * x) - Float64(Float64(z * y) * Float64(z * 4.0))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+242], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+242}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(z \cdot y\right) \cdot \left(z \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000004e242Initial program 98.8%
cancel-sign-sub-inv98.8%
distribute-lft-neg-out98.8%
+-commutative98.8%
distribute-lft-neg-out98.8%
distribute-lft-neg-in98.8%
distribute-rgt-neg-in98.8%
fma-define99.4%
sub-neg99.4%
+-commutative99.4%
distribute-neg-in99.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
if 5.0000000000000004e242 < (*.f64 z z) Initial program 73.1%
fma-neg73.1%
Applied egg-rr73.1%
fma-undefine73.1%
unpow273.1%
flip-+9.7%
pow-prod-up9.7%
metadata-eval9.7%
clear-num9.7%
un-div-inv9.7%
clear-num9.7%
metadata-eval9.7%
pow-sqr9.7%
flip-+73.1%
unpow273.1%
fma-undefine73.1%
add-sqr-sqrt35.1%
sqrt-prod73.1%
Applied egg-rr73.1%
Taylor expanded in z around inf 73.1%
add-sqr-sqrt73.1%
times-frac73.1%
sqrt-div73.1%
metadata-eval73.1%
sqrt-pow137.5%
metadata-eval37.5%
pow137.5%
sqrt-div37.5%
metadata-eval37.5%
sqrt-pow195.8%
metadata-eval95.8%
pow195.8%
Applied egg-rr95.8%
associate-/r/95.8%
/-rgt-identity95.8%
associate-/r/95.8%
metadata-eval95.8%
Simplified95.8%
Final simplification98.3%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 5e+242) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* (* z y) (* z 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+242) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - ((z * y) * (z * 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 * z) <= 5d+242) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - ((z * y) * (z * 4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+242) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - ((z * y) * (z * 4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 5e+242: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - ((z * y) * (z * 4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+242) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(Float64(z * y) * Float64(z * 4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 5e+242) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - ((z * y) * (z * 4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+242], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+242}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(z \cdot y\right) \cdot \left(z \cdot 4\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.0000000000000004e242Initial program 98.8%
if 5.0000000000000004e242 < (*.f64 z z) Initial program 73.1%
fma-neg73.1%
Applied egg-rr73.1%
fma-undefine73.1%
unpow273.1%
flip-+9.7%
pow-prod-up9.7%
metadata-eval9.7%
clear-num9.7%
un-div-inv9.7%
clear-num9.7%
metadata-eval9.7%
pow-sqr9.7%
flip-+73.1%
unpow273.1%
fma-undefine73.1%
add-sqr-sqrt35.1%
sqrt-prod73.1%
Applied egg-rr73.1%
Taylor expanded in z around inf 73.1%
add-sqr-sqrt73.1%
times-frac73.1%
sqrt-div73.1%
metadata-eval73.1%
sqrt-pow137.5%
metadata-eval37.5%
pow137.5%
sqrt-div37.5%
metadata-eval37.5%
sqrt-pow195.8%
metadata-eval95.8%
pow195.8%
Applied egg-rr95.8%
associate-/r/95.8%
/-rgt-identity95.8%
associate-/r/95.8%
metadata-eval95.8%
Simplified95.8%
Final simplification97.9%
(FPCore (x y z t) :precision binary64 (if (<= z 3.25e-6) (- (* x x) (* y (* t -4.0))) (- (* x x) (* (* z y) (* z 4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.25e-6) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (x * x) - ((z * y) * (z * 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.25d-6) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (x * x) - ((z * y) * (z * 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.25e-6) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (x * x) - ((z * y) * (z * 4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 3.25e-6: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (x * x) - ((z * y) * (z * 4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 3.25e-6) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(x * x) - Float64(Float64(z * y) * Float64(z * 4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 3.25e-6) tmp = (x * x) - (y * (t * -4.0)); else tmp = (x * x) - ((z * y) * (z * 4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.25e-6], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] - N[(N[(z * y), $MachinePrecision] * N[(z * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.25 \cdot 10^{-6}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \left(z \cdot y\right) \cdot \left(z \cdot 4\right)\\
\end{array}
\end{array}
if z < 3.2499999999999998e-6Initial program 93.8%
Taylor expanded in z around 0 76.4%
*-commutative76.4%
*-commutative76.4%
associate-*l*76.4%
Simplified76.4%
if 3.2499999999999998e-6 < z Initial program 84.8%
fma-neg84.9%
Applied egg-rr84.9%
fma-undefine84.8%
unpow284.8%
flip-+40.9%
pow-prod-up40.9%
metadata-eval40.9%
clear-num40.8%
un-div-inv40.9%
clear-num40.9%
metadata-eval40.9%
pow-sqr40.9%
flip-+84.8%
unpow284.8%
fma-undefine84.8%
add-sqr-sqrt47.1%
sqrt-prod82.0%
Applied egg-rr78.0%
Taylor expanded in z around inf 81.1%
add-sqr-sqrt81.0%
times-frac81.0%
sqrt-div81.0%
metadata-eval81.0%
sqrt-pow181.0%
metadata-eval81.0%
pow181.0%
sqrt-div81.0%
metadata-eval81.0%
sqrt-pow193.0%
metadata-eval93.0%
pow193.0%
Applied egg-rr93.0%
associate-/r/93.1%
/-rgt-identity93.1%
associate-/r/93.1%
metadata-eval93.1%
Simplified93.1%
Final simplification80.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.4%
Taylor expanded in z around 0 64.9%
*-commutative64.9%
*-commutative64.9%
associate-*l*64.9%
Simplified64.9%
Final simplification64.9%
(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.4%
Taylor expanded in t around inf 32.0%
*-commutative32.0%
Simplified32.0%
Final simplification32.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 2024080
(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))))