
(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 -2.4e+234) (* x x) (fma x x (* y (- y)))))
double code(double x, double y) {
double tmp;
if (x <= -2.4e+234) {
tmp = x * x;
} else {
tmp = fma(x, x, (y * -y));
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -2.4e+234) tmp = Float64(x * x); else tmp = fma(x, x, Float64(y * Float64(-y))); end return tmp end
code[x_, y_] := If[LessEqual[x, -2.4e+234], N[(x * x), $MachinePrecision], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+234}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\end{array}
\end{array}
if x < -2.40000000000000011e234Initial program 66.7%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
if -2.40000000000000011e234 < x Initial program 93.4%
fma-neg97.5%
distribute-rgt-neg-in97.5%
Simplified97.5%
Final simplification97.7%
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 7.4e-36)
(and (not (<= (* x x) 2e+63)) (<= (* x x) 5.5e+144)))
(* y (- y))
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 7.4e-36) || (!((x * x) <= 2e+63) && ((x * x) <= 5.5e+144))) {
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) <= 7.4d-36) .or. (.not. ((x * x) <= 2d+63)) .and. ((x * x) <= 5.5d+144)) 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) <= 7.4e-36) || (!((x * x) <= 2e+63) && ((x * x) <= 5.5e+144))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 7.4e-36) or (not ((x * x) <= 2e+63) and ((x * x) <= 5.5e+144)): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 7.4e-36) || (!(Float64(x * x) <= 2e+63) && (Float64(x * x) <= 5.5e+144))) 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) <= 7.4e-36) || (~(((x * x) <= 2e+63)) && ((x * x) <= 5.5e+144))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 7.4e-36], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 2e+63]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 5.5e+144]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 7.4 \cdot 10^{-36} \lor \neg \left(x \cdot x \leq 2 \cdot 10^{+63}\right) \land x \cdot x \leq 5.5 \cdot 10^{+144}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 7.40000000000000003e-36 or 2.00000000000000012e63 < (*.f64 x x) < 5.50000000000000022e144Initial program 100.0%
Taylor expanded in x around 0 84.9%
unpow284.9%
mul-1-neg84.9%
distribute-rgt-neg-in84.9%
Simplified84.9%
if 7.40000000000000003e-36 < (*.f64 x x) < 2.00000000000000012e63 or 5.50000000000000022e144 < (*.f64 x x) Initial program 82.8%
Taylor expanded in x around inf 78.2%
unpow278.3%
Simplified78.3%
Final simplification81.7%
(FPCore (x y) :precision binary64 (if (<= (* x x) 3e+294) (- (* x x) (* y y)) (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 3e+294) {
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) <= 3d+294) 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) <= 3e+294) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 3e+294: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 3e+294) 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) <= 3e+294) tmp = (x * x) - (y * y); else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 3e+294], 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 3 \cdot 10^{+294}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 3.00000000000000006e294Initial program 100.0%
if 3.00000000000000006e294 < (*.f64 x x) Initial program 68.2%
Taylor expanded in x around inf 84.8%
unpow284.8%
Simplified84.8%
Final simplification96.1%
(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 51.4%
unpow251.4%
Simplified51.4%
Final simplification51.4%
herbie shell --seed 2023192
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))