
(FPCore (d1) :precision binary64 (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))
double code(double d1) {
return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
end function
public static double code(double d1) {
return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
def code(d1): return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
function code(d1) return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(d1 * Float64(d1 * d1)) * d1) * d1) * Float64(d1 * d1)) * d1)) * d1) end
function tmp = code(d1) tmp = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1; end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\begin{array}{l}
\\
\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (d1) :precision binary64 (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))
double code(double d1) {
return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
end function
public static double code(double d1) {
return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
def code(d1): return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
function code(d1) return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(d1 * Float64(d1 * d1)) * d1) * d1) * Float64(d1 * d1)) * d1)) * d1) end
function tmp = code(d1) tmp = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1; end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\begin{array}{l}
\\
\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1
\end{array}
(FPCore (d1) :precision binary64 (pow d1 10.0))
double code(double d1) {
return pow(d1, 10.0);
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = d1 ** 10.0d0
end function
public static double code(double d1) {
return Math.pow(d1, 10.0);
}
def code(d1): return math.pow(d1, 10.0)
function code(d1) return d1 ^ 10.0 end
function tmp = code(d1) tmp = d1 ^ 10.0; end
code[d1_] := N[Power[d1, 10.0], $MachinePrecision]
\begin{array}{l}
\\
{d1}^{10}
\end{array}
Initial program 99.8%
*-commutative99.8%
associate-*l*99.8%
sqr-neg99.8%
associate-*l*99.8%
sqr-neg99.8%
associate-*r*99.8%
sqr-neg99.8%
associate-*l*99.8%
sqr-neg99.8%
associate-*l*99.8%
Simplified100.0%
Final simplification100.0%
(FPCore (d1) :precision binary64 (* d1 (* d1 (* d1 (* (* d1 d1) (* d1 (* d1 (* d1 (* d1 d1)))))))))
double code(double d1) {
return d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))));
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))))
end function
public static double code(double d1) {
return d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))));
}
def code(d1): return d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1)))))))
function code(d1) return Float64(d1 * Float64(d1 * Float64(d1 * Float64(Float64(d1 * d1) * Float64(d1 * Float64(d1 * Float64(d1 * Float64(d1 * d1)))))))) end
function tmp = code(d1) tmp = d1 * (d1 * (d1 * ((d1 * d1) * (d1 * (d1 * (d1 * (d1 * d1))))))); end
code[d1_] := N[(d1 * N[(d1 * N[(d1 * N[(N[(d1 * d1), $MachinePrecision] * N[(d1 * N[(d1 * N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(\left(d1 \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)\right)\right)\right)\right)
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (d1) :precision binary64 (* d1 (* d1 (* (* d1 (* d1 d1)) (* d1 (* d1 27.0))))))
double code(double d1) {
return d1 * (d1 * ((d1 * (d1 * d1)) * (d1 * (d1 * 27.0))));
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = d1 * (d1 * ((d1 * (d1 * d1)) * (d1 * (d1 * 27.0d0))))
end function
public static double code(double d1) {
return d1 * (d1 * ((d1 * (d1 * d1)) * (d1 * (d1 * 27.0))));
}
def code(d1): return d1 * (d1 * ((d1 * (d1 * d1)) * (d1 * (d1 * 27.0))))
function code(d1) return Float64(d1 * Float64(d1 * Float64(Float64(d1 * Float64(d1 * d1)) * Float64(d1 * Float64(d1 * 27.0))))) end
function tmp = code(d1) tmp = d1 * (d1 * ((d1 * (d1 * d1)) * (d1 * (d1 * 27.0)))); end
code[d1_] := N[(d1 * N[(d1 * N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * N[(d1 * N[(d1 * 27.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(d1 \cdot \left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot \left(d1 \cdot \left(d1 \cdot 27\right)\right)\right)\right)
\end{array}
Initial program 99.8%
Applied egg-rr63.4%
log1p-expm1-u_binary6464.3%
Applied rewrite-once64.3%
log1p-expm163.4%
associate-*l*63.4%
*-commutative63.4%
*-commutative63.4%
Simplified63.4%
Final simplification63.4%
(FPCore (d1) :precision binary64 (if (<= d1 3.7e-21) (* d1 (* d1 (* d1 0.0))) (* d1 (* d1 (* 27.0 (* d1 (* d1 d1)))))))
double code(double d1) {
double tmp;
if (d1 <= 3.7e-21) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * (27.0 * (d1 * (d1 * d1))));
}
return tmp;
}
real(8) function code(d1)
real(8), intent (in) :: d1
real(8) :: tmp
if (d1 <= 3.7d-21) then
tmp = d1 * (d1 * (d1 * 0.0d0))
else
tmp = d1 * (d1 * (27.0d0 * (d1 * (d1 * d1))))
end if
code = tmp
end function
public static double code(double d1) {
double tmp;
if (d1 <= 3.7e-21) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * (27.0 * (d1 * (d1 * d1))));
}
return tmp;
}
def code(d1): tmp = 0 if d1 <= 3.7e-21: tmp = d1 * (d1 * (d1 * 0.0)) else: tmp = d1 * (d1 * (27.0 * (d1 * (d1 * d1)))) return tmp
function code(d1) tmp = 0.0 if (d1 <= 3.7e-21) tmp = Float64(d1 * Float64(d1 * Float64(d1 * 0.0))); else tmp = Float64(d1 * Float64(d1 * Float64(27.0 * Float64(d1 * Float64(d1 * d1))))); end return tmp end
function tmp_2 = code(d1) tmp = 0.0; if (d1 <= 3.7e-21) tmp = d1 * (d1 * (d1 * 0.0)); else tmp = d1 * (d1 * (27.0 * (d1 * (d1 * d1)))); end tmp_2 = tmp; end
code[d1_] := If[LessEqual[d1, 3.7e-21], N[(d1 * N[(d1 * N[(d1 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d1 * N[(27.0 * N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq 3.7 \cdot 10^{-21}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(d1 \cdot 0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(27 \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)\right)\\
\end{array}
\end{array}
if d1 < 3.7000000000000002e-21Initial program 99.9%
Applied egg-rr59.8%
Taylor expanded in d1 around 0 60.1%
if 3.7000000000000002e-21 < d1 Initial program 99.7%
Applied egg-rr73.8%
log1p-expm1-u_binary6476.8%
Applied rewrite-once76.8%
log1p-expm173.8%
associate-*l*73.8%
*-commutative73.8%
*-commutative73.8%
Simplified73.8%
Applied egg-rr69.8%
Final simplification63.0%
(FPCore (d1) :precision binary64 (if (<= d1 9.5e-18) (* d1 (* d1 (* d1 0.0))) (* d1 (* d1 27.0))))
double code(double d1) {
double tmp;
if (d1 <= 9.5e-18) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * 27.0);
}
return tmp;
}
real(8) function code(d1)
real(8), intent (in) :: d1
real(8) :: tmp
if (d1 <= 9.5d-18) then
tmp = d1 * (d1 * (d1 * 0.0d0))
else
tmp = d1 * (d1 * 27.0d0)
end if
code = tmp
end function
public static double code(double d1) {
double tmp;
if (d1 <= 9.5e-18) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * 27.0);
}
return tmp;
}
def code(d1): tmp = 0 if d1 <= 9.5e-18: tmp = d1 * (d1 * (d1 * 0.0)) else: tmp = d1 * (d1 * 27.0) return tmp
function code(d1) tmp = 0.0 if (d1 <= 9.5e-18) tmp = Float64(d1 * Float64(d1 * Float64(d1 * 0.0))); else tmp = Float64(d1 * Float64(d1 * 27.0)); end return tmp end
function tmp_2 = code(d1) tmp = 0.0; if (d1 <= 9.5e-18) tmp = d1 * (d1 * (d1 * 0.0)); else tmp = d1 * (d1 * 27.0); end tmp_2 = tmp; end
code[d1_] := If[LessEqual[d1, 9.5e-18], N[(d1 * N[(d1 * N[(d1 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d1 * 27.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq 9.5 \cdot 10^{-18}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(d1 \cdot 0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot 27\right)\\
\end{array}
\end{array}
if d1 < 9.5000000000000003e-18Initial program 99.9%
Applied egg-rr59.8%
Taylor expanded in d1 around 0 60.1%
if 9.5000000000000003e-18 < d1 Initial program 99.7%
Applied egg-rr73.8%
log1p-expm1-u_binary6476.8%
Applied rewrite-once76.8%
log1p-expm173.8%
associate-*l*73.8%
*-commutative73.8%
*-commutative73.8%
Simplified73.8%
Applied egg-rr69.8%
Applied egg-rr49.8%
Final simplification57.0%
(FPCore (d1) :precision binary64 (if (<= d1 5.5e-19) (* d1 (* d1 (* d1 0.0))) (* d1 (* d1 (* d1 0.00390625)))))
double code(double d1) {
double tmp;
if (d1 <= 5.5e-19) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * (d1 * 0.00390625));
}
return tmp;
}
real(8) function code(d1)
real(8), intent (in) :: d1
real(8) :: tmp
if (d1 <= 5.5d-19) then
tmp = d1 * (d1 * (d1 * 0.0d0))
else
tmp = d1 * (d1 * (d1 * 0.00390625d0))
end if
code = tmp
end function
public static double code(double d1) {
double tmp;
if (d1 <= 5.5e-19) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * (d1 * 0.00390625));
}
return tmp;
}
def code(d1): tmp = 0 if d1 <= 5.5e-19: tmp = d1 * (d1 * (d1 * 0.0)) else: tmp = d1 * (d1 * (d1 * 0.00390625)) return tmp
function code(d1) tmp = 0.0 if (d1 <= 5.5e-19) tmp = Float64(d1 * Float64(d1 * Float64(d1 * 0.0))); else tmp = Float64(d1 * Float64(d1 * Float64(d1 * 0.00390625))); end return tmp end
function tmp_2 = code(d1) tmp = 0.0; if (d1 <= 5.5e-19) tmp = d1 * (d1 * (d1 * 0.0)); else tmp = d1 * (d1 * (d1 * 0.00390625)); end tmp_2 = tmp; end
code[d1_] := If[LessEqual[d1, 5.5e-19], N[(d1 * N[(d1 * N[(d1 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d1 * N[(d1 * 0.00390625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq 5.5 \cdot 10^{-19}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(d1 \cdot 0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(d1 \cdot 0.00390625\right)\right)\\
\end{array}
\end{array}
if d1 < 5.4999999999999996e-19Initial program 99.9%
Applied egg-rr59.8%
Taylor expanded in d1 around 0 60.1%
if 5.4999999999999996e-19 < d1 Initial program 99.7%
Applied egg-rr73.7%
Applied egg-rr58.6%
Final simplification59.6%
(FPCore (d1) :precision binary64 (if (<= d1 9.8e-19) (* d1 (* d1 (* d1 0.0))) (* d1 (* d1 (* d1 64.0)))))
double code(double d1) {
double tmp;
if (d1 <= 9.8e-19) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * (d1 * 64.0));
}
return tmp;
}
real(8) function code(d1)
real(8), intent (in) :: d1
real(8) :: tmp
if (d1 <= 9.8d-19) then
tmp = d1 * (d1 * (d1 * 0.0d0))
else
tmp = d1 * (d1 * (d1 * 64.0d0))
end if
code = tmp
end function
public static double code(double d1) {
double tmp;
if (d1 <= 9.8e-19) {
tmp = d1 * (d1 * (d1 * 0.0));
} else {
tmp = d1 * (d1 * (d1 * 64.0));
}
return tmp;
}
def code(d1): tmp = 0 if d1 <= 9.8e-19: tmp = d1 * (d1 * (d1 * 0.0)) else: tmp = d1 * (d1 * (d1 * 64.0)) return tmp
function code(d1) tmp = 0.0 if (d1 <= 9.8e-19) tmp = Float64(d1 * Float64(d1 * Float64(d1 * 0.0))); else tmp = Float64(d1 * Float64(d1 * Float64(d1 * 64.0))); end return tmp end
function tmp_2 = code(d1) tmp = 0.0; if (d1 <= 9.8e-19) tmp = d1 * (d1 * (d1 * 0.0)); else tmp = d1 * (d1 * (d1 * 64.0)); end tmp_2 = tmp; end
code[d1_] := If[LessEqual[d1, 9.8e-19], N[(d1 * N[(d1 * N[(d1 * 0.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(d1 * N[(d1 * N[(d1 * 64.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d1 \leq 9.8 \cdot 10^{-19}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(d1 \cdot 0\right)\right)\\
\mathbf{else}:\\
\;\;\;\;d1 \cdot \left(d1 \cdot \left(d1 \cdot 64\right)\right)\\
\end{array}
\end{array}
if d1 < 9.79999999999999985e-19Initial program 99.9%
Applied egg-rr59.8%
Taylor expanded in d1 around 0 60.1%
if 9.79999999999999985e-19 < d1 Initial program 99.7%
Applied egg-rr1.1%
Applied egg-rr58.6%
Final simplification59.6%
(FPCore (d1) :precision binary64 (* d1 (* d1 27.0)))
double code(double d1) {
return d1 * (d1 * 27.0);
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = d1 * (d1 * 27.0d0)
end function
public static double code(double d1) {
return d1 * (d1 * 27.0);
}
def code(d1): return d1 * (d1 * 27.0)
function code(d1) return Float64(d1 * Float64(d1 * 27.0)) end
function tmp = code(d1) tmp = d1 * (d1 * 27.0); end
code[d1_] := N[(d1 * N[(d1 * 27.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
d1 \cdot \left(d1 \cdot 27\right)
\end{array}
Initial program 99.8%
Applied egg-rr63.4%
log1p-expm1-u_binary6464.3%
Applied rewrite-once64.3%
log1p-expm163.4%
associate-*l*63.4%
*-commutative63.4%
*-commutative63.4%
Simplified63.4%
Applied egg-rr60.0%
Applied egg-rr56.8%
Final simplification56.8%
(FPCore (d1) :precision binary64 0.00390625)
double code(double d1) {
return 0.00390625;
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = 0.00390625d0
end function
public static double code(double d1) {
return 0.00390625;
}
def code(d1): return 0.00390625
function code(d1) return 0.00390625 end
function tmp = code(d1) tmp = 0.00390625; end
code[d1_] := 0.00390625
\begin{array}{l}
\\
0.00390625
\end{array}
Initial program 99.8%
Applied egg-rr63.4%
Applied egg-rr53.9%
Applied egg-rr3.4%
Final simplification3.4%
(FPCore (d1) :precision binary64 64.0)
double code(double d1) {
return 64.0;
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = 64.0d0
end function
public static double code(double d1) {
return 64.0;
}
def code(d1): return 64.0
function code(d1) return 64.0 end
function tmp = code(d1) tmp = 64.0; end
code[d1_] := 64.0
\begin{array}{l}
\\
64
\end{array}
Initial program 99.8%
Applied egg-rr42.1%
Applied egg-rr53.8%
Applied egg-rr3.4%
Final simplification3.4%
(FPCore (d1) :precision binary64 (pow d1 10.0))
double code(double d1) {
return pow(d1, 10.0);
}
real(8) function code(d1)
real(8), intent (in) :: d1
code = d1 ** 10.0d0
end function
public static double code(double d1) {
return Math.pow(d1, 10.0);
}
def code(d1): return math.pow(d1, 10.0)
function code(d1) return d1 ^ 10.0 end
function tmp = code(d1) tmp = d1 ^ 10.0; end
code[d1_] := N[Power[d1, 10.0], $MachinePrecision]
\begin{array}{l}
\\
{d1}^{10}
\end{array}
herbie shell --seed 2023297
(FPCore (d1)
:name "FastMath test5"
:precision binary64
:herbie-target
(pow d1 10.0)
(* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))