
(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 10 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 (<= (exp re) 0.98)
(exp re)
(if (<= (exp re) 1.0000000001)
(* (cos im) (+ (+ re 1.0) (* re (* re 0.5))))
(exp re))))
double code(double re, double im) {
double tmp;
if (exp(re) <= 0.98) {
tmp = exp(re);
} else if (exp(re) <= 1.0000000001) {
tmp = cos(im) * ((re + 1.0) + (re * (re * 0.5)));
} else {
tmp = exp(re);
}
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.98d0) then
tmp = exp(re)
else if (exp(re) <= 1.0000000001d0) then
tmp = cos(im) * ((re + 1.0d0) + (re * (re * 0.5d0)))
else
tmp = exp(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 0.98) {
tmp = Math.exp(re);
} else if (Math.exp(re) <= 1.0000000001) {
tmp = Math.cos(im) * ((re + 1.0) + (re * (re * 0.5)));
} else {
tmp = Math.exp(re);
}
return tmp;
}
def code(re, im): tmp = 0 if math.exp(re) <= 0.98: tmp = math.exp(re) elif math.exp(re) <= 1.0000000001: tmp = math.cos(im) * ((re + 1.0) + (re * (re * 0.5))) else: tmp = math.exp(re) return tmp
function code(re, im) tmp = 0.0 if (exp(re) <= 0.98) tmp = exp(re); elseif (exp(re) <= 1.0000000001) tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(re * Float64(re * 0.5)))); else tmp = exp(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 0.98) tmp = exp(re); elseif (exp(re) <= 1.0000000001) tmp = cos(im) * ((re + 1.0) + (re * (re * 0.5))); else tmp = exp(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.98], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 1.0000000001], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(re * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Exp[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.98:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;e^{re} \leq 1.0000000001:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + re \cdot \left(re \cdot 0.5\right)\right)\\
\mathbf{else}:\\
\;\;\;\;e^{re}\\
\end{array}
\end{array}
if (exp.f64 re) < 0.97999999999999998 or 1.0000000001 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 84.8%
if 0.97999999999999998 < (exp.f64 re) < 1.0000000001Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-lft1-in100.0%
distribute-rgt-out100.0%
+-commutative100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
Final simplification91.9%
(FPCore (re im) :precision binary64 (if (<= (exp re) 0.98) (exp re) (if (<= (exp re) 1.0000000001) (* (cos im) (+ re 1.0)) (exp re))))
double code(double re, double im) {
double tmp;
if (exp(re) <= 0.98) {
tmp = exp(re);
} else if (exp(re) <= 1.0000000001) {
tmp = cos(im) * (re + 1.0);
} else {
tmp = exp(re);
}
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.98d0) then
tmp = exp(re)
else if (exp(re) <= 1.0000000001d0) then
tmp = cos(im) * (re + 1.0d0)
else
tmp = exp(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 0.98) {
tmp = Math.exp(re);
} else if (Math.exp(re) <= 1.0000000001) {
tmp = Math.cos(im) * (re + 1.0);
} else {
tmp = Math.exp(re);
}
return tmp;
}
def code(re, im): tmp = 0 if math.exp(re) <= 0.98: tmp = math.exp(re) elif math.exp(re) <= 1.0000000001: tmp = math.cos(im) * (re + 1.0) else: tmp = math.exp(re) return tmp
function code(re, im) tmp = 0.0 if (exp(re) <= 0.98) tmp = exp(re); elseif (exp(re) <= 1.0000000001) tmp = Float64(cos(im) * Float64(re + 1.0)); else tmp = exp(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 0.98) tmp = exp(re); elseif (exp(re) <= 1.0000000001) tmp = cos(im) * (re + 1.0); else tmp = exp(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 0.98], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 1.0000000001], N[(N[Cos[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision], N[Exp[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 0.98:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;e^{re} \leq 1.0000000001:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\mathbf{else}:\\
\;\;\;\;e^{re}\\
\end{array}
\end{array}
if (exp.f64 re) < 0.97999999999999998 or 1.0000000001 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 84.8%
if 0.97999999999999998 < (exp.f64 re) < 1.0000000001Initial program 100.0%
Taylor expanded in re around 0 99.9%
*-rgt-identity99.9%
distribute-lft-in99.9%
Simplified99.9%
Final simplification91.9%
(FPCore (re im) :precision binary64 (if (<= (exp re) 1.0) (exp re) (if (<= (exp re) 1.0000000001) (cos im) (exp re))))
double code(double re, double im) {
double tmp;
if (exp(re) <= 1.0) {
tmp = exp(re);
} else if (exp(re) <= 1.0000000001) {
tmp = cos(im);
} else {
tmp = exp(re);
}
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) then
tmp = exp(re)
else if (exp(re) <= 1.0000000001d0) then
tmp = cos(im)
else
tmp = exp(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.exp(re) <= 1.0) {
tmp = Math.exp(re);
} else if (Math.exp(re) <= 1.0000000001) {
tmp = Math.cos(im);
} else {
tmp = Math.exp(re);
}
return tmp;
}
def code(re, im): tmp = 0 if math.exp(re) <= 1.0: tmp = math.exp(re) elif math.exp(re) <= 1.0000000001: tmp = math.cos(im) else: tmp = math.exp(re) return tmp
function code(re, im) tmp = 0.0 if (exp(re) <= 1.0) tmp = exp(re); elseif (exp(re) <= 1.0000000001) tmp = cos(im); else tmp = exp(re); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (exp(re) <= 1.0) tmp = exp(re); elseif (exp(re) <= 1.0000000001) tmp = cos(im); else tmp = exp(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Exp[re], $MachinePrecision], 1.0], N[Exp[re], $MachinePrecision], If[LessEqual[N[Exp[re], $MachinePrecision], 1.0000000001], N[Cos[im], $MachinePrecision], N[Exp[re], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;e^{re} \leq 1:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;e^{re} \leq 1.0000000001:\\
\;\;\;\;\cos im\\
\mathbf{else}:\\
\;\;\;\;e^{re}\\
\end{array}
\end{array}
if (exp.f64 re) < 1 or 1.0000000001 < (exp.f64 re) Initial program 100.0%
Taylor expanded in im around 0 72.5%
if 1 < (exp.f64 re) < 1.0000000001Initial program 99.5%
Taylor expanded in re around 0 83.4%
Final simplification72.7%
(FPCore (re im)
:precision binary64
(if (<= re -0.0035)
(exp re)
(if (<= re 1.35e-10)
(* (cos im) (+ (+ re 1.0) (* re (* re 0.5))))
(if (<= re 2.8e+77)
(exp re)
(*
(cos im)
(+
(+ re 1.0)
(/
(* (* re re) (- 0.25 (* (* re re) 0.027777777777777776)))
(+ 0.5 (* re -0.16666666666666666)))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.0035) {
tmp = exp(re);
} else if (re <= 1.35e-10) {
tmp = cos(im) * ((re + 1.0) + (re * (re * 0.5)));
} else if (re <= 2.8e+77) {
tmp = exp(re);
} else {
tmp = cos(im) * ((re + 1.0) + (((re * re) * (0.25 - ((re * re) * 0.027777777777777776))) / (0.5 + (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 <= (-0.0035d0)) then
tmp = exp(re)
else if (re <= 1.35d-10) then
tmp = cos(im) * ((re + 1.0d0) + (re * (re * 0.5d0)))
else if (re <= 2.8d+77) then
tmp = exp(re)
else
tmp = cos(im) * ((re + 1.0d0) + (((re * re) * (0.25d0 - ((re * re) * 0.027777777777777776d0))) / (0.5d0 + (re * (-0.16666666666666666d0)))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.0035) {
tmp = Math.exp(re);
} else if (re <= 1.35e-10) {
tmp = Math.cos(im) * ((re + 1.0) + (re * (re * 0.5)));
} else if (re <= 2.8e+77) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * ((re + 1.0) + (((re * re) * (0.25 - ((re * re) * 0.027777777777777776))) / (0.5 + (re * -0.16666666666666666))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.0035: tmp = math.exp(re) elif re <= 1.35e-10: tmp = math.cos(im) * ((re + 1.0) + (re * (re * 0.5))) elif re <= 2.8e+77: tmp = math.exp(re) else: tmp = math.cos(im) * ((re + 1.0) + (((re * re) * (0.25 - ((re * re) * 0.027777777777777776))) / (0.5 + (re * -0.16666666666666666)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.0035) tmp = exp(re); elseif (re <= 1.35e-10) tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(re * Float64(re * 0.5)))); elseif (re <= 2.8e+77) tmp = exp(re); else tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(Float64(Float64(re * re) * Float64(0.25 - Float64(Float64(re * re) * 0.027777777777777776))) / Float64(0.5 + Float64(re * -0.16666666666666666))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.0035) tmp = exp(re); elseif (re <= 1.35e-10) tmp = cos(im) * ((re + 1.0) + (re * (re * 0.5))); elseif (re <= 2.8e+77) tmp = exp(re); else tmp = cos(im) * ((re + 1.0) + (((re * re) * (0.25 - ((re * re) * 0.027777777777777776))) / (0.5 + (re * -0.16666666666666666)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.0035], N[Exp[re], $MachinePrecision], If[LessEqual[re, 1.35e-10], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(re * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.8e+77], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(N[(N[(re * re), $MachinePrecision] * N[(0.25 - N[(N[(re * re), $MachinePrecision] * 0.027777777777777776), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(re * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.0035:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 1.35 \cdot 10^{-10}:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + re \cdot \left(re \cdot 0.5\right)\right)\\
\mathbf{elif}\;re \leq 2.8 \cdot 10^{+77}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + \frac{\left(re \cdot re\right) \cdot \left(0.25 - \left(re \cdot re\right) \cdot 0.027777777777777776\right)}{0.5 + re \cdot -0.16666666666666666}\right)\\
\end{array}
\end{array}
if re < -0.00350000000000000007 or 1.35e-10 < re < 2.8e77Initial program 100.0%
Taylor expanded in im around 0 93.0%
if -0.00350000000000000007 < re < 1.35e-10Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-lft1-in100.0%
distribute-rgt-out100.0%
+-commutative100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 2.8e77 < re Initial program 100.0%
Taylor expanded in re around 0 78.1%
associate-+r+78.1%
*-commutative78.1%
associate-*r*78.1%
*-commutative78.1%
associate-*r*78.1%
distribute-rgt-out78.1%
*-commutative78.1%
*-commutative78.1%
distribute-lft1-in78.1%
distribute-rgt-out78.1%
+-commutative78.1%
cube-mult78.1%
unpow278.1%
associate-*r*78.1%
Simplified78.1%
*-commutative78.1%
flip-+78.1%
associate-*l/100.0%
metadata-eval100.0%
swap-sqr100.0%
metadata-eval100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification97.4%
(FPCore (re im)
:precision binary64
(if (<= re -0.00245)
(exp re)
(if (<= re 1.35e-10)
(* (cos im) (+ (+ re 1.0) (* re (* re 0.5))))
(if (<= re 1.05e+103)
(exp re)
(*
(cos im)
(+ (+ re 1.0) (* (* re re) (+ 0.5 (* re 0.16666666666666666)))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.00245) {
tmp = exp(re);
} else if (re <= 1.35e-10) {
tmp = cos(im) * ((re + 1.0) + (re * (re * 0.5)));
} else if (re <= 1.05e+103) {
tmp = exp(re);
} else {
tmp = cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (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 <= (-0.00245d0)) then
tmp = exp(re)
else if (re <= 1.35d-10) then
tmp = cos(im) * ((re + 1.0d0) + (re * (re * 0.5d0)))
else if (re <= 1.05d+103) then
tmp = exp(re)
else
tmp = cos(im) * ((re + 1.0d0) + ((re * re) * (0.5d0 + (re * 0.16666666666666666d0))))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.00245) {
tmp = Math.exp(re);
} else if (re <= 1.35e-10) {
tmp = Math.cos(im) * ((re + 1.0) + (re * (re * 0.5)));
} else if (re <= 1.05e+103) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (re * 0.16666666666666666))));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.00245: tmp = math.exp(re) elif re <= 1.35e-10: tmp = math.cos(im) * ((re + 1.0) + (re * (re * 0.5))) elif re <= 1.05e+103: tmp = math.exp(re) else: tmp = math.cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (re * 0.16666666666666666)))) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.00245) tmp = exp(re); elseif (re <= 1.35e-10) tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(re * Float64(re * 0.5)))); elseif (re <= 1.05e+103) tmp = exp(re); else tmp = Float64(cos(im) * Float64(Float64(re + 1.0) + Float64(Float64(re * re) * Float64(0.5 + Float64(re * 0.16666666666666666))))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.00245) tmp = exp(re); elseif (re <= 1.35e-10) tmp = cos(im) * ((re + 1.0) + (re * (re * 0.5))); elseif (re <= 1.05e+103) tmp = exp(re); else tmp = cos(im) * ((re + 1.0) + ((re * re) * (0.5 + (re * 0.16666666666666666)))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.00245], N[Exp[re], $MachinePrecision], If[LessEqual[re, 1.35e-10], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(re * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1.05e+103], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(re + 1.0), $MachinePrecision] + N[(N[(re * re), $MachinePrecision] * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.00245:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 1.35 \cdot 10^{-10}:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + re \cdot \left(re \cdot 0.5\right)\right)\\
\mathbf{elif}\;re \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(\left(re + 1\right) + \left(re \cdot re\right) \cdot \left(0.5 + re \cdot 0.16666666666666666\right)\right)\\
\end{array}
\end{array}
if re < -0.0024499999999999999 or 1.35e-10 < re < 1.0500000000000001e103Initial program 100.0%
Taylor expanded in im around 0 91.7%
if -0.0024499999999999999 < re < 1.35e-10Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
distribute-lft1-in100.0%
distribute-rgt-out100.0%
+-commutative100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1.0500000000000001e103 < re Initial program 100.0%
Taylor expanded in re around 0 100.0%
associate-+r+100.0%
*-commutative100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
distribute-rgt-out100.0%
*-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
distribute-rgt-out100.0%
+-commutative100.0%
cube-mult100.0%
unpow2100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification96.6%
(FPCore (re im) :precision binary64 (if (<= re 2.8e+36) (cos im) (* (* re re) (+ 0.5 (* -0.25 (* im im))))))
double code(double re, double im) {
double tmp;
if (re <= 2.8e+36) {
tmp = cos(im);
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 2.8d+36) then
tmp = cos(im)
else
tmp = (re * re) * (0.5d0 + ((-0.25d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 2.8e+36) {
tmp = Math.cos(im);
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.8e+36: tmp = math.cos(im) else: tmp = (re * re) * (0.5 + (-0.25 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.8e+36) tmp = cos(im); else tmp = Float64(Float64(re * re) * Float64(0.5 + Float64(-0.25 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.8e+36) tmp = cos(im); else tmp = (re * re) * (0.5 + (-0.25 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.8e+36], N[Cos[im], $MachinePrecision], N[(N[(re * re), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.8 \cdot 10^{+36}:\\
\;\;\;\;\cos im\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot re\right) \cdot \left(0.5 + -0.25 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 2.8000000000000001e36Initial program 100.0%
Taylor expanded in re around 0 59.5%
if 2.8000000000000001e36 < re Initial program 100.0%
Taylor expanded in re around 0 44.6%
*-commutative44.6%
associate-*r*44.6%
*-commutative44.6%
distribute-lft1-in44.6%
distribute-rgt-out44.6%
+-commutative44.6%
*-commutative44.6%
unpow244.6%
associate-*l*44.6%
Simplified44.6%
Taylor expanded in re around inf 44.6%
*-commutative44.6%
unpow244.6%
associate-*r*44.6%
associate-*r*44.6%
Simplified44.6%
Taylor expanded in im around 0 13.9%
unpow213.9%
*-commutative13.9%
associate-*r*13.9%
fma-def25.6%
unpow225.6%
associate-*r*25.6%
*-commutative25.6%
unpow225.6%
Simplified25.6%
Taylor expanded in re around 0 41.3%
unpow241.3%
*-commutative41.3%
unpow241.3%
Simplified41.3%
Final simplification55.9%
(FPCore (re im) :precision binary64 (if (<= re 2.7e+36) (+ re 1.0) (* (* re re) (+ 0.5 (* -0.25 (* im im))))))
double code(double re, double im) {
double tmp;
if (re <= 2.7e+36) {
tmp = re + 1.0;
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= 2.7d+36) then
tmp = re + 1.0d0
else
tmp = (re * re) * (0.5d0 + ((-0.25d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 2.7e+36) {
tmp = re + 1.0;
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.7e+36: tmp = re + 1.0 else: tmp = (re * re) * (0.5 + (-0.25 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.7e+36) tmp = Float64(re + 1.0); else tmp = Float64(Float64(re * re) * Float64(0.5 + Float64(-0.25 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 2.7e+36) tmp = re + 1.0; else tmp = (re * re) * (0.5 + (-0.25 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.7e+36], N[(re + 1.0), $MachinePrecision], N[(N[(re * re), $MachinePrecision] * N[(0.5 + N[(-0.25 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 2.7 \cdot 10^{+36}:\\
\;\;\;\;re + 1\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot re\right) \cdot \left(0.5 + -0.25 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 2.7000000000000001e36Initial program 100.0%
Taylor expanded in re around 0 60.4%
*-rgt-identity60.4%
distribute-lft-in60.4%
Simplified60.4%
Taylor expanded in im around 0 35.7%
+-commutative35.7%
Simplified35.7%
if 2.7000000000000001e36 < re Initial program 100.0%
Taylor expanded in re around 0 44.6%
*-commutative44.6%
associate-*r*44.6%
*-commutative44.6%
distribute-lft1-in44.6%
distribute-rgt-out44.6%
+-commutative44.6%
*-commutative44.6%
unpow244.6%
associate-*l*44.6%
Simplified44.6%
Taylor expanded in re around inf 44.6%
*-commutative44.6%
unpow244.6%
associate-*r*44.6%
associate-*r*44.6%
Simplified44.6%
Taylor expanded in im around 0 13.9%
unpow213.9%
*-commutative13.9%
associate-*r*13.9%
fma-def25.6%
unpow225.6%
associate-*r*25.6%
*-commutative25.6%
unpow225.6%
Simplified25.6%
Taylor expanded in re around 0 41.3%
unpow241.3%
*-commutative41.3%
unpow241.3%
Simplified41.3%
Final simplification36.8%
(FPCore (re im) :precision binary64 (+ 1.0 (+ re (* (* im im) -0.5))))
double code(double re, double im) {
return 1.0 + (re + ((im * im) * -0.5));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 1.0d0 + (re + ((im * im) * (-0.5d0)))
end function
public static double code(double re, double im) {
return 1.0 + (re + ((im * im) * -0.5));
}
def code(re, im): return 1.0 + (re + ((im * im) * -0.5))
function code(re, im) return Float64(1.0 + Float64(re + Float64(Float64(im * im) * -0.5))) end
function tmp = code(re, im) tmp = 1.0 + (re + ((im * im) * -0.5)); end
code[re_, im_] := N[(1.0 + N[(re + N[(N[(im * im), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \left(re + \left(im \cdot im\right) \cdot -0.5\right)
\end{array}
Initial program 100.0%
Taylor expanded in re around 0 49.4%
*-rgt-identity49.4%
distribute-lft-in49.4%
Simplified49.4%
Taylor expanded in im around 0 31.5%
associate-*r*31.5%
+-commutative31.5%
unpow231.5%
Simplified31.5%
Taylor expanded in re around 0 30.4%
unpow230.4%
Simplified30.4%
Final simplification30.4%
(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.4%
*-rgt-identity49.4%
distribute-lft-in49.4%
Simplified49.4%
Taylor expanded in im around 0 29.3%
+-commutative29.3%
Simplified29.3%
Final simplification29.3%
herbie shell --seed 2023174
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))