
(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 94.5%
fma-neg97.7%
distribute-rgt-neg-in97.7%
Simplified97.7%
Final simplification97.7%
(FPCore (x y) :precision binary64 (if (<= (* y y) 2e+306) (- (* x x) (* y y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+306) {
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) <= 2d+306) 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) <= 2e+306) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2e+306: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e+306) 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) <= 2e+306) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e+306], 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 2 \cdot 10^{+306}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 2.00000000000000003e306Initial program 100.0%
if 2.00000000000000003e306 < (*.f64 y y) Initial program 77.4%
Taylor expanded in x around 0 90.3%
unpow290.3%
mul-1-neg90.3%
distribute-rgt-neg-in90.3%
Simplified90.3%
Final simplification97.7%
(FPCore (x y) :precision binary64 (if (or (<= y 7.5e-66) (and (not (<= y 2.65e-39)) (<= y 2.4e+48))) (* x x) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y <= 7.5e-66) || (!(y <= 2.65e-39) && (y <= 2.4e+48))) {
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 <= 7.5d-66) .or. (.not. (y <= 2.65d-39)) .and. (y <= 2.4d+48)) 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 <= 7.5e-66) || (!(y <= 2.65e-39) && (y <= 2.4e+48))) {
tmp = x * x;
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 7.5e-66) or (not (y <= 2.65e-39) and (y <= 2.4e+48)): tmp = x * x else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if ((y <= 7.5e-66) || (!(y <= 2.65e-39) && (y <= 2.4e+48))) 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 <= 7.5e-66) || (~((y <= 2.65e-39)) && (y <= 2.4e+48))) tmp = x * x; else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 7.5e-66], And[N[Not[LessEqual[y, 2.65e-39]], $MachinePrecision], LessEqual[y, 2.4e+48]]], N[(x * x), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7.5 \cdot 10^{-66} \lor \neg \left(y \leq 2.65 \cdot 10^{-39}\right) \land y \leq 2.4 \cdot 10^{+48}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 7.49999999999999995e-66 or 2.65000000000000002e-39 < y < 2.4000000000000001e48Initial program 96.9%
Taylor expanded in x around inf 66.5%
unpow266.5%
Simplified66.5%
if 7.49999999999999995e-66 < y < 2.65000000000000002e-39 or 2.4000000000000001e48 < y Initial program 87.1%
Taylor expanded in x around 0 82.3%
unpow282.3%
mul-1-neg82.3%
distribute-rgt-neg-in82.3%
Simplified82.3%
Final simplification70.3%
(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 94.5%
Taylor expanded in x around inf 54.9%
unpow254.9%
Simplified54.9%
Final simplification54.9%
herbie shell --seed 2023221
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))