
(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 (or (<= (* x x) 1200.0)
(and (not (<= (* x x) 5.3e+96)) (<= (* x x) 1.15e+128)))
(* y (- y))
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 1200.0) || (!((x * x) <= 5.3e+96) && ((x * x) <= 1.15e+128))) {
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 (((x * x) <= 1200.0d0) .or. (.not. ((x * x) <= 5.3d+96)) .and. ((x * x) <= 1.15d+128)) 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 (((x * x) <= 1200.0) || (!((x * x) <= 5.3e+96) && ((x * x) <= 1.15e+128))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 1200.0) or (not ((x * x) <= 5.3e+96) and ((x * x) <= 1.15e+128)): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 1200.0) || (!(Float64(x * x) <= 5.3e+96) && (Float64(x * x) <= 1.15e+128))) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (((x * x) <= 1200.0) || (~(((x * x) <= 5.3e+96)) && ((x * x) <= 1.15e+128))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 1200.0], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 5.3e+96]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 1.15e+128]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1200 \lor \neg \left(x \cdot x \leq 5.3 \cdot 10^{+96}\right) \land x \cdot x \leq 1.15 \cdot 10^{+128}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1200 or 5.29999999999999971e96 < (*.f64 x x) < 1.14999999999999999e128Initial program 100.0%
Taylor expanded in x around 0 82.5%
unpow282.5%
mul-1-neg82.5%
distribute-rgt-neg-in82.5%
Simplified82.5%
if 1200 < (*.f64 x x) < 5.29999999999999971e96 or 1.14999999999999999e128 < (*.f64 x x) Initial program 88.7%
Taylor expanded in x around inf 80.7%
unpow280.7%
Simplified80.7%
Final simplification81.7%
(FPCore (x y) :precision binary64 (if (<= (* y y) 2e+254) (- (* x x) (* y y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+254) {
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+254) 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+254) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2e+254: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e+254) 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+254) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e+254], 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^{+254}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 1.9999999999999999e254Initial program 100.0%
if 1.9999999999999999e254 < (*.f64 y y) Initial program 80.0%
Taylor expanded in x around 0 91.4%
unpow291.4%
mul-1-neg91.4%
distribute-rgt-neg-in91.4%
Simplified91.4%
Final simplification97.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 94.5%
Taylor expanded in x around inf 52.9%
unpow252.9%
Simplified52.9%
Final simplification52.9%
herbie shell --seed 2023195
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))