
(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 (let* ((t_0 (* a (sqrt b_m)))) (* t_0 (* b_m (- t_0)))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
double t_0 = a * sqrt(b_m);
return t_0 * (b_m * -t_0);
}
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
real(8) :: t_0
t_0 = a * sqrt(b_m)
code = t_0 * (b_m * -t_0)
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
double t_0 = a * Math.sqrt(b_m);
return t_0 * (b_m * -t_0);
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): t_0 = a * math.sqrt(b_m) return t_0 * (b_m * -t_0)
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) t_0 = Float64(a * sqrt(b_m)) return Float64(t_0 * Float64(b_m * Float64(-t_0))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
t_0 = a * sqrt(b_m);
tmp = t_0 * (b_m * -t_0);
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_] := Block[{t$95$0 = N[(a * N[Sqrt[b$95$m], $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * N[(b$95$m * (-t$95$0)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\begin{array}{l}
t_0 := a \cdot \sqrt{b\_m}\\
t\_0 \cdot \left(b\_m \cdot \left(-t\_0\right)\right)
\end{array}
\end{array}
Initial program 79.7%
add-cube-cbrt79.4%
pow379.4%
associate-*l*76.7%
swap-sqr99.1%
cbrt-unprod98.7%
pow298.7%
Applied egg-rr98.7%
unpow398.7%
pow298.7%
unpow-prod-down98.7%
unpow298.7%
add-cube-cbrt99.7%
unpow-prod-down77.0%
unpow277.0%
associate-*r*79.7%
add-sqr-sqrt45.3%
pow245.3%
pow-prod-down53.5%
*-commutative53.5%
unpow253.5%
associate-*r*56.4%
Applied egg-rr56.4%
Final simplification56.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 (let* ((t_0 (* b_m (sqrt a)))) (- (* t_0 (* a t_0)))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
double t_0 = b_m * sqrt(a);
return -(t_0 * (a * t_0));
}
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
real(8) :: t_0
t_0 = b_m * sqrt(a)
code = -(t_0 * (a * t_0))
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
double t_0 = b_m * Math.sqrt(a);
return -(t_0 * (a * t_0));
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): t_0 = b_m * math.sqrt(a) return -(t_0 * (a * t_0))
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) t_0 = Float64(b_m * sqrt(a)) return Float64(-Float64(t_0 * Float64(a * t_0))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
t_0 = b_m * sqrt(a);
tmp = -(t_0 * (a * t_0));
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_] := Block[{t$95$0 = N[(b$95$m * N[Sqrt[a], $MachinePrecision]), $MachinePrecision]}, (-N[(t$95$0 * N[(a * t$95$0), $MachinePrecision]), $MachinePrecision])]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\begin{array}{l}
t_0 := b\_m \cdot \sqrt{a}\\
-t\_0 \cdot \left(a \cdot t\_0\right)
\end{array}
\end{array}
Initial program 79.7%
add-cube-cbrt79.4%
pow379.4%
associate-*l*76.7%
swap-sqr99.1%
cbrt-unprod98.7%
pow298.7%
Applied egg-rr98.7%
unpow398.7%
pow298.7%
unpow-prod-down98.7%
unpow298.7%
add-cube-cbrt99.7%
unpow-prod-down77.0%
unpow277.0%
add-sqr-sqrt77.0%
sqrt-unprod68.6%
sqr-neg68.6%
sqrt-unprod16.7%
add-sqr-sqrt27.9%
associate-*r*28.1%
*-commutative28.1%
add-sqr-sqrt25.1%
associate-*l*25.1%
Applied egg-rr52.6%
Final simplification52.6%
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 (let* ((t_0 (* b_m (* a a)))) (if (<= (* b_m t_0) 1e-12) (* a (* b_m (* b_m (- a)))) (* (- b_m) t_0))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
double t_0 = b_m * (a * a);
double tmp;
if ((b_m * t_0) <= 1e-12) {
tmp = a * (b_m * (b_m * -a));
} else {
tmp = -b_m * t_0;
}
return tmp;
}
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
real(8) :: t_0
real(8) :: tmp
t_0 = b_m * (a * a)
if ((b_m * t_0) <= 1d-12) then
tmp = a * (b_m * (b_m * -a))
else
tmp = -b_m * t_0
end if
code = tmp
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
double t_0 = b_m * (a * a);
double tmp;
if ((b_m * t_0) <= 1e-12) {
tmp = a * (b_m * (b_m * -a));
} else {
tmp = -b_m * t_0;
}
return tmp;
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): t_0 = b_m * (a * a) tmp = 0 if (b_m * t_0) <= 1e-12: tmp = a * (b_m * (b_m * -a)) else: tmp = -b_m * t_0 return tmp
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) t_0 = Float64(b_m * Float64(a * a)) tmp = 0.0 if (Float64(b_m * t_0) <= 1e-12) tmp = Float64(a * Float64(b_m * Float64(b_m * Float64(-a)))); else tmp = Float64(Float64(-b_m) * t_0); end return tmp end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp_2 = code(a, b_m)
t_0 = b_m * (a * a);
tmp = 0.0;
if ((b_m * t_0) <= 1e-12)
tmp = a * (b_m * (b_m * -a));
else
tmp = -b_m * t_0;
end
tmp_2 = tmp;
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_] := Block[{t$95$0 = N[(b$95$m * N[(a * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(b$95$m * t$95$0), $MachinePrecision], 1e-12], N[(a * N[(b$95$m * N[(b$95$m * (-a)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-b$95$m) * t$95$0), $MachinePrecision]]]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\begin{array}{l}
t_0 := b\_m \cdot \left(a \cdot a\right)\\
\mathbf{if}\;b\_m \cdot t\_0 \leq 10^{-12}:\\
\;\;\;\;a \cdot \left(b\_m \cdot \left(b\_m \cdot \left(-a\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\left(-b\_m\right) \cdot t\_0\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 a a) b) b) < 9.9999999999999998e-13Initial program 80.2%
associate-*l*77.4%
associate-*r*83.5%
*-commutative83.5%
distribute-rgt-neg-in83.5%
distribute-rgt-neg-in83.5%
associate-*r*95.1%
Simplified95.1%
if 9.9999999999999998e-13 < (*.f64 (*.f64 (*.f64 a a) b) b) Initial program 79.3%
Final simplification87.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 (if (<= b_m 3.25e+267) (* a (* b_m (* b_m (- a)))) (* b_m (- (* a (* b_m a))))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
double tmp;
if (b_m <= 3.25e+267) {
tmp = a * (b_m * (b_m * -a));
} else {
tmp = b_m * -(a * (b_m * a));
}
return tmp;
}
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
real(8) :: tmp
if (b_m <= 3.25d+267) then
tmp = a * (b_m * (b_m * -a))
else
tmp = b_m * -(a * (b_m * a))
end if
code = tmp
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
double tmp;
if (b_m <= 3.25e+267) {
tmp = a * (b_m * (b_m * -a));
} else {
tmp = b_m * -(a * (b_m * a));
}
return tmp;
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): tmp = 0 if b_m <= 3.25e+267: tmp = a * (b_m * (b_m * -a)) else: tmp = b_m * -(a * (b_m * a)) return tmp
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) tmp = 0.0 if (b_m <= 3.25e+267) tmp = Float64(a * Float64(b_m * Float64(b_m * Float64(-a)))); else tmp = Float64(b_m * Float64(-Float64(a * Float64(b_m * a)))); end return tmp end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp_2 = code(a, b_m)
tmp = 0.0;
if (b_m <= 3.25e+267)
tmp = a * (b_m * (b_m * -a));
else
tmp = b_m * -(a * (b_m * a));
end
tmp_2 = tmp;
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_] := If[LessEqual[b$95$m, 3.25e+267], N[(a * N[(b$95$m * N[(b$95$m * (-a)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b$95$m * (-N[(a * N[(b$95$m * a), $MachinePrecision]), $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\begin{array}{l}
\mathbf{if}\;b\_m \leq 3.25 \cdot 10^{+267}:\\
\;\;\;\;a \cdot \left(b\_m \cdot \left(b\_m \cdot \left(-a\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;b\_m \cdot \left(-a \cdot \left(b\_m \cdot a\right)\right)\\
\end{array}
\end{array}
if b < 3.24999999999999991e267Initial program 79.9%
associate-*l*77.1%
associate-*r*84.0%
*-commutative84.0%
distribute-rgt-neg-in84.0%
distribute-rgt-neg-in84.0%
associate-*r*94.9%
Simplified94.9%
if 3.24999999999999991e267 < b Initial program 75.7%
distribute-rgt-neg-in75.7%
associate-*l*99.9%
Simplified99.9%
Final simplification95.1%
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) (* b_m (* a a))))
b_m = fabs(b);
assert(a < b_m);
double code(double a, double b_m) {
return -b_m * (b_m * (a * a));
}
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 * (b_m * (a * a))
end function
b_m = Math.abs(b);
assert a < b_m;
public static double code(double a, double b_m) {
return -b_m * (b_m * (a * a));
}
b_m = math.fabs(b) [a, b_m] = sort([a, b_m]) def code(a, b_m): return -b_m * (b_m * (a * a))
b_m = abs(b) a, b_m = sort([a, b_m]) function code(a, b_m) return Float64(Float64(-b_m) * Float64(b_m * Float64(a * a))) end
b_m = abs(b);
a, b_m = num2cell(sort([a, b_m])){:}
function tmp = code(a, b_m)
tmp = -b_m * (b_m * (a * a));
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[(b$95$m * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
b_m = \left|b\right|
\\
[a, b_m] = \mathsf{sort}([a, b_m])\\
\\
\left(-b\_m\right) \cdot \left(b\_m \cdot \left(a \cdot a\right)\right)
\end{array}
Initial program 79.7%
Final simplification79.7%
herbie shell --seed 2024044
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))