
(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 5e+198) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 5e+198) {
tmp = fma(x, x, (y * -y));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 5e+198) 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, 5e+198], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 5 \cdot 10^{+198}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 5.00000000000000049e198Initial program 94.5%
sqr-neg94.5%
cancel-sign-sub94.5%
fma-def97.9%
Simplified97.9%
if 5.00000000000000049e198 < x Initial program 70.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification98.0%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 1.05e+150) (- (* x x) (* y y)) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 1.05e+150) {
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.05d+150) 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.05e+150) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 1.05e+150: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 1.05e+150) 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.05e+150) 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.05e+150], 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.05 \cdot 10^{+150}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.04999999999999999e150Initial program 97.3%
if 1.04999999999999999e150 < x Initial program 62.9%
Taylor expanded in x around inf 82.9%
unpow282.9%
Simplified82.9%
Final simplification95.3%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (* x x) 1.3e+39) (* y (- y)) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if ((x * x) <= 1.3e+39) {
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.3d+39) 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.3e+39) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if (x * x) <= 1.3e+39: tmp = y * -y else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (Float64(x * x) <= 1.3e+39) 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.3e+39) 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[LessEqual[N[(x * x), $MachinePrecision], 1.3e+39], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 1.3 \cdot 10^{+39}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 1.3e39Initial program 100.0%
Taylor expanded in x around 0 82.1%
unpow282.1%
mul-1-neg82.1%
distribute-rgt-neg-in82.1%
Simplified82.1%
if 1.3e39 < (*.f64 x x) Initial program 85.2%
Taylor expanded in x around inf 78.6%
unpow278.6%
Simplified78.6%
Final simplification80.4%
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 92.6%
Taylor expanded in x around inf 54.6%
unpow254.6%
Simplified54.6%
Final simplification54.6%
herbie shell --seed 2023274
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))