
(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 b) a_m)))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * b) / ((-1.0 / b) / 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 = (a_m * b) / (((-1.0d0) / b) / a_m)
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 / b) / a_m);
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * b) / ((-1.0 / b) / a_m)
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(a_m * b) / Float64(Float64(-1.0 / b) / a_m)) 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 / b) / 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[(N[(a$95$m * b), $MachinePrecision] / N[(N[(-1.0 / b), $MachinePrecision] / a$95$m), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\frac{a\_m \cdot b}{\frac{\frac{-1}{b}}{a\_m}}
\end{array}
Initial program 81.4%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
remove-double-divN/A
unpow-1N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
associate-/r*N/A
metadata-evalN/A
pow-flipN/A
metadata-evalN/A
unpow1N/A
lower-/.f64N/A
lower-pow.f6499.7
Applied rewrites99.7%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.7
Applied rewrites99.7%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-/.f64N/A
remove-double-divN/A
lift-*.f64N/A
remove-double-divN/A
metadata-evalN/A
lift-neg.f64N/A
frac-2negN/A
lift-/.f64N/A
div-invN/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lift-/.f64N/A
associate-/l/N/A
associate-/r*N/A
metadata-evalN/A
distribute-neg-fracN/A
lift-/.f64N/A
lower-/.f64N/A
Applied rewrites99.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 (* (/ 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 81.4%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
remove-double-divN/A
unpow-1N/A
metadata-evalN/A
metadata-evalN/A
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
unpow-prod-downN/A
associate-/r*N/A
metadata-evalN/A
pow-flipN/A
metadata-evalN/A
unpow1N/A
lower-/.f64N/A
lower-pow.f6499.7
Applied rewrites99.7%
lift-pow.f64N/A
unpow-1N/A
lower-/.f6499.7
Applied rewrites99.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 (/ (* a_m b) (/ -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 / (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) / (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 / (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 / (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(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 / (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[(a$95$m * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\frac{a\_m \cdot b}{\frac{-1}{a\_m \cdot b}}
\end{array}
Initial program 81.4%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/A
lower-*.f6499.6
Applied rewrites99.6%
lift-*.f64N/A
remove-double-divN/A
unpow-1N/A
metadata-evalN/A
div-invN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
*-commutativeN/A
lift-*.f64N/A
distribute-neg-fracN/A
distribute-neg-frac2N/A
lower-/.f64N/A
metadata-evalN/A
unpow-1N/A
metadata-evalN/A
distribute-neg-fracN/A
metadata-evalN/A
metadata-evalN/A
lower-/.f6499.7
Applied rewrites99.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 (* (* (- 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(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(\left(-a\_m\right) \cdot b\right) \cdot \left(a\_m \cdot b\right)
\end{array}
Initial program 81.4%
lift-neg.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
unswap-sqrN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
*-commutativeN/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) (* (* 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(Float64(-b) * Float64(Float64(a_m * 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[(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])\\
\\
\left(-b\right) \cdot \left(\left(a\_m \cdot a\_m\right) \cdot b\right)
\end{array}
Initial program 81.4%
Final simplification81.4%
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 a_m) b) b))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return ((a_m * a_m) * b) * 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 * a_m) * b) * b
end function
a_m = Math.abs(a);
assert a_m < b;
public static double code(double a_m, double b) {
return ((a_m * a_m) * b) * b;
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return ((a_m * a_m) * b) * b
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(Float64(a_m * a_m) * b) * b) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = ((a_m * a_m) * b) * 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[(N[(a$95$m * a$95$m), $MachinePrecision] * b), $MachinePrecision] * b), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(\left(a\_m \cdot a\_m\right) \cdot b\right) \cdot b
\end{array}
Initial program 81.4%
lift-neg.f64N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied rewrites29.6%
Final simplification29.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 (* (* 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 81.4%
lift-neg.f64N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied rewrites29.5%
Final simplification29.5%
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(Float64(Float64(b * b) * 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[(N[(N[(b * b), $MachinePrecision] * a$95$m), $MachinePrecision] * a$95$m), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(\left(b \cdot b\right) \cdot a\_m\right) \cdot a\_m
\end{array}
Initial program 81.4%
lift-neg.f64N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied rewrites29.4%
Taylor expanded in b around 0
*-commutativeN/A
unpow2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6429.5
Applied rewrites29.5%
herbie shell --seed 2024271
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))