
(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 (<= re 1.5e+78) (exp re) (* (exp re) (+ 1.0 (* -0.5 (* im im))))))
double code(double re, double im) {
double tmp;
if (re <= 1.5e+78) {
tmp = exp(re);
} else {
tmp = exp(re) * (1.0 + (-0.5 * (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 <= 1.5d+78) then
tmp = exp(re)
else
tmp = exp(re) * (1.0d0 + ((-0.5d0) * (im * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 1.5e+78) {
tmp = Math.exp(re);
} else {
tmp = Math.exp(re) * (1.0 + (-0.5 * (im * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 1.5e+78: tmp = math.exp(re) else: tmp = math.exp(re) * (1.0 + (-0.5 * (im * im))) return tmp
function code(re, im) tmp = 0.0 if (re <= 1.5e+78) tmp = exp(re); else tmp = Float64(exp(re) * Float64(1.0 + Float64(-0.5 * Float64(im * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 1.5e+78) tmp = exp(re); else tmp = exp(re) * (1.0 + (-0.5 * (im * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 1.5e+78], N[Exp[re], $MachinePrecision], N[(N[Exp[re], $MachinePrecision] * N[(1.0 + N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 1.5 \cdot 10^{+78}:\\
\;\;\;\;e^{re}\\
\mathbf{else}:\\
\;\;\;\;e^{re} \cdot \left(1 + -0.5 \cdot \left(im \cdot im\right)\right)\\
\end{array}
\end{array}
if re < 1.49999999999999991e78Initial program 100.0%
Taylor expanded in im around 0 57.0%
unpow257.0%
Simplified57.0%
Taylor expanded in im around 0 67.4%
if 1.49999999999999991e78 < re Initial program 100.0%
Taylor expanded in im around 0 73.8%
unpow273.8%
Simplified73.8%
Final simplification68.4%
(FPCore (re im) :precision binary64 (exp re))
double code(double re, double im) {
return exp(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = exp(re)
end function
public static double code(double re, double im) {
return Math.exp(re);
}
def code(re, im): return math.exp(re)
function code(re, im) return exp(re) end
function tmp = code(re, im) tmp = exp(re); end
code[re_, im_] := N[Exp[re], $MachinePrecision]
\begin{array}{l}
\\
e^{re}
\end{array}
Initial program 100.0%
Taylor expanded in im around 0 59.7%
unpow259.7%
Simplified59.7%
Taylor expanded in im around 0 66.1%
Final simplification66.1%
(FPCore (re im)
:precision binary64
(if (<= re -0.056)
(* -0.5 (* im im))
(if (<= re 1400000.0)
(+ re 1.0)
(if (<= re 3.3e+165)
(*
(* im im)
(+
(+ -0.5 (* re (* re -0.25)))
(* re (+ -0.5 (* (* re re) -0.08333333333333333)))))
(/ (- 1.0 (* re re)) (- 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 1400000.0) {
tmp = re + 1.0;
} else if (re <= 3.3e+165) {
tmp = (im * im) * ((-0.5 + (re * (re * -0.25))) + (re * (-0.5 + ((re * re) * -0.08333333333333333))));
} else {
tmp = (1.0 - (re * re)) / (1.0 - re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.056d0)) then
tmp = (-0.5d0) * (im * im)
else if (re <= 1400000.0d0) then
tmp = re + 1.0d0
else if (re <= 3.3d+165) then
tmp = (im * im) * (((-0.5d0) + (re * (re * (-0.25d0)))) + (re * ((-0.5d0) + ((re * re) * (-0.08333333333333333d0)))))
else
tmp = (1.0d0 - (re * re)) / (1.0d0 - re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 1400000.0) {
tmp = re + 1.0;
} else if (re <= 3.3e+165) {
tmp = (im * im) * ((-0.5 + (re * (re * -0.25))) + (re * (-0.5 + ((re * re) * -0.08333333333333333))));
} else {
tmp = (1.0 - (re * re)) / (1.0 - re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.056: tmp = -0.5 * (im * im) elif re <= 1400000.0: tmp = re + 1.0 elif re <= 3.3e+165: tmp = (im * im) * ((-0.5 + (re * (re * -0.25))) + (re * (-0.5 + ((re * re) * -0.08333333333333333)))) else: tmp = (1.0 - (re * re)) / (1.0 - re) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.056) tmp = Float64(-0.5 * Float64(im * im)); elseif (re <= 1400000.0) tmp = Float64(re + 1.0); elseif (re <= 3.3e+165) tmp = Float64(Float64(im * im) * Float64(Float64(-0.5 + Float64(re * Float64(re * -0.25))) + Float64(re * Float64(-0.5 + Float64(Float64(re * re) * -0.08333333333333333))))); else tmp = Float64(Float64(1.0 - Float64(re * re)) / Float64(1.0 - re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.056) tmp = -0.5 * (im * im); elseif (re <= 1400000.0) tmp = re + 1.0; elseif (re <= 3.3e+165) tmp = (im * im) * ((-0.5 + (re * (re * -0.25))) + (re * (-0.5 + ((re * re) * -0.08333333333333333)))); else tmp = (1.0 - (re * re)) / (1.0 - re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.056], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1400000.0], N[(re + 1.0), $MachinePrecision], If[LessEqual[re, 3.3e+165], N[(N[(im * im), $MachinePrecision] * N[(N[(-0.5 + N[(re * N[(re * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(re * N[(-0.5 + N[(N[(re * re), $MachinePrecision] * -0.08333333333333333), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[(re * re), $MachinePrecision]), $MachinePrecision] / N[(1.0 - re), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.056:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\
\mathbf{elif}\;re \leq 1400000:\\
\;\;\;\;re + 1\\
\mathbf{elif}\;re \leq 3.3 \cdot 10^{+165}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(\left(-0.5 + re \cdot \left(re \cdot -0.25\right)\right) + re \cdot \left(-0.5 + \left(re \cdot re\right) \cdot -0.08333333333333333\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - re \cdot re}{1 - re}\\
\end{array}
\end{array}
if re < -0.0560000000000000012Initial program 100.0%
Taylor expanded in im around 0 80.9%
unpow280.9%
Simplified80.9%
Taylor expanded in im around inf 78.2%
unpow278.2%
associate-*r*78.2%
*-commutative78.2%
associate-*r*78.2%
Simplified78.2%
Taylor expanded in re around 0 29.1%
unpow229.1%
Simplified29.1%
if -0.0560000000000000012 < re < 1.4e6Initial program 100.0%
Taylor expanded in im around 0 41.9%
unpow241.9%
Simplified41.9%
Taylor expanded in re around 0 40.2%
associate-+r+40.2%
*-commutative40.2%
distribute-rgt1-in40.4%
*-commutative40.4%
+-commutative40.4%
unpow240.4%
fma-udef40.4%
+-commutative40.4%
Simplified40.4%
Taylor expanded in im around 0 45.4%
+-commutative45.4%
Simplified45.4%
if 1.4e6 < re < 3.2999999999999999e165Initial program 100.0%
Taylor expanded in im around 0 69.7%
unpow269.7%
Simplified69.7%
Taylor expanded in im around inf 33.3%
unpow233.3%
associate-*r*33.3%
*-commutative33.3%
associate-*r*33.3%
Simplified33.3%
Taylor expanded in re around 0 33.5%
associate-+r+33.5%
+-commutative33.5%
associate-*r*33.5%
distribute-rgt-out33.5%
associate-*r*33.5%
associate-*r*33.5%
distribute-rgt-out33.5%
distribute-lft-out33.5%
unpow233.5%
unpow233.5%
associate-*r*33.5%
*-commutative33.5%
*-commutative33.5%
Simplified33.5%
if 3.2999999999999999e165 < re Initial program 100.0%
Taylor expanded in im around 0 75.0%
unpow275.0%
Simplified75.0%
Taylor expanded in re around 0 36.0%
associate-+r+36.0%
*-commutative36.0%
distribute-rgt1-in36.0%
*-commutative36.0%
+-commutative36.0%
unpow236.0%
fma-udef36.0%
+-commutative36.0%
Simplified36.0%
flip-+75.0%
associate-*r/75.0%
metadata-eval75.0%
Applied egg-rr75.0%
Taylor expanded in im around 0 62.5%
unpow262.5%
Simplified62.5%
Final simplification40.8%
(FPCore (re im)
:precision binary64
(if (<= re -0.056)
(* -0.5 (* im im))
(if (<= re 80000000.0)
(+ re 1.0)
(if (<= re 3.3e+165)
(* (* im im) (* -0.25 (* re re)))
(/ (- 1.0 (* re re)) (- 1.0 re))))))
double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 80000000.0) {
tmp = re + 1.0;
} else if (re <= 3.3e+165) {
tmp = (im * im) * (-0.25 * (re * re));
} else {
tmp = (1.0 - (re * re)) / (1.0 - re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.056d0)) then
tmp = (-0.5d0) * (im * im)
else if (re <= 80000000.0d0) then
tmp = re + 1.0d0
else if (re <= 3.3d+165) then
tmp = (im * im) * ((-0.25d0) * (re * re))
else
tmp = (1.0d0 - (re * re)) / (1.0d0 - re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 80000000.0) {
tmp = re + 1.0;
} else if (re <= 3.3e+165) {
tmp = (im * im) * (-0.25 * (re * re));
} else {
tmp = (1.0 - (re * re)) / (1.0 - re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.056: tmp = -0.5 * (im * im) elif re <= 80000000.0: tmp = re + 1.0 elif re <= 3.3e+165: tmp = (im * im) * (-0.25 * (re * re)) else: tmp = (1.0 - (re * re)) / (1.0 - re) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.056) tmp = Float64(-0.5 * Float64(im * im)); elseif (re <= 80000000.0) tmp = Float64(re + 1.0); elseif (re <= 3.3e+165) tmp = Float64(Float64(im * im) * Float64(-0.25 * Float64(re * re))); else tmp = Float64(Float64(1.0 - Float64(re * re)) / Float64(1.0 - re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.056) tmp = -0.5 * (im * im); elseif (re <= 80000000.0) tmp = re + 1.0; elseif (re <= 3.3e+165) tmp = (im * im) * (-0.25 * (re * re)); else tmp = (1.0 - (re * re)) / (1.0 - re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.056], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 80000000.0], N[(re + 1.0), $MachinePrecision], If[LessEqual[re, 3.3e+165], N[(N[(im * im), $MachinePrecision] * N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[(re * re), $MachinePrecision]), $MachinePrecision] / N[(1.0 - re), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.056:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\
\mathbf{elif}\;re \leq 80000000:\\
\;\;\;\;re + 1\\
\mathbf{elif}\;re \leq 3.3 \cdot 10^{+165}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - re \cdot re}{1 - re}\\
\end{array}
\end{array}
if re < -0.0560000000000000012Initial program 100.0%
Taylor expanded in im around 0 80.9%
unpow280.9%
Simplified80.9%
Taylor expanded in im around inf 78.2%
unpow278.2%
associate-*r*78.2%
*-commutative78.2%
associate-*r*78.2%
Simplified78.2%
Taylor expanded in re around 0 29.1%
unpow229.1%
Simplified29.1%
if -0.0560000000000000012 < re < 8e7Initial program 100.0%
Taylor expanded in im around 0 41.9%
unpow241.9%
Simplified41.9%
Taylor expanded in re around 0 40.2%
associate-+r+40.2%
*-commutative40.2%
distribute-rgt1-in40.4%
*-commutative40.4%
+-commutative40.4%
unpow240.4%
fma-udef40.4%
+-commutative40.4%
Simplified40.4%
Taylor expanded in im around 0 45.4%
+-commutative45.4%
Simplified45.4%
if 8e7 < re < 3.2999999999999999e165Initial program 100.0%
Taylor expanded in im around 0 69.7%
unpow269.7%
Simplified69.7%
Taylor expanded in im around inf 33.3%
unpow233.3%
associate-*r*33.3%
*-commutative33.3%
associate-*r*33.3%
Simplified33.3%
Taylor expanded in re around 0 31.0%
+-commutative31.0%
+-commutative31.0%
associate-+l+31.0%
associate-*r*31.0%
*-commutative31.0%
associate-*r*31.0%
distribute-rgt-out31.0%
metadata-eval31.0%
distribute-lft-in31.0%
distribute-lft-out31.0%
unpow231.0%
unpow231.0%
associate-*r*31.0%
*-commutative31.0%
*-commutative31.0%
distribute-lft-in31.0%
metadata-eval31.0%
Simplified31.0%
Taylor expanded in re around inf 31.0%
*-commutative31.0%
unpow231.0%
Simplified31.0%
if 3.2999999999999999e165 < re Initial program 100.0%
Taylor expanded in im around 0 75.0%
unpow275.0%
Simplified75.0%
Taylor expanded in re around 0 36.0%
associate-+r+36.0%
*-commutative36.0%
distribute-rgt1-in36.0%
*-commutative36.0%
+-commutative36.0%
unpow236.0%
fma-udef36.0%
+-commutative36.0%
Simplified36.0%
flip-+75.0%
associate-*r/75.0%
metadata-eval75.0%
Applied egg-rr75.0%
Taylor expanded in im around 0 62.5%
unpow262.5%
Simplified62.5%
Final simplification40.5%
(FPCore (re im) :precision binary64 (if (<= re -0.056) (* -0.5 (* im im)) (if (<= re 1500000.0) (+ re 1.0) (* (* im im) (* -0.25 (* re re))))))
double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 1500000.0) {
tmp = re + 1.0;
} else {
tmp = (im * im) * (-0.25 * (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 <= (-0.056d0)) then
tmp = (-0.5d0) * (im * im)
else if (re <= 1500000.0d0) then
tmp = re + 1.0d0
else
tmp = (im * im) * ((-0.25d0) * (re * re))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 1500000.0) {
tmp = re + 1.0;
} else {
tmp = (im * im) * (-0.25 * (re * re));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.056: tmp = -0.5 * (im * im) elif re <= 1500000.0: tmp = re + 1.0 else: tmp = (im * im) * (-0.25 * (re * re)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.056) tmp = Float64(-0.5 * Float64(im * im)); elseif (re <= 1500000.0) tmp = Float64(re + 1.0); else tmp = Float64(Float64(im * im) * Float64(-0.25 * Float64(re * re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.056) tmp = -0.5 * (im * im); elseif (re <= 1500000.0) tmp = re + 1.0; else tmp = (im * im) * (-0.25 * (re * re)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.056], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 1500000.0], N[(re + 1.0), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(-0.25 * N[(re * re), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.056:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\
\mathbf{elif}\;re \leq 1500000:\\
\;\;\;\;re + 1\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(-0.25 \cdot \left(re \cdot re\right)\right)\\
\end{array}
\end{array}
if re < -0.0560000000000000012Initial program 100.0%
Taylor expanded in im around 0 80.9%
unpow280.9%
Simplified80.9%
Taylor expanded in im around inf 78.2%
unpow278.2%
associate-*r*78.2%
*-commutative78.2%
associate-*r*78.2%
Simplified78.2%
Taylor expanded in re around 0 29.1%
unpow229.1%
Simplified29.1%
if -0.0560000000000000012 < re < 1.5e6Initial program 100.0%
Taylor expanded in im around 0 41.9%
unpow241.9%
Simplified41.9%
Taylor expanded in re around 0 40.2%
associate-+r+40.2%
*-commutative40.2%
distribute-rgt1-in40.4%
*-commutative40.4%
+-commutative40.4%
unpow240.4%
fma-udef40.4%
+-commutative40.4%
Simplified40.4%
Taylor expanded in im around 0 45.4%
+-commutative45.4%
Simplified45.4%
if 1.5e6 < re Initial program 100.0%
Taylor expanded in im around 0 71.9%
unpow271.9%
Simplified71.9%
Taylor expanded in im around inf 35.1%
unpow235.1%
associate-*r*35.1%
*-commutative35.1%
associate-*r*35.1%
Simplified35.1%
Taylor expanded in re around 0 33.8%
+-commutative33.8%
+-commutative33.8%
associate-+l+33.8%
associate-*r*33.8%
*-commutative33.8%
associate-*r*33.8%
distribute-rgt-out33.8%
metadata-eval33.8%
distribute-lft-in33.8%
distribute-lft-out33.8%
unpow233.8%
unpow233.8%
associate-*r*33.8%
*-commutative33.8%
*-commutative33.8%
distribute-lft-in33.8%
metadata-eval33.8%
Simplified33.8%
Taylor expanded in re around inf 33.8%
*-commutative33.8%
unpow233.8%
Simplified33.8%
Final simplification38.2%
(FPCore (re im) :precision binary64 (if (<= re -0.056) (* -0.5 (* im im)) (if (<= re 6700000.0) (+ re 1.0) (* (* im im) (* re -0.5)))))
double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 6700000.0) {
tmp = re + 1.0;
} else {
tmp = (im * im) * (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.056d0)) then
tmp = (-0.5d0) * (im * im)
else if (re <= 6700000.0d0) then
tmp = re + 1.0d0
else
tmp = (im * im) * (re * (-0.5d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.056) {
tmp = -0.5 * (im * im);
} else if (re <= 6700000.0) {
tmp = re + 1.0;
} else {
tmp = (im * im) * (re * -0.5);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.056: tmp = -0.5 * (im * im) elif re <= 6700000.0: tmp = re + 1.0 else: tmp = (im * im) * (re * -0.5) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.056) tmp = Float64(-0.5 * Float64(im * im)); elseif (re <= 6700000.0) tmp = Float64(re + 1.0); else tmp = Float64(Float64(im * im) * Float64(re * -0.5)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.056) tmp = -0.5 * (im * im); elseif (re <= 6700000.0) tmp = re + 1.0; else tmp = (im * im) * (re * -0.5); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.056], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6700000.0], N[(re + 1.0), $MachinePrecision], N[(N[(im * im), $MachinePrecision] * N[(re * -0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.056:\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\
\mathbf{elif}\;re \leq 6700000:\\
\;\;\;\;re + 1\\
\mathbf{else}:\\
\;\;\;\;\left(im \cdot im\right) \cdot \left(re \cdot -0.5\right)\\
\end{array}
\end{array}
if re < -0.0560000000000000012Initial program 100.0%
Taylor expanded in im around 0 80.9%
unpow280.9%
Simplified80.9%
Taylor expanded in im around inf 78.2%
unpow278.2%
associate-*r*78.2%
*-commutative78.2%
associate-*r*78.2%
Simplified78.2%
Taylor expanded in re around 0 29.1%
unpow229.1%
Simplified29.1%
if -0.0560000000000000012 < re < 6.7e6Initial program 100.0%
Taylor expanded in im around 0 41.9%
unpow241.9%
Simplified41.9%
Taylor expanded in re around 0 40.2%
associate-+r+40.2%
*-commutative40.2%
distribute-rgt1-in40.4%
*-commutative40.4%
+-commutative40.4%
unpow240.4%
fma-udef40.4%
+-commutative40.4%
Simplified40.4%
Taylor expanded in im around 0 45.4%
+-commutative45.4%
Simplified45.4%
if 6.7e6 < re Initial program 100.0%
Taylor expanded in im around 0 71.9%
unpow271.9%
Simplified71.9%
Taylor expanded in im around inf 35.1%
unpow235.1%
associate-*r*35.1%
*-commutative35.1%
associate-*r*35.1%
Simplified35.1%
Taylor expanded in re around 0 30.6%
+-commutative30.6%
associate-*r*30.6%
distribute-rgt-out30.6%
unpow230.6%
Simplified30.6%
Taylor expanded in re around inf 30.6%
unpow230.6%
associate-*r*30.6%
*-commutative30.6%
Simplified30.6%
Final simplification37.5%
(FPCore (re im) :precision binary64 (if (or (<= re -0.056) (not (<= re 1400000.0))) (* -0.5 (* im im)) (+ re 1.0)))
double code(double re, double im) {
double tmp;
if ((re <= -0.056) || !(re <= 1400000.0)) {
tmp = -0.5 * (im * im);
} else {
tmp = 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.056d0)) .or. (.not. (re <= 1400000.0d0))) then
tmp = (-0.5d0) * (im * im)
else
tmp = re + 1.0d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((re <= -0.056) || !(re <= 1400000.0)) {
tmp = -0.5 * (im * im);
} else {
tmp = re + 1.0;
}
return tmp;
}
def code(re, im): tmp = 0 if (re <= -0.056) or not (re <= 1400000.0): tmp = -0.5 * (im * im) else: tmp = re + 1.0 return tmp
function code(re, im) tmp = 0.0 if ((re <= -0.056) || !(re <= 1400000.0)) tmp = Float64(-0.5 * Float64(im * im)); else tmp = Float64(re + 1.0); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((re <= -0.056) || ~((re <= 1400000.0))) tmp = -0.5 * (im * im); else tmp = re + 1.0; end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[re, -0.056], N[Not[LessEqual[re, 1400000.0]], $MachinePrecision]], N[(-0.5 * N[(im * im), $MachinePrecision]), $MachinePrecision], N[(re + 1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.056 \lor \neg \left(re \leq 1400000\right):\\
\;\;\;\;-0.5 \cdot \left(im \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;re + 1\\
\end{array}
\end{array}
if re < -0.0560000000000000012 or 1.4e6 < re Initial program 100.0%
Taylor expanded in im around 0 77.0%
unpow277.0%
Simplified77.0%
Taylor expanded in im around inf 59.3%
unpow259.3%
associate-*r*59.3%
*-commutative59.3%
associate-*r*59.3%
Simplified59.3%
Taylor expanded in re around 0 23.9%
unpow223.9%
Simplified23.9%
if -0.0560000000000000012 < re < 1.4e6Initial program 100.0%
Taylor expanded in im around 0 41.9%
unpow241.9%
Simplified41.9%
Taylor expanded in re around 0 40.2%
associate-+r+40.2%
*-commutative40.2%
distribute-rgt1-in40.4%
*-commutative40.4%
+-commutative40.4%
unpow240.4%
fma-udef40.4%
+-commutative40.4%
Simplified40.4%
Taylor expanded in im around 0 45.4%
+-commutative45.4%
Simplified45.4%
Final simplification34.5%
(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 im around 0 59.7%
unpow259.7%
Simplified59.7%
Taylor expanded in re around 0 27.4%
associate-+r+27.4%
*-commutative27.4%
distribute-rgt1-in27.6%
*-commutative27.6%
+-commutative27.6%
unpow227.6%
fma-udef27.6%
+-commutative27.6%
Simplified27.6%
Taylor expanded in im around 0 23.7%
+-commutative23.7%
Simplified23.7%
Final simplification23.7%
(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 im around 0 59.7%
unpow259.7%
Simplified59.7%
Taylor expanded in re around 0 27.4%
associate-+r+27.4%
*-commutative27.4%
distribute-rgt1-in27.6%
*-commutative27.6%
+-commutative27.6%
unpow227.6%
fma-udef27.6%
+-commutative27.6%
Simplified27.6%
Taylor expanded in re around inf 9.5%
*-commutative9.5%
+-commutative9.5%
unpow29.5%
fma-udef9.5%
Simplified9.5%
Taylor expanded in im around 0 3.3%
Final simplification3.3%
herbie shell --seed 2023195
(FPCore (re im)
:name "math.exp on complex, real part"
:precision binary64
(* (exp re) (cos im)))