
(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 (* (+ x y) (- x y)))
double code(double x, double y) {
return (x + y) * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) * (x - y)
end function
public static double code(double x, double y) {
return (x + y) * (x - y);
}
def code(x, y): return (x + y) * (x - y)
function code(x, y) return Float64(Float64(x + y) * Float64(x - y)) end
function tmp = code(x, y) tmp = (x + y) * (x - y); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) \cdot \left(x - y\right)
\end{array}
Initial program 94.1%
Simplified0
(FPCore (x y)
:precision binary64
(let* ((t_0 (- (* y y))))
(if (<= (* x x) 6.5e-72)
t_0
(if (<= (* x x) 1.95e+61)
(* x x)
(if (<= (* x x) 8.5e+168) t_0 (* x x))))))
double code(double x, double y) {
double t_0 = -(y * y);
double tmp;
if ((x * x) <= 6.5e-72) {
tmp = t_0;
} else if ((x * x) <= 1.95e+61) {
tmp = x * x;
} else if ((x * x) <= 8.5e+168) {
tmp = t_0;
} else {
tmp = x * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = -(y * y)
if ((x * x) <= 6.5d-72) then
tmp = t_0
else if ((x * x) <= 1.95d+61) then
tmp = x * x
else if ((x * x) <= 8.5d+168) then
tmp = t_0
else
tmp = x * x
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = -(y * y);
double tmp;
if ((x * x) <= 6.5e-72) {
tmp = t_0;
} else if ((x * x) <= 1.95e+61) {
tmp = x * x;
} else if ((x * x) <= 8.5e+168) {
tmp = t_0;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): t_0 = -(y * y) tmp = 0 if (x * x) <= 6.5e-72: tmp = t_0 elif (x * x) <= 1.95e+61: tmp = x * x elif (x * x) <= 8.5e+168: tmp = t_0 else: tmp = x * x return tmp
function code(x, y) t_0 = Float64(-Float64(y * y)) tmp = 0.0 if (Float64(x * x) <= 6.5e-72) tmp = t_0; elseif (Float64(x * x) <= 1.95e+61) tmp = Float64(x * x); elseif (Float64(x * x) <= 8.5e+168) tmp = t_0; else tmp = Float64(x * x); end return tmp end
function tmp_2 = code(x, y) t_0 = -(y * y); tmp = 0.0; if ((x * x) <= 6.5e-72) tmp = t_0; elseif ((x * x) <= 1.95e+61) tmp = x * x; elseif ((x * x) <= 8.5e+168) tmp = t_0; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = (-N[(y * y), $MachinePrecision])}, If[LessEqual[N[(x * x), $MachinePrecision], 6.5e-72], t$95$0, If[LessEqual[N[(x * x), $MachinePrecision], 1.95e+61], N[(x * x), $MachinePrecision], If[LessEqual[N[(x * x), $MachinePrecision], 8.5e+168], t$95$0, N[(x * x), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -y \cdot y\\
\mathbf{if}\;x \cdot x \leq 6.5 \cdot 10^{-72}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \cdot x \leq 1.95 \cdot 10^{+61}:\\
\;\;\;\;x \cdot x\\
\mathbf{elif}\;x \cdot x \leq 8.5 \cdot 10^{+168}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 6.4999999999999997e-72 or 1.94999999999999994e61 < (*.f64 x x) < 8.50000000000000069e168Initial program 100.0%
Simplified0
Taylor expanded in x around 0 0
Simplified0
Applied egg-rr0
if 6.4999999999999997e-72 < (*.f64 x x) < 1.94999999999999994e61 or 8.50000000000000069e168 < (*.f64 x x) Initial program 87.7%
Simplified0
Taylor expanded in x around inf 0
Simplified0
(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 94.1%
Simplified0
Taylor expanded in x around inf 0
Simplified0
herbie shell --seed 2024110
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))