
(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 5 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+257) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (- (* x x) (* t (* y (+ -4.0 (* (* z 2.0) (/ (* z 2.0) t))))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+257) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (t * (y * (-4.0 + ((z * 2.0) * ((z * 2.0) / 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 * z) <= 5d+257) then
tmp = (x * x) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x * x) - (t * (y * ((-4.0d0) + ((z * 2.0d0) * ((z * 2.0d0) / t)))))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 5e+257) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x * x) - (t * (y * (-4.0 + ((z * 2.0) * ((z * 2.0) / t)))));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z * z) <= 5e+257: tmp = (x * x) + ((y * 4.0) * (t - (z * z))) else: tmp = (x * x) - (t * (y * (-4.0 + ((z * 2.0) * ((z * 2.0) / t))))) return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 5e+257) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x * x) - Float64(t * Float64(y * Float64(-4.0 + Float64(Float64(z * 2.0) * Float64(Float64(z * 2.0) / t)))))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z * z) <= 5e+257) tmp = (x * x) + ((y * 4.0) * (t - (z * z))); else tmp = (x * x) - (t * (y * (-4.0 + ((z * 2.0) * ((z * 2.0) / t))))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 5e+257], 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[(t * N[(y * N[(-4.0 + N[(N[(z * 2.0), $MachinePrecision] * N[(N[(z * 2.0), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 5 \cdot 10^{+257}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x - t \cdot \left(y \cdot \left(-4 + \left(z \cdot 2\right) \cdot \frac{z \cdot 2}{t}\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 5.00000000000000028e257Initial program 98.8%
if 5.00000000000000028e257 < (*.f64 z z) Initial program 82.9%
Taylor expanded in t around inf 82.9%
*-commutative82.9%
associate-/l*82.9%
associate-*r*82.9%
*-commutative82.9%
associate-/l*82.9%
associate-*l*81.6%
associate-/l*81.6%
distribute-lft-out81.6%
Simplified81.6%
add-sqr-sqrt81.6%
*-un-lft-identity81.6%
times-frac81.6%
*-commutative81.6%
sqrt-prod81.6%
sqrt-pow149.3%
metadata-eval49.3%
pow149.3%
metadata-eval49.3%
*-commutative49.3%
sqrt-prod50.6%
sqrt-pow189.2%
metadata-eval89.2%
pow189.2%
metadata-eval89.2%
Applied egg-rr89.2%
Final simplification96.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 94.4%
fma-neg95.9%
distribute-lft-neg-in95.9%
*-commutative95.9%
distribute-rgt-neg-in95.9%
metadata-eval95.9%
Simplified95.9%
Final simplification95.9%
(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 94.4%
Final simplification94.4%
(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 94.4%
Taylor expanded in z around 0 69.5%
*-commutative69.5%
*-commutative69.5%
associate-*l*69.5%
Simplified69.5%
Final simplification69.5%
(FPCore (x y z t) :precision binary64 (* 4.0 (* t y)))
double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
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 * (t * y)
end function
public static double code(double x, double y, double z, double t) {
return 4.0 * (t * y);
}
def code(x, y, z, t): return 4.0 * (t * y)
function code(x, y, z, t) return Float64(4.0 * Float64(t * y)) end
function tmp = code(x, y, z, t) tmp = 4.0 * (t * y); end
code[x_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 94.4%
Taylor expanded in t around inf 33.4%
*-commutative33.4%
Simplified33.4%
Final simplification33.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 2024078
(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))))