
(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 8 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%
Final simplification100.0%
(FPCore (re im) :precision binary64 (if (or (<= (exp re) 1.0) (not (<= (exp re) 1.0002))) (exp re) (cos im)))
double code(double re, double im) {
double tmp;
if ((exp(re) <= 1.0) || !(exp(re) <= 1.0002)) {
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) <= 1.0d0) .or. (.not. (exp(re) <= 1.0002d0))) 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) <= 1.0) || !(Math.exp(re) <= 1.0002)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.exp(re) <= 1.0) or not (math.exp(re) <= 1.0002): tmp = math.exp(re) else: tmp = math.cos(im) return tmp
function code(re, im) tmp = 0.0 if ((exp(re) <= 1.0) || !(exp(re) <= 1.0002)) tmp = exp(re); else tmp = cos(im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((exp(re) <= 1.0) || ~((exp(re) <= 1.0002))) tmp = exp(re); else tmp = cos(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 1.0], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.0002]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Cos[im], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 1 \lor \neg \left(e^{re} \leq 1.0002\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im\\
\end{array}
\end{array}
if (exp.f64 re) < 1 or 1.0002 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 74.4%
if 1 < (exp.f64 re) < 1.0002Initial program 99.2%
Taylor expanded in re around 0 78.1%
Final simplification74.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.06e-8)
(exp re)
(if (<= re 0.0004)
(* (cos im) (+ (+ re 1.0) (* 0.5 (* re re))))
(if (<= re 1e+103)
(exp re)
(* (cos im) (+ (+ re 1.0) (* (* re re) (* re 0.16666666666666666))))))))
double code(double re, double im) {
double tmp;
if (re <= -1.06e-8) {
tmp = exp(re);
} else if (re <= 0.0004) {
tmp = cos(im) * ((re + 1.0) + (0.5 * (re * re)));
} else if (re <= 1e+103) {
tmp = exp(re);
} else {
tmp = cos(im) * ((re + 1.0) + ((re * re) * (re * 0.16666666666666666)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.06d-8)) then
tmp = exp(re)
else if (re <= 0.0004d0) then
tmp = cos(im) * ((re + 1.0d0) + (0.5d0 * (re * re)))
else if (re <= 1d+103) then
tmp = exp(re)
else
tmp = cos(im) * ((re + 1.0d0) + ((re * re) * (re * 0.16666666666666666d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.06e-8) {
tmp = Math.exp(re);
} else if (re <= 0.0004) {
tmp = Math.cos(im) * ((re + 1.0) + (0.5 * (re * re)));
} else if (re <= 1e+103) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * ((re + 1.0) + ((re * re) * (re * 0.16666666666666666)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.06e-8: tmp = math.exp(re) elif re <= 0.0004: tmp = math.cos(im) * ((re + 1.0) + (0.5 * (re * re))) elif re <= 1e+103: tmp = math.exp(re) else: tmp = math.cos(im) * ((re + 1.0) + ((re * re) * (re * 0.16666666666666666))) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.06e-8) tmp = exp(re); elseif (re <= 0.0004) tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(0.5 * Float64(re * re)))); elseif (re <= 1e+103) tmp = exp(re); else tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(Float64(re * re) * Float64(re * 0.16666666666666666)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.06e-8) tmp = exp(re); elseif (re <= 0.0004) tmp = cos(im) * ((re + 1.0) + (0.5 * (re * re))); elseif (re <= 1e+103) tmp = exp(re); else tmp = cos(im) * ((re + 1.0) + ((re * re) * (re * 0.16666666666666666))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.06e-8], N[Exp[re], $MachinePrecision], If[LessEqual[re, 0.0004], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1e+103], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] * N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.06 \cdot 10^{-8}:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 0.0004:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + 0.5 \cdot \left(re \cdot re\right)\right)\\
\mathbf{elif}\;re \leq 10^{+103}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + \left(re \cdot re\right) \cdot \left(re \cdot 0.16666666666666666\right)\right)\\
\end{array}
\end{array}
if re < -1.06000000000000006e-8 or 4.00000000000000019e-4 < re < 1e103Initial program 100.0%
Taylor expanded in im around 0 93.1%
if -1.06000000000000006e-8 < re < 4.00000000000000019e-4Initial program 100.0%
Taylor expanded in re around 0 100.0%
distribute-rgt-in100.0%
*-commutative100.0%
associate-+r+100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
associate-*l*100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in re around 0 100.0%
if 1e103 < re Initial program 100.0%
Taylor expanded in re around 0 100.0%
distribute-rgt-in100.0%
*-commutative100.0%
associate-+r+100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
associate-*l*100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in re around inf 100.0%
*-commutative100.0%
Simplified100.0%
Final simplification97.7%
(FPCore (re im) :precision binary64 (if (or (<= re -1.06e-8) (and (not (<= re 0.00042)) (<= re 1.32e+154))) (exp re) (* (cos im) (+ (+ re 1.0) (* 0.5 (* re re))))))
double code(double re, double im) {
double tmp;
if ((re <= -1.06e-8) || (!(re <= 0.00042) && (re <= 1.32e+154))) {
tmp = exp(re);
} else {
tmp = cos(im) * ((re + 1.0) + (0.5 * (re * re)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-1.06d-8)) .or. (.not. (re <= 0.00042d0)) .and. (re <= 1.32d+154)) then
tmp = exp(re)
else
tmp = cos(im) * ((re + 1.0d0) + (0.5d0 * (re * re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -1.06e-8) || (!(re <= 0.00042) && (re <= 1.32e+154))) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * ((re + 1.0) + (0.5 * (re * re)));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -1.06e-8) or (not (re <= 0.00042) and (re <= 1.32e+154)): tmp = math.exp(re) else: tmp = math.cos(im) * ((re + 1.0) + (0.5 * (re * re))) return tmp
function code(re, im) tmp = 0.0 if ((re <= -1.06e-8) || (!(re <= 0.00042) && (re <= 1.32e+154))) tmp = exp(re); else tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(0.5 * Float64(re * re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -1.06e-8) || (~((re <= 0.00042)) && (re <= 1.32e+154))) tmp = exp(re); else tmp = cos(im) * ((re + 1.0) + (0.5 * (re * re))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -1.06e-8], And[N[Not[LessEqual[re, 0.00042]], $MachinePrecision], LessEqual[re, 1.32e+154]]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(0.5 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.06 \cdot 10^{-8} \lor \neg \left(re \leq 0.00042\right) \land re \leq 1.32 \cdot 10^{+154}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + 0.5 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if re < -1.06000000000000006e-8 or 4.2000000000000002e-4 < re < 1.31999999999999998e154Initial program 100.0%
Taylor expanded in im around 0 93.5%
if -1.06000000000000006e-8 < re < 4.2000000000000002e-4 or 1.31999999999999998e154 < re Initial program 100.0%
Taylor expanded in re around 0 100.0%
distribute-rgt-in100.0%
*-commutative100.0%
associate-+r+100.0%
distribute-rgt1-in100.0%
*-commutative100.0%
*-commutative100.0%
associate-*l*100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
associate-*l*100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in re around 0 100.0%
Final simplification97.7%
(FPCore (re im) :precision binary64 (if (or (<= re -0.00029) (not (<= re 0.000102))) (exp re) (* (cos im) (+ re 1.0))))
double code(double re, double im) {
double tmp;
if ((re <= -0.00029) || !(re <= 0.000102)) {
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 <= (-0.00029d0)) .or. (.not. (re <= 0.000102d0))) 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 <= -0.00029) || !(re <= 0.000102)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.00029) or not (re <= 0.000102): tmp = math.exp(re) else: tmp = math.cos(im) * (re + 1.0) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.00029) || !(re <= 0.000102)) 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 <= -0.00029) || ~((re <= 0.000102))) tmp = exp(re); else tmp = cos(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.00029], N[Not[LessEqual[re, 0.000102]], $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 -0.00029 \lor \neg \left(re \leq 0.000102\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\end{array}
\end{array}
if re < -2.9e-4 or 1.01999999999999999e-4 < re Initial program 100.0%
Taylor expanded in im around 0 87.2%
if -2.9e-4 < re < 1.01999999999999999e-4Initial program 100.0%
Taylor expanded in re around 0 100.0%
distribute-rgt1-in100.0%
Simplified100.0%
Final simplification93.8%
(FPCore (re im) :precision binary64 (cos im))
double code(double re, double im) {
return cos(im);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = cos(im)
end function
public static double code(double re, double im) {
return Math.cos(im);
}
def code(re, im): return math.cos(im)
function code(re, im) return cos(im) end
function tmp = code(re, im) tmp = cos(im); end
code[re_, im_] := N[Cos[im], $MachinePrecision]
\begin{array}{l}
\\
\cos im
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 52.8%
Final simplification52.8%
(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 53.8%
distribute-rgt1-in53.8%
Simplified53.8%
Taylor expanded in im around 0 33.7%
+-commutative33.7%
Simplified33.7%
Final simplification33.7%
(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 53.8%
distribute-rgt1-in53.8%
Simplified53.8%
Taylor expanded in im around 0 35.4%
associate-+r+35.4%
+-commutative35.4%
associate-*r*35.4%
+-commutative35.4%
distribute-rgt1-in35.4%
*-commutative35.4%
Simplified35.4%
Taylor expanded in re around 0 33.6%
Taylor expanded in im around 0 33.0%
Final simplification33.0%
herbie shell --seed 2024058
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))