
(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}
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= x_m 5e+230) (fma x_m x_m (* (- (* z z) t) (* y -4.0))) (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 5e+230) {
tmp = fma(x_m, x_m, (((z * z) - t) * (y * -4.0)));
} else {
tmp = pow(x_m, 2.0);
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (x_m <= 5e+230) tmp = fma(x_m, x_m, Float64(Float64(Float64(z * z) - t) * Float64(y * -4.0))); else tmp = x_m ^ 2.0; end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 5e+230], N[(x$95$m * x$95$m + N[(N[(N[(z * z), $MachinePrecision] - t), $MachinePrecision] * N[(y * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$95$m, 2.0], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 5 \cdot 10^{+230}:\\
\;\;\;\;\mathsf{fma}\left(x\_m, x\_m, \left(z \cdot z - t\right) \cdot \left(y \cdot -4\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{2}\\
\end{array}
\end{array}
if x < 5.0000000000000003e230Initial program 91.8%
fma-neg94.3%
distribute-lft-neg-in94.3%
*-commutative94.3%
distribute-rgt-neg-in94.3%
metadata-eval94.3%
Simplified94.3%
if 5.0000000000000003e230 < x Initial program 80.0%
Taylor expanded in x around 0 80.0%
Simplified100.0%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= x_m 1.3e+138) (+ (* x_m x_m) (* (* y 4.0) (- t (* z z)))) (fma (* y 4.0) t (* x_m x_m))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (x_m <= 1.3e+138) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = fma((y * 4.0), t, (x_m * x_m));
}
return tmp;
}
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (x_m <= 1.3e+138) tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = fma(Float64(y * 4.0), t, Float64(x_m * x_m)); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[x$95$m, 1.3e+138], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * 4.0), $MachinePrecision] * t + N[(x$95$m * x$95$m), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \leq 1.3 \cdot 10^{+138}:\\
\;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y \cdot 4, t, x\_m \cdot x\_m\right)\\
\end{array}
\end{array}
if x < 1.3e138Initial program 91.7%
if 1.3e138 < x Initial program 88.1%
cancel-sign-sub-inv88.1%
distribute-lft-neg-out88.1%
+-commutative88.1%
distribute-lft-neg-out88.1%
distribute-lft-neg-in88.1%
distribute-rgt-neg-in88.1%
fma-define92.9%
sub-neg92.9%
+-commutative92.9%
distribute-neg-in92.9%
remove-double-neg92.9%
sub-neg92.9%
Simplified92.9%
Taylor expanded in t around inf 97.6%
Final simplification92.7%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= (* x_m x_m) 1e+278) (+ (* x_m x_m) (* (* y 4.0) (- t (* z z)))) (pow x_m 2.0)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if ((x_m * x_m) <= 1e+278) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = pow(x_m, 2.0);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((x_m * x_m) <= 1d+278) then
tmp = (x_m * x_m) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = x_m ** 2.0d0
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if ((x_m * x_m) <= 1e+278) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = Math.pow(x_m, 2.0);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if (x_m * x_m) <= 1e+278: tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))) else: tmp = math.pow(x_m, 2.0) return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (Float64(x_m * x_m) <= 1e+278) tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = x_m ^ 2.0; end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if ((x_m * x_m) <= 1e+278) tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))); else tmp = x_m ^ 2.0; end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 1e+278], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[x$95$m, 2.0], $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x\_m \cdot x\_m \leq 10^{+278}:\\
\;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;{x\_m}^{2}\\
\end{array}
\end{array}
if (*.f64 x x) < 9.99999999999999964e277Initial program 96.1%
if 9.99999999999999964e277 < (*.f64 x x) Initial program 80.5%
Taylor expanded in x around 0 80.5%
Simplified92.7%
Final simplification95.0%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= (* z z) 1e+112) (+ (* x_m x_m) (* (* y 4.0) (- t (* z z)))) (- (* x_m x_m) (* z (* z (* y 4.0))))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+112) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x_m * x_m) - (z * (z * (y * 4.0)));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if ((z * z) <= 1d+112) then
tmp = (x_m * x_m) + ((y * 4.0d0) * (t - (z * z)))
else
tmp = (x_m * x_m) - (z * (z * (y * 4.0d0)))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if ((z * z) <= 1e+112) {
tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z)));
} else {
tmp = (x_m * x_m) - (z * (z * (y * 4.0)));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if (z * z) <= 1e+112: tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))) else: tmp = (x_m * x_m) - (z * (z * (y * 4.0))) return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (Float64(z * z) <= 1e+112) tmp = Float64(Float64(x_m * x_m) + Float64(Float64(y * 4.0) * Float64(t - Float64(z * z)))); else tmp = Float64(Float64(x_m * x_m) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if ((z * z) <= 1e+112) tmp = (x_m * x_m) + ((y * 4.0) * (t - (z * z))); else tmp = (x_m * x_m) - (z * (z * (y * 4.0))); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[N[(z * z), $MachinePrecision], 1e+112], N[(N[(x$95$m * x$95$m), $MachinePrecision] + N[(N[(y * 4.0), $MachinePrecision] * N[(t - N[(z * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;z \cdot z \leq 10^{+112}:\\
\;\;\;\;x\_m \cdot x\_m + \left(y \cdot 4\right) \cdot \left(t - z \cdot z\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if (*.f64 z z) < 9.9999999999999993e111Initial program 97.9%
if 9.9999999999999993e111 < (*.f64 z z) Initial program 81.6%
*-commutative81.6%
add-sqr-sqrt30.0%
sqrt-unprod34.8%
swap-sqr34.8%
metadata-eval34.8%
metadata-eval34.8%
swap-sqr34.8%
sqrt-unprod5.7%
add-sqr-sqrt21.6%
add-sqr-sqrt5.7%
pow25.7%
Applied egg-rr30.0%
Taylor expanded in z around -inf 34.5%
*-commutative34.5%
*-commutative34.5%
associate-*l*34.5%
Simplified34.5%
unpow234.5%
swap-sqr30.0%
swap-sqr30.0%
add-sqr-sqrt81.6%
metadata-eval81.6%
associate-*l*89.7%
Applied egg-rr89.7%
Final simplification94.5%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (if (<= z 6e-33) (- (* x_m x_m) (* y (* t -4.0))) (- (* x_m x_m) (* z (* z (* y 4.0))))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
double tmp;
if (z <= 6e-33) {
tmp = (x_m * x_m) - (y * (t * -4.0));
} else {
tmp = (x_m * x_m) - (z * (z * (y * 4.0)));
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: tmp
if (z <= 6d-33) then
tmp = (x_m * x_m) - (y * (t * (-4.0d0)))
else
tmp = (x_m * x_m) - (z * (z * (y * 4.0d0)))
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
double tmp;
if (z <= 6e-33) {
tmp = (x_m * x_m) - (y * (t * -4.0));
} else {
tmp = (x_m * x_m) - (z * (z * (y * 4.0)));
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y, z, t): tmp = 0 if z <= 6e-33: tmp = (x_m * x_m) - (y * (t * -4.0)) else: tmp = (x_m * x_m) - (z * (z * (y * 4.0))) return tmp
x_m = abs(x) function code(x_m, y, z, t) tmp = 0.0 if (z <= 6e-33) tmp = Float64(Float64(x_m * x_m) - Float64(y * Float64(t * -4.0))); else tmp = Float64(Float64(x_m * x_m) - Float64(z * Float64(z * Float64(y * 4.0)))); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y, z, t) tmp = 0.0; if (z <= 6e-33) tmp = (x_m * x_m) - (y * (t * -4.0)); else tmp = (x_m * x_m) - (z * (z * (y * 4.0))); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := If[LessEqual[z, 6e-33], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(z * N[(z * N[(y * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;z \leq 6 \cdot 10^{-33}:\\
\;\;\;\;x\_m \cdot x\_m - y \cdot \left(t \cdot -4\right)\\
\mathbf{else}:\\
\;\;\;\;x\_m \cdot x\_m - z \cdot \left(z \cdot \left(y \cdot 4\right)\right)\\
\end{array}
\end{array}
if z < 6.0000000000000003e-33Initial program 93.3%
Taylor expanded in z around 0 77.0%
associate-*r*77.0%
Simplified77.0%
if 6.0000000000000003e-33 < z Initial program 86.0%
*-commutative86.0%
add-sqr-sqrt32.6%
sqrt-unprod39.5%
swap-sqr39.5%
metadata-eval39.5%
metadata-eval39.5%
swap-sqr39.5%
sqrt-unprod13.2%
add-sqr-sqrt28.9%
add-sqr-sqrt13.1%
pow213.1%
Applied egg-rr32.6%
Taylor expanded in z around -inf 33.8%
*-commutative33.8%
*-commutative33.8%
associate-*l*33.8%
Simplified33.8%
unpow233.8%
swap-sqr30.1%
swap-sqr30.1%
add-sqr-sqrt81.1%
metadata-eval81.1%
associate-*l*88.5%
Applied egg-rr88.5%
Final simplification80.5%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (- (* x_m x_m) (* y (* t -4.0))))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return (x_m * x_m) - (y * (t * -4.0));
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x_m * x_m) - (y * (t * (-4.0d0)))
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return (x_m * x_m) - (y * (t * -4.0));
}
x_m = math.fabs(x) def code(x_m, y, z, t): return (x_m * x_m) - (y * (t * -4.0))
x_m = abs(x) function code(x_m, y, z, t) return Float64(Float64(x_m * x_m) - Float64(y * Float64(t * -4.0))) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = (x_m * x_m) - (y * (t * -4.0)); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y * N[(t * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
x\_m \cdot x\_m - y \cdot \left(t \cdot -4\right)
\end{array}
Initial program 91.1%
Taylor expanded in z around 0 68.3%
associate-*r*68.3%
Simplified68.3%
Final simplification68.3%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 (* 4.0 (* t y)))
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return 4.0 * (t * y);
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 4.0d0 * (t * y)
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return 4.0 * (t * y);
}
x_m = math.fabs(x) def code(x_m, y, z, t): return 4.0 * (t * y)
x_m = abs(x) function code(x_m, y, z, t) return Float64(4.0 * Float64(t * y)) end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = 4.0 * (t * y); end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := N[(4.0 * N[(t * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
4 \cdot \left(t \cdot y\right)
\end{array}
Initial program 91.1%
Taylor expanded in t around inf 28.4%
*-commutative28.4%
Simplified28.4%
Final simplification28.4%
x_m = (fabs.f64 x) (FPCore (x_m y z t) :precision binary64 0.0)
x_m = fabs(x);
double code(double x_m, double y, double z, double t) {
return 0.0;
}
x_m = abs(x)
real(8) function code(x_m, y, z, t)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = 0.0d0
end function
x_m = Math.abs(x);
public static double code(double x_m, double y, double z, double t) {
return 0.0;
}
x_m = math.fabs(x) def code(x_m, y, z, t): return 0.0
x_m = abs(x) function code(x_m, y, z, t) return 0.0 end
x_m = abs(x); function tmp = code(x_m, y, z, t) tmp = 0.0; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_, z_, t_] := 0.0
\begin{array}{l}
x_m = \left|x\right|
\\
0
\end{array}
Initial program 91.1%
Taylor expanded in x around 0 62.5%
Simplified3.6%
(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 2024106
(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))))