
(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 10 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(Float64(-im)) + exp(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%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 2.6)
(fma (* t_0 im) im (sin re))
(if (<= im 1.95e+149)
(* (+ (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 <= 2.6) {
tmp = fma((t_0 * im), im, sin(re));
} else if (im <= 1.95e+149) {
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 <= 2.6) tmp = fma(Float64(t_0 * im), im, sin(re)); elseif (im <= 1.95e+149) tmp = Float64(Float64(exp(Float64(-im)) + exp(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, 2.6], N[(N[(t$95$0 * im), $MachinePrecision] * im + N[Sin[re], $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.95e+149], 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 2.6:\\
\;\;\;\;\mathsf{fma}\left(t_0 \cdot im, im, \sin re\right)\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+149}:\\
\;\;\;\;\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 < 2.60000000000000009Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 81.6%
distribute-rgt-in81.6%
associate-*r*81.6%
metadata-eval81.6%
*-un-lft-identity81.6%
+-commutative81.6%
*-commutative81.6%
unpow281.6%
associate-*r*77.5%
fma-def77.5%
Applied egg-rr77.5%
if 2.60000000000000009 < im < 1.95e149Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 82.5%
if 1.95e149 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 94.8%
Taylor expanded in im around inf 94.8%
associate-*r*94.8%
*-commutative94.8%
associate-*r*94.8%
Simplified94.8%
Final simplification80.6%
(FPCore (re im)
:precision binary64
(if (<= im 6.2e+14)
(sin re)
(if (<= im 1.98e+59)
(pow re -4.0)
(if (<= im 1.3e+154)
(+ re (* (pow re 3.0) -0.16666666666666666))
(* (* 0.5 (sin re)) (pow im 2.0))))))
double code(double re, double im) {
double tmp;
if (im <= 6.2e+14) {
tmp = sin(re);
} else if (im <= 1.98e+59) {
tmp = pow(re, -4.0);
} else if (im <= 1.3e+154) {
tmp = re + (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 <= 6.2d+14) then
tmp = sin(re)
else if (im <= 1.98d+59) then
tmp = re ** (-4.0d0)
else if (im <= 1.3d+154) then
tmp = re + ((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 <= 6.2e+14) {
tmp = Math.sin(re);
} else if (im <= 1.98e+59) {
tmp = Math.pow(re, -4.0);
} else if (im <= 1.3e+154) {
tmp = re + (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 <= 6.2e+14: tmp = math.sin(re) elif im <= 1.98e+59: tmp = math.pow(re, -4.0) elif im <= 1.3e+154: tmp = re + (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 <= 6.2e+14) tmp = sin(re); elseif (im <= 1.98e+59) tmp = re ^ -4.0; elseif (im <= 1.3e+154) tmp = Float64(re + 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 <= 6.2e+14) tmp = sin(re); elseif (im <= 1.98e+59) tmp = re ^ -4.0; elseif (im <= 1.3e+154) tmp = re + ((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, 6.2e+14], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.98e+59], N[Power[re, -4.0], $MachinePrecision], If[LessEqual[im, 1.3e+154], N[(re + 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 6.2 \cdot 10^{+14}:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.98 \cdot 10^{+59}:\\
\;\;\;\;{re}^{-4}\\
\mathbf{elif}\;im \leq 1.3 \cdot 10^{+154}:\\
\;\;\;\;re + {re}^{3} \cdot -0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 6.2e14Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 62.0%
if 6.2e14 < im < 1.98000000000000001e59Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 94.1%
Applied egg-rr31.7%
if 1.98000000000000001e59 < im < 1.29999999999999994e154Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 2.7%
Taylor expanded in re around 0 27.5%
Simplified27.5%
if 1.29999999999999994e154 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification61.7%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 5600000000.0)
(* t_0 (fma im im 2.0))
(if (<= im 1.25e+61)
(pow re -4.0)
(if (<= im 1.4e+154)
(+ re (* (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 <= 5600000000.0) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.25e+61) {
tmp = pow(re, -4.0);
} else if (im <= 1.4e+154) {
tmp = re + (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 <= 5600000000.0) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.25e+61) tmp = re ^ -4.0; elseif (im <= 1.4e+154) tmp = Float64(re + 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, 5600000000.0], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.25e+61], N[Power[re, -4.0], $MachinePrecision], If[LessEqual[im, 1.4e+154], N[(re + 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 5600000000:\\
\;\;\;\;t_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.25 \cdot 10^{+61}:\\
\;\;\;\;{re}^{-4}\\
\mathbf{elif}\;im \leq 1.4 \cdot 10^{+154}:\\
\;\;\;\;re + {re}^{3} \cdot -0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot {im}^{2}\\
\end{array}
\end{array}
if im < 5.6e9Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 80.7%
Taylor expanded in re around inf 80.7%
associate-*r*80.7%
*-commutative80.7%
+-commutative80.7%
unpow280.7%
fma-udef80.7%
Simplified80.7%
if 5.6e9 < im < 1.25000000000000004e61Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 94.1%
Applied egg-rr31.7%
if 1.25000000000000004e61 < im < 1.4e154Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 2.7%
Taylor expanded in re around 0 27.5%
Simplified27.5%
if 1.4e154 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 100.0%
Taylor expanded in im around inf 100.0%
associate-*r*100.0%
*-commutative100.0%
associate-*r*100.0%
Simplified100.0%
Final simplification75.1%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (sin re))))
(if (<= im 2.6)
(* t_0 (fma im im 2.0))
(if (<= im 1.95e+149)
(* (+ (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 <= 2.6) {
tmp = t_0 * fma(im, im, 2.0);
} else if (im <= 1.95e+149) {
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 <= 2.6) tmp = Float64(t_0 * fma(im, im, 2.0)); elseif (im <= 1.95e+149) tmp = Float64(Float64(exp(Float64(-im)) + exp(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, 2.6], N[(t$95$0 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1.95e+149], 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 2.6:\\
\;\;\;\;t_0 \cdot \mathsf{fma}\left(im, im, 2\right)\\
\mathbf{elif}\;im \leq 1.95 \cdot 10^{+149}:\\
\;\;\;\;\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 < 2.60000000000000009Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 81.6%
Taylor expanded in re around inf 81.6%
associate-*r*81.6%
*-commutative81.6%
+-commutative81.6%
unpow281.6%
fma-udef81.6%
Simplified81.6%
if 2.60000000000000009 < im < 1.95e149Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 82.5%
if 1.95e149 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 94.8%
Taylor expanded in im around inf 94.8%
associate-*r*94.8%
*-commutative94.8%
associate-*r*94.8%
Simplified94.8%
Final simplification83.5%
(FPCore (re im)
:precision binary64
(if (<= im 5600000000.0)
(sin re)
(if (<= im 1.75e+60)
(pow re -4.0)
(if (<= im 6.4e+118)
(+ re (* (pow re 3.0) -0.16666666666666666))
(* re (* 0.5 (fma im im 2.0)))))))
double code(double re, double im) {
double tmp;
if (im <= 5600000000.0) {
tmp = sin(re);
} else if (im <= 1.75e+60) {
tmp = pow(re, -4.0);
} else if (im <= 6.4e+118) {
tmp = re + (pow(re, 3.0) * -0.16666666666666666);
} else {
tmp = re * (0.5 * fma(im, im, 2.0));
}
return tmp;
}
function code(re, im) tmp = 0.0 if (im <= 5600000000.0) tmp = sin(re); elseif (im <= 1.75e+60) tmp = re ^ -4.0; elseif (im <= 6.4e+118) tmp = Float64(re + Float64((re ^ 3.0) * -0.16666666666666666)); else tmp = Float64(re * Float64(0.5 * fma(im, im, 2.0))); end return tmp end
code[re_, im_] := If[LessEqual[im, 5600000000.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.75e+60], N[Power[re, -4.0], $MachinePrecision], If[LessEqual[im, 6.4e+118], N[(re + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision], N[(re * N[(0.5 * N[(im * im + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5600000000:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.75 \cdot 10^{+60}:\\
\;\;\;\;{re}^{-4}\\
\mathbf{elif}\;im \leq 6.4 \cdot 10^{+118}:\\
\;\;\;\;re + {re}^{3} \cdot -0.16666666666666666\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left(0.5 \cdot \mathsf{fma}\left(im, im, 2\right)\right)\\
\end{array}
\end{array}
if im < 5.6e9Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 62.0%
if 5.6e9 < im < 1.7500000000000001e60Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 94.1%
Applied egg-rr31.7%
if 1.7500000000000001e60 < im < 6.40000000000000032e118Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 2.7%
Taylor expanded in re around 0 30.1%
Simplified30.1%
if 6.40000000000000032e118 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 79.7%
Taylor expanded in re around 0 71.1%
*-commutative71.1%
associate-*l*71.1%
+-commutative71.1%
unpow271.1%
fma-udef71.1%
Simplified71.1%
Final simplification59.7%
(FPCore (re im)
:precision binary64
(if (<= im 6400000000.0)
(sin re)
(if (<= im 1.5e+60)
(pow re -4.0)
(+ re (* (pow re 3.0) -0.16666666666666666)))))
double code(double re, double im) {
double tmp;
if (im <= 6400000000.0) {
tmp = sin(re);
} else if (im <= 1.5e+60) {
tmp = pow(re, -4.0);
} else {
tmp = re + (pow(re, 3.0) * -0.16666666666666666);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 6400000000.0d0) then
tmp = sin(re)
else if (im <= 1.5d+60) then
tmp = re ** (-4.0d0)
else
tmp = re + ((re ** 3.0d0) * (-0.16666666666666666d0))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 6400000000.0) {
tmp = Math.sin(re);
} else if (im <= 1.5e+60) {
tmp = Math.pow(re, -4.0);
} else {
tmp = re + (Math.pow(re, 3.0) * -0.16666666666666666);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 6400000000.0: tmp = math.sin(re) elif im <= 1.5e+60: tmp = math.pow(re, -4.0) else: tmp = re + (math.pow(re, 3.0) * -0.16666666666666666) return tmp
function code(re, im) tmp = 0.0 if (im <= 6400000000.0) tmp = sin(re); elseif (im <= 1.5e+60) tmp = re ^ -4.0; else tmp = Float64(re + Float64((re ^ 3.0) * -0.16666666666666666)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 6400000000.0) tmp = sin(re); elseif (im <= 1.5e+60) tmp = re ^ -4.0; else tmp = re + ((re ^ 3.0) * -0.16666666666666666); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 6400000000.0], N[Sin[re], $MachinePrecision], If[LessEqual[im, 1.5e+60], N[Power[re, -4.0], $MachinePrecision], N[(re + N[(N[Power[re, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 6400000000:\\
\;\;\;\;\sin re\\
\mathbf{elif}\;im \leq 1.5 \cdot 10^{+60}:\\
\;\;\;\;{re}^{-4}\\
\mathbf{else}:\\
\;\;\;\;re + {re}^{3} \cdot -0.16666666666666666\\
\end{array}
\end{array}
if im < 6.4e9Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 62.0%
if 6.4e9 < im < 1.4999999999999999e60Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 94.1%
Applied egg-rr31.7%
if 1.4999999999999999e60 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 2.7%
Taylor expanded in re around 0 16.4%
Simplified16.4%
Final simplification50.2%
(FPCore (re im) :precision binary64 (if (<= im 21000000000000.0) (sin re) (pow re -4.0)))
double code(double re, double im) {
double tmp;
if (im <= 21000000000000.0) {
tmp = sin(re);
} else {
tmp = pow(re, -4.0);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 21000000000000.0d0) then
tmp = sin(re)
else
tmp = re ** (-4.0d0)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 21000000000000.0) {
tmp = Math.sin(re);
} else {
tmp = Math.pow(re, -4.0);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 21000000000000.0: tmp = math.sin(re) else: tmp = math.pow(re, -4.0) return tmp
function code(re, im) tmp = 0.0 if (im <= 21000000000000.0) tmp = sin(re); else tmp = re ^ -4.0; end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 21000000000000.0) tmp = sin(re); else tmp = re ^ -4.0; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 21000000000000.0], N[Sin[re], $MachinePrecision], N[Power[re, -4.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 21000000000000:\\
\;\;\;\;\sin re\\
\mathbf{else}:\\
\;\;\;\;{re}^{-4}\\
\end{array}
\end{array}
if im < 2.1e13Initial program 100.0%
distribute-lft-in99.9%
*-commutative99.9%
cancel-sign-sub99.9%
distribute-lft-neg-out99.9%
*-commutative99.9%
distribute-rgt-neg-out99.9%
neg-mul-199.9%
associate-*r*99.9%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 62.0%
if 2.1e13 < im Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 79.2%
Applied egg-rr22.3%
Final simplification50.8%
(FPCore (re im) :precision binary64 (sin re))
double code(double re, double im) {
return sin(re);
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = sin(re)
end function
public static double code(double re, double im) {
return Math.sin(re);
}
def code(re, im): return math.sin(re)
function code(re, im) return sin(re) end
function tmp = code(re, im) tmp = sin(re); end
code[re_, im_] := N[Sin[re], $MachinePrecision]
\begin{array}{l}
\\
\sin re
\end{array}
Initial program 100.0%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in im around 0 45.3%
Final simplification45.3%
(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%
distribute-lft-in100.0%
*-commutative100.0%
cancel-sign-sub100.0%
distribute-lft-neg-out100.0%
*-commutative100.0%
distribute-rgt-neg-out100.0%
neg-mul-1100.0%
associate-*r*100.0%
distribute-rgt-out--100.0%
sub-neg100.0%
neg-sub0100.0%
*-commutative100.0%
neg-mul-1100.0%
remove-double-neg100.0%
Simplified100.0%
Taylor expanded in re around 0 61.1%
Taylor expanded in im around 0 22.1%
Final simplification22.1%
herbie shell --seed 2023312
(FPCore (re im)
:name "math.sin on complex, real part"
:precision binary64
(* (* 0.5 (sin re)) (+ (exp (- 0.0 im)) (exp im))))