
(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}
(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 82.4%
associate-*l*N/A
unswap-sqrN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.6%
Applied egg-rr99.6%
Final simplification99.6%
(FPCore (a b) :precision binary64 (if (<= b 2e+110) (* (* b b) (* a a)) (- 0.0 (* a b))))
double code(double a, double b) {
double tmp;
if (b <= 2e+110) {
tmp = (b * b) * (a * a);
} 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 <= 2d+110) then
tmp = (b * b) * (a * a)
else
tmp = 0.0d0 - (a * b)
end if
code = tmp
end function
public static double code(double a, double b) {
double tmp;
if (b <= 2e+110) {
tmp = (b * b) * (a * a);
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 2e+110: tmp = (b * b) * (a * a) else: tmp = 0.0 - (a * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 2e+110) tmp = Float64(Float64(b * b) * Float64(a * a)); else tmp = Float64(0.0 - Float64(a * b)); end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 2e+110) tmp = (b * b) * (a * a); else tmp = 0.0 - (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 2e+110], N[(N[(b * b), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2 \cdot 10^{+110}:\\
\;\;\;\;\left(b \cdot b\right) \cdot \left(a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\
\end{array}
\end{array}
if b < 2e110Initial program 82.9%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr29.1%
if 2e110 < b Initial program 79.9%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6473.8%
Applied egg-rr73.8%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6498.0%
Applied egg-rr98.0%
*-commutativeN/A
rem-exp-logN/A
*-rgt-identityN/A
metadata-evalN/A
distribute-lft-outN/A
count-2N/A
exp-prodN/A
rem-log-expN/A
pow-to-expN/A
sqr-powN/A
log-prodN/A
flip-+N/A
Applied egg-rr23.0%
*-rgt-identityN/A
*-lowering-*.f6423.0%
Applied egg-rr23.0%
Final simplification28.0%
(FPCore (a b) :precision binary64 (if (<= b 3.25e+109) (* b (* a (* a b))) (- 0.0 (* a b))))
double code(double a, double b) {
double tmp;
if (b <= 3.25e+109) {
tmp = b * (a * (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 <= 3.25d+109) then
tmp = b * (a * (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 <= 3.25e+109) {
tmp = b * (a * (a * b));
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.25e+109: tmp = b * (a * (a * b)) else: tmp = 0.0 - (a * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.25e+109) tmp = Float64(b * Float64(a * 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 <= 3.25e+109) tmp = b * (a * (a * b)); else tmp = 0.0 - (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.25e+109], N[(b * N[(a * N[(a * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.0 - N[(a * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.25 \cdot 10^{+109}:\\
\;\;\;\;b \cdot \left(a \cdot \left(a \cdot b\right)\right)\\
\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\
\end{array}
\end{array}
if b < 3.25e109Initial program 82.9%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr29.2%
if 3.25e109 < b Initial program 79.9%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6473.8%
Applied egg-rr73.8%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6498.0%
Applied egg-rr98.0%
*-commutativeN/A
rem-exp-logN/A
*-rgt-identityN/A
metadata-evalN/A
distribute-lft-outN/A
count-2N/A
exp-prodN/A
rem-log-expN/A
pow-to-expN/A
sqr-powN/A
log-prodN/A
flip-+N/A
Applied egg-rr23.0%
*-rgt-identityN/A
*-lowering-*.f6423.0%
Applied egg-rr23.0%
Final simplification28.0%
(FPCore (a b) :precision binary64 (if (<= b 3.8e+109) (* (* a b) (* a b)) (- 0.0 (* a b))))
double code(double a, double b) {
double tmp;
if (b <= 3.8e+109) {
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 <= 3.8d+109) 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 <= 3.8e+109) {
tmp = (a * b) * (a * b);
} else {
tmp = 0.0 - (a * b);
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 3.8e+109: tmp = (a * b) * (a * b) else: tmp = 0.0 - (a * b) return tmp
function code(a, b) tmp = 0.0 if (b <= 3.8e+109) 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 <= 3.8e+109) tmp = (a * b) * (a * b); else tmp = 0.0 - (a * b); end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 3.8e+109], 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 3.8 \cdot 10^{+109}:\\
\;\;\;\;\left(a \cdot b\right) \cdot \left(a \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;0 - a \cdot b\\
\end{array}
\end{array}
if b < 3.80000000000000039e109Initial program 82.9%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr29.1%
if 3.80000000000000039e109 < b Initial program 79.9%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6473.8%
Applied egg-rr73.8%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6498.0%
Applied egg-rr98.0%
*-commutativeN/A
rem-exp-logN/A
*-rgt-identityN/A
metadata-evalN/A
distribute-lft-outN/A
count-2N/A
exp-prodN/A
rem-log-expN/A
pow-to-expN/A
sqr-powN/A
log-prodN/A
flip-+N/A
Applied egg-rr23.0%
*-rgt-identityN/A
*-lowering-*.f6423.0%
Applied egg-rr23.0%
Final simplification28.0%
(FPCore (a b) :precision binary64 (if (<= b 1.65e-15) (* a b) -1.0))
double code(double a, double b) {
double tmp;
if (b <= 1.65e-15) {
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 <= 1.65d-15) 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 <= 1.65e-15) {
tmp = a * b;
} else {
tmp = -1.0;
}
return tmp;
}
def code(a, b): tmp = 0 if b <= 1.65e-15: tmp = a * b else: tmp = -1.0 return tmp
function code(a, b) tmp = 0.0 if (b <= 1.65e-15) tmp = Float64(a * b); else tmp = -1.0; end return tmp end
function tmp_2 = code(a, b) tmp = 0.0; if (b <= 1.65e-15) tmp = a * b; else tmp = -1.0; end tmp_2 = tmp; end
code[a_, b_] := If[LessEqual[b, 1.65e-15], N[(a * b), $MachinePrecision], -1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.65 \cdot 10^{-15}:\\
\;\;\;\;a \cdot b\\
\mathbf{else}:\\
\;\;\;\;-1\\
\end{array}
\end{array}
if b < 1.65e-15Initial program 81.2%
associate-*l*N/A
associate-*r*N/A
+-lft-identityN/A
flip3-+N/A
distribute-neg-fracN/A
Applied egg-rr31.8%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6431.7%
Applied egg-rr31.7%
*-commutativeN/A
rem-exp-logN/A
*-rgt-identityN/A
metadata-evalN/A
distribute-lft-outN/A
count-2N/A
exp-prodN/A
rem-log-expN/A
pow-to-expN/A
sqr-powN/A
log-prodN/A
flip-+N/A
Applied egg-rr25.1%
*-rgt-identityN/A
*-lowering-*.f6425.1%
Applied egg-rr25.1%
if 1.65e-15 < b Initial program 85.3%
associate-*l*N/A
unswap-sqrN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.7%
Applied egg-rr99.7%
unpow1N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
metadata-eval45.5%
Applied egg-rr45.5%
Applied egg-rr4.4%
Final simplification19.3%
(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 82.4%
associate-*l*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6482.1%
Applied egg-rr82.1%
associate-*r*N/A
*-lowering-*.f64N/A
*-lowering-*.f6495.4%
Applied egg-rr95.4%
*-commutativeN/A
rem-exp-logN/A
*-rgt-identityN/A
metadata-evalN/A
distribute-lft-outN/A
count-2N/A
exp-prodN/A
rem-log-expN/A
pow-to-expN/A
sqr-powN/A
log-prodN/A
flip-+N/A
Applied egg-rr23.6%
*-rgt-identityN/A
*-lowering-*.f6423.6%
Applied egg-rr23.6%
Final simplification23.6%
(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 82.4%
associate-*l*N/A
unswap-sqrN/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f6499.6%
Applied egg-rr99.6%
unpow1N/A
sqr-powN/A
pow2N/A
pow-lowering-pow.f64N/A
pow-lowering-pow.f64N/A
*-lowering-*.f64N/A
metadata-eval56.7%
Applied egg-rr56.7%
Applied egg-rr4.3%
herbie shell --seed 2024138
(FPCore (a b)
:name "ab-angle->ABCF D"
:precision binary64
(- (* (* (* a a) b) b)))