
(FPCore (a b) :precision binary64 (- (* (* (* a a) b) b)))
double code(double a, double b) {
return -(((a * a) * b) * b);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -(((a * a) * b) * b)
end function
public static double code(double a, double b) {
return -(((a * a) * b) * b);
}
def code(a, b): return -(((a * a) * b) * b)
function code(a, b) return Float64(-Float64(Float64(Float64(a * a) * b) * b)) end
function tmp = code(a, b) tmp = -(((a * a) * b) * b); end
code[a_, b_] := (-N[(N[(N[(a * a), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision])
\begin{array}{l}
\\
-\left(\left(a \cdot a\right) \cdot b\right) \cdot b
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b) :precision binary64 (- (* (* (* a a) b) b)))
double code(double a, double b) {
return -(((a * a) * b) * b);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -(((a * a) * b) * b)
end function
public static double code(double a, double b) {
return -(((a * a) * b) * b);
}
def code(a, b): return -(((a * a) * b) * b)
function code(a, b) return Float64(-Float64(Float64(Float64(a * a) * b) * b)) end
function tmp = code(a, b) tmp = -(((a * a) * b) * b); end
code[a_, b_] := (-N[(N[(N[(a * a), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision])
\begin{array}{l}
\\
-\left(\left(a \cdot a\right) \cdot b\right) \cdot b
\end{array}
b_m = (fabs.f64 b) NOTE: a and b_m should be sorted in increasing order before calling this function. (FPCore (a b_m) :precision binary64 (* (* a b_m) (/ a (/ -1.0 b_m))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
return (a * b_m) * (a / (-1.0 / b_m));
}
b_m = abs(b)
NOTE: a and b_m should be sorted in increasing order before calling this function.
real(8) function code(a, b_m)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
code = (a * b_m) * (a / ((-1.0d0) / b_m))
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
return (a * b_m) * (a / (-1.0 / b_m));
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): return (a * b_m) * (a / (-1.0 / b_m))
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) return Float64(Float64(a * b_m) * Float64(a / Float64(-1.0 / b_m))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
tmp = (a * b_m) * (a / (-1.0 / b_m));
end
b_m = N[Abs[b], $MachinePrecision] NOTE: a and b_m should be sorted in increasing order before calling this function. code[a_, b$95$m_] := N[(N[(a * b$95$m), $MachinePrecision] * N[(a / N[(-1.0 / b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\left(a \cdot b\_m\right) \cdot \frac{a}{\frac{-1}{b\_m}}
\end{array}
Initial program 85.6%
Taylor expanded in a around 0 78.2%
unpow278.2%
unpow278.2%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
Applied egg-rr48.2%
add-sqr-sqrt10.9%
sqrt-unprod11.5%
sqr-neg11.5%
sqrt-unprod11.4%
add-sqr-sqrt11.4%
associate-*r*11.4%
*-commutative11.4%
associate-*l*11.4%
*-commutative11.4%
associate-*l*11.4%
add-sqr-sqrt27.3%
*-commutative27.3%
associate-*r*27.4%
*-commutative27.4%
associate-*r*27.4%
remove-double-div27.4%
div-inv27.4%
Applied egg-rr99.8%
b_m = (fabs.f64 b) NOTE: a and b_m should be sorted in increasing order before calling this function. (FPCore (a b_m) :precision binary64 (* (* a b_m) (* a (- b_m))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
return (a * b_m) * (a * -b_m);
}
b_m = abs(b)
NOTE: a and b_m should be sorted in increasing order before calling this function.
real(8) function code(a, b_m)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
code = (a * b_m) * (a * -b_m)
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
return (a * b_m) * (a * -b_m);
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): return (a * b_m) * (a * -b_m)
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) return Float64(Float64(a * b_m) * Float64(a * Float64(-b_m))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
tmp = (a * b_m) * (a * -b_m);
end
b_m = N[Abs[b], $MachinePrecision] NOTE: a and b_m should be sorted in increasing order before calling this function. code[a_, b$95$m_] := N[(N[(a * b$95$m), $MachinePrecision] * N[(a * (-b$95$m)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\left(a \cdot b\_m\right) \cdot \left(a \cdot \left(-b\_m\right)\right)
\end{array}
Initial program 85.6%
Taylor expanded in a around 0 78.2%
unpow278.2%
unpow278.2%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
Applied egg-rr99.7%
Final simplification99.7%
b_m = (fabs.f64 b) NOTE: a and b_m should be sorted in increasing order before calling this function. (FPCore (a b_m) :precision binary64 (* b_m (* a (* a b_m))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
return b_m * (a * (a * b_m));
}
b_m = abs(b)
NOTE: a and b_m should be sorted in increasing order before calling this function.
real(8) function code(a, b_m)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
code = b_m * (a * (a * b_m))
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
return b_m * (a * (a * b_m));
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): return b_m * (a * (a * b_m))
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) return Float64(b_m * Float64(a * Float64(a * b_m))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
tmp = b_m * (a * (a * b_m));
end
b_m = N[Abs[b], $MachinePrecision] NOTE: a and b_m should be sorted in increasing order before calling this function. code[a_, b$95$m_] := N[(b$95$m * N[(a * N[(a * b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
b\_m \cdot \left(a \cdot \left(a \cdot b\_m\right)\right)
\end{array}
Initial program 85.6%
distribute-rgt-neg-in85.6%
associate-*l*94.6%
Simplified94.6%
neg-sub094.6%
sub-neg94.6%
add-sqr-sqrt49.4%
sqrt-unprod53.3%
sqr-neg53.3%
sqrt-unprod11.4%
add-sqr-sqrt27.4%
Applied egg-rr27.4%
+-lft-identity27.4%
Simplified27.4%
Final simplification27.4%
b_m = (fabs.f64 b) NOTE: a and b_m should be sorted in increasing order before calling this function. (FPCore (a b_m) :precision binary64 (* (* a b_m) (* a b_m)))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
return (a * b_m) * (a * b_m);
}
b_m = abs(b)
NOTE: a and b_m should be sorted in increasing order before calling this function.
real(8) function code(a, b_m)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
code = (a * b_m) * (a * b_m)
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
return (a * b_m) * (a * b_m);
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): return (a * b_m) * (a * b_m)
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) return Float64(Float64(a * b_m) * Float64(a * b_m)) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
tmp = (a * b_m) * (a * b_m);
end
b_m = N[Abs[b], $MachinePrecision] NOTE: a and b_m should be sorted in increasing order before calling this function. code[a_, b$95$m_] := N[(N[(a * b$95$m), $MachinePrecision] * N[(a * b$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\left(a \cdot b\_m\right) \cdot \left(a \cdot b\_m\right)
\end{array}
Initial program 85.6%
add-sqr-sqrt26.5%
sqrt-unprod27.5%
sqr-neg27.5%
sqrt-unprod27.4%
add-sqr-sqrt27.4%
associate-*l*27.2%
swap-sqr27.3%
Applied egg-rr27.3%
b_m = (fabs.f64 b) NOTE: a and b_m should be sorted in increasing order before calling this function. (FPCore (a b_m) :precision binary64 (* a (* b_m (* a b_m))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
return a * (b_m * (a * b_m));
}
b_m = abs(b)
NOTE: a and b_m should be sorted in increasing order before calling this function.
real(8) function code(a, b_m)
real(8), intent (in) :: a
real(8), intent (in) :: b_m
code = a * (b_m * (a * b_m))
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
return a * (b_m * (a * b_m));
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): return a * (b_m * (a * b_m))
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) return Float64(a * Float64(b_m * Float64(a * b_m))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
tmp = a * (b_m * (a * b_m));
end
b_m = N[Abs[b], $MachinePrecision] NOTE: a and b_m should be sorted in increasing order before calling this function. code[a_, b$95$m_] := N[(a * N[(b$95$m * N[(a * b$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
a \cdot \left(b\_m \cdot \left(a \cdot b\_m\right)\right)
\end{array}
Initial program 85.6%
associate-*l*78.2%
associate-*r*82.1%
*-commutative82.1%
distribute-rgt-neg-in82.1%
distribute-rgt-neg-in82.1%
associate-*r*93.6%
Simplified93.6%
neg-sub093.6%
sub-neg93.6%
add-sqr-sqrt41.1%
sqrt-unprod51.0%
sqr-neg51.0%
sqrt-prod14.6%
add-sqr-sqrt27.4%
Applied egg-rr27.4%
+-lft-identity27.4%
Simplified27.4%
Final simplification27.4%
herbie shell --seed 2024123
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))