
(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 6 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}
(FPCore (a b) :precision binary64 (* (* a b) (- 0.0 (* a b))))
double code(double a, double b) {
return (a * b) * (0.0 - (a * b));
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = (a * b) * (0.0d0 - (a * b))
end function
public static double code(double a, double b) {
return (a * b) * (0.0 - (a * b));
}
def code(a, b): return (a * b) * (0.0 - (a * b))
function code(a, b) return Float64(Float64(a * b) * Float64(0.0 - Float64(a * b))) end
function tmp = code(a, b) tmp = (a * b) * (0.0 - (a * b)); end
code[a_, b_] := N[(N[(a * b), $MachinePrecision] * N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(a \cdot b\right) \cdot \left(0 - a \cdot b\right)
\end{array}
Initial program 85.0%
associate-*l*N/A
unswap-sqrN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (a b) :precision binary64 (let* ((t_0 (* b (* b (* a a))))) (if (<= t_0 1e-258) t_0 (- 0.0 (* a b)))))
double code(double a, double b) {
double t_0 = b * (b * (a * a));
double tmp;
if (t_0 <= 1e-258) {
tmp = t_0;
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: t_0
real(8) :: tmp
t_0 = b * (b * (a * a))
if (t_0 <= 1d-258) then
tmp = t_0
else
tmp = 0.0d0 - (a * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double t_0 = b * (b * (a * a));
double tmp;
if (t_0 <= 1e-258) {
tmp = t_0;
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
def code(a, b): t_0 = b * (b * (a * a)) tmp = 0 if t_0 <= 1e-258: tmp = t_0 else: tmp = 0.0 - (a * b) return tmp
function code(a, b) t_0 = Float64(b * Float64(b * Float64(a * a))) tmp = 0.0 if (t_0 <= 1e-258) tmp = t_0; else tmp = Float64(0.0 - Float64(a * b)); end return tmp end
function tmp_2 = code(a, b) t_0 = b * (b * (a * a)); tmp = 0.0; if (t_0 <= 1e-258) tmp = t_0; else tmp = 0.0 - (a * b); end tmp_2 = tmp; end
code[a_, b_] := Block[{t$95$0 = N[(b * N[(b * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 1e-258], t$95$0, N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b \cdot \left(b \cdot \left(a \cdot a\right)\right)\\
\mathbf{if}\;t\_0 \leq 10^{-258}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\
\end{array}
\end{array}
if (*.f64 (*.f64 (*.f64 a a) b) b) < 9.99999999999999954e-259Initial program 81.2%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr71.3%
if 9.99999999999999954e-259 < (*.f64 (*.f64 (*.f64 a a) b) b) Initial program 87.3%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6481.4%
Applied egg-rr81.4%
Applied egg-rr14.7%
*-rgt-identity14.7%
Applied egg-rr14.7%
Final simplification35.9%
(FPCore (a b) :precision binary64 (if (<= b 2.4e+105) (* (* a b) (* a b)) (- 0.0 (* a b))))
double code(double a, double b) {
double tmp;
if (b <= 2.4e+105) {
tmp = (a * b) * (a * b);
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 2.4d+105) then
tmp = (a * b) * (a * b)
else
tmp = 0.0d0 - (a * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2.4e+105) {
tmp = (a * b) * (a * b);
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2.4e+105: tmp = (a * b) * (a * b) else: tmp = 0.0 - (a * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2.4e+105) tmp = Float64(Float64(a * b) * Float64(a * b)); else tmp = Float64(0.0 - Float64(a * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2.4e+105) tmp = (a * b) * (a * b); else tmp = 0.0 - (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2.4e+105], N[(N[(a * b), $MachinePrecision] * N[(a * b), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.4 \cdot 10^{+105}:\\
\;\;\;\;\left(a \cdot b\right) \cdot \left(a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\
\end{array}
\end{array}
if b < 2.39999999999999975e105Initial program 86.3%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr31.0%
if 2.39999999999999975e105 < b Initial program 76.0%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6470.0%
Applied egg-rr70.0%
Applied egg-rr22.1%
*-rgt-identity22.1%
Applied egg-rr22.1%
Final simplification29.9%
(FPCore (a b) :precision binary64 (if (<= b 8.2e-19) (* a b) -1.0))
double code(double a, double b) {
double tmp;
if (b <= 8.2e-19) {
tmp = a * b;
} else {
tmp = -1.0;
}
return tmp;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8) :: tmp
if (b <= 8.2d-19) then
tmp = a * b
else
tmp = -1.0d0
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 8.2e-19) {
tmp = a * b;
} else {
tmp = -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 8.2e-19: tmp = a * b else: tmp = -1.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 8.2e-19) tmp = Float64(a * b); else tmp = -1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 8.2e-19) tmp = a * b; else tmp = -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 8.2e-19], N[(a * b), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.2 \cdot 10^{-19}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if b < 8.1999999999999997e-19Initial program 85.2%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr31.7%
Applied egg-rr22.3%
*-rgt-identity22.3%
Applied egg-rr22.3%
if 8.1999999999999997e-19 < b Initial program 84.3%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6482.5%
Applied egg-rr82.5%
Applied egg-rr3.9%
Final simplification18.4%
(FPCore (a b) :precision binary64 (- 0.0 (* a b)))
double code(double a, double b) {
return 0.0 - (a * b);
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = 0.0d0 - (a * b)
end function
public static double code(double a, double b) {
return 0.0 - (a * b);
}
def code(a, b): return 0.0 - (a * b)
function code(a, b) return Float64(0.0 - Float64(a * b)) end
function tmp = code(a, b) tmp = 0.0 - (a * b); end
code[a_, b_] := N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0 - a \cdot b
\end{array}
Initial program 85.0%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6483.0%
Applied egg-rr83.0%
Applied egg-rr23.5%
*-rgt-identity23.5%
Applied egg-rr23.5%
Final simplification23.5%
(FPCore (a b) :precision binary64 -1.0)
double code(double a, double b) {
return -1.0;
}
real(8) function code(a, b)
real(8), intent (in) :: a
real(8), intent (in) :: b
code = -1.0d0
end function
public static double code(double a, double b) {
return -1.0;
}
def code(a, b): return -1.0
function code(a, b) return -1.0 end
function tmp = code(a, b) tmp = -1.0; end
code[a_, b_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 85.0%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6483.0%
Applied egg-rr83.0%
Applied egg-rr4.1%
herbie shell --seed 2024161
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))