
(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%
(FPCore (re im) :precision binary64 (if (or (<= (exp re) 0.8) (not (<= (exp re) 1.5))) (exp re) (cos im)))
double code(double re, double im) {
double tmp;
if ((exp(re) <= 0.8) || !(exp(re) <= 1.5)) {
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.8d0) .or. (.not. (exp(re) <= 1.5d0))) 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.8) || !(Math.exp(re) <= 1.5)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (math.exp(re) <= 0.8) or not (math.exp(re) <= 1.5): tmp = math.exp(re) else: tmp = math.cos(im) return tmp
function code(re, im) tmp = 0.0 if ((exp(re) <= 0.8) || !(exp(re) <= 1.5)) tmp = exp(re); else tmp = cos(im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((exp(re) <= 0.8) || ~((exp(re) <= 1.5))) tmp = exp(re); else tmp = cos(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[N[Exp[re], $MachinePrecision], 0.8], N[Not[LessEqual[N[Exp[re], $MachinePrecision], 1.5]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Cos[im], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.8 \lor \neg \left(e^{re} \leq 1.5\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im\\
\end{array}
\end{array}
if (exp.f64 re) < 0.80000000000000004 or 1.5 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 86.2%
if 0.80000000000000004 < (exp.f64 re) < 1.5Initial program 100.0%
Taylor expanded in re around 0 97.9%
Final simplification91.8%
(FPCore (re im) :precision binary64 (if (or (<= re -0.065) (and (not (<= re 0.025)) (<= re 7.8e+149))) (exp re) (* (cos im) (+ 1.0 (* re (+ 1.0 (* re 0.5)))))))
double code(double re, double im) {
double tmp;
if ((re <= -0.065) || (!(re <= 0.025) && (re <= 7.8e+149))) {
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.065d0)) .or. (.not. (re <= 0.025d0)) .and. (re <= 7.8d+149)) 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.065) || (!(re <= 0.025) && (re <= 7.8e+149))) {
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.065) or (not (re <= 0.025) and (re <= 7.8e+149)): 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.065) || (!(re <= 0.025) && (re <= 7.8e+149))) 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.065) || (~((re <= 0.025)) && (re <= 7.8e+149))) 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.065], And[N[Not[LessEqual[re, 0.025]], $MachinePrecision], LessEqual[re, 7.8e+149]]], 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.065 \lor \neg \left(re \leq 0.025\right) \land re \leq 7.8 \cdot 10^{+149}:\\
\;\;\;\;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.065000000000000002 or 0.025000000000000001 < re < 7.7999999999999998e149Initial program 100.0%
Taylor expanded in im around 0 93.3%
if -0.065000000000000002 < re < 0.025000000000000001 or 7.7999999999999998e149 < re Initial program 100.0%
add-exp-log70.1%
prod-exp70.1%
Applied egg-rr70.1%
Taylor expanded in re around 0 98.5%
distribute-lft-in98.5%
associate-+r+98.5%
distribute-rgt1-in98.5%
+-commutative98.5%
associate-*r*98.5%
associate-*r*98.5%
distribute-rgt-out98.5%
+-commutative98.5%
Simplified98.5%
Taylor expanded in re around 0 98.5%
Final simplification96.6%
(FPCore (re im) :precision binary64 (if (or (<= re -0.00188) (not (<= re 0.0105))) (exp re) (* (cos im) (+ re 1.0))))
double code(double re, double im) {
double tmp;
if ((re <= -0.00188) || !(re <= 0.0105)) {
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.00188d0)) .or. (.not. (re <= 0.0105d0))) 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.00188) || !(re <= 0.0105)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.00188) or not (re <= 0.0105): tmp = math.exp(re) else: tmp = math.cos(im) * (re + 1.0) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.00188) || !(re <= 0.0105)) 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.00188) || ~((re <= 0.0105))) tmp = exp(re); else tmp = cos(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.00188], N[Not[LessEqual[re, 0.0105]], $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.00188 \lor \neg \left(re \leq 0.0105\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\end{array}
\end{array}
if re < -0.00187999999999999994 or 0.0105000000000000007 < re Initial program 100.0%
Taylor expanded in im around 0 86.2%
if -0.00187999999999999994 < re < 0.0105000000000000007Initial program 100.0%
Taylor expanded in re around 0 98.9%
distribute-rgt1-in98.9%
Simplified98.9%
Final simplification92.3%
(FPCore (re im) :precision binary64 (if (<= re 3.6e-7) (cos im) (+ 1.0 (* re (+ 1.0 (* re 0.5))))))
double code(double re, double im) {
double tmp;
if (re <= 3.6e-7) {
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 <= 3.6d-7) 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 <= 3.6e-7) {
tmp = Math.cos(im);
} else {
tmp = 1.0 + (re * (1.0 + (re * 0.5)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 3.6e-7: 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 <= 3.6e-7) 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 <= 3.6e-7) tmp = cos(im); else tmp = 1.0 + (re * (1.0 + (re * 0.5))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 3.6e-7], 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 3.6 \cdot 10^{-7}:\\
\;\;\;\;\cos im\\
\mathbf{else}:\\
\;\;\;\;1 + re \cdot \left(1 + re \cdot 0.5\right)\\
\end{array}
\end{array}
if re < 3.59999999999999994e-7Initial program 100.0%
Taylor expanded in re around 0 64.6%
if 3.59999999999999994e-7 < re Initial program 100.0%
add-exp-log74.2%
prod-exp74.2%
Applied egg-rr74.2%
Taylor expanded in re around 0 57.5%
distribute-lft-in57.5%
associate-+r+57.5%
distribute-rgt1-in57.5%
+-commutative57.5%
associate-*r*57.5%
associate-*r*57.5%
distribute-rgt-out57.5%
+-commutative57.5%
Simplified57.5%
Taylor expanded in re around 0 57.5%
Taylor expanded in im around 0 41.6%
Final simplification58.7%
(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-exp-log71.8%
prod-exp71.8%
Applied egg-rr71.8%
Taylor expanded in re around 0 63.3%
distribute-lft-in63.3%
associate-+r+63.3%
distribute-rgt1-in63.3%
+-commutative63.3%
associate-*r*63.3%
associate-*r*63.3%
distribute-rgt-out63.3%
+-commutative63.3%
Simplified63.3%
Taylor expanded in re around 0 63.3%
Taylor expanded in im around 0 36.8%
Final simplification36.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 49.7%
distribute-rgt1-in49.7%
Simplified49.7%
Taylor expanded in im around 0 27.2%
+-commutative27.2%
Simplified27.2%
(FPCore (re im) :precision binary64 re)
double code(double re, double im) {
return re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re
end function
public static double code(double re, double im) {
return re;
}
def code(re, im): return re
function code(re, im) return re end
function tmp = code(re, im) tmp = re; end
code[re_, im_] := re
\begin{array}{l}
\\
re
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 49.7%
distribute-rgt1-in49.7%
Simplified49.7%
Taylor expanded in re around inf 3.6%
*-commutative3.6%
Simplified3.6%
Taylor expanded in im around 0 3.5%
herbie shell --seed 2024085
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))