
(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 4.3e+190) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 4.3e+190) {
tmp = fma(x, x, (y * -y));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 4.3e+190) 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, 4.3e+190], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.3 \cdot 10^{+190}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 4.3000000000000001e190Initial program 92.3%
sqr-neg92.3%
cancel-sign-sub92.3%
fma-def97.0%
Simplified97.0%
if 4.3000000000000001e190 < x Initial program 69.6%
Taylor expanded in x around inf 87.0%
unpow287.0%
Simplified87.0%
Final simplification96.1%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (* y y) 2e+307) (- (* x x) (* y y)) (* y (- y))))
x = abs(x);
double code(double x, double y) {
double tmp;
if ((y * y) <= 2e+307) {
tmp = (x * x) - (y * y);
} 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 * y) <= 2d+307) then
tmp = (x * x) - (y * y)
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 * y) <= 2e+307) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if (y * y) <= 2e+307: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (Float64(y * y) <= 2e+307) tmp = Float64(Float64(x * x) - Float64(y * y)); else tmp = Float64(y * Float64(-y)); end return tmp end
x = abs(x) function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 2e+307) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
NOTE: x should be positive before calling this function code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 2e+307], N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 2 \cdot 10^{+307}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 1.99999999999999997e307Initial program 100.0%
if 1.99999999999999997e307 < (*.f64 y y) Initial program 64.3%
Taylor expanded in x around 0 84.3%
unpow284.3%
mul-1-neg84.3%
distribute-rgt-neg-in84.3%
Simplified84.3%
Final simplification95.7%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= y 1.48e+23) (* x x) (* y (- y))))
x = abs(x);
double code(double x, double y) {
double tmp;
if (y <= 1.48e+23) {
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 <= 1.48d+23) 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 <= 1.48e+23) {
tmp = x * x;
} else {
tmp = y * -y;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if y <= 1.48e+23: tmp = x * x else: tmp = y * -y return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (y <= 1.48e+23) 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 <= 1.48e+23) 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, 1.48e+23], N[(x * x), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 1.48 \cdot 10^{+23}:\\
\;\;\;\;x \cdot x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if y < 1.4799999999999999e23Initial program 94.0%
Taylor expanded in x around inf 64.3%
unpow264.3%
Simplified64.3%
if 1.4799999999999999e23 < y Initial program 76.8%
Taylor expanded in x around 0 76.8%
unpow276.8%
mul-1-neg76.8%
distribute-rgt-neg-in76.8%
Simplified76.8%
Final simplification67.0%
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 90.2%
Taylor expanded in x around inf 55.3%
unpow255.3%
Simplified55.3%
Final simplification55.3%
herbie shell --seed 2023268
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))