
(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 12 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) 1.0) (exp re) (if (<= (exp re) 1.0002) (* (cos im) (+ re 1.0)) (exp re))))
double code(double re, double im) {
double tmp;
if (exp(re) <= 1.0) {
tmp = exp(re);
} else if (exp(re) <= 1.0002) {
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) <= 1.0d0) then
tmp = exp(re)
else if (exp(re) <= 1.0002d0) 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) <= 1.0) {
tmp = Math.exp(re);
} else if (Math.exp(re) <= 1.0002) {
tmp = Math.cos(im) * (re + 1.0);
} 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.0002: tmp = math.cos(im) * (re + 1.0) 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.0002) 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) <= 1.0) tmp = exp(re); elseif (exp(re) <= 1.0002) tmp = cos(im) * (re + 1.0); 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.0002], 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 1:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;e^{re} \leq 1.0002:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\mathbf{else}:\\
\;\;\;\;e^{re}\\
\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 73.7%
if 1 < (exp.f64 re) < 1.0002Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-rgt-identity100.0%
distribute-lft-in100.0%
Simplified100.0%
Final simplification73.8%
(FPCore (re im) :precision binary64 (if (<= (exp re) 1.0) (exp re) (if (<= (exp re) 1.0002) (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.0002) {
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.0002d0) 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.0002) {
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.0002: 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.0002) 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.0002) 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.0002], 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.0002:\\
\;\;\;\;\cos im\\
\mathbf{else}:\\
\;\;\;\;e^{re}\\
\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 73.7%
if 1 < (exp.f64 re) < 1.0002Initial program 100.0%
Taylor expanded in re around 0 94.2%
Final simplification73.8%
(FPCore (re im)
:precision binary64
(if (or (<= re -0.095) (and (not (<= re 0.000285)) (<= re 1.05e+103)))
(exp re)
(*
(cos im)
(+ (* (* re re) (+ 0.5 (* re 0.16666666666666666))) (+ re 1.0)))))
double code(double re, double im) {
double tmp;
if ((re <= -0.095) || (!(re <= 0.000285) && (re <= 1.05e+103))) {
tmp = exp(re);
} else {
tmp = cos(im) * (((re * re) * (0.5 + (re * 0.16666666666666666))) + (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.095d0)) .or. (.not. (re <= 0.000285d0)) .and. (re <= 1.05d+103)) then
tmp = exp(re)
else
tmp = cos(im) * (((re * re) * (0.5d0 + (re * 0.16666666666666666d0))) + (re + 1.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.095) || (!(re <= 0.000285) && (re <= 1.05e+103))) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (((re * re) * (0.5 + (re * 0.16666666666666666))) + (re + 1.0));
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.095) or (not (re <= 0.000285) and (re <= 1.05e+103)): tmp = math.exp(re) else: tmp = math.cos(im) * (((re * re) * (0.5 + (re * 0.16666666666666666))) + (re + 1.0)) return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.095) || (!(re <= 0.000285) && (re <= 1.05e+103))) tmp = exp(re); else tmp = Float64(cos(im) * Float64(Float64(Float64(re * re) * Float64(0.5 + Float64(re * 0.16666666666666666))) + Float64(re + 1.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.095) || (~((re <= 0.000285)) && (re <= 1.05e+103))) tmp = exp(re); else tmp = cos(im) * (((re * re) * (0.5 + (re * 0.16666666666666666))) + (re + 1.0)); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.095], And[N[Not[LessEqual[re, 0.000285]], $MachinePrecision], LessEqual[re, 1.05e+103]]], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(N[(N[(re * re), $MachinePrecision] * N[(0.5 + N[(re * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(re + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.095 \lor \neg \left(re \leq 0.000285\right) \land re \leq 1.05 \cdot 10^{+103}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(\left(re \cdot re\right) \cdot \left(0.5 + re \cdot 0.16666666666666666\right) + \left(re + 1\right)\right)\\
\end{array}
\end{array}
if re < -0.095000000000000001 or 2.8499999999999999e-4 < re < 1.0500000000000001e103Initial program 100.0%
Taylor expanded in im around 0 97.9%
if -0.095000000000000001 < re < 2.8499999999999999e-4 or 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 simplification99.2%
(FPCore (re im)
:precision binary64
(if (<= re -1.55e-5)
(exp re)
(if (<= re 0.000104)
(* (cos im) (+ re 1.0))
(if (<= re 5.9e+147) (exp re) (* (cos im) (* re (* re 0.5)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.55e-5) {
tmp = exp(re);
} else if (re <= 0.000104) {
tmp = cos(im) * (re + 1.0);
} else if (re <= 5.9e+147) {
tmp = exp(re);
} else {
tmp = cos(im) * (re * (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 <= (-1.55d-5)) then
tmp = exp(re)
else if (re <= 0.000104d0) then
tmp = cos(im) * (re + 1.0d0)
else if (re <= 5.9d+147) then
tmp = exp(re)
else
tmp = cos(im) * (re * (re * 0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.55e-5) {
tmp = Math.exp(re);
} else if (re <= 0.000104) {
tmp = Math.cos(im) * (re + 1.0);
} else if (re <= 5.9e+147) {
tmp = Math.exp(re);
} else {
tmp = Math.cos(im) * (re * (re * 0.5));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.55e-5: tmp = math.exp(re) elif re <= 0.000104: tmp = math.cos(im) * (re + 1.0) elif re <= 5.9e+147: tmp = math.exp(re) else: tmp = math.cos(im) * (re * (re * 0.5)) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.55e-5) tmp = exp(re); elseif (re <= 0.000104) tmp = Float64(cos(im) * Float64(re + 1.0)); elseif (re <= 5.9e+147) tmp = exp(re); else tmp = Float64(cos(im) * Float64(re * Float64(re * 0.5))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.55e-5) tmp = exp(re); elseif (re <= 0.000104) tmp = cos(im) * (re + 1.0); elseif (re <= 5.9e+147) tmp = exp(re); else tmp = cos(im) * (re * (re * 0.5)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.55e-5], N[Exp[re], $MachinePrecision], If[LessEqual[re, 0.000104], N[(N[Cos[im], $MachinePrecision] * N[(re + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 5.9e+147], N[Exp[re], $MachinePrecision], N[(N[Cos[im], $MachinePrecision] * N[(re * N[(re * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.55 \cdot 10^{-5}:\\
\;\;\;\;e^{re}\\
\mathbf{elif}\;re \leq 0.000104:\\
\;\;\;\;\cos im \cdot \left(re + 1\right)\\
\mathbf{elif}\;re \leq 5.9 \cdot 10^{+147}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;\cos im \cdot \left(re \cdot \left(re \cdot 0.5\right)\right)\\
\end{array}
\end{array}
if re < -1.55000000000000007e-5 or 1.03999999999999994e-4 < re < 5.9000000000000001e147Initial program 100.0%
Taylor expanded in im around 0 98.0%
if -1.55000000000000007e-5 < re < 1.03999999999999994e-4Initial program 100.0%
Taylor expanded in re around 0 100.0%
*-rgt-identity100.0%
distribute-lft-in100.0%
Simplified100.0%
if 5.9000000000000001e147 < re Initial program 100.0%
Taylor expanded in re around 0 98.0%
*-commutative98.0%
associate-*r*98.0%
*-commutative98.0%
distribute-lft1-in98.0%
distribute-rgt-out98.0%
+-commutative98.0%
*-commutative98.0%
unpow298.0%
associate-*l*98.0%
Simplified98.0%
Taylor expanded in re around inf 98.0%
unpow298.0%
*-commutative98.0%
associate-*r*98.0%
Simplified98.0%
Final simplification98.9%
(FPCore (re im)
:precision binary64
(if (<= re -4e+36)
(* -0.25 (* (* re re) (* im im)))
(if (<= re 3.3e-7)
(cos im)
(if (<= re 8e+100)
(+ (+ re 1.0) (* -0.5 (/ (- 1.0 (* re re)) (/ 1.0 (* im im)))))
(* (* re re) (+ 0.5 (* -0.25 (* im im))))))))
double code(double re, double im) {
double tmp;
if (re <= -4e+36) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 3.3e-7) {
tmp = cos(im);
} else if (re <= 8e+100) {
tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * 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 <= (-4d+36)) then
tmp = (-0.25d0) * ((re * re) * (im * im))
else if (re <= 3.3d-7) then
tmp = cos(im)
else if (re <= 8d+100) then
tmp = (re + 1.0d0) + ((-0.5d0) * ((1.0d0 - (re * re)) / (1.0d0 / (im * 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 <= -4e+36) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 3.3e-7) {
tmp = Math.cos(im);
} else if (re <= 8e+100) {
tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * im))));
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -4e+36: tmp = -0.25 * ((re * re) * (im * im)) elif re <= 3.3e-7: tmp = math.cos(im) elif re <= 8e+100: tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * im)))) else: tmp = (re * re) * (0.5 + (-0.25 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= -4e+36) tmp = Float64(-0.25 * Float64(Float64(re * re) * Float64(im * im))); elseif (re <= 3.3e-7) tmp = cos(im); elseif (re <= 8e+100) tmp = Float64(Float64(re + 1.0) + Float64(-0.5 * Float64(Float64(1.0 - Float64(re * re)) / Float64(1.0 / Float64(im * 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 <= -4e+36) tmp = -0.25 * ((re * re) * (im * im)); elseif (re <= 3.3e-7) tmp = cos(im); elseif (re <= 8e+100) tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * im)))); else tmp = (re * re) * (0.5 + (-0.25 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -4e+36], N[(-0.25 * N[(N[(re * re), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.3e-7], N[Cos[im], $MachinePrecision], If[LessEqual[re, 8e+100], N[(N[(re + 1.0), $MachinePrecision] + N[(-0.5 * N[(N[(1.0 - N[(re * re), $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -4 \cdot 10^{+36}:\\
\;\;\;\;-0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot im\right)\right)\\
\mathbf{elif}\;re \leq 3.3 \cdot 10^{-7}:\\
\;\;\;\;\cos im\\
\mathbf{elif}\;re \leq 8 \cdot 10^{+100}:\\
\;\;\;\;\left(re + 1\right) + -0.5 \cdot \frac{1 - re \cdot re}{\frac{1}{im \cdot 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 < -4.00000000000000017e36Initial program 100.0%
Taylor expanded in re around 0 1.8%
*-commutative1.8%
associate-*r*1.8%
*-commutative1.8%
distribute-lft1-in1.8%
distribute-rgt-out1.8%
+-commutative1.8%
*-commutative1.8%
unpow21.8%
associate-*l*1.8%
Simplified1.8%
Taylor expanded in re around inf 1.8%
unpow21.8%
*-commutative1.8%
associate-*r*1.8%
Simplified1.8%
Taylor expanded in im around 0 0.9%
*-commutative0.9%
*-commutative0.9%
unpow20.9%
associate-*l*0.9%
distribute-lft-out1.7%
unpow21.7%
Simplified1.7%
Taylor expanded in im around inf 11.3%
unpow211.3%
*-commutative11.3%
unpow211.3%
Simplified11.3%
if -4.00000000000000017e36 < re < 3.3000000000000002e-7Initial program 100.0%
Taylor expanded in re around 0 92.0%
if 3.3000000000000002e-7 < re < 8.00000000000000013e100Initial program 100.0%
Taylor expanded in re around 0 7.7%
*-rgt-identity7.7%
distribute-lft-in7.7%
Simplified7.7%
Taylor expanded in im around 0 6.3%
associate-+r+6.3%
+-commutative6.3%
*-commutative6.3%
unpow26.3%
+-commutative6.3%
Simplified6.3%
flip-+6.3%
associate-*r/6.3%
metadata-eval6.3%
Applied egg-rr6.3%
*-commutative6.3%
associate-/l*6.3%
Simplified6.3%
Taylor expanded in re around 0 44.3%
unpow244.3%
Simplified44.3%
if 8.00000000000000013e100 < re Initial program 100.0%
Taylor expanded in re around 0 87.2%
*-commutative87.2%
associate-*r*87.2%
*-commutative87.2%
distribute-lft1-in87.2%
distribute-rgt-out87.2%
+-commutative87.2%
*-commutative87.2%
unpow287.2%
associate-*l*87.2%
Simplified87.2%
Taylor expanded in re around inf 87.2%
unpow287.2%
*-commutative87.2%
associate-*r*87.2%
Simplified87.2%
Taylor expanded in im around 0 2.7%
*-commutative2.7%
*-commutative2.7%
unpow22.7%
associate-*l*2.7%
distribute-lft-out73.3%
unpow273.3%
Simplified73.3%
Final simplification65.1%
(FPCore (re im)
:precision binary64
(if (<= re -0.4)
(* -0.25 (* (* re re) (* im im)))
(if (<= re 0.000285)
(+ re 1.0)
(if (<= re 4.2e+100)
(+ (+ re 1.0) (* -0.5 (/ (- 1.0 (* re re)) (/ 1.0 (* im im)))))
(* (* re re) (+ 0.5 (* -0.25 (* im im))))))))
double code(double re, double im) {
double tmp;
if (re <= -0.4) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 0.000285) {
tmp = re + 1.0;
} else if (re <= 4.2e+100) {
tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * 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 <= (-0.4d0)) then
tmp = (-0.25d0) * ((re * re) * (im * im))
else if (re <= 0.000285d0) then
tmp = re + 1.0d0
else if (re <= 4.2d+100) then
tmp = (re + 1.0d0) + ((-0.5d0) * ((1.0d0 - (re * re)) / (1.0d0 / (im * 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 <= -0.4) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 0.000285) {
tmp = re + 1.0;
} else if (re <= 4.2e+100) {
tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * im))));
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.4: tmp = -0.25 * ((re * re) * (im * im)) elif re <= 0.000285: tmp = re + 1.0 elif re <= 4.2e+100: tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * im)))) else: tmp = (re * re) * (0.5 + (-0.25 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.4) tmp = Float64(-0.25 * Float64(Float64(re * re) * Float64(im * im))); elseif (re <= 0.000285) tmp = Float64(re + 1.0); elseif (re <= 4.2e+100) tmp = Float64(Float64(re + 1.0) + Float64(-0.5 * Float64(Float64(1.0 - Float64(re * re)) / Float64(1.0 / Float64(im * 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 <= -0.4) tmp = -0.25 * ((re * re) * (im * im)); elseif (re <= 0.000285) tmp = re + 1.0; elseif (re <= 4.2e+100) tmp = (re + 1.0) + (-0.5 * ((1.0 - (re * re)) / (1.0 / (im * im)))); else tmp = (re * re) * (0.5 + (-0.25 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.4], N[(-0.25 * N[(N[(re * re), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 0.000285], N[(re + 1.0), $MachinePrecision], If[LessEqual[re, 4.2e+100], N[(N[(re + 1.0), $MachinePrecision] + N[(-0.5 * N[(N[(1.0 - N[(re * re), $MachinePrecision]), $MachinePrecision] / N[(1.0 / N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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 -0.4:\\
\;\;\;\;-0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot im\right)\right)\\
\mathbf{elif}\;re \leq 0.000285:\\
\;\;\;\;re + 1\\
\mathbf{elif}\;re \leq 4.2 \cdot 10^{+100}:\\
\;\;\;\;\left(re + 1\right) + -0.5 \cdot \frac{1 - re \cdot re}{\frac{1}{im \cdot 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 < -0.40000000000000002Initial program 100.0%
Taylor expanded in re around 0 2.4%
*-commutative2.4%
associate-*r*2.4%
*-commutative2.4%
distribute-lft1-in2.4%
distribute-rgt-out2.4%
+-commutative2.4%
*-commutative2.4%
unpow22.4%
associate-*l*2.4%
Simplified2.4%
Taylor expanded in re around inf 2.2%
unpow22.2%
*-commutative2.2%
associate-*r*2.2%
Simplified2.2%
Taylor expanded in im around 0 1.2%
*-commutative1.2%
*-commutative1.2%
unpow21.2%
associate-*l*1.2%
distribute-lft-out1.9%
unpow21.9%
Simplified1.9%
Taylor expanded in im around inf 10.2%
unpow210.2%
*-commutative10.2%
unpow210.2%
Simplified10.2%
if -0.40000000000000002 < re < 2.8499999999999999e-4Initial program 100.0%
Taylor expanded in re around 0 99.1%
*-rgt-identity99.1%
distribute-lft-in99.1%
Simplified99.1%
Taylor expanded in im around 0 51.0%
if 2.8499999999999999e-4 < re < 4.1999999999999997e100Initial program 100.0%
Taylor expanded in re around 0 7.7%
*-rgt-identity7.7%
distribute-lft-in7.7%
Simplified7.7%
Taylor expanded in im around 0 6.3%
associate-+r+6.3%
+-commutative6.3%
*-commutative6.3%
unpow26.3%
+-commutative6.3%
Simplified6.3%
flip-+6.3%
associate-*r/6.3%
metadata-eval6.3%
Applied egg-rr6.3%
*-commutative6.3%
associate-/l*6.3%
Simplified6.3%
Taylor expanded in re around 0 44.3%
unpow244.3%
Simplified44.3%
if 4.1999999999999997e100 < re Initial program 100.0%
Taylor expanded in re around 0 87.2%
*-commutative87.2%
associate-*r*87.2%
*-commutative87.2%
distribute-lft1-in87.2%
distribute-rgt-out87.2%
+-commutative87.2%
*-commutative87.2%
unpow287.2%
associate-*l*87.2%
Simplified87.2%
Taylor expanded in re around inf 87.2%
unpow287.2%
*-commutative87.2%
associate-*r*87.2%
Simplified87.2%
Taylor expanded in im around 0 2.7%
*-commutative2.7%
*-commutative2.7%
unpow22.7%
associate-*l*2.7%
distribute-lft-out73.3%
unpow273.3%
Simplified73.3%
Final simplification43.7%
(FPCore (re im) :precision binary64 (if (<= re -0.4) (* -0.25 (* (* re re) (* im im))) (if (<= re 3.8e+97) (+ re 1.0) (* (* re re) (+ 0.5 (* -0.25 (* im im)))))))
double code(double re, double im) {
double tmp;
if (re <= -0.4) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 3.8e+97) {
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 <= (-0.4d0)) then
tmp = (-0.25d0) * ((re * re) * (im * im))
else if (re <= 3.8d+97) 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 <= -0.4) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 3.8e+97) {
tmp = re + 1.0;
} else {
tmp = (re * re) * (0.5 + (-0.25 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.4: tmp = -0.25 * ((re * re) * (im * im)) elif re <= 3.8e+97: 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 <= -0.4) tmp = Float64(-0.25 * Float64(Float64(re * re) * Float64(im * im))); elseif (re <= 3.8e+97) 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 <= -0.4) tmp = -0.25 * ((re * re) * (im * im)); elseif (re <= 3.8e+97) 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, -0.4], N[(-0.25 * N[(N[(re * re), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 3.8e+97], 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 -0.4:\\
\;\;\;\;-0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot im\right)\right)\\
\mathbf{elif}\;re \leq 3.8 \cdot 10^{+97}:\\
\;\;\;\;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 < -0.40000000000000002Initial program 100.0%
Taylor expanded in re around 0 2.4%
*-commutative2.4%
associate-*r*2.4%
*-commutative2.4%
distribute-lft1-in2.4%
distribute-rgt-out2.4%
+-commutative2.4%
*-commutative2.4%
unpow22.4%
associate-*l*2.4%
Simplified2.4%
Taylor expanded in re around inf 2.2%
unpow22.2%
*-commutative2.2%
associate-*r*2.2%
Simplified2.2%
Taylor expanded in im around 0 1.2%
*-commutative1.2%
*-commutative1.2%
unpow21.2%
associate-*l*1.2%
distribute-lft-out1.9%
unpow21.9%
Simplified1.9%
Taylor expanded in im around inf 10.2%
unpow210.2%
*-commutative10.2%
unpow210.2%
Simplified10.2%
if -0.40000000000000002 < re < 3.80000000000000036e97Initial program 100.0%
Taylor expanded in re around 0 84.9%
*-rgt-identity84.9%
distribute-lft-in84.9%
Simplified84.9%
Taylor expanded in im around 0 44.2%
if 3.80000000000000036e97 < re Initial program 100.0%
Taylor expanded in re around 0 87.2%
*-commutative87.2%
associate-*r*87.2%
*-commutative87.2%
distribute-lft1-in87.2%
distribute-rgt-out87.2%
+-commutative87.2%
*-commutative87.2%
unpow287.2%
associate-*l*87.2%
Simplified87.2%
Taylor expanded in re around inf 87.2%
unpow287.2%
*-commutative87.2%
associate-*r*87.2%
Simplified87.2%
Taylor expanded in im around 0 2.7%
*-commutative2.7%
*-commutative2.7%
unpow22.7%
associate-*l*2.7%
distribute-lft-out73.3%
unpow273.3%
Simplified73.3%
Final simplification40.7%
(FPCore (re im) :precision binary64 (if (<= re -0.4) (* -0.25 (* (* re re) (* im im))) (if (<= re 2.7) (+ re 1.0) (* (* re re) 0.5))))
double code(double re, double im) {
double tmp;
if (re <= -0.4) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 2.7) {
tmp = re + 1.0;
} else {
tmp = (re * 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.4d0)) then
tmp = (-0.25d0) * ((re * re) * (im * im))
else if (re <= 2.7d0) then
tmp = re + 1.0d0
else
tmp = (re * re) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.4) {
tmp = -0.25 * ((re * re) * (im * im));
} else if (re <= 2.7) {
tmp = re + 1.0;
} else {
tmp = (re * re) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.4: tmp = -0.25 * ((re * re) * (im * im)) elif re <= 2.7: tmp = re + 1.0 else: tmp = (re * re) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= -0.4) tmp = Float64(-0.25 * Float64(Float64(re * re) * Float64(im * im))); elseif (re <= 2.7) tmp = Float64(re + 1.0); else tmp = Float64(Float64(re * re) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.4) tmp = -0.25 * ((re * re) * (im * im)); elseif (re <= 2.7) tmp = re + 1.0; else tmp = (re * re) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.4], N[(-0.25 * N[(N[(re * re), $MachinePrecision] * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.7], N[(re + 1.0), $MachinePrecision], N[(N[(re * re), $MachinePrecision] * 0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.4:\\
\;\;\;\;-0.25 \cdot \left(\left(re \cdot re\right) \cdot \left(im \cdot im\right)\right)\\
\mathbf{elif}\;re \leq 2.7:\\
\;\;\;\;re + 1\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot re\right) \cdot 0.5\\
\end{array}
\end{array}
if re < -0.40000000000000002Initial program 100.0%
Taylor expanded in re around 0 2.4%
*-commutative2.4%
associate-*r*2.4%
*-commutative2.4%
distribute-lft1-in2.4%
distribute-rgt-out2.4%
+-commutative2.4%
*-commutative2.4%
unpow22.4%
associate-*l*2.4%
Simplified2.4%
Taylor expanded in re around inf 2.2%
unpow22.2%
*-commutative2.2%
associate-*r*2.2%
Simplified2.2%
Taylor expanded in im around 0 1.2%
*-commutative1.2%
*-commutative1.2%
unpow21.2%
associate-*l*1.2%
distribute-lft-out1.9%
unpow21.9%
Simplified1.9%
Taylor expanded in im around inf 10.2%
unpow210.2%
*-commutative10.2%
unpow210.2%
Simplified10.2%
if -0.40000000000000002 < re < 2.7000000000000002Initial program 100.0%
Taylor expanded in re around 0 98.2%
*-rgt-identity98.2%
distribute-lft-in98.2%
Simplified98.2%
Taylor expanded in im around 0 50.9%
if 2.7000000000000002 < re Initial program 100.0%
Taylor expanded in re around 0 64.6%
*-commutative64.6%
associate-*r*64.6%
*-commutative64.6%
distribute-lft1-in64.6%
distribute-rgt-out64.6%
+-commutative64.6%
*-commutative64.6%
unpow264.6%
associate-*l*64.6%
Simplified64.6%
Taylor expanded in re around inf 64.6%
unpow264.6%
*-commutative64.6%
associate-*r*64.6%
Simplified64.6%
Taylor expanded in im around 0 50.2%
unpow250.2%
Simplified50.2%
Final simplification39.6%
(FPCore (re im) :precision binary64 (if (<= re 1.45) 1.0 (* (* re re) 0.5)))
double code(double re, double im) {
double tmp;
if (re <= 1.45) {
tmp = 1.0;
} else {
tmp = (re * 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 <= 1.45d0) then
tmp = 1.0d0
else
tmp = (re * re) * 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.45) {
tmp = 1.0;
} else {
tmp = (re * re) * 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.45: tmp = 1.0 else: tmp = (re * re) * 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= 1.45) tmp = 1.0; else tmp = Float64(Float64(re * re) * 0.5); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.45) tmp = 1.0; else tmp = (re * re) * 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.45], 1.0, N[(N[(re * re), $MachinePrecision] * 0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.45:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\left(re \cdot re\right) \cdot 0.5\\
\end{array}
\end{array}
if re < 1.44999999999999996Initial program 100.0%
Taylor expanded in re around 0 62.2%
*-rgt-identity62.2%
distribute-lft-in62.2%
Simplified62.2%
Taylor expanded in im around 0 29.7%
associate-+r+29.7%
+-commutative29.7%
*-commutative29.7%
unpow229.7%
+-commutative29.7%
Simplified29.7%
Taylor expanded in re around inf 30.3%
unpow230.3%
*-commutative30.3%
associate-*r*30.3%
associate-*r*30.3%
*-commutative30.3%
associate-*l*30.3%
*-commutative30.3%
Simplified30.3%
Taylor expanded in re around 0 32.6%
if 1.44999999999999996 < re Initial program 100.0%
Taylor expanded in re around 0 64.6%
*-commutative64.6%
associate-*r*64.6%
*-commutative64.6%
distribute-lft1-in64.6%
distribute-rgt-out64.6%
+-commutative64.6%
*-commutative64.6%
unpow264.6%
associate-*l*64.6%
Simplified64.6%
Taylor expanded in re around inf 64.6%
unpow264.6%
*-commutative64.6%
associate-*r*64.6%
Simplified64.6%
Taylor expanded in im around 0 50.2%
unpow250.2%
Simplified50.2%
Final simplification37.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 46.7%
*-rgt-identity46.7%
distribute-lft-in46.7%
Simplified46.7%
Taylor expanded in im around 0 25.0%
Final simplification25.0%
(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 46.7%
*-rgt-identity46.7%
distribute-lft-in46.7%
Simplified46.7%
Taylor expanded in im around 0 25.7%
associate-+r+25.7%
+-commutative25.7%
*-commutative25.7%
unpow225.7%
+-commutative25.7%
Simplified25.7%
Taylor expanded in re around inf 26.1%
unpow226.1%
*-commutative26.1%
associate-*r*26.2%
associate-*r*26.2%
*-commutative26.2%
associate-*l*26.2%
*-commutative26.2%
Simplified26.2%
Taylor expanded in re around 0 24.4%
Final simplification24.4%
herbie shell --seed 2023230
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))