
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
return exp(re) * cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
def code(re, im): return math.exp(re) * math.cos(im)
function code(re, im) return Float64(exp(re) * cos(im)) end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \cos im
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
return exp(re) * cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
def code(re, im): return math.exp(re) * math.cos(im)
function code(re, im) return Float64(exp(re) * cos(im)) end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \cos im
\end{array}
(FPCore (re im) :precision binary64 (* (exp re) (cos im)))
double code(double re, double im) {
return exp(re) * cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re) * cos(im)
end function
public static double code(double re, double im) {
return Math.exp(re) * Math.cos(im);
}
def code(re, im): return math.exp(re) * math.cos(im)
function code(re, im) return Float64(exp(re) * cos(im)) end
function tmp = code(re, im) tmp = exp(re) * cos(im); end
code[re_, im_] := N[(N[Exp[re], $MachinePrecision] * N[Cos[im], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
e^{re} \cdot \cos im
\end{array}
Initial program 100.0%
(FPCore (re im) :precision binary64 (if (or (<= (exp re) 0.9999998) (not (<= (exp re) 1.0232))) (exp re) (+ re (cos im))))
double code(double re, double im) {
double tmp;
if ((exp(re) <= 0.9999998) || !(exp(re) <= 1.0232)) {
tmp = exp(re);
} else {
tmp = re + cos(im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((exp(re) <= 0.9999998d0) .or. (.not. (exp(re) <= 1.0232d0))) then
tmp = exp(re)
else
tmp = re + cos(im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((Math.exp(re) <= 0.9999998) || !(Math.exp(re) <= 1.0232)) {
tmp = Math.exp(re);
} else {
tmp = re + Math.cos(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.exp(re) <= 0.9999998) or not (math.exp(re) <= 1.0232): tmp = math.exp(re) else: tmp = re + math.cos(im) return tmp
function code(re, im) tmp = 0.0 if ((exp(re) <= 0.9999998) || !(exp(re) <= 1.0232)) tmp = exp(re); else tmp = Float64(re + cos(im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((exp(re) <= 0.9999998) || ~((exp(re) <= 1.0232))) tmp = exp(re); else tmp = re + cos(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 0.9999998], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.0232]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[(re + N[Cos[im], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.9999998 \lor \neg \left(e^{re} \leq 1.0232\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;re + \cos im\\
\end{array}
\end{array}
if (exp.f64 re) < 0.999999799999999994 or 1.0232000000000001 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 84.4%
if 0.999999799999999994 < (exp.f64 re) < 1.0232000000000001Initial program 100.0%
Taylor expanded in re around 0 99.0%
Taylor expanded in im around 0 97.7%
Final simplification90.8%
(FPCore (re im) :precision binary64 (if (or (<= (exp re) 0.999999995) (not (<= (exp re) 1.0232))) (exp re) (cos im)))
double code(double re, double im) {
double tmp;
if ((exp(re) <= 0.999999995) || !(exp(re) <= 1.0232)) {
tmp = exp(re);
} else {
tmp = cos(im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((exp(re) <= 0.999999995d0) .or. (.not. (exp(re) <= 1.0232d0))) then
tmp = exp(re)
else
tmp = cos(im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((Math.exp(re) <= 0.999999995) || !(Math.exp(re) <= 1.0232)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.exp(re) <= 0.999999995) or not (math.exp(re) <= 1.0232): tmp = math.exp(re) else: tmp = math.cos(im) return tmp
function code(re, im) tmp = 0.0 if ((exp(re) <= 0.999999995) || !(exp(re) <= 1.0232)) tmp = exp(re); else tmp = cos(im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((exp(re) <= 0.999999995) || ~((exp(re) <= 1.0232))) tmp = exp(re); else tmp = cos(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 0.999999995], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.0232]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Cos[im], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.999999995 \lor \neg \left(e^{re} \leq 1.0232\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im\\
\end{array}
\end{array}
if (exp.f64 re) < 0.99999999500000003 or 1.0232000000000001 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 84.6%
if 0.99999999500000003 < (exp.f64 re) < 1.0232000000000001Initial program 100.0%
Taylor expanded in re around 0 97.3%
Final simplification90.6%
(FPCore (re im) :precision binary64 (if (or (<= re -0.0052) (and (not (<= re 0.023)) (<= re 1.9e+154))) (exp re) (* (cos im) (+ 1.0 (* re (+ 1.0 (* re 0.5)))))))
double code(double re, double im) {
double tmp;
if ((re <= -0.0052) || (!(re <= 0.023) && (re <= 1.9e+154))) {
tmp = exp(re);
} else {
tmp = cos(im) * (1.0 + (re * (1.0 + (re * 0.5))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-0.0052d0)) .or. (.not. (re <= 0.023d0)) .and. (re <= 1.9d+154)) then
tmp = exp(re)
else
tmp = cos(im) * (1.0d0 + (re * (1.0d0 + (re * 0.5d0))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.0052) || (!(re <= 0.023) && (re <= 1.9e+154))) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (1.0 + (re * (1.0 + (re * 0.5))));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.0052) or (not (re <= 0.023) and (re <= 1.9e+154)): tmp = math.exp(re) else: tmp = math.cos(im) * (1.0 + (re * (1.0 + (re * 0.5)))) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.0052) || (!(re <= 0.023) && (re <= 1.9e+154))) tmp = exp(re); else tmp = Float64(cos(im) * Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.0052) || (~((re <= 0.023)) && (re <= 1.9e+154))) tmp = exp(re); else tmp = cos(im) * (1.0 + (re * (1.0 + (re * 0.5)))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.0052], And[N[Not[LessEqual[re, 0.023]], $MachinePrecision], LessEqual[re, 1.9e+154]]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0052 \lor \neg \left(re \leq 0.023\right) \land re \leq 1.9 \cdot 10^{+154}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(1 + re \cdot \left(1 + re \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if re < -0.0051999999999999998 or 0.023 < re < 1.8999999999999999e154Initial program 100.0%
Taylor expanded in im around 0 90.2%
if -0.0051999999999999998 < re < 0.023 or 1.8999999999999999e154 < re Initial program 100.0%
add-cbrt-cube99.6%
pow399.5%
Applied egg-rr99.5%
Taylor expanded in re around 0 99.5%
distribute-lft-in99.5%
*-commutative99.5%
associate-+r+99.5%
*-rgt-identity99.5%
distribute-lft-in99.5%
*-commutative99.5%
associate-*r*99.5%
associate-*r*99.5%
distribute-rgt-out99.5%
Simplified99.5%
Taylor expanded in re around 0 99.5%
Final simplification95.9%
(FPCore (re im) :precision binary64 (if (or (<= re -3.4e-7) (not (<= re 0.023))) (exp re) (* (cos im) (+ re 1.0))))
double code(double re, double im) {
double tmp;
if ((re <= -3.4e-7) || !(re <= 0.023)) {
tmp = exp(re);
} else {
tmp = cos(im) * (re + 1.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-3.4d-7)) .or. (.not. (re <= 0.023d0))) then
tmp = exp(re)
else
tmp = cos(im) * (re + 1.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -3.4e-7) || !(re <= 0.023)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -3.4e-7) or not (re <= 0.023): tmp = math.exp(re) else: tmp = math.cos(im) * (re + 1.0) return tmp
function code(re, im) tmp = 0.0 if ((re <= -3.4e-7) || !(re <= 0.023)) tmp = exp(re); else tmp = Float64(cos(im) * Float64(re + 1.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -3.4e-7) || ~((re <= 0.023))) tmp = exp(re); else tmp = cos(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -3.4e-7], N[Not[LessEqual[re, 0.023]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.4 \cdot 10^{-7} \lor \neg \left(re \leq 0.023\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\end{array}
\end{array}
if re < -3.39999999999999974e-7 or 0.023 < re Initial program 100.0%
Taylor expanded in im around 0 84.4%
if -3.39999999999999974e-7 < re < 0.023Initial program 100.0%
Taylor expanded in re around 0 99.0%
distribute-rgt1-in99.0%
Simplified99.0%
Final simplification91.4%
(FPCore (re im) :precision binary64 (if (<= re 0.023) (cos im) (+ 1.0 (* re (+ 1.0 (* re 0.5))))))
double code(double re, double im) {
double tmp;
if (re <= 0.023) {
tmp = cos(im);
} else {
tmp = 1.0 + (re * (1.0 + (re * 0.5)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 0.023d0) then
tmp = cos(im)
else
tmp = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 0.023) {
tmp = Math.cos(im);
} else {
tmp = 1.0 + (re * (1.0 + (re * 0.5)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 0.023: tmp = math.cos(im) else: tmp = 1.0 + (re * (1.0 + (re * 0.5))) return tmp
function code(re, im) tmp = 0.0 if (re <= 0.023) tmp = cos(im); else tmp = Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 0.023) tmp = cos(im); else tmp = 1.0 + (re * (1.0 + (re * 0.5))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 0.023], N[Cos[im], $MachinePrecision], N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 0.023:\\
\;\;\;\;\cos im\\
\mathbf{else}:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\
\end{array}
\end{array}
if re < 0.023Initial program 100.0%
Taylor expanded in re around 0 67.2%
if 0.023 < re Initial program 100.0%
add-cbrt-cube100.0%
pow3100.0%
Applied egg-rr100.0%
Taylor expanded in re around 0 47.4%
distribute-lft-in47.4%
*-commutative47.4%
associate-+r+47.4%
*-rgt-identity47.4%
distribute-lft-in47.4%
*-commutative47.4%
associate-*r*47.4%
associate-*r*47.4%
distribute-rgt-out47.4%
Simplified47.4%
Taylor expanded in re around 0 47.4%
Taylor expanded in im around 0 32.2%
Final simplification57.0%
(FPCore (re im) :precision binary64 (+ 1.0 (* re (+ 1.0 (* re 0.5)))))
double code(double re, double im) {
return 1.0 + (re * (1.0 + (re * 0.5)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (re * (1.0d0 + (re * 0.5d0)))
end function
public static double code(double re, double im) {
return 1.0 + (re * (1.0 + (re * 0.5)));
}
def code(re, im): return 1.0 + (re * (1.0 + (re * 0.5)))
function code(re, im) return Float64(1.0 + Float64(re * Float64(1.0 + Float64(re * 0.5)))) end
function tmp = code(re, im) tmp = 1.0 + (re * (1.0 + (re * 0.5))); end
code[re_, im_] := N[(1.0 + N[(re * N[(1.0 + N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + re \cdot \left(1 + re \cdot 0.5\right)
\end{array}
Initial program 100.0%
add-cbrt-cube99.7%
pow399.7%
Applied egg-rr99.7%
Taylor expanded in re around 0 62.5%
distribute-lft-in62.5%
*-commutative62.5%
associate-+r+62.4%
*-rgt-identity62.4%
distribute-lft-in62.4%
*-commutative62.4%
associate-*r*62.4%
associate-*r*62.4%
distribute-rgt-out62.4%
Simplified62.4%
Taylor expanded in re around 0 62.4%
Taylor expanded in im around 0 34.3%
Final simplification34.3%
(FPCore (re im) :precision binary64 (+ re 1.0))
double code(double re, double im) {
return re + 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re + 1.0d0
end function
public static double code(double re, double im) {
return re + 1.0;
}
def code(re, im): return re + 1.0
function code(re, im) return Float64(re + 1.0) end
function tmp = code(re, im) tmp = re + 1.0; end
code[re_, im_] := N[(re + 1.0), $MachinePrecision]
\begin{array}{l}
\\
re + 1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 50.0%
distribute-rgt1-in50.0%
Simplified50.0%
Taylor expanded in im around 0 26.1%
Final simplification26.1%
(FPCore (re im) :precision binary64 1.0)
double code(double re, double im) {
return 1.0;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0
end function
public static double code(double re, double im) {
return 1.0;
}
def code(re, im): return 1.0
function code(re, im) return 1.0 end
function tmp = code(re, im) tmp = 1.0; end
code[re_, im_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 48.6%
Taylor expanded in im around 0 25.5%
herbie shell --seed 2024100
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))