
(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 6 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 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (* x x))))
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;
}
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;
}
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 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(x * x); 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; 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[(x * x), $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\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 95.8%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y 4) (-.f64 (*.f64 z z) t))) Initial program 0.0%
Taylor expanded in y around 0 0.0%
Simplified100.0%
Final simplification95.9%
(FPCore (x y z t) :precision binary64 (fma (* y 4.0) (- t (* z z)) (* x x)))
double code(double x, double y, double z, double t) {
return fma((y * 4.0), (t - (z * z)), (x * x));
}
function code(x, y, z, t) return fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)) end
code[x_, y_, z_, t_] := N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)
\end{array}
Initial program 93.6%
cancel-sign-sub-inv93.6%
distribute-lft-neg-out93.6%
+-commutative93.6%
distribute-lft-neg-out93.6%
distribute-lft-neg-in93.6%
distribute-rgt-neg-in93.6%
fma-define94.8%
sub-neg94.8%
+-commutative94.8%
distribute-neg-in94.8%
remove-double-neg94.8%
sub-neg94.8%
Simplified94.8%
Final simplification94.8%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 3.1e-7) (* y (* 4.0 t)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 3.1e-7) {
tmp = y * (4.0 * t);
} else {
tmp = x * x;
}
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) <= 3.1d-7) then
tmp = y * (4.0d0 * t)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 3.1e-7) {
tmp = y * (4.0 * t);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 3.1e-7: tmp = y * (4.0 * t) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 3.1e-7) tmp = Float64(y * Float64(4.0 * t)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 3.1e-7) tmp = y * (4.0 * t); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 3.1e-7], N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 3.1 \cdot 10^{-7}:\\
\;\;\;\;y \cdot \left(4 \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.1e-7Initial program 92.9%
Taylor expanded in t around inf 48.0%
associate-*r*48.0%
*-commutative48.0%
Simplified48.0%
if 3.1e-7 < (*.f64 x x) Initial program 94.4%
Taylor expanded in y around 0 94.4%
Simplified82.6%
Final simplification64.8%
(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 93.6%
Taylor expanded in z around 0 71.1%
*-commutative71.1%
*-commutative71.1%
associate-*l*71.1%
Simplified71.1%
Final simplification71.1%
(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 93.6%
Applied egg-rr18.6%
Taylor expanded in z around 0 18.6%
associate-*r*18.6%
*-commutative18.6%
*-commutative18.6%
associate-*l*19.0%
*-commutative19.0%
associate-*l*19.0%
Simplified19.0%
Taylor expanded in x around inf 46.3%
Taylor expanded in t around inf 7.4%
Final simplification7.4%
(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 93.6%
Taylor expanded in t around inf 31.9%
associate-*r*31.9%
*-commutative31.9%
Simplified31.9%
Final simplification31.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 2024041
(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))))