
(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}
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 3.5e+217) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 3.5e+217) {
tmp = fma(x, x, (y * -y));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 3.5e+217) tmp = fma(x, x, Float64(y * Float64(-y))); else tmp = Float64(x * x); end return tmp end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[x, 3.5e+217], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.5 \cdot 10^{+217}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 3.4999999999999998e217Initial program 96.6%
fma-neg99.2%
distribute-rgt-neg-in99.2%
Simplified99.2%
if 3.4999999999999998e217 < x Initial program 58.8%
Taylor expanded in x around inf 94.1%
unpow294.1%
Simplified94.1%
Final simplification98.8%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 1.05e-127)
(and (not (<= (* x x) 1.5e-5)) (<= (* x x) 1.85e+82)))
(* y (- y))
(* x x)))x = abs(x);
double code(double x, double y) {
double tmp;
if (((x * x) <= 1.05e-127) || (!((x * x) <= 1.5e-5) && ((x * x) <= 1.85e+82))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (((x * x) <= 1.05d-127) .or. (.not. ((x * x) <= 1.5d-5)) .and. ((x * x) <= 1.85d+82)) then
tmp = y * -y
else
tmp = x * x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if (((x * x) <= 1.05e-127) || (!((x * x) <= 1.5e-5) && ((x * x) <= 1.85e+82))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if ((x * x) <= 1.05e-127) or (not ((x * x) <= 1.5e-5) and ((x * x) <= 1.85e+82)): tmp = y * -y else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 1.05e-127) || (!(Float64(x * x) <= 1.5e-5) && (Float64(x * x) <= 1.85e+82))) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * x); end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if (((x * x) <= 1.05e-127) || (~(((x * x) <= 1.5e-5)) && ((x * x) <= 1.85e+82))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 1.05e-127], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 1.5e-5]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 1.85e+82]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.05 \cdot 10^{-127} \lor \neg \left(x \cdot x \leq 1.5 \cdot 10^{-5}\right) \land x \cdot x \leq 1.85 \cdot 10^{+82}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.05000000000000005e-127 or 1.50000000000000004e-5 < (*.f64 x x) < 1.8500000000000001e82Initial 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.05000000000000005e-127 < (*.f64 x x) < 1.50000000000000004e-5 or 1.8500000000000001e82 < (*.f64 x x) Initial program 89.0%
Taylor expanded in x around inf 75.4%
unpow275.4%
Simplified75.4%
Final simplification80.2%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 1.32e+154) (- (* x x) (* y y)) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 1.32e+154) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= 1.32d+154) then
tmp = (x * x) - (y * y)
else
tmp = x * x
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if (x <= 1.32e+154) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 1.32e+154: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 1.32e+154) tmp = Float64(Float64(x * x) - Float64(y * y)); else tmp = Float64(x * x); end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if (x <= 1.32e+154) tmp = (x * x) - (y * y); else tmp = x * x; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[x, 1.32e+154], N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.31999999999999998e154Initial program 97.4%
if 1.31999999999999998e154 < x Initial program 64.0%
Taylor expanded in x around inf 88.0%
unpow288.0%
Simplified88.0%
Final simplification96.5%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (* x x))
x = abs(x);
double code(double x, double y) {
return x * x;
}
NOTE: x should be positive before calling this function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * x
end function
x = Math.abs(x);
public static double code(double x, double y) {
return x * x;
}
x = abs(x) def code(x, y): return x * x
x = abs(x) function code(x, y) return Float64(x * x) end
x = abs(x) function tmp = code(x, y) tmp = x * x; end
NOTE: x should be positive before calling this function code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
x = |x|\\
\\
x \cdot x
\end{array}
Initial program 94.1%
Taylor expanded in x around inf 51.5%
unpow251.5%
Simplified51.5%
Final simplification51.5%
herbie shell --seed 2023257
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))