
(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 x) 2.5e+267) (- (* x x) (* y y)) (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 2.5e+267) {
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) <= 2.5d+267) 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) <= 2.5e+267) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 2.5e+267: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 2.5e+267) 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) <= 2.5e+267) tmp = (x * x) - (y * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 2.5e+267], 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 2.5 \cdot 10^{+267}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 2.4999999999999999e267Initial program 100.0%
if 2.4999999999999999e267 < (*.f64 x x) Initial program 76.9%
Taylor expanded in x around inf 89.2%
unpow289.2%
Simplified89.2%
Final simplification97.3%
(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.1%
fma-neg96.9%
distribute-rgt-neg-in96.9%
Simplified96.9%
Final simplification96.9%
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 1.75e-28)
(and (not (<= (* x x) 5.2e+84)) (<= (* x x) 3.6e+130)))
(* y (- y))
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 1.75e-28) || (!((x * x) <= 5.2e+84) && ((x * x) <= 3.6e+130))) {
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) <= 1.75d-28) .or. (.not. ((x * x) <= 5.2d+84)) .and. ((x * x) <= 3.6d+130)) 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) <= 1.75e-28) || (!((x * x) <= 5.2e+84) && ((x * x) <= 3.6e+130))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 1.75e-28) or (not ((x * x) <= 5.2e+84) and ((x * x) <= 3.6e+130)): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 1.75e-28) || (!(Float64(x * x) <= 5.2e+84) && (Float64(x * x) <= 3.6e+130))) 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) <= 1.75e-28) || (~(((x * x) <= 5.2e+84)) && ((x * x) <= 3.6e+130))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 1.75e-28], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 5.2e+84]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 3.6e+130]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.75 \cdot 10^{-28} \lor \neg \left(x \cdot x \leq 5.2 \cdot 10^{+84}\right) \land x \cdot x \leq 3.6 \cdot 10^{+130}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.75e-28 or 5.2000000000000002e84 < (*.f64 x x) < 3.6000000000000001e130Initial program 100.0%
Taylor expanded in x around 0 85.7%
unpow285.7%
mul-1-neg85.7%
distribute-rgt-neg-in85.7%
Simplified85.7%
if 1.75e-28 < (*.f64 x x) < 5.2000000000000002e84 or 3.6000000000000001e130 < (*.f64 x x) Initial program 87.2%
Taylor expanded in x around inf 80.4%
unpow280.4%
Simplified80.4%
Final simplification83.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.1%
Taylor expanded in x around inf 53.3%
unpow253.3%
Simplified53.3%
Final simplification53.3%
herbie shell --seed 2023185
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))