
(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+253) (fma x x (* y (- y))) (* x x)))
x = abs(x);
double code(double x, double y) {
double tmp;
if (x <= 5e+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 <= 5e+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, 5e+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 5 \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 < 4.9999999999999997e253Initial program 95.9%
sqr-neg95.9%
cancel-sign-sub95.9%
fma-def99.2%
Simplified99.2%
if 4.9999999999999997e253 < x Initial program 72.7%
Taylor expanded in x around inf 100.0%
unpow2100.0%
Simplified100.0%
Final simplification99.2%
NOTE: x should be positive before calling this function
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 5.4e-138)
(and (not (<= (* x x) 108000000.0)) (<= (* x x) 2.4e+117)))
(* y (- y))
(* x x)))x = abs(x);
double code(double x, double y) {
double tmp;
if (((x * x) <= 5.4e-138) || (!((x * x) <= 108000000.0) && ((x * x) <= 2.4e+117))) {
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) <= 5.4d-138) .or. (.not. ((x * x) <= 108000000.0d0)) .and. ((x * x) <= 2.4d+117)) 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) <= 5.4e-138) || (!((x * x) <= 108000000.0) && ((x * x) <= 2.4e+117))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if ((x * x) <= 5.4e-138) or (not ((x * x) <= 108000000.0) and ((x * x) <= 2.4e+117)): tmp = y * -y else: tmp = x * x return tmp
x = abs(x) function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 5.4e-138) || (!(Float64(x * x) <= 108000000.0) && (Float64(x * x) <= 2.4e+117))) 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) <= 5.4e-138) || (~(((x * x) <= 108000000.0)) && ((x * x) <= 2.4e+117))) 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], 5.4e-138], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 108000000.0]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 2.4e+117]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
x = |x|\\
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 5.4 \cdot 10^{-138} \lor \neg \left(x \cdot x \leq 108000000\right) \land x \cdot x \leq 2.4 \cdot 10^{+117}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 5.40000000000000057e-138 or 1.08e8 < (*.f64 x x) < 2.3999999999999999e117Initial program 100.0%
Taylor expanded in x around 0 87.8%
unpow287.8%
mul-1-neg87.8%
distribute-rgt-neg-in87.8%
Simplified87.8%
if 5.40000000000000057e-138 < (*.f64 x x) < 1.08e8 or 2.3999999999999999e117 < (*.f64 x x) Initial program 90.6%
Taylor expanded in x around inf 78.2%
unpow278.2%
Simplified78.2%
Final simplification82.7%
NOTE: x should be positive before calling this function (FPCore (x y) :precision binary64 (if (<= (* y y) 5e+298) (- (* x x) (* y y)) (* y (- y))))
x = abs(x);
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+298) {
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) <= 5d+298) 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) <= 5e+298) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
x = abs(x) def code(x, y): tmp = 0 if (y * y) <= 5e+298: 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) <= 5e+298) 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) <= 5e+298) 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], 5e+298], 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 5 \cdot 10^{+298}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 5.0000000000000003e298Initial program 100.0%
if 5.0000000000000003e298 < (*.f64 y y) Initial program 77.2%
Taylor expanded in x around 0 91.2%
unpow291.2%
mul-1-neg91.2%
distribute-rgt-neg-in91.2%
Simplified91.2%
Final simplification98.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 94.9%
Taylor expanded in x around inf 54.7%
unpow254.7%
Simplified54.7%
Final simplification54.7%
herbie shell --seed 2023271
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))