
(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}
(FPCore (x y) :precision binary64 (fma x x (* y (- y))))
double code(double x, double y) {
return fma(x, x, (y * -y));
}
function code(x, y) return fma(x, x, Float64(y * Float64(-y))) end
code[x_, y_] := N[(x * x + N[(y * (-y)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, x, y \cdot \left(-y\right)\right)
\end{array}
Initial program 95.7%
sqr-neg95.7%
cancel-sign-sub95.7%
fma-define98.4%
Simplified98.4%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+28) (* (+ x y) (+ x y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+28) {
tmp = (x + y) * (x + y);
} else {
tmp = y * -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 5d+28) then
tmp = (x + y) * (x + y)
else
tmp = y * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+28) {
tmp = (x + y) * (x + y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+28: tmp = (x + y) * (x + y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+28) tmp = Float64(Float64(x + y) * Float64(x + y)); else tmp = Float64(y * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+28) tmp = (x + y) * (x + y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+28], N[(N[(x + y), $MachinePrecision] * N[(x + y), $MachinePrecision]), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+28}:\\
\;\;\;\;\left(x + y\right) \cdot \left(x + y\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.99999999999999957e28Initial program 100.0%
difference-of-squares100.0%
sub-neg100.0%
add-sqr-sqrt53.8%
sqrt-unprod94.6%
sqr-neg94.6%
sqrt-prod40.7%
add-sqr-sqrt86.2%
Applied egg-rr86.2%
if 4.99999999999999957e28 < (*.f64 y y) Initial program 90.4%
Taylor expanded in x around 0 83.1%
mul-1-neg83.1%
Simplified83.1%
unpow283.2%
Applied egg-rr83.2%
Final simplification84.8%
(FPCore (x y) :precision binary64 (if (<= (* y y) 5e+274) (- (* x x) (* y y)) (* y (- y))))
double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+274) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y * y) <= 5d+274) then
tmp = (x * x) - (y * y)
else
tmp = y * -y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y * y) <= 5e+274) {
tmp = (x * x) - (y * y);
} else {
tmp = y * -y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y * y) <= 5e+274: tmp = (x * x) - (y * y) else: tmp = y * -y return tmp
function code(x, y) tmp = 0.0 if (Float64(y * y) <= 5e+274) tmp = Float64(Float64(x * x) - Float64(y * y)); else tmp = Float64(y * Float64(-y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y * y) <= 5e+274) tmp = (x * x) - (y * y); else tmp = y * -y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(y * y), $MachinePrecision], 5e+274], N[(N[(x * x), $MachinePrecision] - N[(y * y), $MachinePrecision]), $MachinePrecision], N[(y * (-y)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \cdot y \leq 5 \cdot 10^{+274}:\\
\;\;\;\;x \cdot x - y \cdot y\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(-y\right)\\
\end{array}
\end{array}
if (*.f64 y y) < 4.9999999999999998e274Initial program 100.0%
if 4.9999999999999998e274 < (*.f64 y y) Initial program 82.3%
Taylor expanded in x around 0 93.5%
mul-1-neg93.5%
Simplified93.5%
unpow293.5%
Applied egg-rr93.5%
Final simplification98.4%
(FPCore (x y) :precision binary64 (* y (- y)))
double code(double x, double y) {
return y * -y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y * -y
end function
public static double code(double x, double y) {
return y * -y;
}
def code(x, y): return y * -y
function code(x, y) return Float64(y * Float64(-y)) end
function tmp = code(x, y) tmp = y * -y; end
code[x_, y_] := N[(y * (-y)), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(-y\right)
\end{array}
Initial program 95.7%
Taylor expanded in x around 0 51.6%
mul-1-neg51.6%
Simplified51.6%
unpow251.6%
Applied egg-rr51.6%
Final simplification51.6%
herbie shell --seed 2024095
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))