
(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 (<= re -0.0088) (and (not (<= re 132000000.0)) (<= re 1.8e+103)))
(exp re)
(*
(+ 1.0 (* re 0.6666666666666666))
(*
(cos im)
(+ 1.0 (* re (+ 0.3333333333333333 (* re 0.05555555555555555))))))))
double code(double re, double im) {
double tmp;
if ((re <= -0.0088) || (!(re <= 132000000.0) && (re <= 1.8e+103))) {
tmp = exp(re);
} else {
tmp = (1.0 + (re * 0.6666666666666666)) * (cos(im) * (1.0 + (re * (0.3333333333333333 + (re * 0.05555555555555555)))));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-0.0088d0)) .or. (.not. (re <= 132000000.0d0)) .and. (re <= 1.8d+103)) then
tmp = exp(re)
else
tmp = (1.0d0 + (re * 0.6666666666666666d0)) * (cos(im) * (1.0d0 + (re * (0.3333333333333333d0 + (re * 0.05555555555555555d0)))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.0088) || (!(re <= 132000000.0) && (re <= 1.8e+103))) {
tmp = Math.exp(re);
} else {
tmp = (1.0 + (re * 0.6666666666666666)) * (Math.cos(im) * (1.0 + (re * (0.3333333333333333 + (re * 0.05555555555555555)))));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.0088) or (not (re <= 132000000.0) and (re <= 1.8e+103)): tmp = math.exp(re) else: tmp = (1.0 + (re * 0.6666666666666666)) * (math.cos(im) * (1.0 + (re * (0.3333333333333333 + (re * 0.05555555555555555))))) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.0088) || (!(re <= 132000000.0) && (re <= 1.8e+103))) tmp = exp(re); else tmp = Float64(Float64(1.0 + Float64(re * 0.6666666666666666)) * Float64(cos(im) * Float64(1.0 + Float64(re * Float64(0.3333333333333333 + Float64(re * 0.05555555555555555)))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.0088) || (~((re <= 132000000.0)) && (re <= 1.8e+103))) tmp = exp(re); else tmp = (1.0 + (re * 0.6666666666666666)) * (cos(im) * (1.0 + (re * (0.3333333333333333 + (re * 0.05555555555555555))))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.0088], And[N[Not[LessEqual[re, 132000000.0]], $MachinePrecision], LessEqual[re, 1.8e+103]]], N[Exp[re], $MachinePrecision], N[(N[(1.0 + N[(re * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[im], $MachinePrecision] * N[(1.0 + N[(re * N[(0.3333333333333333 + N[(re * 0.05555555555555555), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0088 \lor \neg \left(re \leq 132000000\right) \land re \leq 1.8 \cdot 10^{+103}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot 0.6666666666666666\right) \cdot \left(\cos im \cdot \left(1 + re \cdot \left(0.3333333333333333 + re \cdot 0.05555555555555555\right)\right)\right)\\
\end{array}
\end{array}
if re < -0.00880000000000000053 or 1.32e8 < re < 1.80000000000000008e103Initial program 100.0%
Taylor expanded in im around 0 90.6%
if -0.00880000000000000053 < re < 1.32e8 or 1.80000000000000008e103 < re Initial program 100.0%
add-cube-cbrt99.0%
pow399.0%
pow-to-exp70.8%
pow1/371.1%
log-pow71.3%
log-prod71.3%
add-log-exp71.3%
Applied egg-rr71.3%
*-commutative71.3%
associate-*r*71.3%
metadata-eval71.3%
*-un-lft-identity71.3%
prod-exp71.3%
add-exp-log100.0%
add-cube-cbrt99.8%
associate-*l*99.8%
pow299.8%
Applied egg-rr99.8%
Taylor expanded in re around 0 98.8%
*-commutative98.8%
Simplified98.8%
Taylor expanded in re around 0 98.3%
+-commutative98.3%
*-commutative98.3%
*-commutative98.3%
unpow298.3%
associate-*l*98.3%
distribute-lft-out98.3%
Simplified98.3%
Final simplification95.7%
(FPCore (re im)
:precision binary64
(if (or (<= re -0.009) (and (not (<= re 132000000.0)) (<= re 6e+149)))
(exp re)
(*
(+ 1.0 (* re 0.6666666666666666))
(* (cos im) (+ 1.0 (* re 0.3333333333333333))))))
double code(double re, double im) {
double tmp;
if ((re <= -0.009) || (!(re <= 132000000.0) && (re <= 6e+149))) {
tmp = exp(re);
} else {
tmp = (1.0 + (re * 0.6666666666666666)) * (cos(im) * (1.0 + (re * 0.3333333333333333)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((re <= (-0.009d0)) .or. (.not. (re <= 132000000.0d0)) .and. (re <= 6d+149)) then
tmp = exp(re)
else
tmp = (1.0d0 + (re * 0.6666666666666666d0)) * (cos(im) * (1.0d0 + (re * 0.3333333333333333d0)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.009) || (!(re <= 132000000.0) && (re <= 6e+149))) {
tmp = Math.exp(re);
} else {
tmp = (1.0 + (re * 0.6666666666666666)) * (Math.cos(im) * (1.0 + (re * 0.3333333333333333)));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.009) or (not (re <= 132000000.0) and (re <= 6e+149)): tmp = math.exp(re) else: tmp = (1.0 + (re * 0.6666666666666666)) * (math.cos(im) * (1.0 + (re * 0.3333333333333333))) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.009) || (!(re <= 132000000.0) && (re <= 6e+149))) tmp = exp(re); else tmp = Float64(Float64(1.0 + Float64(re * 0.6666666666666666)) * Float64(cos(im) * Float64(1.0 + Float64(re * 0.3333333333333333)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.009) || (~((re <= 132000000.0)) && (re <= 6e+149))) tmp = exp(re); else tmp = (1.0 + (re * 0.6666666666666666)) * (cos(im) * (1.0 + (re * 0.3333333333333333))); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.009], And[N[Not[LessEqual[re, 132000000.0]], $MachinePrecision], LessEqual[re, 6e+149]]], N[Exp[re], $MachinePrecision], N[(N[(1.0 + N[(re * 0.6666666666666666), $MachinePrecision]), $MachinePrecision] * N[(N[Cos[im], $MachinePrecision] * N[(1.0 + N[(re * 0.3333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.009 \lor \neg \left(re \leq 132000000\right) \land re \leq 6 \cdot 10^{+149}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\left(1 + re \cdot 0.6666666666666666\right) \cdot \left(\cos im \cdot \left(1 + re \cdot 0.3333333333333333\right)\right)\\
\end{array}
\end{array}
if re < -0.00899999999999999932 or 1.32e8 < re < 6.00000000000000007e149Initial program 100.0%
Taylor expanded in im around 0 88.0%
if -0.00899999999999999932 < re < 1.32e8 or 6.00000000000000007e149 < re Initial program 100.0%
add-cube-cbrt99.0%
pow399.0%
pow-to-exp71.4%
pow1/371.7%
log-pow71.9%
log-prod71.9%
add-log-exp71.9%
Applied egg-rr71.9%
*-commutative71.9%
associate-*r*71.9%
metadata-eval71.9%
*-un-lft-identity71.9%
prod-exp71.9%
add-exp-log100.0%
add-cube-cbrt99.8%
associate-*l*99.8%
pow299.8%
Applied egg-rr99.8%
Taylor expanded in re around 0 98.7%
*-commutative98.7%
Simplified98.7%
Taylor expanded in re around 0 97.1%
*-commutative97.1%
Simplified97.1%
Final simplification93.9%
(FPCore (re im) :precision binary64 (if (or (<= re -0.0155) (not (<= re 132000000.0))) (exp re) (* (cos im) (+ re 1.0))))
double code(double re, double im) {
double tmp;
if ((re <= -0.0155) || !(re <= 132000000.0)) {
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.0155d0)) .or. (.not. (re <= 132000000.0d0))) 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.0155) || !(re <= 132000000.0)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re + 1.0);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.0155) or not (re <= 132000000.0): tmp = math.exp(re) else: tmp = math.cos(im) * (re + 1.0) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.0155) || !(re <= 132000000.0)) 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.0155) || ~((re <= 132000000.0))) tmp = exp(re); else tmp = cos(im) * (re + 1.0); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.0155], N[Not[LessEqual[re, 132000000.0]], $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.0155 \lor \neg \left(re \leq 132000000\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\end{array}
\end{array}
if re < -0.0155 or 1.32e8 < re Initial program 100.0%
Taylor expanded in im around 0 80.3%
if -0.0155 < re < 1.32e8Initial program 100.0%
Taylor expanded in re around 0 97.7%
distribute-rgt1-in97.7%
Simplified97.7%
Final simplification89.4%
(FPCore (re im) :precision binary64 (if (or (<= re -6.5e-11) (not (<= re 2.8e-13))) (exp re) (cos im)))
double code(double re, double im) {
double tmp;
if ((re <= -6.5e-11) || !(re <= 2.8e-13)) {
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 ((re <= (-6.5d-11)) .or. (.not. (re <= 2.8d-13))) 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 ((re <= -6.5e-11) || !(re <= 2.8e-13)) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im);
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -6.5e-11) or not (re <= 2.8e-13): tmp = math.exp(re) else: tmp = math.cos(im) return tmp
function code(re, im) tmp = 0.0 if ((re <= -6.5e-11) || !(re <= 2.8e-13)) tmp = exp(re); else tmp = cos(im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -6.5e-11) || ~((re <= 2.8e-13))) tmp = exp(re); else tmp = cos(im); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -6.5e-11], N[Not[LessEqual[re, 2.8e-13]], $MachinePrecision]], N[Exp[re], $MachinePrecision], N[Cos[im], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -6.5 \cdot 10^{-11} \lor \neg \left(re \leq 2.8 \cdot 10^{-13}\right):\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im\\
\end{array}
\end{array}
if re < -6.49999999999999953e-11 or 2.8000000000000002e-13 < re Initial program 100.0%
Taylor expanded in im around 0 78.4%
if -6.49999999999999953e-11 < re < 2.8000000000000002e-13Initial program 100.0%
Taylor expanded in re around 0 99.3%
Final simplification88.6%
(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 51.6%
Final simplification51.6%
(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 52.9%
distribute-rgt1-in52.9%
Simplified52.9%
Taylor expanded in im around 0 31.5%
+-commutative31.5%
Simplified31.5%
Final simplification31.5%
(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 52.9%
distribute-rgt1-in52.9%
Simplified52.9%
Taylor expanded in re around inf 3.7%
*-commutative3.7%
Simplified3.7%
Taylor expanded in im around 0 3.3%
Final simplification3.3%
herbie shell --seed 2024019
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))