
(FPCore (x y) :precision binary64 (* 2.0 (- (* x x) (* x y))))
double code(double x, double y) {
return 2.0 * ((x * x) - (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * ((x * x) - (x * y))
end function
public static double code(double x, double y) {
return 2.0 * ((x * x) - (x * y));
}
def code(x, y): return 2.0 * ((x * x) - (x * y))
function code(x, y) return Float64(2.0 * Float64(Float64(x * x) - Float64(x * y))) end
function tmp = code(x, y) tmp = 2.0 * ((x * x) - (x * y)); end
code[x_, y_] := N[(2.0 * N[(N[(x * x), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot x - x \cdot y\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (* 2.0 (- (* x x) (* x y))))
double code(double x, double y) {
return 2.0 * ((x * x) - (x * y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * ((x * x) - (x * y))
end function
public static double code(double x, double y) {
return 2.0 * ((x * x) - (x * y));
}
def code(x, y): return 2.0 * ((x * x) - (x * y))
function code(x, y) return Float64(2.0 * Float64(Float64(x * x) - Float64(x * y))) end
function tmp = code(x, y) tmp = 2.0 * ((x * x) - (x * y)); end
code[x_, y_] := N[(2.0 * N[(N[(x * x), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot x - x \cdot y\right)
\end{array}
(FPCore (x y) :precision binary64 (* 2.0 (* x (- x y))))
double code(double x, double y) {
return 2.0 * (x * (x - y));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * (x * (x - y))
end function
public static double code(double x, double y) {
return 2.0 * (x * (x - y));
}
def code(x, y): return 2.0 * (x * (x - y))
function code(x, y) return Float64(2.0 * Float64(x * Float64(x - y))) end
function tmp = code(x, y) tmp = 2.0 * (x * (x - y)); end
code[x_, y_] := N[(2.0 * N[(x * N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot \left(x - y\right)\right)
\end{array}
Initial program 94.5%
distribute-lft-out--100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -7.5e+26) (not (<= y 5.7e-92))) (* (* x y) (- 2.0)) (* 2.0 (* x x))))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e+26) || !(y <= 5.7e-92)) {
tmp = (x * y) * -2.0;
} else {
tmp = 2.0 * (x * x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-7.5d+26)) .or. (.not. (y <= 5.7d-92))) then
tmp = (x * y) * -2.0d0
else
tmp = 2.0d0 * (x * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.5e+26) || !(y <= 5.7e-92)) {
tmp = (x * y) * -2.0;
} else {
tmp = 2.0 * (x * x);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.5e+26) or not (y <= 5.7e-92): tmp = (x * y) * -2.0 else: tmp = 2.0 * (x * x) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.5e+26) || !(y <= 5.7e-92)) tmp = Float64(Float64(x * y) * Float64(-2.0)); else tmp = Float64(2.0 * Float64(x * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.5e+26) || ~((y <= 5.7e-92))) tmp = (x * y) * -2.0; else tmp = 2.0 * (x * x); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.5e+26], N[Not[LessEqual[y, 5.7e-92]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] * (-2.0)), $MachinePrecision], N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+26} \lor \neg \left(y \leq 5.7 \cdot 10^{-92}\right):\\
\;\;\;\;\left(x \cdot y\right) \cdot \left(-2\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(x \cdot x\right)\\
\end{array}
\end{array}
if y < -7.49999999999999941e26 or 5.70000000000000009e-92 < y Initial program 88.5%
distribute-lft-out--100.0%
Simplified100.0%
Taylor expanded in x around 0 78.8%
mul-1-neg78.8%
*-commutative78.8%
distribute-rgt-neg-in78.8%
Simplified78.8%
if -7.49999999999999941e26 < y < 5.70000000000000009e-92Initial program 100.0%
distribute-lft-out--100.0%
Simplified100.0%
distribute-lft-out--100.0%
fma-neg100.0%
distribute-rgt-neg-in100.0%
Applied egg-rr100.0%
fma-undefine100.0%
distribute-rgt-neg-out100.0%
unsub-neg100.0%
add-sqr-sqrt38.1%
sqrt-unprod89.3%
sqr-neg89.3%
sqrt-unprod51.2%
add-sqr-sqrt88.6%
distribute-rgt-neg-out88.6%
neg-mul-188.6%
*-commutative88.6%
*-commutative88.6%
add-sqr-sqrt37.4%
sqrt-unprod99.3%
sqr-neg99.3%
sqrt-unprod61.8%
add-sqr-sqrt100.0%
prod-diff100.0%
Applied egg-rr100.0%
fma-undefine100.0%
distribute-rgt-neg-in100.0%
metadata-eval100.0%
*-rgt-identity100.0%
distribute-rgt-in100.0%
fma-undefine100.0%
distribute-lft-out100.0%
*-commutative100.0%
metadata-eval100.0%
Simplified100.0%
associate-*l*100.0%
distribute-lft-out100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 88.9%
Final simplification84.1%
(FPCore (x y) :precision binary64 (* 2.0 (* x x)))
double code(double x, double y) {
return 2.0 * (x * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * (x * x)
end function
public static double code(double x, double y) {
return 2.0 * (x * x);
}
def code(x, y): return 2.0 * (x * x)
function code(x, y) return Float64(2.0 * Float64(x * x)) end
function tmp = code(x, y) tmp = 2.0 * (x * x); end
code[x_, y_] := N[(2.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot x\right)
\end{array}
Initial program 94.5%
distribute-lft-out--100.0%
Simplified100.0%
distribute-lft-out--94.5%
fma-neg94.9%
distribute-rgt-neg-in94.9%
Applied egg-rr94.9%
fma-undefine94.5%
distribute-rgt-neg-out94.5%
unsub-neg94.5%
add-sqr-sqrt44.4%
sqrt-unprod68.7%
sqr-neg68.7%
sqrt-unprod30.2%
add-sqr-sqrt57.2%
distribute-rgt-neg-out57.2%
neg-mul-157.2%
*-commutative57.2%
*-commutative57.2%
add-sqr-sqrt27.0%
sqrt-unprod69.5%
sqr-neg69.5%
sqrt-unprod49.9%
add-sqr-sqrt94.5%
prod-diff87.5%
Applied egg-rr87.5%
fma-undefine87.5%
distribute-rgt-neg-in87.5%
metadata-eval87.5%
*-rgt-identity87.5%
distribute-rgt-in90.2%
fma-undefine90.2%
distribute-lft-out90.2%
*-commutative90.2%
metadata-eval90.2%
Simplified90.2%
associate-*l*90.2%
distribute-lft-out100.0%
Applied egg-rr100.0%
Taylor expanded in x around inf 62.8%
Final simplification62.8%
(FPCore (x y) :precision binary64 (* (* x 2.0) (- x y)))
double code(double x, double y) {
return (x * 2.0) * (x - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x * 2.0d0) * (x - y)
end function
public static double code(double x, double y) {
return (x * 2.0) * (x - y);
}
def code(x, y): return (x * 2.0) * (x - y)
function code(x, y) return Float64(Float64(x * 2.0) * Float64(x - y)) end
function tmp = code(x, y) tmp = (x * 2.0) * (x - y); end
code[x_, y_] := N[(N[(x * 2.0), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x \cdot 2\right) \cdot \left(x - y\right)
\end{array}
herbie shell --seed 2024066
(FPCore (x y)
:name "Linear.Matrix:fromQuaternion from linear-1.19.1.3, A"
:precision binary64
:alt
(* (* x 2.0) (- x y))
(* 2.0 (- (* x x) (* x y))))