
(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 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (* t (+ (* y -4.0) (* x (/ x t)))))))
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 = t * ((y * -4.0) + (x * (x / t)));
}
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 = t * ((y * -4.0) + (x * (x / t)));
}
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 = t * ((y * -4.0) + (x * (x / t))) 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(t * Float64(Float64(y * -4.0) + Float64(x * Float64(x / t)))); 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 = t * ((y * -4.0) + (x * (x / t))); 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[(t * N[(N[(y * -4.0), $MachinePrecision] + N[(x * N[(x / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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}:\\
\;\;\;\;t \cdot \left(y \cdot -4 + x \cdot \frac{x}{t}\right)\\
\end{array}
\end{array}
if (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 94.5%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
Taylor expanded in z around 0 41.7%
*-commutative41.7%
*-commutative41.7%
associate-*l*41.7%
Simplified41.7%
Taylor expanded in t around inf 50.0%
unpow250.0%
associate-/l*50.0%
*-commutative50.0%
fma-neg50.0%
*-commutative50.0%
distribute-lft-neg-in50.0%
metadata-eval50.0%
Simplified50.0%
fma-undefine50.0%
add-sqr-sqrt41.7%
sqrt-unprod50.0%
*-commutative50.0%
*-commutative50.0%
swap-sqr50.0%
metadata-eval50.0%
metadata-eval50.0%
swap-sqr50.0%
sqrt-unprod8.3%
add-sqr-sqrt58.3%
Applied egg-rr58.3%
Final simplification92.8%
(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.1%
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 3.8e+107) (- (* x x) (* y (* t -4.0))) (* (* z z) (* y -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 3.8e+107) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z * z) * (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 (z <= 3.8d+107) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = (z * z) * (y * (-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.8e+107) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = (z * z) * (y * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 3.8e+107: tmp = (x * x) - (y * (t * -4.0)) else: tmp = (z * z) * (y * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 3.8e+107) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(z * z) * Float64(y * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 3.8e+107) tmp = (x * x) - (y * (t * -4.0)); else tmp = (z * z) * (y * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 3.8e+107], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.8 \cdot 10^{+107}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 3.7999999999999998e107Initial program 91.9%
Taylor expanded in z around 0 77.1%
*-commutative77.1%
*-commutative77.1%
associate-*l*77.1%
Simplified77.1%
if 3.7999999999999998e107 < z Initial program 79.3%
Taylor expanded in z around inf 84.7%
associate-*r*84.7%
*-commutative84.7%
*-commutative84.7%
Simplified84.7%
unpow284.7%
Applied egg-rr84.7%
(FPCore (x y z t) :precision binary64 (if (<= z 2.9e-42) (* 4.0 (* t y)) (* (* z z) (* y -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.9e-42) {
tmp = 4.0 * (t * y);
} else {
tmp = (z * z) * (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 (z <= 2.9d-42) then
tmp = 4.0d0 * (t * y)
else
tmp = (z * z) * (y * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.9e-42) {
tmp = 4.0 * (t * y);
} else {
tmp = (z * z) * (y * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 2.9e-42: tmp = 4.0 * (t * y) else: tmp = (z * z) * (y * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 2.9e-42) tmp = Float64(4.0 * Float64(t * y)); else tmp = Float64(Float64(z * z) * Float64(y * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 2.9e-42) tmp = 4.0 * (t * y); else tmp = (z * z) * (y * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 2.9e-42], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(N[(z * z), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.9 \cdot 10^{-42}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(z \cdot z\right) \cdot \left(y \cdot -4\right)\\
\end{array}
\end{array}
if z < 2.9000000000000003e-42Initial program 91.2%
Taylor expanded in t around inf 36.2%
*-commutative36.2%
Simplified36.2%
if 2.9000000000000003e-42 < z Initial program 87.0%
Taylor expanded in z around inf 61.1%
associate-*r*61.1%
*-commutative61.1%
*-commutative61.1%
Simplified61.1%
unpow261.1%
Applied egg-rr61.1%
Final simplification42.7%
(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 90.1%
Taylor expanded in t around inf 32.4%
*-commutative32.4%
Simplified32.4%
Final simplification32.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 2024087
(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))))