
(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 93.0%
difference-of-squares100.0%
*-commutative100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= (* x x) 4.6e-134)
(and (not (<= (* x x) 2.2e-50)) (<= (* x x) 350000000.0)))
(* y (- y))
(* x x)))
double code(double x, double y) {
double tmp;
if (((x * x) <= 4.6e-134) || (!((x * x) <= 2.2e-50) && ((x * x) <= 350000000.0))) {
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) <= 4.6d-134) .or. (.not. ((x * x) <= 2.2d-50)) .and. ((x * x) <= 350000000.0d0)) 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) <= 4.6e-134) || (!((x * x) <= 2.2e-50) && ((x * x) <= 350000000.0))) {
tmp = y * -y;
} else {
tmp = x * x;
}
return tmp;
}
def code(x, y): tmp = 0 if ((x * x) <= 4.6e-134) or (not ((x * x) <= 2.2e-50) and ((x * x) <= 350000000.0)): tmp = y * -y else: tmp = x * x return tmp
function code(x, y) tmp = 0.0 if ((Float64(x * x) <= 4.6e-134) || (!(Float64(x * x) <= 2.2e-50) && (Float64(x * x) <= 350000000.0))) 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) <= 4.6e-134) || (~(((x * x) <= 2.2e-50)) && ((x * x) <= 350000000.0))) tmp = y * -y; else tmp = x * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[N[(x * x), $MachinePrecision], 4.6e-134], And[N[Not[LessEqual[N[(x * x), $MachinePrecision], 2.2e-50]], $MachinePrecision], LessEqual[N[(x * x), $MachinePrecision], 350000000.0]]], N[(y * (-y)), $MachinePrecision], N[(x * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \cdot x \leq 4.6 \cdot 10^{-134} \lor \neg \left(x \cdot x \leq 2.2 \cdot 10^{-50}\right) \land x \cdot x \leq 350000000:\\
\;\;\;\;y \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot x\\
\end{array}
\end{array}
if (*.f64 x x) < 4.6000000000000001e-134 or 2.1999999999999999e-50 < (*.f64 x x) < 3.5e8Initial program 100.0%
Taylor expanded in x around 0 88.4%
mul-1-neg88.4%
unpow288.4%
distribute-rgt-neg-out88.4%
Simplified88.4%
if 4.6000000000000001e-134 < (*.f64 x x) < 2.1999999999999999e-50 or 3.5e8 < (*.f64 x x) Initial program 87.0%
Taylor expanded in x around inf 79.4%
unpow279.4%
Simplified79.4%
Final simplification83.6%
(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 93.0%
Taylor expanded in x around inf 52.6%
unpow252.6%
Simplified52.6%
Final simplification52.6%
herbie shell --seed 2023297
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))