
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * (sqrt(((re * re) + (im * im))) - re)))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re)));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re)))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re)))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}
\end{array}
(FPCore (re im) :precision binary64 (if (<= (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re))) 0.0) (* 0.5 (* im (sqrt (/ 1.0 re)))) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re))))))
double code(double re, double im) {
double tmp;
if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im * sqrt((1.0 / re)));
} else {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (Math.sqrt((2.0 * (Math.sqrt(((re * re) + (im * im))) - re))) <= 0.0) {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
} else {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
}
return tmp;
}
def code(re, im): tmp = 0 if math.sqrt((2.0 * (math.sqrt(((re * re) + (im * im))) - re))) <= 0.0: tmp = 0.5 * (im * math.sqrt((1.0 / re))) else: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) return tmp
function code(re, im) tmp = 0.0 if (sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) <= 0.0) tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, im) - re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re))) <= 0.0) tmp = 0.5 * (im * sqrt((1.0 / re))); else tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 0.0], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)} \leq 0:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 5.5%
Taylor expanded in im around 0
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6455.1
Simplified55.1%
Taylor expanded in im around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6499.7
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 43.7%
lower-hypot.f6491.6
Applied egg-rr91.6%
(FPCore (re im)
:precision binary64
(let* ((t_0 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))
(if (<= t_0 0.0)
(* 0.5 (* im (sqrt (/ 1.0 re))))
(if (<= t_0 1e+77)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma re re (* im im))) re))))
(* (* 0.5 (sqrt 2.0)) (sqrt (- im re)))))))
double code(double re, double im) {
double t_0 = sqrt((2.0 * (sqrt(((re * re) + (im * im))) - re)));
double tmp;
if (t_0 <= 0.0) {
tmp = 0.5 * (im * sqrt((1.0 / re)));
} else if (t_0 <= 1e+77) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(re, re, (im * im))) - re)));
} else {
tmp = (0.5 * sqrt(2.0)) * sqrt((im - re));
}
return tmp;
}
function code(re, im) t_0 = sqrt(Float64(2.0 * Float64(sqrt(Float64(Float64(re * re) + Float64(im * im))) - re))) tmp = 0.0 if (t_0 <= 0.0) tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); elseif (t_0 <= 1e+77) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(re, re, Float64(im * im))) - re)))); else tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(im - re))); end return tmp end
code[re_, im_] := Block[{t$95$0 = N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(N[(re * re), $MachinePrecision] + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[t$95$0, 0.0], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 1e+77], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(re * re + N[(im * im), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(im - re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{2 \cdot \left(\sqrt{re \cdot re + im \cdot im} - re\right)}\\
\mathbf{if}\;t\_0 \leq 0:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\mathbf{elif}\;t\_0 \leq 10^{+77}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(re, re, im \cdot im\right)} - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{im - re}\\
\end{array}
\end{array}
if (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 0.0Initial program 5.5%
Taylor expanded in im around 0
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6455.1
Simplified55.1%
Taylor expanded in im around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6499.7
Simplified99.7%
if 0.0 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) < 9.99999999999999983e76Initial program 91.3%
lift-*.f64N/A
lift-*.f64N/A
lift-+.f64N/A
lift-sqrt.f64N/A
lift--.f64N/A
lift-*.f64N/A
lift-sqrt.f6491.3
lift-*.f64N/A
*-commutativeN/A
lower-*.f6491.3
lift-+.f64N/A
lift-*.f64N/A
lower-fma.f6491.3
Applied egg-rr91.3%
if 9.99999999999999983e76 < (sqrt.f64 (*.f64 #s(literal 2 binary64) (-.f64 (sqrt.f64 (+.f64 (*.f64 re re) (*.f64 im im))) re))) Initial program 3.6%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6461.9
Simplified61.9%
lift--.f64N/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6462.2
Applied egg-rr62.2%
Final simplification79.5%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 7.2e-24)
(* (* 0.5 (sqrt 2.0)) (sqrt (- im re)))
(* 0.5 (* im (sqrt (/ 1.0 re)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 7.2e-24) {
tmp = (0.5 * sqrt(2.0)) * sqrt((im - re));
} else {
tmp = 0.5 * (im * sqrt((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 <= (-1.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 7.2d-24) then
tmp = (0.5d0 * sqrt(2.0d0)) * sqrt((im - re))
else
tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 7.2e-24) {
tmp = (0.5 * Math.sqrt(2.0)) * Math.sqrt((im - re));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 7.2e-24: tmp = (0.5 * math.sqrt(2.0)) * math.sqrt((im - re)) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 7.2e-24) tmp = Float64(Float64(0.5 * sqrt(2.0)) * sqrt(Float64(im - re))); else tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 7.2e-24) tmp = (0.5 * sqrt(2.0)) * sqrt((im - re)); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 7.2e-24], N[(N[(0.5 * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(im - re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 7.2 \cdot 10^{-24}:\\
\;\;\;\;\left(0.5 \cdot \sqrt{2}\right) \cdot \sqrt{im - re}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Simplified81.9%
if -1.8e112 < re < 7.2000000000000002e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Simplified77.8%
lift--.f64N/A
sqrt-prodN/A
pow1/2N/A
pow1/2N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
pow1/2N/A
lower-sqrt.f64N/A
pow1/2N/A
lower-sqrt.f6477.9
Applied egg-rr77.9%
if 7.2000000000000002e-24 < re Initial program 9.7%
Taylor expanded in im around 0
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6451.9
Simplified51.9%
Taylor expanded in im around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6480.0
Simplified80.0%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6.4e-24)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* 0.5 (* im (sqrt (/ 1.0 re)))))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * sqrt((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 <= (-1.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.4d-24) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = 0.5d0 * (im * sqrt((1.0d0 / re)))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = 0.5 * (im * Math.sqrt((1.0 / re)));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.4e-24: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = 0.5 * (im * math.sqrt((1.0 / re))) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.4e-24) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(0.5 * Float64(im * sqrt(Float64(1.0 / re)))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.4e-24) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = 0.5 * (im * sqrt((1.0 / re))); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.4e-24], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(im * N[Sqrt[N[(1.0 / re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \left(im \cdot \sqrt{\frac{1}{re}}\right)\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Simplified81.9%
if -1.8e112 < re < 6.40000000000000025e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Simplified77.8%
if 6.40000000000000025e-24 < re Initial program 9.7%
Taylor expanded in im around 0
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
cube-multN/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-/.f6451.9
Simplified51.9%
Taylor expanded in im around 0
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f6480.0
Simplified80.0%
(FPCore (re im)
:precision binary64
(if (<= re -1.8e+112)
(* 0.5 (sqrt (* re -4.0)))
(if (<= re 6.4e-24)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-1.8d+112)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else if (re <= 6.4d-24) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (im * 0.5d0) / sqrt(re)
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -1.8e+112) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else if (re <= 6.4e-24) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -1.8e+112: tmp = 0.5 * math.sqrt((re * -4.0)) elif re <= 6.4e-24: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= -1.8e+112) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); elseif (re <= 6.4e-24) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -1.8e+112) tmp = 0.5 * sqrt((re * -4.0)); elseif (re <= 6.4e-24) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -1.8e+112], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 6.4e-24], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -1.8 \cdot 10^{+112}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{elif}\;re \leq 6.4 \cdot 10^{-24}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -1.8e112Initial program 21.5%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6481.9
Simplified81.9%
if -1.8e112 < re < 6.40000000000000025e-24Initial program 53.8%
Taylor expanded in re around 0
mul-1-negN/A
unsub-negN/A
lower--.f6477.8
Simplified77.8%
if 6.40000000000000025e-24 < re Initial program 9.7%
Taylor expanded in re around inf
lower-/.f64N/A
unpow2N/A
lower-*.f6452.1
Simplified52.1%
lift-*.f64N/A
lift-/.f64N/A
lift-sqrt.f64N/A
*-commutativeN/A
lift-sqrt.f64N/A
lift-/.f64N/A
sqrt-divN/A
associate-*l/N/A
lower-/.f64N/A
lift-*.f64N/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f64N/A
lower-sqrt.f6479.9
Applied egg-rr79.9%
(FPCore (re im) :precision binary64 (if (<= re -3.5e+78) (* 0.5 (sqrt (* re -4.0))) (* 0.5 (sqrt (* 2.0 im)))))
double code(double re, double im) {
double tmp;
if (re <= -3.5e+78) {
tmp = 0.5 * sqrt((re * -4.0));
} else {
tmp = 0.5 * sqrt((2.0 * im));
}
return tmp;
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-3.5d+78)) then
tmp = 0.5d0 * sqrt((re * (-4.0d0)))
else
tmp = 0.5d0 * sqrt((2.0d0 * im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -3.5e+78) {
tmp = 0.5 * Math.sqrt((re * -4.0));
} else {
tmp = 0.5 * Math.sqrt((2.0 * im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -3.5e+78: tmp = 0.5 * math.sqrt((re * -4.0)) else: tmp = 0.5 * math.sqrt((2.0 * im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -3.5e+78) tmp = Float64(0.5 * sqrt(Float64(re * -4.0))); else tmp = Float64(0.5 * sqrt(Float64(2.0 * im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -3.5e+78) tmp = 0.5 * sqrt((re * -4.0)); else tmp = 0.5 * sqrt((2.0 * im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -3.5e+78], N[(0.5 * N[Sqrt[N[(re * -4.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -3.5 \cdot 10^{+78}:\\
\;\;\;\;0.5 \cdot \sqrt{re \cdot -4}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot im}\\
\end{array}
\end{array}
if re < -3.5000000000000001e78Initial program 24.3%
Taylor expanded in re around -inf
*-commutativeN/A
lower-*.f6479.2
Simplified79.2%
if -3.5000000000000001e78 < re Initial program 40.1%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f6460.6
Simplified60.6%
Final simplification63.7%
(FPCore (re im) :precision binary64 (* 0.5 (sqrt (* 2.0 im))))
double code(double re, double im) {
return 0.5 * sqrt((2.0 * im));
}
real(8) function code(re, im)
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.5d0 * sqrt((2.0d0 * im))
end function
public static double code(double re, double im) {
return 0.5 * Math.sqrt((2.0 * im));
}
def code(re, im): return 0.5 * math.sqrt((2.0 * im))
function code(re, im) return Float64(0.5 * sqrt(Float64(2.0 * im))) end
function tmp = code(re, im) tmp = 0.5 * sqrt((2.0 * im)); end
code[re_, im_] := N[(0.5 * N[Sqrt[N[(2.0 * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \sqrt{2 \cdot im}
\end{array}
Initial program 37.5%
Taylor expanded in re around 0
*-commutativeN/A
lower-*.f6454.3
Simplified54.3%
Final simplification54.3%
herbie shell --seed 2024219
(FPCore (re im)
:name "math.sqrt on complex, imaginary part, im greater than 0 branch"
:precision binary64
:pre (> im 0.0)
(* 0.5 (sqrt (* 2.0 (- (sqrt (+ (* re re) (* im im))) re)))))