
(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 8 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}
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* (* a_m b) (/ 1.0 (/ (/ -1.0 a_m) b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * b) * (1.0 / ((-1.0 / a_m) / b));
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = (a_m * b) * (1.0d0 / (((-1.0d0) / a_m) / b))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return (a_m * b) * (1.0 / ((-1.0 / a_m) / b));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * b) * (1.0 / ((-1.0 / a_m) / b))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(a_m * b) * Float64(1.0 / Float64(Float64(-1.0 / a_m) / b))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = (a_m * b) * (1.0 / ((-1.0 / a_m) / b));
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(N[(a$95$m * b), $MachinePrecision] * N[(1.0 / N[(N[(-1.0 / a$95$m), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(a\_m \cdot b\right) \cdot \frac{1}{\frac{\frac{-1}{a\_m}}{b}}
\end{array}
Initial program 84.2%
Taylor expanded in a around 0 80.1%
mul-1-neg80.1%
unpow280.1%
unpow280.1%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
distribute-rgt-neg-in99.7%
Applied egg-rr99.7%
add-sqr-sqrt54.4%
sqrt-prod62.6%
unpow262.6%
add-sqr-sqrt62.6%
sqrt-prod56.5%
sqr-neg56.5%
sqrt-unprod25.0%
add-sqr-sqrt25.0%
metadata-eval25.0%
pow-div0.8%
distribute-frac-neg20.8%
clear-num0.8%
sqrt-div0.5%
metadata-eval0.5%
clear-num0.5%
distribute-frac-neg20.5%
pow-div16.8%
metadata-eval16.8%
Applied egg-rr62.6%
Taylor expanded in a around 0 99.7%
associate-/r*99.7%
Simplified99.7%
Final simplification99.7%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (if (<= (* b (* b (* a_m a_m))) 5e-251) (* a_m (* b (* a_m (- b)))) (* b (* (* a_m a_m) (- b)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
double tmp;
if ((b * (b * (a_m * a_m))) <= 5e-251) {
tmp = a_m * (b * (a_m * -b));
} else {
tmp = b * ((a_m * a_m) * -b);
}
return tmp;
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
real(8) :: tmp
if ((b * (b * (a_m * a_m))) <= 5d-251) then
tmp = a_m * (b * (a_m * -b))
else
tmp = b * ((a_m * a_m) * -b)
end if
code = tmp
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
double tmp;
if ((b * (b * (a_m * a_m))) <= 5e-251) {
tmp = a_m * (b * (a_m * -b));
} else {
tmp = b * ((a_m * a_m) * -b);
}
return tmp;
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): tmp = 0 if (b * (b * (a_m * a_m))) <= 5e-251: tmp = a_m * (b * (a_m * -b)) else: tmp = b * ((a_m * a_m) * -b) return tmp
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) tmp = 0.0 if (Float64(b * Float64(b * Float64(a_m * a_m))) <= 5e-251) tmp = Float64(a_m * Float64(b * Float64(a_m * Float64(-b)))); else tmp = Float64(b * Float64(Float64(a_m * a_m) * Float64(-b))); end return tmp end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp_2 = code(a_m, b)
tmp = 0.0;
if ((b * (b * (a_m * a_m))) <= 5e-251)
tmp = a_m * (b * (a_m * -b));
else
tmp = b * ((a_m * a_m) * -b);
end
tmp_2 = tmp;
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := If[LessEqual[N[(b * N[(b * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-251], N[(a$95$m * N[(b * N[(a$95$m * (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(N[(a$95$m * a$95$m), $MachinePrecision] * (-b)), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\begin{array}{l}
\mathbf{if}\;b \cdot \left(b \cdot \left(a\_m \cdot a\_m\right)\right) \leq 5 \cdot 10^{-251}:\\
\;\;\;\;a\_m \cdot \left(b \cdot \left(a\_m \cdot \left(-b\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(\left(a\_m \cdot a\_m\right) \cdot \left(-b\right)\right)\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 a a) b) b) < 5.0000000000000003e-251Initial program 79.9%
associate-*l*79.1%
associate-*r*82.9%
*-commutative82.9%
distribute-rgt-neg-in82.9%
distribute-rgt-neg-in82.9%
associate-*r*97.7%
Simplified97.7%
if 5.0000000000000003e-251 < (*.f64 (*.f64 (*.f64 a a) b) b) Initial program 86.3%
Final simplification90.1%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* (* a_m b) (/ -1.0 (/ 1.0 (* a_m b)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * b) * (-1.0 / (1.0 / (a_m * b)));
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = (a_m * b) * ((-1.0d0) / (1.0d0 / (a_m * b)))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return (a_m * b) * (-1.0 / (1.0 / (a_m * b)));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * b) * (-1.0 / (1.0 / (a_m * b)))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(a_m * b) * Float64(-1.0 / Float64(1.0 / Float64(a_m * b)))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = (a_m * b) * (-1.0 / (1.0 / (a_m * b)));
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(N[(a$95$m * b), $MachinePrecision] * N[(-1.0 / N[(1.0 / N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(a\_m \cdot b\right) \cdot \frac{-1}{\frac{1}{a\_m \cdot b}}
\end{array}
Initial program 84.2%
Taylor expanded in a around 0 80.1%
mul-1-neg80.1%
unpow280.1%
unpow280.1%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
distribute-rgt-neg-in99.7%
Applied egg-rr99.7%
add-cbrt-cube90.0%
pow390.0%
Applied egg-rr90.0%
rem-cbrt-cube99.7%
add-sqr-sqrt56.0%
sqrt-unprod63.2%
sqr-neg63.2%
unpow263.2%
/-rgt-identity63.2%
clear-num63.1%
metadata-eval63.1%
add-sqr-sqrt63.1%
frac-times63.1%
sqrt-unprod63.1%
add-sqr-sqrt63.1%
frac-2neg63.1%
metadata-eval63.1%
sqrt-div63.2%
metadata-eval63.2%
sqrt-pow126.1%
metadata-eval26.1%
pow126.1%
distribute-neg-frac226.1%
add-sqr-sqrt19.0%
Applied egg-rr99.7%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* (* a_m b) (* a_m (- b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * b) * (a_m * -b);
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = (a_m * b) * (a_m * -b)
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return (a_m * b) * (a_m * -b);
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * b) * (a_m * -b)
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(a_m * b) * Float64(a_m * Float64(-b))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = (a_m * b) * (a_m * -b);
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(N[(a$95$m * b), $MachinePrecision] * N[(a$95$m * (-b)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(a\_m \cdot b\right) \cdot \left(a\_m \cdot \left(-b\right)\right)
\end{array}
Initial program 84.2%
Taylor expanded in a around 0 80.1%
mul-1-neg80.1%
unpow280.1%
unpow280.1%
swap-sqr99.7%
unpow299.7%
Simplified99.7%
unpow299.7%
distribute-rgt-neg-in99.7%
Applied egg-rr99.7%
Final simplification99.7%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* b (* (* a_m a_m) (- b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return b * ((a_m * a_m) * -b);
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = b * ((a_m * a_m) * -b)
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return b * ((a_m * a_m) * -b);
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return b * ((a_m * a_m) * -b)
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(b * Float64(Float64(a_m * a_m) * Float64(-b))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = b * ((a_m * a_m) * -b);
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(b * N[(N[(a$95$m * a$95$m), $MachinePrecision] * (-b)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
b \cdot \left(\left(a\_m \cdot a\_m\right) \cdot \left(-b\right)\right)
\end{array}
Initial program 84.2%
Final simplification84.2%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* b (* a_m (* a_m b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return b * (a_m * (a_m * b));
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = b * (a_m * (a_m * b))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return b * (a_m * (a_m * b));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return b * (a_m * (a_m * b))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(b * Float64(a_m * Float64(a_m * b))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = b * (a_m * (a_m * b));
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(b * N[(a$95$m * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
b \cdot \left(a\_m \cdot \left(a\_m \cdot b\right)\right)
\end{array}
Initial program 84.2%
distribute-rgt-neg-in84.2%
associate-*l*92.9%
Simplified92.9%
neg-sub092.9%
sub-neg92.9%
add-sqr-sqrt44.3%
sqrt-unprod54.2%
sqr-neg54.2%
sqrt-unprod14.9%
add-sqr-sqrt26.2%
Applied egg-rr26.2%
+-lft-identity26.2%
Simplified26.2%
Final simplification26.2%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* (* a_m b) (* a_m b)))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * b) * (a_m * b);
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = (a_m * b) * (a_m * b)
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return (a_m * b) * (a_m * b);
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * b) * (a_m * b)
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(a_m * b) * Float64(a_m * b)) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = (a_m * b) * (a_m * b);
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(N[(a$95$m * b), $MachinePrecision] * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(a\_m \cdot b\right) \cdot \left(a\_m \cdot b\right)
\end{array}
Initial program 84.2%
add-sqr-sqrt25.3%
sqrt-unprod26.2%
sqr-neg26.2%
sqrt-unprod26.2%
add-sqr-sqrt26.2%
associate-*l*25.9%
swap-sqr26.1%
Applied egg-rr26.1%
a_m = (fabs.f64 a) NOTE: a_m and b should be sorted in increasing order before calling this function. (FPCore (a_m b) :precision binary64 (* a_m (* b (* a_m b))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return a_m * (b * (a_m * b));
}
a_m = abs(a)
NOTE: a_m and b should be sorted in increasing order before calling this function.
real(8) function code(a_m, b)
real(8), intent (in) :: a_m
real(8), intent (in) :: b
code = a_m * (b * (a_m * b))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return a_m * (b * (a_m * b));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return a_m * (b * (a_m * b))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(a_m * Float64(b * Float64(a_m * b))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = a_m * (b * (a_m * b));
end
a_m = N[Abs[a], $MachinePrecision] NOTE: a_m and b should be sorted in increasing order before calling this function. code[a$95$m_, b_] := N[(a$95$m * N[(b * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
a\_m \cdot \left(b \cdot \left(a\_m \cdot b\right)\right)
\end{array}
Initial program 84.2%
associate-*l*80.1%
associate-*r*84.8%
*-commutative84.8%
distribute-rgt-neg-in84.8%
distribute-rgt-neg-in84.8%
associate-*r*96.2%
Simplified96.2%
neg-sub096.2%
sub-neg96.2%
add-sqr-sqrt47.6%
sqrt-unprod55.3%
sqr-neg55.3%
sqrt-prod14.8%
add-sqr-sqrt26.1%
Applied egg-rr26.1%
+-lft-identity26.1%
Simplified26.1%
Final simplification26.1%
herbie shell --seed 2024131
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))