
(FPCore (x y) :precision binary64 (- (* x x) (* y y)))
double code(double x, double y) {
return (x * x) - (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) - (y * y)
end function
public static double code(double x, double y) {
return (x * x) - (y * y);
}
def code(x, y): return (x * x) - (y * y)
function code(x, y) return Float64(Float64(x * x) - Float64(y * y)) end
function tmp = code(x, y) tmp = (x * x) - (y * y); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - y \cdot y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* x x) (* y y)))
double code(double x, double y) {
return (x * x) - (y * y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * x) - (y * y)
end function
public static double code(double x, double y) {
return (x * x) - (y * y);
}
def code(x, y): return (x * x) - (y * y)
function code(x, y) return Float64(Float64(x * x) - Float64(y * y)) end
function tmp = code(x, y) tmp = (x * x) - (y * y); end
code[x_, y_] := N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x - y \cdot y
\end{array}
x_m = (fabs.f64 x) (FPCore (x_m y) :precision binary64 (if (<= x_m 1e+206) (fma x_m x_m (* y (- y))) (* (- x_m y) (- x_m y))))
x_m = fabs(x);
double code(double x_m, double y) {
double tmp;
if (x_m <= 1e+206) {
tmp = fma(x_m, x_m, (y * -y));
} else {
tmp = (x_m - y) * (x_m - y);
}
return tmp;
}
x_m = abs(x) function code(x_m, y) tmp = 0.0 if (x_m <= 1e+206) tmp = fma(x_m, x_m, Float64(y * Float64(-y))); else tmp = Float64(Float64(x_m - y) * Float64(x_m - y)); end return tmp end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_] := If[LessEqual[x$95$m, 1e+206], N[(x$95$m * x$95$m + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m - y), $MachinePrecision] * N[(x$95$m - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 10^{+206}:\\
\;\;\;\;\mathsf{fma}\left(x_m, x_m, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x_m - y\right) \cdot \left(x_m - y\right)\\
\end{array}
\end{array}
if x < 1e206Initial program 93.7%
sqr-neg93.7%
cancel-sign-sub93.7%
fma-def97.0%
Simplified97.0%
if 1e206 < x Initial program 78.9%
difference-of-squares100.0%
add-sqr-sqrt68.4%
sqrt-prod94.7%
sqr-neg94.7%
sqrt-unprod26.3%
add-sqr-sqrt94.7%
sub-neg94.7%
pow194.7%
pow194.7%
pow-prod-up94.7%
metadata-eval94.7%
add-sqr-sqrt94.7%
add-sqr-sqrt68.4%
difference-of-squares68.4%
unpow-prod-down68.4%
Applied egg-rr68.4%
unpow268.4%
unpow268.4%
unswap-sqr68.4%
difference-of-squares68.4%
unpow1/268.4%
unpow1/268.4%
pow-sqr68.4%
metadata-eval68.4%
unpow168.4%
unpow1/268.4%
unpow1/268.4%
pow-sqr68.4%
metadata-eval68.4%
unpow168.4%
difference-of-squares68.4%
unpow1/268.4%
unpow1/268.4%
pow-sqr68.4%
metadata-eval68.4%
unpow168.4%
Simplified94.7%
Final simplification96.9%
x_m = (fabs.f64 x) (FPCore (x_m y) :precision binary64 (if (<= x_m 1.9e-57) (* y (- y)) (* (- x_m y) (- x_m y))))
x_m = fabs(x);
double code(double x_m, double y) {
double tmp;
if (x_m <= 1.9e-57) {
tmp = y * -y;
} else {
tmp = (x_m - y) * (x_m - y);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8) :: tmp
if (x_m <= 1.9d-57) then
tmp = y * -y
else
tmp = (x_m - y) * (x_m - y)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
double tmp;
if (x_m <= 1.9e-57) {
tmp = y * -y;
} else {
tmp = (x_m - y) * (x_m - y);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y): tmp = 0 if x_m <= 1.9e-57: tmp = y * -y else: tmp = (x_m - y) * (x_m - y) return tmp
x_m = abs(x) function code(x_m, y) tmp = 0.0 if (x_m <= 1.9e-57) tmp = Float64(y * Float64(-y)); else tmp = Float64(Float64(x_m - y) * Float64(x_m - y)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y) tmp = 0.0; if (x_m <= 1.9e-57) tmp = y * -y; else tmp = (x_m - y) * (x_m - y); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_] := If[LessEqual[x$95$m, 1.9e-57], N[(y * (-y)), $MachinePrecision], N[(N[(x$95$m - y), $MachinePrecision] * N[(x$95$m - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.9 \cdot 10^{-57}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x_m - y\right) \cdot \left(x_m - y\right)\\
\end{array}
\end{array}
if x < 1.8999999999999999e-57Initial program 93.5%
Taylor expanded in x around 0 62.0%
mul-1-neg62.0%
Simplified62.0%
unpow262.0%
Applied egg-rr62.0%
if 1.8999999999999999e-57 < x Initial program 90.1%
difference-of-squares100.0%
add-sqr-sqrt52.1%
sqrt-prod88.5%
sqr-neg88.5%
sqrt-unprod36.4%
add-sqr-sqrt74.8%
sub-neg74.8%
pow174.8%
pow174.8%
pow-prod-up74.8%
metadata-eval74.8%
add-sqr-sqrt74.4%
add-sqr-sqrt38.2%
difference-of-squares38.2%
unpow-prod-down38.2%
Applied egg-rr38.2%
unpow238.2%
unpow238.2%
unswap-sqr38.2%
difference-of-squares38.2%
unpow1/238.2%
unpow1/238.2%
pow-sqr38.3%
metadata-eval38.3%
unpow138.3%
unpow1/238.3%
unpow1/238.3%
pow-sqr38.3%
metadata-eval38.3%
unpow138.3%
difference-of-squares38.3%
unpow1/238.3%
unpow1/238.3%
pow-sqr38.4%
metadata-eval38.4%
unpow138.4%
Simplified74.8%
Final simplification65.6%
x_m = (fabs.f64 x) (FPCore (x_m y) :precision binary64 (if (<= x_m 1.18e+147) (- (* x_m x_m) (* y y)) (* (- x_m y) (- x_m y))))
x_m = fabs(x);
double code(double x_m, double y) {
double tmp;
if (x_m <= 1.18e+147) {
tmp = (x_m * x_m) - (y * y);
} else {
tmp = (x_m - y) * (x_m - y);
}
return tmp;
}
x_m = abs(x)
real(8) function code(x_m, y)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
real(8) :: tmp
if (x_m <= 1.18d+147) then
tmp = (x_m * x_m) - (y * y)
else
tmp = (x_m - y) * (x_m - y)
end if
code = tmp
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
double tmp;
if (x_m <= 1.18e+147) {
tmp = (x_m * x_m) - (y * y);
} else {
tmp = (x_m - y) * (x_m - y);
}
return tmp;
}
x_m = math.fabs(x) def code(x_m, y): tmp = 0 if x_m <= 1.18e+147: tmp = (x_m * x_m) - (y * y) else: tmp = (x_m - y) * (x_m - y) return tmp
x_m = abs(x) function code(x_m, y) tmp = 0.0 if (x_m <= 1.18e+147) tmp = Float64(Float64(x_m * x_m) - Float64(y * y)); else tmp = Float64(Float64(x_m - y) * Float64(x_m - y)); end return tmp end
x_m = abs(x); function tmp_2 = code(x_m, y) tmp = 0.0; if (x_m <= 1.18e+147) tmp = (x_m * x_m) - (y * y); else tmp = (x_m - y) * (x_m - y); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_] := If[LessEqual[x$95$m, 1.18e+147], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(N[(x$95$m - y), $MachinePrecision] * N[(x$95$m - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \leq 1.18 \cdot 10^{+147}:\\
\;\;\;\;x_m \cdot x_m - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;\left(x_m - y\right) \cdot \left(x_m - y\right)\\
\end{array}
\end{array}
if x < 1.18000000000000006e147Initial program 94.6%
if 1.18000000000000006e147 < x Initial program 78.8%
difference-of-squares100.0%
add-sqr-sqrt51.5%
sqrt-prod90.9%
sqr-neg90.9%
sqrt-unprod39.4%
add-sqr-sqrt87.9%
sub-neg87.9%
pow187.9%
pow187.9%
pow-prod-up87.9%
metadata-eval87.9%
add-sqr-sqrt87.9%
add-sqr-sqrt48.5%
difference-of-squares48.5%
unpow-prod-down48.5%
Applied egg-rr48.5%
unpow248.5%
unpow248.5%
unswap-sqr48.5%
difference-of-squares48.5%
unpow1/248.5%
unpow1/248.5%
pow-sqr48.5%
metadata-eval48.5%
unpow148.5%
unpow1/248.5%
unpow1/248.5%
pow-sqr48.5%
metadata-eval48.5%
unpow148.5%
difference-of-squares48.5%
unpow1/248.5%
unpow1/248.5%
pow-sqr48.5%
metadata-eval48.5%
unpow148.5%
Simplified87.9%
Final simplification93.8%
x_m = (fabs.f64 x) (FPCore (x_m y) :precision binary64 (* y (- y)))
x_m = fabs(x);
double code(double x_m, double y) {
return y * -y;
}
x_m = abs(x)
real(8) function code(x_m, y)
real(8), intent (in) :: x_m
real(8), intent (in) :: y
code = y * -y
end function
x_m = Math.abs(x);
public static double code(double x_m, double y) {
return y * -y;
}
x_m = math.fabs(x) def code(x_m, y): return y * -y
x_m = abs(x) function code(x_m, y) return Float64(y * Float64(-y)) end
x_m = abs(x); function tmp = code(x_m, y) tmp = y * -y; end
x_m = N[Abs[x], $MachinePrecision] code[x$95$m_, y_] := N[(y * (-y)), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y \cdot \left(-y\right)
\end{array}
Initial program 92.6%
Taylor expanded in x around 0 51.8%
mul-1-neg51.8%
Simplified51.8%
unpow251.8%
Applied egg-rr51.8%
Final simplification51.8%
herbie shell --seed 2023315
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))