
(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) 1e+300) (fma (* y 4.0) (- t (* z z)) (* x x)) (* -4.0 (* t (* y (fma z (/ z t) -1.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+300) {
tmp = fma((y * 4.0), (t - (z * z)), (x * x));
} else {
tmp = -4.0 * (t * (y * fma(z, (z / t), -1.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+300) tmp = fma(Float64(y * 4.0), Float64(t - Float64(z * z)), Float64(x * x)); else tmp = Float64(-4.0 * Float64(t * Float64(y * fma(z, Float64(z / t), -1.0)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+300], N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(y * N[(z * N[(z / t), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+300}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t - z \cdot z, x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(y \cdot \mathsf{fma}\left(z, \frac{z}{t}, -1\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e300Initial program 98.9%
cancel-sign-sub-inv98.9%
distribute-lft-neg-out98.9%
+-commutative98.9%
associate-*l*98.9%
distribute-lft-neg-in98.9%
associate-*l*98.9%
distribute-rgt-neg-in98.9%
fma-define100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-in100.0%
remove-double-neg100.0%
sub-neg100.0%
Simplified100.0%
if 1.0000000000000001e300 < (*.f64 z z) Initial program 64.2%
Taylor expanded in t around inf 64.2%
Taylor expanded in x around 0 78.9%
sub-neg78.9%
metadata-eval78.9%
associate-*r*71.0%
*-commutative71.0%
metadata-eval71.0%
sub-neg71.0%
unpow271.0%
associate-*r/75.1%
fma-neg75.1%
metadata-eval75.1%
Simplified75.1%
log1p-expm1-u71.0%
pow171.0%
log1p-expm1-u75.1%
*-commutative75.1%
metadata-eval75.1%
fma-neg75.1%
associate-*l*83.0%
fma-neg83.0%
metadata-eval83.0%
Applied egg-rr83.0%
pow183.0%
pow183.0%
associate-*r*75.1%
Applied egg-rr75.1%
unpow175.1%
associate-*l*83.0%
Simplified83.0%
Final simplification95.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (+ (* x x) (* (* y 4.0) (- t (* z z)))))) (if (<= t_1 INFINITY) t_1 (* y (* -4.0 (pow z 2.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 = y * (-4.0 * pow(z, 2.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 = y * (-4.0 * Math.pow(z, 2.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 = y * (-4.0 * math.pow(z, 2.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(y * Float64(-4.0 * (z ^ 2.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 = y * (-4.0 * (z ^ 2.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[(y * N[(-4.0 * N[Power[z, 2.0], $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}:\\
\;\;\;\;y \cdot \left(-4 \cdot {z}^{2}\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 96.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 inf 61.1%
associate-*r*61.1%
*-commutative61.1%
associate-*l*61.1%
Simplified61.1%
Final simplification94.0%
(FPCore (x y z t) :precision binary64 (if (<= (* z z) 1e+300) (+ (* x x) (* (* y 4.0) (- t (* z z)))) (* -4.0 (* t (* y (fma z (/ z t) -1.0))))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+300) {
tmp = (x * x) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = -4.0 * (t * (y * fma(z, (z / t), -1.0)));
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+300) tmp = Float64(Float64(x * x) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(-4.0 * Float64(t * Float64(y * fma(z, Float64(z / t), -1.0)))); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+300], N[(N[(x * x), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-4.0 * N[(t * N[(y * N[(z * N[(z / t), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+300}:\\
\;\;\;\;x \cdot x + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;-4 \cdot \left(t \cdot \left(y \cdot \mathsf{fma}\left(z, \frac{z}{t}, -1\right)\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 1.0000000000000001e300Initial program 98.9%
if 1.0000000000000001e300 < (*.f64 z z) Initial program 64.2%
Taylor expanded in t around inf 64.2%
Taylor expanded in x around 0 78.9%
sub-neg78.9%
metadata-eval78.9%
associate-*r*71.0%
*-commutative71.0%
metadata-eval71.0%
sub-neg71.0%
unpow271.0%
associate-*r/75.1%
fma-neg75.1%
metadata-eval75.1%
Simplified75.1%
log1p-expm1-u71.0%
pow171.0%
log1p-expm1-u75.1%
*-commutative75.1%
metadata-eval75.1%
fma-neg75.1%
associate-*l*83.0%
fma-neg83.0%
metadata-eval83.0%
Applied egg-rr83.0%
pow183.0%
pow183.0%
associate-*r*75.1%
Applied egg-rr75.1%
unpow175.1%
associate-*l*83.0%
Simplified83.0%
Final simplification94.7%
(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 89.7%
fma-neg93.6%
distribute-lft-neg-in93.6%
*-commutative93.6%
distribute-rgt-neg-in93.6%
metadata-eval93.6%
Simplified93.6%
Final simplification93.6%
(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 #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) < +inf.0Initial program 96.5%
if +inf.0 < (-.f64 (*.f64 x x) (*.f64 (*.f64 y #s(literal 4 binary64)) (-.f64 (*.f64 z z) t))) Initial program 0.0%
sub-neg0.0%
distribute-lft-neg-in0.0%
*-commutative0.0%
distribute-lft-neg-in0.0%
metadata-eval0.0%
*-commutative0.0%
add-sqr-sqrt0.0%
sqrt-unprod11.1%
swap-sqr11.1%
metadata-eval11.1%
metadata-eval11.1%
swap-sqr11.1%
sqrt-unprod38.9%
add-sqr-sqrt44.4%
expm1-log1p-u44.4%
add-sqr-sqrt38.9%
Applied egg-rr0.0%
Simplified44.4%
expm1-log1p-u44.4%
pow244.4%
Applied egg-rr44.4%
Final simplification92.8%
(FPCore (x y z t) :precision binary64 (if (or (<= x 7e-99) (and (not (<= x 6.5e-72)) (<= x 7.2e+31))) (* y (* 4.0 t)) (* x x)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= 7e-99) || (!(x <= 6.5e-72) && (x <= 7.2e+31))) {
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 <= 7d-99) .or. (.not. (x <= 6.5d-72)) .and. (x <= 7.2d+31)) 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 <= 7e-99) || (!(x <= 6.5e-72) && (x <= 7.2e+31))) {
tmp = y * (4.0 * t);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= 7e-99) or (not (x <= 6.5e-72) and (x <= 7.2e+31)): tmp = y * (4.0 * t) else: tmp = x * x return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= 7e-99) || (!(x <= 6.5e-72) && (x <= 7.2e+31))) 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 <= 7e-99) || (~((x <= 6.5e-72)) && (x <= 7.2e+31))) tmp = y * (4.0 * t); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, 7e-99], And[N[Not[LessEqual[x, 6.5e-72]], $MachinePrecision], LessEqual[x, 7.2e+31]]], N[(y * N[(4.0 * t), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7 \cdot 10^{-99} \lor \neg \left(x \leq 6.5 \cdot 10^{-72}\right) \land x \leq 7.2 \cdot 10^{+31}:\\
\;\;\;\;y \cdot \left(4 \cdot t\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 6.9999999999999997e-99 or 6.4999999999999997e-72 < x < 7.19999999999999992e31Initial program 93.3%
Taylor expanded in t around inf 39.0%
associate-*r*39.0%
Simplified39.0%
if 6.9999999999999997e-99 < x < 6.4999999999999997e-72 or 7.19999999999999992e31 < x Initial program 79.8%
sub-neg79.8%
distribute-lft-neg-in79.8%
*-commutative79.8%
distribute-lft-neg-in79.8%
metadata-eval79.8%
*-commutative79.8%
add-sqr-sqrt33.3%
sqrt-unprod65.2%
swap-sqr65.2%
metadata-eval65.2%
metadata-eval65.2%
swap-sqr65.2%
sqrt-unprod39.1%
add-sqr-sqrt62.3%
expm1-log1p-u60.5%
add-sqr-sqrt38.3%
Applied egg-rr64.8%
Simplified69.5%
expm1-log1p-u71.3%
pow271.3%
Applied egg-rr71.3%
Final simplification47.7%
(FPCore (x y z t) :precision binary64 (- (* x x) (* -4.0 (* y t))))
double code(double x, double y, double z, double t) {
return (x * x) - (-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 = (x * x) - ((-4.0d0) * (y * t))
end function
public static double code(double x, double y, double z, double t) {
return (x * x) - (-4.0 * (y * t));
}
def code(x, y, z, t): return (x * x) - (-4.0 * (y * t))
function code(x, y, z, t) return Float64(Float64(x * x) - Float64(-4.0 * Float64(y * t))) end
function tmp = code(x, y, z, t) tmp = (x * x) - (-4.0 * (y * t)); end
code[x_, y_, z_, t_] := N[(N[(x * x), $MachinePrecision] - N[(-4.0 * N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - -4 \cdot \left(y \cdot t\right)
\end{array}
Initial program 89.7%
Taylor expanded in z around 0 69.1%
*-commutative69.1%
Simplified69.1%
Final simplification69.1%
(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 89.7%
sub-neg89.7%
distribute-lft-neg-in89.7%
*-commutative89.7%
distribute-lft-neg-in89.7%
metadata-eval89.7%
*-commutative89.7%
add-sqr-sqrt44.9%
sqrt-unprod55.6%
swap-sqr55.6%
metadata-eval55.6%
metadata-eval55.6%
swap-sqr55.6%
sqrt-unprod20.4%
add-sqr-sqrt37.4%
expm1-log1p-u36.2%
add-sqr-sqrt19.9%
Applied egg-rr65.0%
Simplified41.3%
expm1-log1p-u42.5%
pow242.5%
Applied egg-rr42.5%
Final simplification42.5%
(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 2024059
(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))))