
(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 (sqrt b)) (* b (* (sqrt b) (- a_m)))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * sqrt(b)) * (b * (sqrt(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 * sqrt(b)) * (b * (sqrt(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 * Math.sqrt(b)) * (b * (Math.sqrt(b) * -a_m));
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * math.sqrt(b)) * (b * (math.sqrt(b) * -a_m))
a_m = abs(a) a_m, b = sort([a_m, b]) function code(a_m, b) return Float64(Float64(a_m * sqrt(b)) * Float64(b * Float64(sqrt(b) * Float64(-a_m)))) end
a_m = abs(a);
a_m, b = num2cell(sort([a_m, b])){:}
function tmp = code(a_m, b)
tmp = (a_m * sqrt(b)) * (b * (sqrt(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 * N[Sqrt[b], $MachinePrecision]), $MachinePrecision] * N[(b * N[(N[Sqrt[b], $MachinePrecision] * (-a$95$m)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
a_m = \left|a\right|
\\
[a_m, b] = \mathsf{sort}([a_m, b])\\
\\
\left(a\_m \cdot \sqrt{b}\right) \cdot \left(b \cdot \left(\sqrt{b} \cdot \left(-a\_m\right)\right)\right)
\end{array}
Initial program 80.4%
Taylor expanded in a around 0 74.5%
mul-1-neg74.5%
unpow274.5%
unpow274.5%
swap-sqr99.6%
unpow299.6%
Simplified99.6%
unpow299.6%
associate-*r*95.0%
*-commutative95.0%
distribute-rgt-neg-in95.0%
associate-*r*80.4%
add-sqr-sqrt37.9%
swap-sqr46.4%
associate-*l*48.5%
Applied egg-rr48.5%
Final simplification48.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 (if (<= (* b (* b (* a_m a_m))) 0.2) (* a_m (* b (* b (- a_m)))) (* b (* b (* a_m (- a_m))))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
double tmp;
if ((b * (b * (a_m * a_m))) <= 0.2) {
tmp = a_m * (b * (b * -a_m));
} 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 ((b * (b * (a_m * a_m))) <= 0.2d0) then
tmp = a_m * (b * (b * -a_m))
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 ((b * (b * (a_m * a_m))) <= 0.2) {
tmp = a_m * (b * (b * -a_m));
} 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 (b * (b * (a_m * a_m))) <= 0.2: tmp = a_m * (b * (b * -a_m)) 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 (Float64(b * Float64(b * Float64(a_m * a_m))) <= 0.2) tmp = Float64(a_m * Float64(b * Float64(b * Float64(-a_m)))); 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 ((b * (b * (a_m * a_m))) <= 0.2)
tmp = a_m * (b * (b * -a_m));
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[N[(b * N[(b * N[(a$95$m * a$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.2], N[(a$95$m * N[(b * N[(b * (-a$95$m)), $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}\;b \cdot \left(b \cdot \left(a\_m \cdot a\_m\right)\right) \leq 0.2:\\
\;\;\;\;a\_m \cdot \left(b \cdot \left(b \cdot \left(-a\_m\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 (*.f64 (*.f64 (*.f64 a a) b) b) < 0.20000000000000001Initial program 78.2%
associate-*l*70.8%
associate-*r*76.6%
*-commutative76.6%
distribute-rgt-neg-in76.6%
distribute-rgt-neg-in76.6%
associate-*r*92.8%
Simplified92.8%
if 0.20000000000000001 < (*.f64 (*.f64 (*.f64 a a) b) b) Initial program 82.5%
Final simplification87.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 (* (* a_m b) (* b (- a_m))))
a_m = fabs(a);
assert(a_m < b);
double code(double a_m, double b) {
return (a_m * b) * (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) * (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) * (b * -a_m);
}
a_m = math.fabs(a) [a_m, b] = sort([a_m, b]) def code(a_m, b): return (a_m * b) * (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(b * Float64(-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) * (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[(b * (-a$95$m)), $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(b \cdot \left(-a\_m\right)\right)
\end{array}
Initial program 80.4%
Taylor expanded in a around 0 74.5%
mul-1-neg74.5%
unpow274.5%
unpow274.5%
swap-sqr99.6%
unpow299.6%
Simplified99.6%
unpow299.6%
distribute-rgt-neg-in99.6%
Applied egg-rr99.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 80.4%
Final simplification80.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 (* 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 80.4%
distribute-rgt-neg-in80.4%
associate-*l*95.0%
Simplified95.0%
neg-sub095.0%
sub-neg95.0%
add-sqr-sqrt48.4%
sqrt-unprod55.1%
sqr-neg55.1%
sqrt-unprod12.9%
add-sqr-sqrt25.5%
Applied egg-rr25.5%
+-lft-identity25.5%
Simplified25.5%
Final simplification25.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 (* (* 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 80.4%
add-sqr-sqrt24.6%
sqrt-unprod25.7%
sqr-neg25.7%
sqrt-unprod25.6%
add-sqr-sqrt25.6%
associate-*l*25.3%
swap-sqr25.5%
Applied egg-rr25.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 (* 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 80.4%
associate-*l*74.5%
associate-*r*81.2%
*-commutative81.2%
distribute-rgt-neg-in81.2%
distribute-rgt-neg-in81.2%
associate-*r*94.2%
Simplified94.2%
neg-sub094.2%
sub-neg94.2%
add-sqr-sqrt43.8%
sqrt-unprod50.5%
sqr-neg50.5%
sqrt-prod12.3%
add-sqr-sqrt25.6%
Applied egg-rr25.6%
+-lft-identity25.6%
Simplified25.6%
Final simplification25.6%
herbie shell --seed 2024136
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))