
(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 (<= (* x x) 1e+224) (fma x x (* (- (* z z) t) (* y -4.0))) (* (pow x 2.0) (- 1.0 (* -4.0 (* y (/ (/ (- t (* z z)) x) x)))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1e+224) {
tmp = fma(x, x, (((z * z) - t) * (y * -4.0)));
} else {
tmp = pow(x, 2.0) * (1.0 - (-4.0 * (y * (((t - (z * z)) / x) / x))));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 1e+224) tmp = fma(x, x, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = Float64((x ^ 2.0) * Float64(1.0 - Float64(-4.0 * Float64(y * Float64(Float64(Float64(t - Float64(z * z)) / x) / x))))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1e+224], N[(x * x + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, 2.0], $MachinePrecision] * N[(1.0 - N[(-4.0 * N[(y * N[(N[(N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 10^{+224}:\\
\;\;\;\;\mathsf{fma}\left(x, x, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x}^{2} \cdot \left(1 - -4 \cdot \left(y \cdot \frac{\frac{t - z \cdot z}{x}}{x}\right)\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 9.9999999999999997e223Initial program 94.5%
fma-neg94.5%
distribute-lft-neg-in94.5%
*-commutative94.5%
distribute-rgt-neg-in94.5%
metadata-eval94.5%
Simplified94.5%
if 9.9999999999999997e223 < (*.f64 x x) Initial program 79.4%
fma-neg89.7%
*-commutative89.7%
distribute-rgt-neg-in89.7%
distribute-rgt-neg-in89.7%
metadata-eval89.7%
add-cube-cbrt89.1%
pow389.1%
Applied egg-rr89.1%
Taylor expanded in x around inf 67.6%
associate-/l*77.9%
Simplified77.9%
*-un-lft-identity77.9%
pow277.9%
times-frac98.5%
Applied egg-rr98.5%
associate-*l/98.5%
*-lft-identity98.5%
Simplified98.5%
unpow298.5%
Applied egg-rr98.5%
Final simplification95.6%
(FPCore (x y z t) :precision binary64 (if (<= z 2e+143) (fma (* y 4.0) (- t (* z z)) (* x x)) (* y (* (* z z) -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2e+143) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = y * ((z * z) * -4.0);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= 2e+143) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(y * Float64(Float64(z * z) * -4.0)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, 2e+143], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2 \cdot 10^{+143}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\
\end{array}
\end{array}
if z < 2e143Initial 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-define96.4%
sub-neg96.4%
+-commutative96.4%
distribute-neg-in96.4%
remove-double-neg96.4%
sub-neg96.4%
Simplified96.4%
if 2e143 < z Initial program 73.7%
Taylor expanded in z around inf 81.2%
associate-*r*81.2%
*-commutative81.2%
associate-*l*81.2%
Simplified81.2%
unpow253.2%
Applied egg-rr81.2%
Final simplification94.0%
(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-neg93.2%
distribute-lft-neg-in93.2%
*-commutative93.2%
distribute-rgt-neg-in93.2%
metadata-eval93.2%
Simplified93.2%
(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)))))
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;
}
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;
}
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 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(Float64(t * y) * Float64(-4.0)); 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; 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[(N[(t * y), $MachinePrecision] * (-4.0)), $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}:\\
\;\;\;\;\left(t \cdot y\right) \cdot \left(-4\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 95.7%
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 t around inf 7.8%
*-commutative7.8%
Simplified7.8%
*-commutative7.8%
add-sqr-sqrt7.4%
sqrt-unprod29.0%
sqr-neg29.0%
sqrt-unprod14.6%
add-sqr-sqrt51.7%
distribute-lft-neg-out51.7%
*-commutative51.7%
Applied egg-rr51.7%
distribute-rgt-neg-in51.7%
Simplified51.7%
Final simplification93.3%
(FPCore (x y z t) :precision binary64 (if (<= z 2.3e-95) (* 4.0 (* t y)) (if (<= z 3.1e+42) (* x x) (* y (* (* z z) -4.0)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 2.3e-95) {
tmp = 4.0 * (t * y);
} else if (z <= 3.1e+42) {
tmp = x * x;
} else {
tmp = y * ((z * z) * -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.3d-95) then
tmp = 4.0d0 * (t * y)
else if (z <= 3.1d+42) then
tmp = x * x
else
tmp = y * ((z * z) * (-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.3e-95) {
tmp = 4.0 * (t * y);
} else if (z <= 3.1e+42) {
tmp = x * x;
} else {
tmp = y * ((z * z) * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 2.3e-95: tmp = 4.0 * (t * y) elif z <= 3.1e+42: tmp = x * x else: tmp = y * ((z * z) * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 2.3e-95) tmp = Float64(4.0 * Float64(t * y)); elseif (z <= 3.1e+42) tmp = Float64(x * x); else tmp = Float64(y * Float64(Float64(z * z) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 2.3e-95) tmp = 4.0 * (t * y); elseif (z <= 3.1e+42) tmp = x * x; else tmp = y * ((z * z) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 2.3e-95], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.1e+42], N[(x * x), $MachinePrecision], N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 2.3 \cdot 10^{-95}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{+42}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\
\end{array}
\end{array}
if z < 2.29999999999999999e-95Initial program 93.8%
Taylor expanded in t around inf 39.6%
*-commutative39.6%
Simplified39.6%
if 2.29999999999999999e-95 < z < 3.1000000000000002e42Initial program 93.9%
Taylor expanded in y around 0 93.9%
Simplified46.7%
--rgt-identity46.7%
Applied egg-rr46.7%
if 3.1000000000000002e42 < z Initial program 80.6%
Taylor expanded in z around inf 73.6%
associate-*r*73.6%
*-commutative73.6%
associate-*l*73.6%
Simplified73.6%
unpow260.5%
Applied egg-rr73.6%
Final simplification49.1%
(FPCore (x y z t) :precision binary64 (if (<= z 7.2e+54) (- (* x x) (* y (* t -4.0))) (* y (* (* z z) -4.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= 7.2e+54) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = y * ((z * z) * -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 <= 7.2d+54) then
tmp = (x * x) - (y * (t * (-4.0d0)))
else
tmp = y * ((z * z) * (-4.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= 7.2e+54) {
tmp = (x * x) - (y * (t * -4.0));
} else {
tmp = y * ((z * z) * -4.0);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= 7.2e+54: tmp = (x * x) - (y * (t * -4.0)) else: tmp = y * ((z * z) * -4.0) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= 7.2e+54) tmp = Float64(Float64(x * x) - Float64(y * Float64(t * -4.0))); else tmp = Float64(y * Float64(Float64(z * z) * -4.0)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= 7.2e+54) tmp = (x * x) - (y * (t * -4.0)); else tmp = y * ((z * z) * -4.0); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, 7.2e+54], N[(N[(x * x), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(z * z), $MachinePrecision] * -4.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 7.2 \cdot 10^{+54}:\\
\;\;\;\;x \cdot x - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(\left(z \cdot z\right) \cdot -4\right)\\
\end{array}
\end{array}
if z < 7.2000000000000003e54Initial program 93.9%
Taylor expanded in z around 0 74.7%
*-commutative74.7%
*-commutative74.7%
associate-*l*74.7%
Simplified74.7%
if 7.2000000000000003e54 < z Initial program 80.0%
Taylor expanded in z around inf 74.3%
associate-*r*74.3%
*-commutative74.3%
associate-*l*74.3%
Simplified74.3%
unpow260.7%
Applied egg-rr74.3%
Final simplification74.6%
(FPCore (x y z t) :precision binary64 (if (<= (* x x) 1.9e+51) (* 4.0 (* t y)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x * x) <= 1.9e+51) {
tmp = 4.0 * (t * y);
} 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) <= 1.9d+51) then
tmp = 4.0d0 * (t * y)
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) <= 1.9e+51) {
tmp = 4.0 * (t * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x * x) <= 1.9e+51: tmp = 4.0 * (t * y) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if (Float64(x * x) <= 1.9e+51) tmp = Float64(4.0 * Float64(t * y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x * x) <= 1.9e+51) tmp = 4.0 * (t * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[N[(x * x), $MachinePrecision], 1.9e+51], N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.9 \cdot 10^{+51}:\\
\;\;\;\;4 \cdot \left(t \cdot y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.8999999999999999e51Initial program 93.2%
Taylor expanded in t around inf 49.1%
*-commutative49.1%
Simplified49.1%
if 1.8999999999999999e51 < (*.f64 x x) Initial program 86.4%
Taylor expanded in y around 0 86.4%
Simplified69.7%
--rgt-identity69.7%
Applied egg-rr69.7%
Final simplification57.4%
(FPCore (x y z t) :precision binary64 (* x x))
double code(double x, double y, double z, double t) {
return x * x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x * x;
}
def code(x, y, z, t): return x * x
function code(x, y, z, t) return Float64(x * x) end
function tmp = code(x, y, z, t) tmp = x * x; end
code[x_, y_, z_, t_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 90.5%
Taylor expanded in y around 0 90.5%
Simplified35.3%
--rgt-identity35.3%
Applied egg-rr35.3%
(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 2024135
(FPCore (x y z t)
:name "Graphics.Rasterific.Shading:$sradialGradientWithFocusShader from Rasterific-0.6.1, B"
:precision binary64
:alt
(! :herbie-platform default (- (* x x) (* 4 (* y (- (* z z) t)))))
(- (* x x) (* (* y 4.0) (- (* z z) t))))