
(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 7 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 (/ -1.0 b)) (* a_m b)))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m / (-1.0 / 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 / ((-1.0d0) / 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 / (-1.0 / b)) * (a_m * b);
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m / (-1.0 / 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 / Float64(-1.0 / 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 / (-1.0 / 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 / N[(-1.0 / b), $MachinePrecision]), $MachinePrecision] * N[(a$95$m * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\frac{a\_m}{\frac{-1}{b}} \cdot \left(a\_m \cdot b\right)
\end{array}
Initial program 83.8%
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6499.6
Applied rewrites99.6%
neg-sub0N/A
flip3--N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
metadata-evalN/A
+-lft-identityN/A
mul0-lftN/A
+-rgt-identityN/A
clear-numN/A
*-inversesN/A
+-rgt-identityN/A
mul0-lftN/A
+-lft-identityN/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
lift-neg.f64N/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
Applied rewrites99.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 (let* ((t_0 (* a_m (- b)))) (if (<= a_m 3.2e-214) (* a_m (* b t_0)) (* b (* a_m t_0)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
double t_0 = a_m * -b;
double tmp;
if (a_m <= 3.2e-214) {
tmp = a_m * (b * t_0);
} else {
tmp = b * (a_m * t_0);
}
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) :: t_0
real(8) :: tmp
t_0 = a_m * -b
if (a_m <= 3.2d-214) then
tmp = a_m * (b * t_0)
else
tmp = b * (a_m * t_0)
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 t_0 = a_m * -b;
double tmp;
if (a_m <= 3.2e-214) {
tmp = a_m * (b * t_0);
} else {
tmp = b * (a_m * t_0);
}
return tmp;
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): t_0 = a_m * -b tmp = 0 if a_m <= 3.2e-214: tmp = a_m * (b * t_0) else: tmp = b * (a_m * t_0) return tmp
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) t_0 = Float64(a_m * Float64(-b)) tmp = 0.0 if (a_m <= 3.2e-214) tmp = Float64(a_m * Float64(b * t_0)); else tmp = Float64(b * Float64(a_m * t_0)); end return tmp end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp_2 = code(a_m, b)
t_0 = a_m * -b;
tmp = 0.0;
if (a_m <= 3.2e-214)
tmp = a_m * (b * t_0);
else
tmp = b * (a_m * t_0);
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_] := Block[{t$95$0 = N[(a$95$m * (-b)), $MachinePrecision]}, If[LessEqual[a$95$m, 3.2e-214], N[(a$95$m * N[(b * t$95$0), $MachinePrecision]), $MachinePrecision], N[(b * N[(a$95$m * t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\begin{array}{l}
t_0 := a\_m \cdot \left(-b\right)\\
\mathbf{if}\;a\_m \leq 3.2 \cdot 10^{-214}:\\
\;\;\;\;a\_m \cdot \left(b \cdot t\_0\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(a\_m \cdot t\_0\right)\\
\end{array}
\end{array}
if a < 3.20000000000000013e-214Initial program 83.6%
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6499.6
Applied rewrites99.6%
neg-sub0N/A
flip3--N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
metadata-evalN/A
+-lft-identityN/A
mul0-lftN/A
+-rgt-identityN/A
clear-numN/A
*-inversesN/A
+-rgt-identityN/A
mul0-lftN/A
+-lft-identityN/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
lift-neg.f64N/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
Applied rewrites99.7%
Taylor expanded in a around 0
mul-1-negN/A
unpow2N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
if 3.20000000000000013e-214 < a Initial program 84.0%
Taylor expanded in a around 0
mul-1-negN/A
unpow2N/A
associate-*r*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6496.3
Applied rewrites96.3%
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 (<= a_m 1.9e-161) (* a_m (* b (* a_m (- b)))) (* b (* b (* a_m (- a_m))))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
double tmp;
if (a_m <= 1.9e-161) {
tmp = a_m * (b * (a_m * -b));
} else {
tmp = b * (b * (a_m * -a_m));
}
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 (a_m <= 1.9d-161) then
tmp = a_m * (b * (a_m * -b))
else
tmp = b * (b * (a_m * -a_m))
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 (a_m <= 1.9e-161) {
tmp = a_m * (b * (a_m * -b));
} else {
tmp = b * (b * (a_m * -a_m));
}
return tmp;
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): tmp = 0 if a_m <= 1.9e-161: tmp = a_m * (b * (a_m * -b)) else: tmp = b * (b * (a_m * -a_m)) return tmp
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) tmp = 0.0 if (a_m <= 1.9e-161) tmp = Float64(a_m * Float64(b * Float64(a_m * Float64(-b)))); else tmp = Float64(b * Float64(b * Float64(a_m * Float64(-a_m)))); 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 (a_m <= 1.9e-161)
tmp = a_m * (b * (a_m * -b));
else
tmp = b * (b * (a_m * -a_m));
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[a$95$m, 1.9e-161], N[(a$95$m * N[(b * N[(a$95$m * (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(b * N[(a$95$m * (-a$95$m)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\begin{array}{l}
\mathbf{if}\;a\_m \leq 1.9 \cdot 10^{-161}:\\
\;\;\;\;a\_m \cdot \left(b \cdot \left(a\_m \cdot \left(-b\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(b \cdot \left(a\_m \cdot \left(-a\_m\right)\right)\right)\\
\end{array}
\end{array}
if a < 1.9000000000000001e-161Initial program 83.6%
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6499.6
Applied rewrites99.6%
neg-sub0N/A
flip3--N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
metadata-evalN/A
+-lft-identityN/A
mul0-lftN/A
+-rgt-identityN/A
clear-numN/A
*-inversesN/A
+-rgt-identityN/A
mul0-lftN/A
+-lft-identityN/A
metadata-evalN/A
flip3--N/A
neg-sub0N/A
lift-neg.f64N/A
associate-/r*N/A
*-commutativeN/A
associate-/r*N/A
Applied rewrites99.7%
Taylor expanded in a around 0
mul-1-negN/A
unpow2N/A
associate-*l*N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
unpow2N/A
associate-*r*N/A
distribute-lft-neg-inN/A
mul-1-negN/A
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f6495.4
Applied rewrites95.4%
if 1.9000000000000001e-161 < a Initial program 84.0%
Final simplification90.8%
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 83.8%
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-rgt-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-*.f6499.6
Applied rewrites99.6%
Final simplification99.6%
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 (* b (* a_m (- a_m)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return b * (b * (a_m * -a_m));
}
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 * (b * (a_m * -a_m))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return b * (b * (a_m * -a_m));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return b * (b * (a_m * -a_m))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(b * Float64(b * Float64(a_m * Float64(-a_m)))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = b * (b * (a_m * -a_m));
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[(b * N[(a$95$m * (-a$95$m)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
b \cdot \left(b \cdot \left(a\_m \cdot \left(-a\_m\right)\right)\right)
\end{array}
Initial program 83.8%
Final simplification83.8%
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 (* b (* a_m a_m))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return b * (b * (a_m * a_m));
}
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 * (b * (a_m * a_m))
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return b * (b * (a_m * a_m));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return b * (b * (a_m * a_m))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(b * Float64(b * Float64(a_m * a_m))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = b * (b * (a_m * a_m));
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[(b * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
b \cdot \left(b \cdot \left(a\_m \cdot a\_m\right)\right)
\end{array}
Initial program 83.8%
lift-*.f64N/A
associate-*l*N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied rewrites29.7%
Final simplification29.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 * 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 83.8%
lift-*.f64N/A
associate-*l*N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied rewrites29.7%
herbie shell --seed 2024219
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))