
(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.8e+253) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 3.8e+253) {
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.8e+253) 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.8e+253], 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.8 \cdot 10^{+253}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 3.79999999999999989e253Initial program 89.7%
fma-neg95.5%
distribute-rgt-neg-in95.5%
Simplified95.5%
if 3.79999999999999989e253 < x Initial program 66.7%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification95.7%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 7.8e+150) (- (* x x) (* y y)) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 7.8e+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 <= 7.8d+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 <= 7.8e+150) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 7.8e+150: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 7.8e+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 <= 7.8e+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, 7.8e+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 7.8 \cdot 10^{+150}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 7.79999999999999981e150Initial program 90.9%
if 7.79999999999999981e150 < x Initial program 66.7%
Taylor expanded in x around inf 87.5%
unpow287.5%
Simplified87.5%
Final simplification90.6%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 0.000155) (* x x) (* y (- y))))
x = abs(x);
double code(double x, double y) {
double tmp;
if (y <= 0.000155) {
tmp = x * x;
} else {
tmp = y * -y;
}
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 (y <= 0.000155d0) then
tmp = x * x
else
tmp = y * -y
end if
code = tmp
end function
x = Math.abs(x);
public static double code(double x, double y) {
double tmp;
if (y <= 0.000155) {
tmp = x * x;
} else {
tmp = y * -y;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if y <= 0.000155: tmp = x * x else: tmp = y * -y return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (y <= 0.000155) tmp = Float64(x * x); else tmp = Float64(y * Float64(-y)); end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if (y <= 0.000155) tmp = x * x; else tmp = y * -y; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[y, 0.000155], N[(x * x), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.000155:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 1.55e-4Initial program 94.4%
Taylor expanded in x around inf 67.2%
unpow267.2%
Simplified67.2%
if 1.55e-4 < y Initial program 69.5%
Taylor expanded in x around 0 78.0%
unpow278.0%
mul-1-neg78.0%
distribute-rgt-neg-in78.0%
Simplified78.0%
Final simplification69.7%
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 88.7%
Taylor expanded in x around inf 56.8%
unpow256.8%
Simplified56.8%
Final simplification56.8%
herbie shell --seed 2023238
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))