
(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) 2e+280) (fma (* y 4.0) (fma z (- z) t) (* x x)) (* (* t -4.0) (* y (+ -1.0 (/ z (/ t z)))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+280) {
tmp = fma((y * 4.0), fma(z, -z, t), (x * x));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+280) tmp = fma(Float64(y * 4.0), fma(z, Float64(-z), t), Float64(x * x)); else tmp = Float64(Float64(t * -4.0) * Float64(y * Float64(-1.0 + Float64(z / Float64(t / z))))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+280], N[(N[(y * 4.0), $MachinePrecision] * N[(z * (-z) + t), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(t * -4.0), $MachinePrecision] * N[(y * N[(-1.0 + N[(z / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+280}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, \mathsf{fma}\left(z, -z, t\right), x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t \cdot -4\right) \cdot \left(y \cdot \left(-1 + \frac{z}{\frac{t}{z}}\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.0000000000000001e280Initial program 99.4%
cancel-sign-sub-inv99.4%
distribute-lft-neg-out99.4%
+-commutative99.4%
associate-*l*99.4%
distribute-lft-neg-in99.4%
associate-*l*99.4%
distribute-rgt-neg-in99.4%
fma-define99.9%
neg-sub099.9%
associate-+l-99.9%
neg-sub099.9%
distribute-rgt-neg-out99.9%
fma-define99.9%
Simplified99.9%
if 2.0000000000000001e280 < (*.f64 z z) Initial program 68.3%
Taylor expanded in t around inf 68.3%
Taylor expanded in x around 0 75.2%
associate-*r*75.2%
*-commutative75.2%
sub-neg75.2%
metadata-eval75.2%
+-commutative75.2%
Simplified75.2%
unpow275.2%
associate-/l*80.3%
Applied egg-rr80.3%
clear-num80.3%
un-div-inv80.3%
Applied egg-rr80.3%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 2e+280) (fma (* y 4.0) (- t (* z z)) (* x x)) (* (* t -4.0) (* y (+ -1.0 (/ z (/ t z)))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+280) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+280) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(Float64(t * -4.0) * Float64(y * Float64(-1.0 + Float64(z / Float64(t / z))))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+280], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(N[(t * -4.0), $MachinePrecision] * N[(y * N[(-1.0 + N[(z / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+280}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t \cdot -4\right) \cdot \left(y \cdot \left(-1 + \frac{z}{\frac{t}{z}}\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.0000000000000001e280Initial program 99.4%
cancel-sign-sub-inv99.4%
distribute-lft-neg-out99.4%
+-commutative99.4%
associate-*l*99.4%
distribute-lft-neg-in99.4%
associate-*l*99.4%
distribute-rgt-neg-in99.4%
fma-define99.9%
sub-neg99.9%
+-commutative99.9%
distribute-neg-in99.9%
remove-double-neg99.9%
sub-neg99.9%
Simplified99.9%
if 2.0000000000000001e280 < (*.f64 z z) Initial program 68.3%
Taylor expanded in t around inf 68.3%
Taylor expanded in x around 0 75.2%
associate-*r*75.2%
*-commutative75.2%
sub-neg75.2%
metadata-eval75.2%
+-commutative75.2%
Simplified75.2%
unpow275.2%
associate-/l*80.3%
Applied egg-rr80.3%
clear-num80.3%
un-div-inv80.3%
Applied egg-rr80.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 90.5%
fma-neg92.5%
distribute-lft-neg-in92.5%
*-commutative92.5%
distribute-rgt-neg-in92.5%
metadata-eval92.5%
Simplified92.5%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 2e+280) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* (* t -4.0) (* y (+ -1.0 (/ z (/ t z)))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+280) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z / (t / 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 * z) <= 2d+280) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (t * (-4.0d0)) * (y * ((-1.0d0) + (z / (t / z))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 2e+280) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 2e+280: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z)))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 2e+280) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(t * -4.0) * Float64(y * Float64(-1.0 + Float64(z / Float64(t / z))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 2e+280) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 2e+280], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t * -4.0), $MachinePrecision] * N[(y * N[(-1.0 + N[(z / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 2 \cdot 10^{+280}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t \cdot -4\right) \cdot \left(y \cdot \left(-1 + \frac{z}{\frac{t}{z}}\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 2.0000000000000001e280Initial program 99.4%
if 2.0000000000000001e280 < (*.f64 z z) Initial program 68.3%
Taylor expanded in t around inf 68.3%
Taylor expanded in x around 0 75.2%
associate-*r*75.2%
*-commutative75.2%
sub-neg75.2%
metadata-eval75.2%
+-commutative75.2%
Simplified75.2%
unpow275.2%
associate-/l*80.3%
Applied egg-rr80.3%
clear-num80.3%
un-div-inv80.3%
Applied egg-rr80.3%
Final simplification93.9%
(FPCore (x y z t) :precision binary64 (if (<= z 5.2e+40) (- (* x x) (* y (* t -4.0))) (* (* t -4.0) (* y (+ -1.0 (/ z (/ t z)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.2e+40) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z / (t / 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 <= 5.2d+40) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (t * (-4.0d0)) * (y * ((-1.0d0) + (z / (t / z))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.2e+40) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 5.2e+40: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z)))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 5.2e+40) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(t * -4.0) * Float64(y * Float64(-1.0 + Float64(z / Float64(t / z))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 5.2e+40) tmp = (x * x) - (y * (t * -4.0)); else tmp = (t * -4.0) * (y * (-1.0 + (z / (t / z)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 5.2e+40], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t * -4.0), $MachinePrecision] * N[(y * N[(-1.0 + N[(z / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.2 \cdot 10^{+40}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t \cdot -4\right) \cdot \left(y \cdot \left(-1 + \frac{z}{\frac{t}{z}}\right)\right)\\
\end{array}
\end{array}
if z < 5.2000000000000001e40Initial program 92.9%
Taylor expanded in z around 0 75.1%
*-commutative75.1%
*-commutative75.1%
associate-*l*75.1%
Simplified75.1%
if 5.2000000000000001e40 < z Initial program 81.3%
Taylor expanded in t around inf 72.0%
Taylor expanded in x around 0 74.3%
associate-*r*74.3%
*-commutative74.3%
sub-neg74.3%
metadata-eval74.3%
+-commutative74.3%
Simplified74.3%
unpow274.3%
associate-/l*77.9%
Applied egg-rr77.9%
clear-num77.9%
un-div-inv77.9%
Applied egg-rr77.9%
(FPCore (x y z t) :precision binary64 (if (<= z 5.8e+40) (- (* x x) (* y (* t -4.0))) (* (* t -4.0) (* y (+ -1.0 (* z (/ z t)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.8e+40) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z * (z / t))));
}
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 <= 5.8d+40) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (t * (-4.0d0)) * (y * ((-1.0d0) + (z * (z / t))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 5.8e+40) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (t * -4.0) * (y * (-1.0 + (z * (z / t))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 5.8e+40: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (t * -4.0) * (y * (-1.0 + (z * (z / t)))) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 5.8e+40) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(t * -4.0) * Float64(y * Float64(-1.0 + Float64(z * Float64(z / t))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 5.8e+40) tmp = (x * x) - (y * (t * -4.0)); else tmp = (t * -4.0) * (y * (-1.0 + (z * (z / t)))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 5.8e+40], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t * -4.0), $MachinePrecision] * N[(y * N[(-1.0 + N[(z * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 5.8 \cdot 10^{+40}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(t \cdot -4\right) \cdot \left(y \cdot \left(-1 + z \cdot \frac{z}{t}\right)\right)\\
\end{array}
\end{array}
if z < 5.80000000000000035e40Initial program 92.9%
Taylor expanded in z around 0 75.1%
*-commutative75.1%
*-commutative75.1%
associate-*l*75.1%
Simplified75.1%
if 5.80000000000000035e40 < z Initial program 81.3%
Taylor expanded in t around inf 72.0%
Taylor expanded in x around 0 74.3%
associate-*r*74.3%
*-commutative74.3%
sub-neg74.3%
metadata-eval74.3%
+-commutative74.3%
Simplified74.3%
unpow274.3%
associate-/l*77.9%
Applied egg-rr77.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 90.5%
Taylor expanded in z around 0 64.3%
*-commutative64.3%
*-commutative64.3%
associate-*l*64.3%
Simplified64.3%
(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 90.5%
Taylor expanded in t around inf 31.9%
*-commutative31.9%
Simplified31.9%
(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 2024085
(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))))