
(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}
(FPCore (x y) :precision binary64 (fma x x (* y (- y))))
double code(double x, double y) {
return fma(x, x, (y * -y));
}
function code(x, y) return fma(x, x, Float64(y * Float64(-y))) end
code[x_, y_] := N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)
\end{array}
Initial program 96.1%
sqr-neg96.1%
cancel-sign-sub96.1%
fma-define98.0%
Simplified98.0%
(FPCore (x y) :precision binary64 (if (<= (* y y) 4e+292) (- (* x x) (* y y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+292) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 4d+292) then
tmp = (x * x) - (y * y)
else
tmp = y * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 4e+292) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 4e+292: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 4e+292) tmp = Float64(Float64(x * x) - Float64(y * y)); else tmp = Float64(y * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 4e+292) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 4e+292], N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 4 \cdot 10^{+292}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.0000000000000001e292Initial program 100.0%
if 4.0000000000000001e292 < (*.f64 y y) Initial program 83.9%
Taylor expanded in x around 0 91.9%
neg-mul-191.9%
Simplified91.9%
unpow291.9%
distribute-lft-neg-in91.9%
Applied egg-rr91.9%
Final simplification98.0%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+45) (* x x) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+45) {
tmp = x * x;
} else {
tmp = y * -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 5d+45) then
tmp = x * x
else
tmp = y * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+45) {
tmp = x * x;
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+45: tmp = x * x else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+45) tmp = Float64(x * x); else tmp = Float64(y * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+45) tmp = x * x; else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+45], N[(x * x), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+45}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 5e45Initial program 100.0%
difference-of-squares100.0%
sub-neg100.0%
add-sqr-sqrt57.9%
sqrt-unprod91.2%
sqr-neg91.2%
sqrt-prod33.3%
add-sqr-sqrt83.3%
Applied egg-rr83.3%
Taylor expanded in x around inf 83.6%
Taylor expanded in x around inf 83.9%
if 5e45 < (*.f64 y y) Initial program 91.0%
Taylor expanded in x around 0 79.3%
neg-mul-179.3%
Simplified79.3%
unpow279.3%
distribute-lft-neg-in79.3%
Applied egg-rr79.3%
Final simplification81.9%
(FPCore (x y) :precision binary64 (* x x))
double code(double x, double y) {
return x * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * x
end function
public static double code(double x, double y) {
return x * x;
}
def code(x, y): return x * x
function code(x, y) return Float64(x * x) end
function tmp = code(x, y) tmp = x * x; end
code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 96.1%
difference-of-squares100.0%
sub-neg100.0%
add-sqr-sqrt55.4%
sqrt-unprod78.6%
sqr-neg78.6%
sqrt-prod23.9%
add-sqr-sqrt55.8%
Applied egg-rr55.8%
Taylor expanded in x around inf 58.4%
Taylor expanded in x around inf 56.6%
herbie shell --seed 2024186
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))