
(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 1.4e+236) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 1.4e+236) {
tmp = fma(x, x, (y * -y));
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 1.4e+236) 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, 1.4e+236], N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4 \cdot 10^{+236}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.39999999999999996e236Initial program 94.2%
sqr-neg94.2%
cancel-sign-sub94.2%
fma-def97.5%
Simplified97.5%
if 1.39999999999999996e236 < x Initial program 73.3%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification97.7%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 4.6e-134)
(and (not (<= (* x x) 1.7e-49)) (<= (* x x) 100000000.0)))
(* y (- y))
(* x x)))x = abs(x);
double code(double x, double y) {
double tmp;
if (((x * x) <= 4.6e-134) || (!((x * x) <= 1.7e-49) && ((x * x) <= 100000000.0))) {
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) <= 4.6d-134) .or. (.not. ((x * x) <= 1.7d-49)) .and. ((x * x) <= 100000000.0d0)) 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) <= 4.6e-134) || (!((x * x) <= 1.7e-49) && ((x * x) <= 100000000.0))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if ((x * x) <= 4.6e-134) or (not ((x * x) <= 1.7e-49) and ((x * x) <= 100000000.0)): tmp = y * -y else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 4.6e-134) || (!(Float64(x * x) <= 1.7e-49) && (Float64(x * x) <= 100000000.0))) 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) <= 4.6e-134) || (~(((x * x) <= 1.7e-49)) && ((x * x) <= 100000000.0))) 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], 4.6e-134], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 1.7e-49]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 100000000.0]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4.6 \cdot 10^{-134} \lor \neg \left(x \cdot x \leq 1.7 \cdot 10^{-49}\right) \land x \cdot x \leq 100000000:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.6000000000000001e-134 or 1.70000000000000002e-49 < (*.f64 x x) < 1e8Initial program 100.0%
Taylor expanded in x around 0 88.4%
unpow288.4%
mul-1-neg88.4%
distribute-rgt-neg-in88.4%
Simplified88.4%
if 4.6000000000000001e-134 < (*.f64 x x) < 1.70000000000000002e-49 or 1e8 < (*.f64 x x) Initial program 87.0%
Taylor expanded in x around inf 79.4%
unpow279.4%
Simplified79.4%
Final simplification83.6%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 6.2e+150) (- (* x x) (* y y)) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 6.2e+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 <= 6.2d+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 <= 6.2e+150) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 6.2e+150: tmp = (x * x) - (y * y) else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if (x <= 6.2e+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 <= 6.2e+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, 6.2e+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 6.2 \cdot 10^{+150}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 6.20000000000000028e150Initial program 94.8%
if 6.20000000000000028e150 < x Initial program 76.0%
Taylor expanded in x around inf 96.0%
unpow296.0%
Simplified96.0%
Final simplification94.9%
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 93.0%
Taylor expanded in x around inf 52.6%
unpow252.6%
Simplified52.6%
Final simplification52.6%
herbie shell --seed 2023297
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))