
(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}
x_m = (fabs.f64 x) y_m = (fabs.f64 y) (FPCore (x_m y_m) :precision binary64 (if (<= (* x_m x_m) 5e+272) (- (* x_m x_m) (* y_m y_m)) (* x_m (+ x_m (* y_m -2.0)))))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
double tmp;
if ((x_m * x_m) <= 5e+272) {
tmp = (x_m * x_m) - (y_m * y_m);
} else {
tmp = x_m * (x_m + (y_m * -2.0));
}
return tmp;
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
real(8) :: tmp
if ((x_m * x_m) <= 5d+272) then
tmp = (x_m * x_m) - (y_m * y_m)
else
tmp = x_m * (x_m + (y_m * (-2.0d0)))
end if
code = tmp
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
double tmp;
if ((x_m * x_m) <= 5e+272) {
tmp = (x_m * x_m) - (y_m * y_m);
} else {
tmp = x_m * (x_m + (y_m * -2.0));
}
return tmp;
}
x_m = math.fabs(x) y_m = math.fabs(y) def code(x_m, y_m): tmp = 0 if (x_m * x_m) <= 5e+272: tmp = (x_m * x_m) - (y_m * y_m) else: tmp = x_m * (x_m + (y_m * -2.0)) return tmp
x_m = abs(x) y_m = abs(y) function code(x_m, y_m) tmp = 0.0 if (Float64(x_m * x_m) <= 5e+272) tmp = Float64(Float64(x_m * x_m) - Float64(y_m * y_m)); else tmp = Float64(x_m * Float64(x_m + Float64(y_m * -2.0))); end return tmp end
x_m = abs(x); y_m = abs(y); function tmp_2 = code(x_m, y_m) tmp = 0.0; if ((x_m * x_m) <= 5e+272) tmp = (x_m * x_m) - (y_m * y_m); else tmp = x_m * (x_m + (y_m * -2.0)); end tmp_2 = tmp; end
x_m = N[Abs[x], $MachinePrecision] y_m = N[Abs[y], $MachinePrecision] code[x$95$m_, y$95$m_] := If[LessEqual[N[(x$95$m * x$95$m), $MachinePrecision], 5e+272], N[(N[(x$95$m * x$95$m), $MachinePrecision] - N[(y$95$m * y$95$m), $MachinePrecision]), $MachinePrecision], N[(x$95$m * N[(x$95$m + N[(y$95$m * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|
\\
\begin{array}{l}
\mathbf{if}\;x_m \cdot x_m \leq 5 \cdot 10^{+272}:\\
\;\;\;\;x_m \cdot x_m - y_m \cdot y_m\\
\mathbf{else}:\\
\;\;\;\;x_m \cdot \left(x_m + y_m \cdot -2\right)\\
\end{array}
\end{array}
if (*.f64 x x) < 4.99999999999999973e272Initial program 100.0%
if 4.99999999999999973e272 < (*.f64 x x) Initial program 73.5%
difference-of-squares100.0%
add-sqr-sqrt49.4%
sqrt-prod85.5%
sqr-neg85.5%
sqrt-unprod44.6%
add-sqr-sqrt88.0%
sub-neg88.0%
pow188.0%
pow188.0%
pow-prod-up88.0%
metadata-eval88.0%
add-sqr-sqrt44.5%
add-sqr-sqrt19.2%
difference-of-squares19.2%
unpow-prod-down19.2%
Applied egg-rr19.2%
unpow219.2%
unpow219.2%
unswap-sqr19.2%
difference-of-squares19.2%
unpow1/219.2%
unpow1/219.2%
pow-sqr19.2%
metadata-eval19.2%
unpow119.2%
unpow1/219.2%
unpow1/219.2%
pow-sqr19.2%
metadata-eval19.2%
unpow119.2%
difference-of-squares19.2%
unpow1/219.2%
unpow1/219.2%
pow-sqr43.4%
metadata-eval43.4%
unpow143.4%
Simplified88.0%
Taylor expanded in x around inf 78.3%
*-commutative78.3%
associate-*l*78.3%
unpow278.3%
distribute-lft-out91.6%
Simplified91.6%
Final simplification97.3%
x_m = (fabs.f64 x) y_m = (fabs.f64 y) (FPCore (x_m y_m) :precision binary64 (* x_m (+ x_m (* y_m -2.0))))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
return x_m * (x_m + (y_m * -2.0));
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
code = x_m * (x_m + (y_m * (-2.0d0)))
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
return x_m * (x_m + (y_m * -2.0));
}
x_m = math.fabs(x) y_m = math.fabs(y) def code(x_m, y_m): return x_m * (x_m + (y_m * -2.0))
x_m = abs(x) y_m = abs(y) function code(x_m, y_m) return Float64(x_m * Float64(x_m + Float64(y_m * -2.0))) end
x_m = abs(x); y_m = abs(y); function tmp = code(x_m, y_m) tmp = x_m * (x_m + (y_m * -2.0)); end
x_m = N[Abs[x], $MachinePrecision] y_m = N[Abs[y], $MachinePrecision] code[x$95$m_, y$95$m_] := N[(x$95$m * N[(x$95$m + N[(y$95$m * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|
\\
x_m \cdot \left(x_m + y_m \cdot -2\right)
\end{array}
Initial program 91.4%
difference-of-squares100.0%
add-sqr-sqrt50.3%
sqrt-prod73.6%
sqr-neg73.6%
sqrt-unprod26.0%
add-sqr-sqrt53.3%
sub-neg53.3%
pow153.3%
pow153.3%
pow-prod-up53.3%
metadata-eval53.3%
add-sqr-sqrt25.4%
add-sqr-sqrt11.3%
difference-of-squares11.3%
unpow-prod-down11.3%
Applied egg-rr11.3%
unpow211.3%
unpow211.3%
unswap-sqr11.3%
difference-of-squares11.3%
unpow1/211.3%
unpow1/211.3%
pow-sqr11.4%
metadata-eval11.4%
unpow111.4%
unpow1/211.4%
unpow1/211.4%
pow-sqr11.4%
metadata-eval11.4%
unpow111.4%
difference-of-squares11.4%
unpow1/211.4%
unpow1/211.4%
pow-sqr27.3%
metadata-eval27.3%
unpow127.3%
Simplified53.3%
Taylor expanded in x around inf 52.3%
*-commutative52.3%
associate-*l*52.6%
unpow252.6%
distribute-lft-out56.9%
Simplified56.9%
Final simplification56.9%
x_m = (fabs.f64 x) y_m = (fabs.f64 y) (FPCore (x_m y_m) :precision binary64 (* -2.0 (* x_m y_m)))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
return -2.0 * (x_m * y_m);
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
code = (-2.0d0) * (x_m * y_m)
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
return -2.0 * (x_m * y_m);
}
x_m = math.fabs(x) y_m = math.fabs(y) def code(x_m, y_m): return -2.0 * (x_m * y_m)
x_m = abs(x) y_m = abs(y) function code(x_m, y_m) return Float64(-2.0 * Float64(x_m * y_m)) end
x_m = abs(x); y_m = abs(y); function tmp = code(x_m, y_m) tmp = -2.0 * (x_m * y_m); end
x_m = N[Abs[x], $MachinePrecision] y_m = N[Abs[y], $MachinePrecision] code[x$95$m_, y$95$m_] := N[(-2.0 * N[(x$95$m * y$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|
\\
-2 \cdot \left(x_m \cdot y_m\right)
\end{array}
Initial program 91.4%
difference-of-squares100.0%
add-sqr-sqrt50.3%
sqrt-prod73.6%
sqr-neg73.6%
sqrt-unprod26.0%
add-sqr-sqrt53.3%
sub-neg53.3%
pow153.3%
pow153.3%
pow-prod-up53.3%
metadata-eval53.3%
add-sqr-sqrt25.4%
add-sqr-sqrt11.3%
difference-of-squares11.3%
unpow-prod-down11.3%
Applied egg-rr11.3%
unpow211.3%
unpow211.3%
unswap-sqr11.3%
difference-of-squares11.3%
unpow1/211.3%
unpow1/211.3%
pow-sqr11.4%
metadata-eval11.4%
unpow111.4%
unpow1/211.4%
unpow1/211.4%
pow-sqr11.4%
metadata-eval11.4%
unpow111.4%
difference-of-squares11.4%
unpow1/211.4%
unpow1/211.4%
pow-sqr27.3%
metadata-eval27.3%
unpow127.3%
Simplified53.3%
Taylor expanded in x around inf 52.3%
*-commutative52.3%
associate-*l*52.6%
unpow252.6%
distribute-lft-out56.9%
Simplified56.9%
Taylor expanded in x around 0 13.4%
Final simplification13.4%
x_m = (fabs.f64 x) y_m = (fabs.f64 y) (FPCore (x_m y_m) :precision binary64 (* x_m (* y_m -2.0)))
x_m = fabs(x);
y_m = fabs(y);
double code(double x_m, double y_m) {
return x_m * (y_m * -2.0);
}
x_m = abs(x)
y_m = abs(y)
real(8) function code(x_m, y_m)
real(8), intent (in) :: x_m
real(8), intent (in) :: y_m
code = x_m * (y_m * (-2.0d0))
end function
x_m = Math.abs(x);
y_m = Math.abs(y);
public static double code(double x_m, double y_m) {
return x_m * (y_m * -2.0);
}
x_m = math.fabs(x) y_m = math.fabs(y) def code(x_m, y_m): return x_m * (y_m * -2.0)
x_m = abs(x) y_m = abs(y) function code(x_m, y_m) return Float64(x_m * Float64(y_m * -2.0)) end
x_m = abs(x); y_m = abs(y); function tmp = code(x_m, y_m) tmp = x_m * (y_m * -2.0); end
x_m = N[Abs[x], $MachinePrecision] y_m = N[Abs[y], $MachinePrecision] code[x$95$m_, y$95$m_] := N[(x$95$m * N[(y$95$m * -2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
x_m = \left|x\right|
\\
y_m = \left|y\right|
\\
x_m \cdot \left(y_m \cdot -2\right)
\end{array}
Initial program 91.4%
difference-of-squares100.0%
add-sqr-sqrt50.3%
sqrt-prod73.6%
sqr-neg73.6%
sqrt-unprod26.0%
add-sqr-sqrt53.3%
sub-neg53.3%
pow153.3%
pow153.3%
pow-prod-up53.3%
metadata-eval53.3%
add-sqr-sqrt25.4%
add-sqr-sqrt11.3%
difference-of-squares11.3%
unpow-prod-down11.3%
Applied egg-rr11.3%
unpow211.3%
unpow211.3%
unswap-sqr11.3%
difference-of-squares11.3%
unpow1/211.3%
unpow1/211.3%
pow-sqr11.4%
metadata-eval11.4%
unpow111.4%
unpow1/211.4%
unpow1/211.4%
pow-sqr11.4%
metadata-eval11.4%
unpow111.4%
difference-of-squares11.4%
unpow1/211.4%
unpow1/211.4%
pow-sqr27.3%
metadata-eval27.3%
unpow127.3%
Simplified53.3%
Taylor expanded in x around inf 52.3%
*-commutative52.3%
associate-*l*52.6%
unpow252.6%
distribute-lft-out56.9%
Simplified56.9%
Taylor expanded in x around 0 13.4%
add-log-exp26.6%
*-un-lft-identity26.6%
log-prod26.6%
metadata-eval26.6%
add-log-exp13.4%
*-commutative13.4%
associate-*l*13.7%
Applied egg-rr13.7%
+-lft-identity13.7%
Simplified13.7%
Final simplification13.7%
herbie shell --seed 2024010
(FPCore (x y)
:name "Examples.Basics.BasicTests:f2 from sbv-4.4"
:precision binary64
(- (* x x) (* y y)))