
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp((0.0d0 - im)) + exp(im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp((0.0 - im)) + Math.exp(im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp((0.0 - im)) + math.exp(im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(0.0 - im)) + exp(im))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp((0.0 - im)) + exp(im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[N[(0.0 - im), $MachinePrecision]], $MachinePrecision] + N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{0 - im} + e^{im}\right)
\end{array}
(FPCore (re im) :precision binary64 (* (* 0.5 (sin re)) (+ (exp im) (exp (- im)))))
double code(double re, double im) {
return (0.5 * sin(re)) * (exp(im) + exp(-im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = (0.5d0 * sin(re)) * (exp(im) + exp(-im))
end function
public static double code(double re, double im) {
return (0.5 * Math.sin(re)) * (Math.exp(im) + Math.exp(-im));
}
def code(re, im): return (0.5 * math.sin(re)) * (math.exp(im) + math.exp(-im))
function code(re, im) return Float64(Float64(0.5 * sin(re)) * Float64(exp(im) + exp(Float64(-im)))) end
function tmp = code(re, im) tmp = (0.5 * sin(re)) * (exp(im) + exp(-im)); end
code[re_, im_] := N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(0.5 \cdot \sin re\right) \cdot \left(e^{im} + e^{-im}\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 0.23)
(* t_0 (fma im im 2.0))
(if (<= im 1.34e+154)
(* (+ (exp im) (exp (- im))) (* 0.5 re))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 0.23) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.34e+154) {
tmp = (exp(im) + exp(-im)) * (0.5 * re);
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 0.23) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.34e+154) tmp = Float64(Float64(exp(im) + exp(Float64(-im))) * Float64(0.5 * re)); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 0.23], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.34e+154], N[(N[(N[Exp[im], $MachinePrecision] + N[Exp[(-im)], $MachinePrecision]), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 0.23:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.34 \cdot 10^{+154}:\\
\;\;\;\;\left(e^{im} + e^{-im}\right) \cdot \left(0.5 \cdot re\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 0.23000000000000001Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 85.6%
+-commutative43.0%
unpow243.0%
fma-define43.0%
Simplified85.6%
if 0.23000000000000001 < im < 1.34000000000000001e154Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 74.4%
associate-*r*74.4%
Simplified74.4%
if 1.34000000000000001e154 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
+-commutative61.5%
unpow261.5%
fma-define61.5%
Simplified100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification85.6%
(FPCore (re im)
:precision binary64
(if (<= im 60.0)
(sin re)
(if (<= im 1.8e+151)
(+ (+ re 8.0) (* (pow re 3.0) -0.16666666666666666))
(* (* 0.5 (sin re)) (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 60.0) {
tmp = sin(re);
} else if (im <= 1.8e+151) {
tmp = (re + 8.0) + (pow(re, 3.0) * -0.16666666666666666);
} else {
tmp = (0.5 * sin(re)) * pow(im, 2.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 60.0d0) then
tmp = sin(re)
else if (im <= 1.8d+151) then
tmp = (re + 8.0d0) + ((re ** 3.0d0) * (-0.16666666666666666d0))
else
tmp = (0.5d0 * sin(re)) * (im ** 2.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 60.0) {
tmp = Math.sin(re);
} else if (im <= 1.8e+151) {
tmp = (re + 8.0) + (Math.pow(re, 3.0) * -0.16666666666666666);
} else {
tmp = (0.5 * Math.sin(re)) * Math.pow(im, 2.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 60.0: tmp = math.sin(re) elif im <= 1.8e+151: tmp = (re + 8.0) + (math.pow(re, 3.0) * -0.16666666666666666) else: tmp = (0.5 * math.sin(re)) * math.pow(im, 2.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 60.0) tmp = sin(re); elseif (im <= 1.8e+151) tmp = Float64(Float64(re + 8.0) + Float64((re ^ 3.0) * -0.16666666666666666)); else tmp = Float64(Float64(0.5 * sin(re)) * (im ^ 2.0)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 60.0) tmp = sin(re); elseif (im <= 1.8e+151) tmp = (re + 8.0) + ((re ^ 3.0) * -0.16666666666666666); else tmp = (0.5 * sin(re)) * (im ^ 2.0); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 60.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.8e+151], N[(N[(re + 8.0), $MachinePrecision] + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 60:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.8 \cdot 10^{+151}:\\
\;\;\;\;\left(re + 8\right) + {re}^{3} \cdot -0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 60Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 66.6%
if 60 < im < 1.8e151Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 48.8%
associate-*r*48.8%
associate-*r*48.8%
distribute-rgt-out48.8%
Simplified48.8%
Applied egg-rr1.9%
Taylor expanded in re around 0 25.8%
associate-+r+25.8%
+-commutative25.8%
*-commutative25.8%
Simplified25.8%
if 1.8e151 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 96.8%
+-commutative63.0%
unpow263.0%
fma-define63.0%
Simplified96.8%
Taylor expanded in im around inf 96.8%
associate-*r*96.8%
*-commutative96.8%
associate-*r*96.8%
Simplified96.8%
Final simplification64.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 60.0)
(* t_0 (fma im im 2.0))
(if (<= im 2.15e+151)
(+ (+ re 8.0) (* (pow re 3.0) -0.16666666666666666))
(* t_0 (pow im 2.0))))))
double code(double re, double im) {
double t_0 = 0.5 * sin(re);
double tmp;
if (im <= 60.0) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 2.15e+151) {
tmp = (re + 8.0) + (pow(re, 3.0) * -0.16666666666666666);
} else {
tmp = t_0 * pow(im, 2.0);
}
return tmp;
}
function code(re, im) t_0 = Float64(0.5 * sin(re)) tmp = 0.0 if (im <= 60.0) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 2.15e+151) tmp = Float64(Float64(re + 8.0) + Float64((re ^ 3.0) * -0.16666666666666666)); else tmp = Float64(t_0 * (im ^ 2.0)); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, 60.0], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2.15e+151], N[(N[(re + 8.0), $MachinePrecision] + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision], N[(t$95$0 * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \sin re\\
\mathbf{if}\;im \leq 60:\\
\;\;\;\;t\_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 2.15 \cdot 10^{+151}:\\
\;\;\;\;\left(re + 8\right) + {re}^{3} \cdot -0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 60Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 84.9%
+-commutative42.7%
unpow242.7%
fma-define42.7%
Simplified84.9%
if 60 < im < 2.14999999999999991e151Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 48.8%
associate-*r*48.8%
associate-*r*48.8%
distribute-rgt-out48.8%
Simplified48.8%
Applied egg-rr1.9%
Taylor expanded in re around 0 25.8%
associate-+r+25.8%
+-commutative25.8%
*-commutative25.8%
Simplified25.8%
if 2.14999999999999991e151 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 96.8%
+-commutative63.0%
unpow263.0%
fma-define63.0%
Simplified96.8%
Taylor expanded in im around inf 96.8%
associate-*r*96.8%
*-commutative96.8%
associate-*r*96.8%
Simplified96.8%
Final simplification78.8%
(FPCore (re im)
:precision binary64
(if (<= im 60.0)
(sin re)
(if (<= im 1.08e+129)
(+ (+ re 8.0) (* (pow re 3.0) -0.16666666666666666))
(* (fma im im 2.0) (* 0.5 re)))))
double code(double re, double im) {
double tmp;
if (im <= 60.0) {
tmp = sin(re);
} else if (im <= 1.08e+129) {
tmp = (re + 8.0) + (pow(re, 3.0) * -0.16666666666666666);
} else {
tmp = fma(im, im, 2.0) * (0.5 * re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 60.0) tmp = sin(re); elseif (im <= 1.08e+129) tmp = Float64(Float64(re + 8.0) + Float64((re ^ 3.0) * -0.16666666666666666)); else tmp = Float64(fma(im, im, 2.0) * Float64(0.5 * re)); end return tmp end
code[re_, im_] := If[LessEqual[im, 60.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.08e+129], N[(N[(re + 8.0), $MachinePrecision] + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 60:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.08 \cdot 10^{+129}:\\
\;\;\;\;\left(re + 8\right) + {re}^{3} \cdot -0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\
\end{array}
\end{array}
if im < 60Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 66.6%
if 60 < im < 1.08e129Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 36.9%
associate-*r*36.9%
associate-*r*36.9%
distribute-rgt-out36.9%
Simplified36.9%
Applied egg-rr2.0%
Taylor expanded in re around 0 24.0%
associate-+r+24.0%
+-commutative24.0%
*-commutative24.0%
Simplified24.0%
if 1.08e129 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 63.6%
associate-*r*63.6%
Simplified63.6%
Taylor expanded in im around 0 60.7%
+-commutative60.7%
unpow260.7%
fma-define60.7%
Simplified60.7%
Final simplification61.5%
(FPCore (re im) :precision binary64 (if (<= im 1.72e+22) (sin re) (* (fma im im 2.0) (* 0.5 re))))
double code(double re, double im) {
double tmp;
if (im <= 1.72e+22) {
tmp = sin(re);
} else {
tmp = fma(im, im, 2.0) * (0.5 * re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 1.72e+22) tmp = sin(re); else tmp = Float64(fma(im, im, 2.0) * Float64(0.5 * re)); end return tmp end
code[re_, im_] := If[LessEqual[im, 1.72e+22], N[Sin[re], $MachinePrecision], N[(N[(im * im + 2.0), $MachinePrecision] * N[(0.5 * re), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 1.72 \cdot 10^{+22}:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(im, im, 2\right) \cdot \left(0.5 \cdot re\right)\\
\end{array}
\end{array}
if im < 1.72e22Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 64.4%
if 1.72e22 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 69.2%
associate-*r*69.2%
Simplified69.2%
Taylor expanded in im around 0 41.5%
+-commutative41.5%
unpow241.5%
fma-define41.5%
Simplified41.5%
Final simplification59.8%
(FPCore (re im) :precision binary64 (if (<= im 4.3e+21) (sin re) (* 0.5 (* re (pow im 2.0)))))
double code(double re, double im) {
double tmp;
if (im <= 4.3e+21) {
tmp = sin(re);
} else {
tmp = 0.5 * (re * pow(im, 2.0));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 4.3d+21) then
tmp = sin(re)
else
tmp = 0.5d0 * (re * (im ** 2.0d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 4.3e+21) {
tmp = Math.sin(re);
} else {
tmp = 0.5 * (re * Math.pow(im, 2.0));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 4.3e+21: tmp = math.sin(re) else: tmp = 0.5 * (re * math.pow(im, 2.0)) return tmp
function code(re, im) tmp = 0.0 if (im <= 4.3e+21) tmp = sin(re); else tmp = Float64(0.5 * Float64(re * (im ^ 2.0))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 4.3e+21) tmp = sin(re); else tmp = 0.5 * (re * (im ^ 2.0)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 4.3e+21], N[Sin[re], $MachinePrecision], N[(0.5 * N[(re * N[Power[im, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 4.3 \cdot 10^{+21}:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(re \cdot {im}^{2}\right)\\
\end{array}
\end{array}
if im < 4.3e21Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 64.4%
if 4.3e21 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 69.2%
associate-*r*69.2%
Simplified69.2%
Taylor expanded in im around 0 41.5%
Taylor expanded in im around inf 41.5%
Final simplification59.8%
(FPCore (re im) :precision binary64 (if (<= im 2.3e+22) (sin re) (+ re (* 0.5 (* im (* re im))))))
double code(double re, double im) {
double tmp;
if (im <= 2.3e+22) {
tmp = sin(re);
} else {
tmp = re + (0.5 * (im * (re * im)));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.3d+22) then
tmp = sin(re)
else
tmp = re + (0.5d0 * (im * (re * im)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.3e+22) {
tmp = Math.sin(re);
} else {
tmp = re + (0.5 * (im * (re * im)));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.3e+22: tmp = math.sin(re) else: tmp = re + (0.5 * (im * (re * im))) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.3e+22) tmp = sin(re); else tmp = Float64(re + Float64(0.5 * Float64(im * Float64(re * im)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.3e+22) tmp = sin(re); else tmp = re + (0.5 * (im * (re * im))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.3e+22], N[Sin[re], $MachinePrecision], N[(re + N[(0.5 * N[(im * N[(re * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.3 \cdot 10^{+22}:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;re + 0.5 \cdot \left(im \cdot \left(re \cdot im\right)\right)\\
\end{array}
\end{array}
if im < 2.3000000000000002e22Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 64.4%
if 2.3000000000000002e22 < im Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 69.2%
associate-*r*69.2%
Simplified69.2%
Taylor expanded in im around 0 41.5%
add041.5%
fma-define41.5%
metadata-eval41.5%
fma-neg41.5%
*-commutative41.5%
unpow241.5%
associate-*r*32.5%
fma-neg32.5%
metadata-eval32.5%
Applied egg-rr32.5%
fma-undefine32.5%
add032.5%
*-commutative32.5%
Applied egg-rr32.5%
Final simplification57.9%
(FPCore (re im) :precision binary64 (+ re (* 0.5 (* im (* re im)))))
double code(double re, double im) {
return re + (0.5 * (im * (re * im)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re + (0.5d0 * (im * (re * im)))
end function
public static double code(double re, double im) {
return re + (0.5 * (im * (re * im)));
}
def code(re, im): return re + (0.5 * (im * (re * im)))
function code(re, im) return Float64(re + Float64(0.5 * Float64(im * Float64(re * im)))) end
function tmp = code(re, im) tmp = re + (0.5 * (im * (re * im))); end
code[re_, im_] := N[(re + N[(0.5 * N[(im * N[(re * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
re + 0.5 \cdot \left(im \cdot \left(re \cdot im\right)\right)
\end{array}
Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 54.4%
associate-*r*54.4%
Simplified54.4%
Taylor expanded in im around 0 41.3%
add041.3%
fma-define41.3%
metadata-eval41.3%
fma-neg41.3%
*-commutative41.3%
unpow241.3%
associate-*r*36.5%
fma-neg36.5%
metadata-eval36.5%
Applied egg-rr36.5%
fma-undefine36.5%
add036.5%
*-commutative36.5%
Applied egg-rr36.5%
Final simplification36.5%
(FPCore (re im) :precision binary64 (if (<= re 380000000000.0) re 0.5))
double code(double re, double im) {
double tmp;
if (re <= 380000000000.0) {
tmp = re;
} else {
tmp = 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 <= 380000000000.0d0) then
tmp = re
else
tmp = 0.5d0
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= 380000000000.0) {
tmp = re;
} else {
tmp = 0.5;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 380000000000.0: tmp = re else: tmp = 0.5 return tmp
function code(re, im) tmp = 0.0 if (re <= 380000000000.0) tmp = re; else tmp = 0.5; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= 380000000000.0) tmp = re; else tmp = 0.5; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 380000000000.0], re, 0.5]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq 380000000000:\\
\;\;\;\;re\\
\mathbf{else}:\\
\;\;\;\;0.5\\
\end{array}
\end{array}
if re < 3.8e11Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in re around 0 66.6%
associate-*r*66.6%
Simplified66.6%
Taylor expanded in im around 0 30.8%
if 3.8e11 < re Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Applied egg-rr6.9%
Final simplification24.4%
(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%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Taylor expanded in im around 0 87.3%
associate-*r*87.3%
associate-*r*87.3%
distribute-rgt-out87.3%
Simplified87.3%
Applied egg-rr5.0%
Taylor expanded in re around 0 5.6%
Final simplification5.6%
(FPCore (re im) :precision binary64 0.25)
double code(double re, double im) {
return 0.25;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.25d0
end function
public static double code(double re, double im) {
return 0.25;
}
def code(re, im): return 0.25
function code(re, im) return 0.25 end
function tmp = code(re, im) tmp = 0.25; end
code[re_, im_] := 0.25
\begin{array}{l}
\\
0.25
\end{array}
Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Applied egg-rr4.5%
Final simplification4.5%
(FPCore (re im) :precision binary64 0.5)
double code(double re, double im) {
return 0.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0
end function
public static double code(double re, double im) {
return 0.5;
}
def code(re, im): return 0.5
function code(re, im) return 0.5 end
function tmp = code(re, im) tmp = 0.5; end
code[re_, im_] := 0.5
\begin{array}{l}
\\
0.5
\end{array}
Initial program 100.0%
+-commutative100.0%
neg-sub0100.0%
Simplified100.0%
Applied egg-rr4.6%
Final simplification4.6%
herbie shell --seed 2024034
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))