
(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 2 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}
NOTE: a should be positive before calling this function NOTE: b should be positive before calling this function (FPCore (a b) :precision binary64 (* (sqrt (* a b)) (- (pow (* a b) 1.5))))
a = abs(a);
b = abs(b);
double code(double a, double b) {
return sqrt((a * b)) * -pow((a * b), 1.5);
}
NOTE: a should be positive before calling this function
NOTE: b should be positive before calling this function
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = sqrt((a * b)) * -((a * b) ** 1.5d0)
end function
a = Math.abs(a);
b = Math.abs(b);
public static double code(double a, double b) {
return Math.sqrt((a * b)) * -Math.pow((a * b), 1.5);
}
a = abs(a) b = abs(b) def code(a, b): return math.sqrt((a * b)) * -math.pow((a * b), 1.5)
a = abs(a) b = abs(b) function code(a, b) return Float64(sqrt(Float64(a * b)) * Float64(-(Float64(a * b) ^ 1.5))) end
a = abs(a) b = abs(b) function tmp = code(a, b) tmp = sqrt((a * b)) * -((a * b) ^ 1.5); end
NOTE: a should be positive before calling this function NOTE: b should be positive before calling this function code[a_, b_] := N[(N[Sqrt[N[(a * b), $MachinePrecision]], $MachinePrecision] * (-N[Power[N[(a * b), $MachinePrecision], 1.5], $MachinePrecision])), $MachinePrecision]
\begin{array}{l}
a = |a|\\
b = |b|\\
\\
\sqrt{a \cdot b} \cdot \left(-{\left(a \cdot b\right)}^{1.5}\right)
\end{array}
Initial program 81.6%
distribute-rgt-neg-in81.6%
associate-*l*74.5%
Simplified74.5%
Taylor expanded in a around 0 74.5%
mul-1-neg74.5%
unpow274.5%
unpow274.5%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
add-sqr-sqrt53.7%
associate-*r*53.8%
Applied egg-rr53.8%
add-log-exp37.8%
*-un-lft-identity37.8%
log-prod37.8%
metadata-eval37.8%
add-log-exp53.8%
*-commutative53.8%
pow1/253.8%
pow-plus53.8%
metadata-eval53.8%
Applied egg-rr53.8%
+-lft-identity53.8%
Simplified53.8%
Final simplification53.8%
NOTE: a should be positive before calling this function NOTE: b should be positive before calling this function (FPCore (a b) :precision binary64 (* (* a b) (* a (- b))))
a = abs(a);
b = abs(b);
double code(double a, double b) {
return (a * b) * (a * -b);
}
NOTE: a should be positive before calling this function
NOTE: b should be positive before calling this function
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a * b) * (a * -b)
end function
a = Math.abs(a);
b = Math.abs(b);
public static double code(double a, double b) {
return (a * b) * (a * -b);
}
a = abs(a) b = abs(b) def code(a, b): return (a * b) * (a * -b)
a = abs(a) b = abs(b) function code(a, b) return Float64(Float64(a * b) * Float64(a * Float64(-b))) end
a = abs(a) b = abs(b) function tmp = code(a, b) tmp = (a * b) * (a * -b); end
NOTE: a should be positive before calling this function NOTE: b should be positive before calling this function code[a_, b_] := N[(N[(a * b), $MachinePrecision] * N[(a * (-b)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a = |a|\\
b = |b|\\
\\
\left(a \cdot b\right) \cdot \left(a \cdot \left(-b\right)\right)
\end{array}
Initial program 81.6%
distribute-rgt-neg-in81.6%
associate-*l*74.5%
Simplified74.5%
Taylor expanded in a around 0 74.5%
mul-1-neg74.5%
unpow274.5%
unpow274.5%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
Applied egg-rr99.7%
Final simplification99.7%
herbie shell --seed 2023279
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))