
(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-neg98.0%
distribute-rgt-neg-in98.0%
Simplified98.0%
Final simplification98.0%
(FPCore (x y)
:precision binary64
(if (or (<= y -4.2e+15)
(and (not (<= y 1.95e-41)) (or (<= y 8.8e-5) (not (<= y 7e+69)))))
(* y (- y))
(* x x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.2e+15) || (!(y <= 1.95e-41) && ((y <= 8.8e-5) || !(y <= 7e+69)))) {
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 <= (-4.2d+15)) .or. (.not. (y <= 1.95d-41)) .and. (y <= 8.8d-5) .or. (.not. (y <= 7d+69))) 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 <= -4.2e+15) || (!(y <= 1.95e-41) && ((y <= 8.8e-5) || !(y <= 7e+69)))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.2e+15) or (not (y <= 1.95e-41) and ((y <= 8.8e-5) or not (y <= 7e+69))): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.2e+15) || (!(y <= 1.95e-41) && ((y <= 8.8e-5) || !(y <= 7e+69)))) 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 <= -4.2e+15) || (~((y <= 1.95e-41)) && ((y <= 8.8e-5) || ~((y <= 7e+69))))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.2e+15], And[N[Not[LessEqual[y, 1.95e-41]], $MachinePrecision], Or[LessEqual[y, 8.8e-5], N[Not[LessEqual[y, 7e+69]], $MachinePrecision]]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{+15} \lor \neg \left(y \leq 1.95 \cdot 10^{-41}\right) \land \left(y \leq 8.8 \cdot 10^{-5} \lor \neg \left(y \leq 7 \cdot 10^{+69}\right)\right):\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if y < -4.2e15 or 1.94999999999999995e-41 < y < 8.7999999999999998e-5 or 6.99999999999999974e69 < y Initial program 88.8%
Taylor expanded in x around 0 80.5%
unpow280.5%
mul-1-neg80.5%
distribute-rgt-neg-in80.5%
Simplified80.5%
if -4.2e15 < y < 1.94999999999999995e-41 or 8.7999999999999998e-5 < y < 6.99999999999999974e69Initial program 100.0%
Taylor expanded in x around inf 85.1%
unpow285.1%
Simplified85.1%
Final simplification82.9%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+301) (- (* x x) (* y y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+301) {
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) <= 5d+301) 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) <= 5e+301) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+301: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+301) 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) <= 5e+301) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+301], 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 5 \cdot 10^{+301}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 5.0000000000000004e301Initial program 100.0%
if 5.0000000000000004e301 < (*.f64 y y) Initial program 79.4%
Taylor expanded in x around 0 92.6%
unpow292.6%
mul-1-neg92.6%
distribute-rgt-neg-in92.6%
Simplified92.6%
Final simplification98.0%
(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 53.0%
unpow253.0%
Simplified53.0%
Final simplification53.0%
herbie shell --seed 2023181
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))