
(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}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (re im)
:precision binary64
(let* ((t_0 (- (exp (- im)) (exp im))))
(if (or (<= t_0 -2e+110) (not (<= t_0 2e-10)))
(* t_0 (* 0.5 (sin re)))
(* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
double t_0 = exp(-im) - exp(im);
double tmp;
if ((t_0 <= -2e+110) || !(t_0 <= 2e-10)) {
tmp = t_0 * (0.5 * sin(re));
} else {
tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = exp(-im) - exp(im)
if ((t_0 <= (-2d+110)) .or. (.not. (t_0 <= 2d-10))) then
tmp = t_0 * (0.5d0 * sin(re))
else
tmp = sin(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = Math.exp(-im) - Math.exp(im);
double tmp;
if ((t_0 <= -2e+110) || !(t_0 <= 2e-10)) {
tmp = t_0 * (0.5 * Math.sin(re));
} else {
tmp = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
def code(re, im): t_0 = math.exp(-im) - math.exp(im) tmp = 0 if (t_0 <= -2e+110) or not (t_0 <= 2e-10): tmp = t_0 * (0.5 * math.sin(re)) else: tmp = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) return tmp
function code(re, im) t_0 = Float64(exp(Float64(-im)) - exp(im)) tmp = 0.0 if ((t_0 <= -2e+110) || !(t_0 <= 2e-10)) tmp = Float64(t_0 * Float64(0.5 * sin(re))); else tmp = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); end return tmp end
function tmp_2 = code(re, im) t_0 = exp(-im) - exp(im); tmp = 0.0; if ((t_0 <= -2e+110) || ~((t_0 <= 2e-10))) tmp = t_0 * (0.5 * sin(re)); else tmp = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im); end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -2e+110], N[Not[LessEqual[t$95$0, 2e-10]], $MachinePrecision]], N[(t$95$0 * N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := e^{-im} - e^{im}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+110} \lor \neg \left(t_0 \leq 2 \cdot 10^{-10}\right):\\
\;\;\;\;t_0 \cdot \left(0.5 \cdot \sin re\right)\\
\mathbf{else}:\\
\;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\end{array}
\end{array}
if (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < -2e110 or 2.00000000000000007e-10 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) Initial program 100.0%
if -2e110 < (-.f64 (exp.f64 (neg.f64 im)) (exp.f64 im)) < 2.00000000000000007e-10Initial program 29.4%
Taylor expanded in im around 0 99.8%
mul-1-neg99.8%
unsub-neg99.8%
*-commutative99.8%
associate-*l*99.8%
distribute-lft-out--99.8%
Simplified99.8%
Final simplification99.9%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (* (- (exp (- im)) (exp im)) re)))
(t_1 (* -0.16666666666666666 (* (sin re) (pow im 3.0)))))
(if (<= im -4.1e+93)
t_1
(if (<= im -0.0014)
t_0
(if (<= im 260.0)
(* im (- (sin re)))
(if (<= im 3.35e+100) t_0 t_1))))))
double code(double re, double im) {
double t_0 = 0.5 * ((exp(-im) - exp(im)) * re);
double t_1 = -0.16666666666666666 * (sin(re) * pow(im, 3.0));
double tmp;
if (im <= -4.1e+93) {
tmp = t_1;
} else if (im <= -0.0014) {
tmp = t_0;
} else if (im <= 260.0) {
tmp = im * -sin(re);
} else if (im <= 3.35e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * ((exp(-im) - exp(im)) * re)
t_1 = (-0.16666666666666666d0) * (sin(re) * (im ** 3.0d0))
if (im <= (-4.1d+93)) then
tmp = t_1
else if (im <= (-0.0014d0)) then
tmp = t_0
else if (im <= 260.0d0) then
tmp = im * -sin(re)
else if (im <= 3.35d+100) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * ((Math.exp(-im) - Math.exp(im)) * re);
double t_1 = -0.16666666666666666 * (Math.sin(re) * Math.pow(im, 3.0));
double tmp;
if (im <= -4.1e+93) {
tmp = t_1;
} else if (im <= -0.0014) {
tmp = t_0;
} else if (im <= 260.0) {
tmp = im * -Math.sin(re);
} else if (im <= 3.35e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * ((math.exp(-im) - math.exp(im)) * re) t_1 = -0.16666666666666666 * (math.sin(re) * math.pow(im, 3.0)) tmp = 0 if im <= -4.1e+93: tmp = t_1 elif im <= -0.0014: tmp = t_0 elif im <= 260.0: tmp = im * -math.sin(re) elif im <= 3.35e+100: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(Float64(exp(Float64(-im)) - exp(im)) * re)) t_1 = Float64(-0.16666666666666666 * Float64(sin(re) * (im ^ 3.0))) tmp = 0.0 if (im <= -4.1e+93) tmp = t_1; elseif (im <= -0.0014) tmp = t_0; elseif (im <= 260.0) tmp = Float64(im * Float64(-sin(re))); elseif (im <= 3.35e+100) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * ((exp(-im) - exp(im)) * re); t_1 = -0.16666666666666666 * (sin(re) * (im ^ 3.0)); tmp = 0.0; if (im <= -4.1e+93) tmp = t_1; elseif (im <= -0.0014) tmp = t_0; elseif (im <= 260.0) tmp = im * -sin(re); elseif (im <= 3.35e+100) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-0.16666666666666666 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -4.1e+93], t$95$1, If[LessEqual[im, -0.0014], t$95$0, If[LessEqual[im, 260.0], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 3.35e+100], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(\left(e^{-im} - e^{im}\right) \cdot re\right)\\
t_1 := -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -4.1 \cdot 10^{+93}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -0.0014:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 260:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\
\mathbf{elif}\;im \leq 3.35 \cdot 10^{+100}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -4.1000000000000001e93 or 3.3499999999999998e100 < im Initial program 100.0%
Taylor expanded in im around 0 97.0%
mul-1-neg97.0%
unsub-neg97.0%
*-commutative97.0%
associate-*l*97.0%
distribute-lft-out--97.0%
Simplified97.0%
Taylor expanded in im around inf 97.0%
if -4.1000000000000001e93 < im < -0.00139999999999999999 or 260 < im < 3.3499999999999998e100Initial program 100.0%
Taylor expanded in re around 0 86.1%
if -0.00139999999999999999 < im < 260Initial program 29.9%
Taylor expanded in im around 0 99.1%
mul-1-neg99.1%
*-commutative99.1%
distribute-rgt-neg-in99.1%
Simplified99.1%
Final simplification96.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* 0.5 (* (- (exp (- im)) (exp im)) re)))
(t_1 (* -0.16666666666666666 (* (sin re) (pow im 3.0)))))
(if (<= im -4.1e+93)
t_1
(if (<= im -0.31)
t_0
(if (<= im 260.0)
(* (sin re) (- (* (pow im 3.0) -0.16666666666666666) im))
(if (<= im 3.35e+100) t_0 t_1))))))
double code(double re, double im) {
double t_0 = 0.5 * ((exp(-im) - exp(im)) * re);
double t_1 = -0.16666666666666666 * (sin(re) * pow(im, 3.0));
double tmp;
if (im <= -4.1e+93) {
tmp = t_1;
} else if (im <= -0.31) {
tmp = t_0;
} else if (im <= 260.0) {
tmp = sin(re) * ((pow(im, 3.0) * -0.16666666666666666) - im);
} else if (im <= 3.35e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = 0.5d0 * ((exp(-im) - exp(im)) * re)
t_1 = (-0.16666666666666666d0) * (sin(re) * (im ** 3.0d0))
if (im <= (-4.1d+93)) then
tmp = t_1
else if (im <= (-0.31d0)) then
tmp = t_0
else if (im <= 260.0d0) then
tmp = sin(re) * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
else if (im <= 3.35d+100) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = 0.5 * ((Math.exp(-im) - Math.exp(im)) * re);
double t_1 = -0.16666666666666666 * (Math.sin(re) * Math.pow(im, 3.0));
double tmp;
if (im <= -4.1e+93) {
tmp = t_1;
} else if (im <= -0.31) {
tmp = t_0;
} else if (im <= 260.0) {
tmp = Math.sin(re) * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
} else if (im <= 3.35e+100) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(re, im): t_0 = 0.5 * ((math.exp(-im) - math.exp(im)) * re) t_1 = -0.16666666666666666 * (math.sin(re) * math.pow(im, 3.0)) tmp = 0 if im <= -4.1e+93: tmp = t_1 elif im <= -0.31: tmp = t_0 elif im <= 260.0: tmp = math.sin(re) * ((math.pow(im, 3.0) * -0.16666666666666666) - im) elif im <= 3.35e+100: tmp = t_0 else: tmp = t_1 return tmp
function code(re, im) t_0 = Float64(0.5 * Float64(Float64(exp(Float64(-im)) - exp(im)) * re)) t_1 = Float64(-0.16666666666666666 * Float64(sin(re) * (im ^ 3.0))) tmp = 0.0 if (im <= -4.1e+93) tmp = t_1; elseif (im <= -0.31) tmp = t_0; elseif (im <= 260.0) tmp = Float64(sin(re) * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); elseif (im <= 3.35e+100) tmp = t_0; else tmp = t_1; end return tmp end
function tmp_2 = code(re, im) t_0 = 0.5 * ((exp(-im) - exp(im)) * re); t_1 = -0.16666666666666666 * (sin(re) * (im ^ 3.0)); tmp = 0.0; if (im <= -4.1e+93) tmp = t_1; elseif (im <= -0.31) tmp = t_0; elseif (im <= 260.0) tmp = sin(re) * (((im ^ 3.0) * -0.16666666666666666) - im); elseif (im <= 3.35e+100) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(0.5 * N[(N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision] * re), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-0.16666666666666666 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -4.1e+93], t$95$1, If[LessEqual[im, -0.31], t$95$0, If[LessEqual[im, 260.0], N[(N[Sin[re], $MachinePrecision] * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 3.35e+100], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.5 \cdot \left(\left(e^{-im} - e^{im}\right) \cdot re\right)\\
t_1 := -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -4.1 \cdot 10^{+93}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;im \leq -0.31:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 260:\\
\;\;\;\;\sin re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\mathbf{elif}\;im \leq 3.35 \cdot 10^{+100}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if im < -4.1000000000000001e93 or 3.3499999999999998e100 < im Initial program 100.0%
Taylor expanded in im around 0 97.0%
mul-1-neg97.0%
unsub-neg97.0%
*-commutative97.0%
associate-*l*97.0%
distribute-lft-out--97.0%
Simplified97.0%
Taylor expanded in im around inf 97.0%
if -4.1000000000000001e93 < im < -0.309999999999999998 or 260 < im < 3.3499999999999998e100Initial program 100.0%
Taylor expanded in re around 0 86.1%
if -0.309999999999999998 < im < 260Initial program 29.9%
Taylor expanded in im around 0 99.1%
mul-1-neg99.1%
unsub-neg99.1%
*-commutative99.1%
associate-*l*99.1%
distribute-lft-out--99.1%
Simplified99.1%
Final simplification96.5%
(FPCore (re im)
:precision binary64
(let* ((t_0 (* -0.16666666666666666 (* (sin re) (pow im 3.0)))))
(if (<= im -2.4)
t_0
(if (<= im 3e+18)
(* im (- (sin re)))
(if (<= im 6e+99) (+ (* -2.25 (pow re 3.0)) (* re 13.5)) t_0)))))
double code(double re, double im) {
double t_0 = -0.16666666666666666 * (sin(re) * pow(im, 3.0));
double tmp;
if (im <= -2.4) {
tmp = t_0;
} else if (im <= 3e+18) {
tmp = im * -sin(re);
} else if (im <= 6e+99) {
tmp = (-2.25 * pow(re, 3.0)) + (re * 13.5);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: t_0
real(8) :: tmp
t_0 = (-0.16666666666666666d0) * (sin(re) * (im ** 3.0d0))
if (im <= (-2.4d0)) then
tmp = t_0
else if (im <= 3d+18) then
tmp = im * -sin(re)
else if (im <= 6d+99) then
tmp = ((-2.25d0) * (re ** 3.0d0)) + (re * 13.5d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double re, double im) {
double t_0 = -0.16666666666666666 * (Math.sin(re) * Math.pow(im, 3.0));
double tmp;
if (im <= -2.4) {
tmp = t_0;
} else if (im <= 3e+18) {
tmp = im * -Math.sin(re);
} else if (im <= 6e+99) {
tmp = (-2.25 * Math.pow(re, 3.0)) + (re * 13.5);
} else {
tmp = t_0;
}
return tmp;
}
def code(re, im): t_0 = -0.16666666666666666 * (math.sin(re) * math.pow(im, 3.0)) tmp = 0 if im <= -2.4: tmp = t_0 elif im <= 3e+18: tmp = im * -math.sin(re) elif im <= 6e+99: tmp = (-2.25 * math.pow(re, 3.0)) + (re * 13.5) else: tmp = t_0 return tmp
function code(re, im) t_0 = Float64(-0.16666666666666666 * Float64(sin(re) * (im ^ 3.0))) tmp = 0.0 if (im <= -2.4) tmp = t_0; elseif (im <= 3e+18) tmp = Float64(im * Float64(-sin(re))); elseif (im <= 6e+99) tmp = Float64(Float64(-2.25 * (re ^ 3.0)) + Float64(re * 13.5)); else tmp = t_0; end return tmp end
function tmp_2 = code(re, im) t_0 = -0.16666666666666666 * (sin(re) * (im ^ 3.0)); tmp = 0.0; if (im <= -2.4) tmp = t_0; elseif (im <= 3e+18) tmp = im * -sin(re); elseif (im <= 6e+99) tmp = (-2.25 * (re ^ 3.0)) + (re * 13.5); else tmp = t_0; end tmp_2 = tmp; end
code[re_, im_] := Block[{t$95$0 = N[(-0.16666666666666666 * N[(N[Sin[re], $MachinePrecision] * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[im, -2.4], t$95$0, If[LessEqual[im, 3e+18], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], If[LessEqual[im, 6e+99], N[(N[(-2.25 * N[Power[re, 3.0], $MachinePrecision]), $MachinePrecision] + N[(re * 13.5), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.16666666666666666 \cdot \left(\sin re \cdot {im}^{3}\right)\\
\mathbf{if}\;im \leq -2.4:\\
\;\;\;\;t_0\\
\mathbf{elif}\;im \leq 3 \cdot 10^{+18}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\
\mathbf{elif}\;im \leq 6 \cdot 10^{+99}:\\
\;\;\;\;-2.25 \cdot {re}^{3} + re \cdot 13.5\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if im < -2.39999999999999991 or 6.00000000000000029e99 < im Initial program 100.0%
Taylor expanded in im around 0 82.9%
mul-1-neg82.9%
unsub-neg82.9%
*-commutative82.9%
associate-*l*82.9%
distribute-lft-out--82.9%
Simplified82.9%
Taylor expanded in im around inf 82.9%
if -2.39999999999999991 < im < 3e18Initial program 31.0%
Taylor expanded in im around 0 97.6%
mul-1-neg97.6%
*-commutative97.6%
distribute-rgt-neg-in97.6%
Simplified97.6%
if 3e18 < im < 6.00000000000000029e99Initial program 100.0%
Applied egg-rr0.9%
Taylor expanded in re around 0 33.9%
Final simplification87.1%
(FPCore (re im)
:precision binary64
(if (<= im -1.3e+25)
(* -0.16666666666666666 (* re (pow im 3.0)))
(if (<= im 2150000000.0)
(* im (- (sin re)))
(* re (- (* (pow im 3.0) -0.16666666666666666) im)))))
double code(double re, double im) {
double tmp;
if (im <= -1.3e+25) {
tmp = -0.16666666666666666 * (re * pow(im, 3.0));
} else if (im <= 2150000000.0) {
tmp = im * -sin(re);
} else {
tmp = re * ((pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= (-1.3d+25)) then
tmp = (-0.16666666666666666d0) * (re * (im ** 3.0d0))
else if (im <= 2150000000.0d0) then
tmp = im * -sin(re)
else
tmp = re * (((im ** 3.0d0) * (-0.16666666666666666d0)) - im)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= -1.3e+25) {
tmp = -0.16666666666666666 * (re * Math.pow(im, 3.0));
} else if (im <= 2150000000.0) {
tmp = im * -Math.sin(re);
} else {
tmp = re * ((Math.pow(im, 3.0) * -0.16666666666666666) - im);
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -1.3e+25: tmp = -0.16666666666666666 * (re * math.pow(im, 3.0)) elif im <= 2150000000.0: tmp = im * -math.sin(re) else: tmp = re * ((math.pow(im, 3.0) * -0.16666666666666666) - im) return tmp
function code(re, im) tmp = 0.0 if (im <= -1.3e+25) tmp = Float64(-0.16666666666666666 * Float64(re * (im ^ 3.0))); elseif (im <= 2150000000.0) tmp = Float64(im * Float64(-sin(re))); else tmp = Float64(re * Float64(Float64((im ^ 3.0) * -0.16666666666666666) - im)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= -1.3e+25) tmp = -0.16666666666666666 * (re * (im ^ 3.0)); elseif (im <= 2150000000.0) tmp = im * -sin(re); else tmp = re * (((im ^ 3.0) * -0.16666666666666666) - im); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -1.3e+25], N[(-0.16666666666666666 * N[(re * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 2150000000.0], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], N[(re * N[(N[(N[Power[im, 3.0], $MachinePrecision] * -0.16666666666666666), $MachinePrecision] - im), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.3 \cdot 10^{+25}:\\
\;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\
\mathbf{elif}\;im \leq 2150000000:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\
\mathbf{else}:\\
\;\;\;\;re \cdot \left({im}^{3} \cdot -0.16666666666666666 - im\right)\\
\end{array}
\end{array}
if im < -1.2999999999999999e25Initial program 100.0%
Taylor expanded in im around 0 83.2%
mul-1-neg83.2%
unsub-neg83.2%
*-commutative83.2%
associate-*l*83.2%
distribute-lft-out--83.2%
Simplified83.2%
Taylor expanded in im around inf 83.2%
Taylor expanded in re around 0 61.9%
*-commutative61.9%
Simplified61.9%
if -1.2999999999999999e25 < im < 2.15e9Initial program 33.5%
Taylor expanded in im around 0 94.3%
mul-1-neg94.3%
*-commutative94.3%
distribute-rgt-neg-in94.3%
Simplified94.3%
if 2.15e9 < im Initial program 100.0%
Taylor expanded in im around 0 65.9%
mul-1-neg65.9%
unsub-neg65.9%
*-commutative65.9%
associate-*l*65.9%
distribute-lft-out--65.9%
Simplified65.9%
Taylor expanded in re around 0 61.5%
Final simplification79.3%
(FPCore (re im) :precision binary64 (if (or (<= im -1.1e+25) (not (<= im 540000000.0))) (* -0.16666666666666666 (* re (pow im 3.0))) (* im (- (sin re)))))
double code(double re, double im) {
double tmp;
if ((im <= -1.1e+25) || !(im <= 540000000.0)) {
tmp = -0.16666666666666666 * (re * pow(im, 3.0));
} else {
tmp = im * -sin(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if ((im <= (-1.1d+25)) .or. (.not. (im <= 540000000.0d0))) then
tmp = (-0.16666666666666666d0) * (re * (im ** 3.0d0))
else
tmp = im * -sin(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if ((im <= -1.1e+25) || !(im <= 540000000.0)) {
tmp = -0.16666666666666666 * (re * Math.pow(im, 3.0));
} else {
tmp = im * -Math.sin(re);
}
return tmp;
}
def code(re, im): tmp = 0 if (im <= -1.1e+25) or not (im <= 540000000.0): tmp = -0.16666666666666666 * (re * math.pow(im, 3.0)) else: tmp = im * -math.sin(re) return tmp
function code(re, im) tmp = 0.0 if ((im <= -1.1e+25) || !(im <= 540000000.0)) tmp = Float64(-0.16666666666666666 * Float64(re * (im ^ 3.0))); else tmp = Float64(im * Float64(-sin(re))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if ((im <= -1.1e+25) || ~((im <= 540000000.0))) tmp = -0.16666666666666666 * (re * (im ^ 3.0)); else tmp = im * -sin(re); end tmp_2 = tmp; end
code[re_, im_] := If[Or[LessEqual[im, -1.1e+25], N[Not[LessEqual[im, 540000000.0]], $MachinePrecision]], N[(-0.16666666666666666 * N[(re * N[Power[im, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1.1 \cdot 10^{+25} \lor \neg \left(im \leq 540000000\right):\\
\;\;\;\;-0.16666666666666666 \cdot \left(re \cdot {im}^{3}\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\
\end{array}
\end{array}
if im < -1.1e25 or 5.4e8 < im Initial program 100.0%
Taylor expanded in im around 0 74.3%
mul-1-neg74.3%
unsub-neg74.3%
*-commutative74.3%
associate-*l*74.3%
distribute-lft-out--74.3%
Simplified74.3%
Taylor expanded in im around inf 74.3%
Taylor expanded in re around 0 61.7%
*-commutative61.7%
Simplified61.7%
if -1.1e25 < im < 5.4e8Initial program 33.5%
Taylor expanded in im around 0 94.3%
mul-1-neg94.3%
*-commutative94.3%
distribute-rgt-neg-in94.3%
Simplified94.3%
Final simplification79.3%
(FPCore (re im) :precision binary64 (if (<= im -1350.0) (* im (* 0.0001984126984126984 (pow re 7.0))) (if (<= im 1220000.0) (* im (- (sin re))) (* im (- re)))))
double code(double re, double im) {
double tmp;
if (im <= -1350.0) {
tmp = im * (0.0001984126984126984 * pow(re, 7.0));
} else if (im <= 1220000.0) {
tmp = im * -sin(re);
} else {
tmp = im * -re;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= (-1350.0d0)) then
tmp = im * (0.0001984126984126984d0 * (re ** 7.0d0))
else if (im <= 1220000.0d0) then
tmp = im * -sin(re)
else
tmp = im * -re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= -1350.0) {
tmp = im * (0.0001984126984126984 * Math.pow(re, 7.0));
} else if (im <= 1220000.0) {
tmp = im * -Math.sin(re);
} else {
tmp = im * -re;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= -1350.0: tmp = im * (0.0001984126984126984 * math.pow(re, 7.0)) elif im <= 1220000.0: tmp = im * -math.sin(re) else: tmp = im * -re return tmp
function code(re, im) tmp = 0.0 if (im <= -1350.0) tmp = Float64(im * Float64(0.0001984126984126984 * (re ^ 7.0))); elseif (im <= 1220000.0) tmp = Float64(im * Float64(-sin(re))); else tmp = Float64(im * Float64(-re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= -1350.0) tmp = im * (0.0001984126984126984 * (re ^ 7.0)); elseif (im <= 1220000.0) tmp = im * -sin(re); else tmp = im * -re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, -1350.0], N[(im * N[(0.0001984126984126984 * N[Power[re, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[im, 1220000.0], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], N[(im * (-re)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq -1350:\\
\;\;\;\;im \cdot \left(0.0001984126984126984 \cdot {re}^{7}\right)\\
\mathbf{elif}\;im \leq 1220000:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(-re\right)\\
\end{array}
\end{array}
if im < -1350Initial program 100.0%
Taylor expanded in im around 0 4.7%
mul-1-neg4.7%
*-commutative4.7%
distribute-rgt-neg-in4.7%
Simplified4.7%
Taylor expanded in re around 0 3.4%
associate-+r+3.4%
+-commutative3.4%
associate-*r*3.4%
associate-*r*3.4%
distribute-rgt-out3.4%
associate-*r*3.4%
associate-*r*3.4%
distribute-rgt-out3.4%
distribute-lft-out6.7%
mul-1-neg6.7%
unsub-neg6.7%
Simplified6.7%
Taylor expanded in re around inf 28.2%
if -1350 < im < 1.22e6Initial program 31.0%
Taylor expanded in im around 0 97.7%
mul-1-neg97.7%
*-commutative97.7%
distribute-rgt-neg-in97.7%
Simplified97.7%
if 1.22e6 < im Initial program 100.0%
Taylor expanded in im around 0 4.2%
mul-1-neg4.2%
*-commutative4.2%
distribute-rgt-neg-in4.2%
Simplified4.2%
Taylor expanded in re around 0 22.4%
mul-1-neg22.4%
distribute-rgt-neg-in22.4%
Simplified22.4%
Final simplification62.9%
(FPCore (re im) :precision binary64 (if (<= im 5200.0) (* im (- (sin re))) (* im (- re))))
double code(double re, double im) {
double tmp;
if (im <= 5200.0) {
tmp = im * -sin(re);
} else {
tmp = im * -re;
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 5200.0d0) then
tmp = im * -sin(re)
else
tmp = im * -re
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 5200.0) {
tmp = im * -Math.sin(re);
} else {
tmp = im * -re;
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 5200.0: tmp = im * -math.sin(re) else: tmp = im * -re return tmp
function code(re, im) tmp = 0.0 if (im <= 5200.0) tmp = Float64(im * Float64(-sin(re))); else tmp = Float64(im * Float64(-re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 5200.0) tmp = im * -sin(re); else tmp = im * -re; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 5200.0], N[(im * (-N[Sin[re], $MachinePrecision])), $MachinePrecision], N[(im * (-re)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 5200:\\
\;\;\;\;im \cdot \left(-\sin re\right)\\
\mathbf{else}:\\
\;\;\;\;im \cdot \left(-re\right)\\
\end{array}
\end{array}
if im < 5200Initial program 52.9%
Taylor expanded in im around 0 68.2%
mul-1-neg68.2%
*-commutative68.2%
distribute-rgt-neg-in68.2%
Simplified68.2%
if 5200 < im Initial program 100.0%
Taylor expanded in im around 0 4.2%
mul-1-neg4.2%
*-commutative4.2%
distribute-rgt-neg-in4.2%
Simplified4.2%
Taylor expanded in re around 0 22.4%
mul-1-neg22.4%
distribute-rgt-neg-in22.4%
Simplified22.4%
Final simplification57.3%
(FPCore (re im) :precision binary64 (* im (- re)))
double code(double re, double im) {
return im * -re;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = im * -re
end function
public static double code(double re, double im) {
return im * -re;
}
def code(re, im): return im * -re
function code(re, im) return Float64(im * Float64(-re)) end
function tmp = code(re, im) tmp = im * -re; end
code[re_, im_] := N[(im * (-re)), $MachinePrecision]
\begin{array}{l}
\\
im \cdot \left(-re\right)
\end{array}
Initial program 64.2%
Taylor expanded in im around 0 52.9%
mul-1-neg52.9%
*-commutative52.9%
distribute-rgt-neg-in52.9%
Simplified52.9%
Taylor expanded in re around 0 33.9%
mul-1-neg33.9%
distribute-rgt-neg-in33.9%
Simplified33.9%
Final simplification33.9%
(FPCore (re im) :precision binary64 (* re 13.5))
double code(double re, double im) {
return re * 13.5;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = re * 13.5d0
end function
public static double code(double re, double im) {
return re * 13.5;
}
def code(re, im): return re * 13.5
function code(re, im) return Float64(re * 13.5) end
function tmp = code(re, im) tmp = re * 13.5; end
code[re_, im_] := N[(re * 13.5), $MachinePrecision]
\begin{array}{l}
\\
re \cdot 13.5
\end{array}
Initial program 64.2%
Applied egg-rr3.3%
Taylor expanded in re around 0 3.0%
*-commutative3.0%
Simplified3.0%
Final simplification3.0%
(FPCore (re im)
:precision binary64
(if (< (fabs im) 1.0)
(-
(*
(sin re)
(+
(+ im (* (* (* 0.16666666666666666 im) im) im))
(* (* (* (* (* 0.008333333333333333 im) im) im) im) im))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im)))))
double code(double re, double im) {
double tmp;
if (fabs(im) < 1.0) {
tmp = -(sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * sin(re)) * (exp(-im) - exp(im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (abs(im) < 1.0d0) then
tmp = -(sin(re) * ((im + (((0.16666666666666666d0 * im) * im) * im)) + (((((0.008333333333333333d0 * im) * im) * im) * im) * im)))
else
tmp = (0.5d0 * sin(re)) * (exp(-im) - exp(im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (Math.abs(im) < 1.0) {
tmp = -(Math.sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im)));
} else {
tmp = (0.5 * Math.sin(re)) * (Math.exp(-im) - Math.exp(im));
}
return tmp;
}
def code(re, im): tmp = 0 if math.fabs(im) < 1.0: tmp = -(math.sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))) else: tmp = (0.5 * math.sin(re)) * (math.exp(-im) - math.exp(im)) return tmp
function code(re, im) tmp = 0.0 if (abs(im) < 1.0) tmp = Float64(-Float64(sin(re) * Float64(Float64(im + Float64(Float64(Float64(0.16666666666666666 * im) * im) * im)) + Float64(Float64(Float64(Float64(Float64(0.008333333333333333 * im) * im) * im) * im) * im)))); else tmp = Float64(Float64(0.5 * sin(re)) * Float64(exp(Float64(-im)) - exp(im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (abs(im) < 1.0) tmp = -(sin(re) * ((im + (((0.16666666666666666 * im) * im) * im)) + (((((0.008333333333333333 * im) * im) * im) * im) * im))); else tmp = (0.5 * sin(re)) * (exp(-im) - exp(im)); end tmp_2 = tmp; end
code[re_, im_] := If[Less[N[Abs[im], $MachinePrecision], 1.0], (-N[(N[Sin[re], $MachinePrecision] * N[(N[(im + N[(N[(N[(0.16666666666666666 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(N[(0.008333333333333333 * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision] * im), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), N[(N[(0.5 * N[Sin[re], $MachinePrecision]), $MachinePrecision] * N[(N[Exp[(-im)], $MachinePrecision] - N[Exp[im], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|im\right| < 1:\\
\;\;\;\;-\sin re \cdot \left(\left(im + \left(\left(0.16666666666666666 \cdot im\right) \cdot im\right) \cdot im\right) + \left(\left(\left(\left(0.008333333333333333 \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right) \cdot im\right)\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sin re\right) \cdot \left(e^{-im} - e^{im}\right)\\
\end{array}
\end{array}
herbie shell --seed 2023224
(FPCore (re im)
:name "math.cos on complex, imaginary part"
:precision binary64
:herbie-target
(if (< (fabs im) 1.0) (- (* (sin re) (+ (+ im (* (* (* 0.16666666666666666 im) im) im)) (* (* (* (* (* 0.008333333333333333 im) im) im) im) im)))) (* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))
(* (* 0.5 (sin re)) (- (exp (- im)) (exp im))))