
(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 93.8%
fma-neg98.4%
distribute-rgt-neg-in98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 8.4e-54)
(and (not (<= (* x x) 6.8e+183)) (<= (* x x) 5.6e+261)))
(* y (- y))
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 8.4e-54) || (!((x * x) <= 6.8e+183) && ((x * x) <= 5.6e+261))) {
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) <= 8.4d-54) .or. (.not. ((x * x) <= 6.8d+183)) .and. ((x * x) <= 5.6d+261)) 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) <= 8.4e-54) || (!((x * x) <= 6.8e+183) && ((x * x) <= 5.6e+261))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 8.4e-54) or (not ((x * x) <= 6.8e+183) and ((x * x) <= 5.6e+261)): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 8.4e-54) || (!(Float64(x * x) <= 6.8e+183) && (Float64(x * x) <= 5.6e+261))) 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) <= 8.4e-54) || (~(((x * x) <= 6.8e+183)) && ((x * x) <= 5.6e+261))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 8.4e-54], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 6.8e+183]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 5.6e+261]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 8.4 \cdot 10^{-54} \lor \neg \left(x \cdot x \leq 6.8 \cdot 10^{+183}\right) \land x \cdot x \leq 5.6 \cdot 10^{+261}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 8.4e-54 or 6.8e183 < (*.f64 x x) < 5.5999999999999996e261Initial program 100.0%
Taylor expanded in x around 0 84.0%
unpow284.0%
mul-1-neg84.0%
distribute-rgt-neg-in84.0%
Simplified84.0%
if 8.4e-54 < (*.f64 x x) < 6.8e183 or 5.5999999999999996e261 < (*.f64 x x) Initial program 85.3%
Taylor expanded in x around inf 77.1%
unpow277.1%
Simplified77.1%
Final simplification81.1%
(FPCore (x y) :precision binary64 (if (<= (* y y) 2e+299) (- (* x x) (* y y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+299) {
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+299) 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+299) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 2e+299: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e+299) 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+299) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e+299], 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^{+299}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 2.0000000000000001e299Initial program 100.0%
if 2.0000000000000001e299 < (*.f64 y y) Initial program 76.1%
Taylor expanded in x around 0 94.0%
unpow294.0%
mul-1-neg94.0%
distribute-rgt-neg-in94.0%
Simplified94.0%
Final simplification98.4%
(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 93.8%
Taylor expanded in x around inf 50.9%
unpow250.9%
Simplified50.9%
Final simplification50.9%
herbie shell --seed 2023224
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))