
(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 3 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 (* (+ y x) (- x y)))
double code(double x, double y) {
return (y + x) * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) * (x - y)
end function
public static double code(double x, double y) {
return (y + x) * (x - y);
}
def code(x, y): return (y + x) * (x - y)
function code(x, y) return Float64(Float64(y + x) * Float64(x - y)) end
function tmp = code(x, y) tmp = (y + x) * (x - y); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) \cdot \left(x - y\right)
\end{array}
Initial program 95.3%
pow295.3%
metadata-eval95.3%
metadata-eval95.3%
pow-pow68.7%
metadata-eval68.7%
Applied egg-rr68.7%
unpow1/369.2%
Simplified69.2%
pow1/368.7%
pow-pow95.3%
metadata-eval95.3%
unpow295.3%
difference-of-squares100.0%
+-commutative100.0%
Applied egg-rr100.0%
(FPCore (x y) :precision binary64 (if (<= (* x x) 0.2) (* y (- y)) (* x x)))
double code(double x, double y) {
double tmp;
if ((x * x) <= 0.2) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x * x) <= 0.2d0) then
tmp = y * -y
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x * x) <= 0.2) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x * x) <= 0.2: tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if (Float64(x * x) <= 0.2) tmp = Float64(y * Float64(-y)); else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x * x) <= 0.2) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[N[(x * x), $MachinePrecision], 0.2], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 0.2:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 0.20000000000000001Initial program 100.0%
Taylor expanded in x around 0 87.6%
neg-mul-187.6%
Simplified87.6%
unpow287.6%
distribute-lft-neg-in87.6%
Applied egg-rr87.6%
if 0.20000000000000001 < (*.f64 x x) Initial program 89.6%
difference-of-squares100.0%
sub-neg100.0%
add-sqr-sqrt42.6%
sqrt-unprod88.7%
sqr-neg88.7%
sqrt-prod49.6%
add-sqr-sqrt84.4%
Applied egg-rr84.4%
Taylor expanded in x around inf 89.0%
Taylor expanded in x around inf 84.4%
Final simplification86.1%
(FPCore (x y) :precision binary64 (* x x))
double code(double x, double y) {
return x * x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * x
end function
public static double code(double x, double y) {
return x * x;
}
def code(x, y): return x * x
function code(x, y) return Float64(x * x) end
function tmp = code(x, y) tmp = x * x; end
code[x_, y_] := N[(x * x), $MachinePrecision]
\begin{array}{l}
\\
x \cdot x
\end{array}
Initial program 95.3%
difference-of-squares100.0%
sub-neg100.0%
add-sqr-sqrt44.4%
sqrt-unprod72.3%
sqr-neg72.3%
sqrt-prod29.3%
add-sqr-sqrt50.4%
Applied egg-rr50.4%
Taylor expanded in x around inf 53.5%
Taylor expanded in x around inf 51.1%
herbie shell --seed 2024165
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))