
(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.45e+176) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 1.45e+176) {
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.45e+176) 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.45e+176], 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.45 \cdot 10^{+176}:\\
\;\;\;\;\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.4500000000000001e176Initial program 93.6%
fma-neg96.6%
distribute-rgt-neg-in96.6%
Simplified96.6%
if 1.4500000000000001e176 < x Initial program 87.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification96.9%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 6.2e-62)
(and (not (<= (* x x) 1.35e+166)) (<= (* x x) 4.2e+219)))
(* y (- y))
(* x x)))x = abs(x);
double code(double x, double y) {
double tmp;
if (((x * x) <= 6.2e-62) || (!((x * x) <= 1.35e+166) && ((x * x) <= 4.2e+219))) {
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) <= 6.2d-62) .or. (.not. ((x * x) <= 1.35d+166)) .and. ((x * x) <= 4.2d+219)) 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) <= 6.2e-62) || (!((x * x) <= 1.35e+166) && ((x * x) <= 4.2e+219))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if ((x * x) <= 6.2e-62) or (not ((x * x) <= 1.35e+166) and ((x * x) <= 4.2e+219)): tmp = y * -y else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 6.2e-62) || (!(Float64(x * x) <= 1.35e+166) && (Float64(x * x) <= 4.2e+219))) 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) <= 6.2e-62) || (~(((x * x) <= 1.35e+166)) && ((x * x) <= 4.2e+219))) 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], 6.2e-62], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 1.35e+166]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 4.2e+219]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 6.2 \cdot 10^{-62} \lor \neg \left(x \cdot x \leq 1.35 \cdot 10^{+166}\right) \land x \cdot x \leq 4.2 \cdot 10^{+219}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 6.1999999999999999e-62 or 1.35000000000000006e166 < (*.f64 x x) < 4.19999999999999976e219Initial program 100.0%
Taylor expanded in x around 0 83.2%
unpow283.2%
mul-1-neg83.2%
distribute-rgt-neg-in83.2%
Simplified83.2%
if 6.1999999999999999e-62 < (*.f64 x x) < 1.35000000000000006e166 or 4.19999999999999976e219 < (*.f64 x x) Initial program 85.2%
Taylor expanded in x around inf 81.4%
unpow281.4%
Simplified81.4%
Final simplification82.3%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= x 1.42e+150) (- (* x x) (* y y)) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 1.42e+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.42d+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.42e+150) {
tmp = (x * x) - (y * y);
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if x <= 1.42e+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.42e+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.42e+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.42e+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.42 \cdot 10^{+150}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if x < 1.42e150Initial program 94.2%
if 1.42e150 < x Initial program 84.8%
Taylor expanded in x around inf 97.0%
unpow297.0%
Simplified97.0%
Final simplification94.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 93.0%
Taylor expanded in x around inf 52.9%
unpow252.9%
Simplified52.9%
Final simplification52.9%
herbie shell --seed 2023228
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))