
(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+299) (fma (* y 4.0) (- t (* z z)) (* x x)) (- (* x x) (* (/ y (/ 1.0 z)) (/ 4.0 (/ 1.0 z))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+299) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+299) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(Float64(x * x) - Float64(Float64(y / Float64(1.0 / z)) * Float64(4.0 / Float64(1.0 / z)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+299], 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[(y / N[(1.0 / z), $MachinePrecision]), $MachinePrecision] * N[(4.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+299}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \frac{y}{\frac{1}{z}} \cdot \frac{4}{\frac{1}{z}}\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e299Initial program 97.7%
cancel-sign-sub-inv97.7%
distribute-lft-neg-out97.7%
+-commutative97.7%
distribute-lft-neg-out97.7%
distribute-lft-neg-in97.7%
distribute-rgt-neg-in97.7%
fma-def99.4%
sub-neg99.4%
+-commutative99.4%
distribute-neg-in99.4%
remove-double-neg99.4%
sub-neg99.4%
Simplified99.4%
if 1.0000000000000001e299 < (*.f64 z z) Initial program 79.4%
add-sqr-sqrt25.9%
sqrt-unprod23.0%
swap-sqr23.0%
metadata-eval23.0%
metadata-eval23.0%
swap-sqr23.0%
sqrt-unprod0.0%
add-sqr-sqrt7.3%
flip--1.4%
associate-*r/1.4%
Applied egg-rr1.4%
associate-/l*1.4%
*-commutative1.4%
Simplified1.4%
Taylor expanded in z around inf 79.4%
*-commutative79.4%
add-sqr-sqrt79.4%
times-frac79.4%
sqrt-div79.4%
metadata-eval79.4%
unpow279.4%
sqrt-prod41.9%
add-sqr-sqrt46.3%
sqrt-div46.3%
metadata-eval46.3%
unpow246.3%
sqrt-prod51.3%
add-sqr-sqrt95.7%
Applied egg-rr95.7%
Final simplification98.4%
(FPCore (x y z t) :precision binary64 (if (<= z 5.1e+157) (fma x x (* (- (* z z) t) (* y -4.0))) (- (* x x) (* (/ y (/ 1.0 z)) (/ 4.0 (/ 1.0 z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.1e+157) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 5.1e+157) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64(Float64(x * x) - Float64(Float64(y / Float64(1.0 / z)) * Float64(4.0 / Float64(1.0 / z)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 5.1e+157], 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[(y / N[(1.0 / z), $MachinePrecision]), $MachinePrecision] * N[(4.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.1 \cdot 10^{+157}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \frac{y}{\frac{1}{z}} \cdot \frac{4}{\frac{1}{z}}\\
\end{array}
\end{array}
if z < 5.09999999999999999e157Initial program 94.6%
fma-neg95.5%
distribute-lft-neg-in95.5%
*-commutative95.5%
distribute-rgt-neg-in95.5%
metadata-eval95.5%
Simplified95.5%
if 5.09999999999999999e157 < z Initial program 81.6%
add-sqr-sqrt28.2%
sqrt-unprod28.0%
swap-sqr28.0%
metadata-eval28.0%
metadata-eval28.0%
swap-sqr28.0%
sqrt-unprod0.0%
add-sqr-sqrt5.6%
flip--0.0%
associate-*r/0.0%
Applied egg-rr0.0%
associate-/l*0.0%
*-commutative0.0%
Simplified0.0%
Taylor expanded in z around inf 81.6%
*-commutative81.6%
add-sqr-sqrt81.6%
times-frac81.6%
sqrt-div81.6%
metadata-eval81.6%
unpow281.6%
sqrt-prod81.6%
add-sqr-sqrt81.6%
sqrt-div81.6%
metadata-eval81.6%
unpow281.6%
sqrt-prod99.8%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Final simplification96.1%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.22e+203) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* y (* t -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.22e+203) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (y * (t * -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 ((x * x) <= 1.22d+203) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (y * (t * (-4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.22e+203) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (y * (t * -4.0));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 1.22e+203: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (y * (t * -4.0)) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 1.22e+203) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 1.22e+203) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (y * (t * -4.0)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.22e+203], 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[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.22 \cdot 10^{+203}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 1.21999999999999992e203Initial program 96.5%
if 1.21999999999999992e203 < (*.f64 x x) Initial program 85.6%
Taylor expanded in z around 0 92.3%
*-commutative92.3%
*-commutative92.3%
associate-*l*92.3%
Simplified92.3%
Final simplification95.1%
(FPCore (x y z t) :precision binary64 (if (<= z 1e+151) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* (/ y (/ 1.0 z)) (/ 4.0 (/ 1.0 z))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1e+151) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / 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 <= 1d+151) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - ((y / (1.0d0 / z)) * (4.0d0 / (1.0d0 / z)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 1e+151) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 1e+151: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 1e+151) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(Float64(y / Float64(1.0 / z)) * Float64(4.0 / Float64(1.0 / z)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 1e+151) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - ((y / (1.0 / z)) * (4.0 / (1.0 / z))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 1e+151], 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[(y / N[(1.0 / z), $MachinePrecision]), $MachinePrecision] * N[(4.0 / N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 10^{+151}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - \frac{y}{\frac{1}{z}} \cdot \frac{4}{\frac{1}{z}}\\
\end{array}
\end{array}
if z < 1.00000000000000002e151Initial program 94.6%
if 1.00000000000000002e151 < z Initial program 81.6%
add-sqr-sqrt28.2%
sqrt-unprod28.0%
swap-sqr28.0%
metadata-eval28.0%
metadata-eval28.0%
swap-sqr28.0%
sqrt-unprod0.0%
add-sqr-sqrt5.6%
flip--0.0%
associate-*r/0.0%
Applied egg-rr0.0%
associate-/l*0.0%
*-commutative0.0%
Simplified0.0%
Taylor expanded in z around inf 81.6%
*-commutative81.6%
add-sqr-sqrt81.6%
times-frac81.6%
sqrt-div81.6%
metadata-eval81.6%
unpow281.6%
sqrt-prod81.6%
add-sqr-sqrt81.6%
sqrt-div81.6%
metadata-eval81.6%
unpow281.6%
sqrt-prod99.8%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Final simplification95.3%
(FPCore (x y z t) :precision binary64 (if (<= x 3.5e+101) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (+ (* x x) (/ -1.0 (/ (/ -1.0 t) (* y 4.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 3.5e+101) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) + (-1.0 / ((-1.0 / t) / (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 (x <= 3.5d+101) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) + ((-1.0d0) / (((-1.0d0) / t) / (y * 4.0d0)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 3.5e+101) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) + (-1.0 / ((-1.0 / t) / (y * 4.0)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 3.5e+101: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) + (-1.0 / ((-1.0 / t) / (y * 4.0))) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 3.5e+101) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) + Float64(-1.0 / Float64(Float64(-1.0 / t) / Float64(y * 4.0)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 3.5e+101) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) + (-1.0 / ((-1.0 / t) / (y * 4.0))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 3.5e+101], 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[(-1.0 / N[(N[(-1.0 / t), $MachinePrecision] / N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5 \cdot 10^{+101}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x + \frac{-1}{\frac{\frac{-1}{t}}{y \cdot 4}}\\
\end{array}
\end{array}
if x < 3.50000000000000023e101Initial program 94.1%
if 3.50000000000000023e101 < x Initial program 85.2%
add-sqr-sqrt40.0%
sqrt-unprod57.8%
swap-sqr57.8%
metadata-eval57.8%
metadata-eval57.8%
swap-sqr57.8%
sqrt-unprod24.9%
add-sqr-sqrt74.9%
flip--52.4%
associate-*r/50.3%
Applied egg-rr50.3%
associate-/l*55.3%
*-commutative55.3%
Simplified55.3%
Taylor expanded in z around 0 92.5%
clear-num92.5%
inv-pow92.5%
Applied egg-rr92.5%
unpow-192.5%
Simplified92.5%
Final simplification93.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 92.7%
Taylor expanded in z around 0 64.7%
*-commutative64.7%
*-commutative64.7%
associate-*l*64.7%
Simplified64.7%
Final simplification64.7%
(FPCore (x y z t) :precision binary64 (* y (* 4.0 t)))
double code(double x, double y, double z, double t) {
return y * (4.0 * 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 = y * (4.0d0 * t)
end function
public static double code(double x, double y, double z, double t) {
return y * (4.0 * t);
}
def code(x, y, z, t): return y * (4.0 * t)
function code(x, y, z, t) return Float64(y * Float64(4.0 * t)) end
function tmp = code(x, y, z, t) tmp = y * (4.0 * t); end
code[x_, y_, z_, t_] := N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(4 \cdot t\right)
\end{array}
Initial program 92.7%
Taylor expanded in t around inf 26.4%
associate-*r*26.4%
*-commutative26.4%
Simplified26.4%
Final simplification26.4%
(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 2023318
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:herbie-target
(- (* x x) (* 4.0 (* y (- (* z z) t))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))