
(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 (if (<= x 2e+217) (fma x x (* y (- y))) (* x x)))
double code(double x, double y) {
double tmp;
if (x <= 2e+217) {
tmp = fma(x, x, (y * -y));
} else {
tmp = x * x;
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= 2e+217) tmp = fma(x, x, Float64(y * Float64(-y))); else tmp = Float64(x * x); end return tmp end
code[x_, y_] := If[LessEqual[x, 2e+217], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2 \cdot 10^{+217}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.99999999999999992e217Initial program 95.3%
fma-neg98.7%
distribute-rgt-neg-in98.7%
Simplified98.7%
if 1.99999999999999992e217 < x Initial program 52.4%
Taylor expanded in x around inf 90.5%
unpow290.5%
Simplified90.5%
Final simplification98.0%
(FPCore (x y) :precision binary64 (if (<= (* x x) 7.5e+298) (- (* x x) (* y y)) (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 7.5e+298) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 7.5d+298) then
tmp = (x * x) - (y * y)
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 7.5e+298) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 7.5e+298: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 7.5e+298) tmp = Float64(Float64(x * x) - Float64(y * y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 7.5e+298) tmp = (x * x) - (y * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 7.5e+298], N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 7.5 \cdot 10^{+298}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 7.5000000000000004e298Initial program 100.0%
if 7.5000000000000004e298 < (*.f64 x x) Initial program 67.7%
Taylor expanded in x around inf 84.6%
unpow284.6%
Simplified84.6%
Final simplification96.1%
(FPCore (x y) :precision binary64 (if (or (<= y -2.15e+51) (not (<= y 8e+57))) (* y (- y)) (* x x)))
double code(double x, double y) {
double tmp;
if ((y <= -2.15e+51) || !(y <= 8e+57)) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2.15d+51)) .or. (.not. (y <= 8d+57))) then
tmp = y * -y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.15e+51) || !(y <= 8e+57)) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.15e+51) or not (y <= 8e+57): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.15e+51) || !(y <= 8e+57)) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.15e+51) || ~((y <= 8e+57))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.15e+51], N[Not[LessEqual[y, 8e+57]], $MachinePrecision]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{+51} \lor \neg \left(y \leq 8 \cdot 10^{+57}\right):\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if y < -2.1499999999999999e51 or 8.00000000000000039e57 < y Initial program 83.5%
Taylor expanded in x around 0 80.3%
unpow280.3%
mul-1-neg80.3%
distribute-rgt-neg-in80.3%
Simplified80.3%
if -2.1499999999999999e51 < y < 8.00000000000000039e57Initial program 100.0%
Taylor expanded in x around inf 84.9%
unpow284.9%
Simplified84.9%
Final simplification82.6%
(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 91.8%
Taylor expanded in x around inf 53.0%
unpow253.0%
Simplified53.0%
Final simplification53.0%
herbie shell --seed 2023196
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))