
(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)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
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 8 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)));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
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 (<= re 2.1e-35) (* 0.5 (sqrt (* 2.0 (- (hypot re im) re)))) (/ (* im 0.5) (sqrt re))))
double code(double re, double im) {
double tmp;
if (re <= 2.1e-35) {
tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re)));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
public static double code(double re, double im) {
double tmp;
if (re <= 2.1e-35) {
tmp = 0.5 * Math.sqrt((2.0 * (Math.hypot(re, im) - re)));
} else {
tmp = (im * 0.5) / Math.sqrt(re);
}
return tmp;
}
def code(re, im): tmp = 0 if re <= 2.1e-35: tmp = 0.5 * math.sqrt((2.0 * (math.hypot(re, im) - re))) else: tmp = (im * 0.5) / math.sqrt(re) return tmp
function code(re, im) tmp = 0.0 if (re <= 2.1e-35) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(hypot(re, 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 <= 2.1e-35) tmp = 0.5 * sqrt((2.0 * (hypot(re, im) - re))); else tmp = (im * 0.5) / sqrt(re); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, 2.1e-35], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[re ^ 2 + im ^ 2], $MachinePrecision] - 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 2.1 \cdot 10^{-35}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\mathsf{hypot}\left(re, im\right) - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < 2.1e-35Initial program 55.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites95.2%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites76.2%
Applied rewrites76.3%
(FPCore (re im)
:precision binary64
(if (<= re -4e+146)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re -2.8e-125)
(* 0.5 (sqrt (* 2.0 (- (sqrt (fma im im (* re re))) re))))
(if (<= re 2.1e-35)
(* 0.5 (sqrt (* (fma (/ re im) -2.0 2.0) im)))
(/ (* im 0.5) (sqrt re))))))
double code(double re, double im) {
double tmp;
if (re <= -4e+146) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= -2.8e-125) {
tmp = 0.5 * sqrt((2.0 * (sqrt(fma(im, im, (re * re))) - re)));
} else if (re <= 2.1e-35) {
tmp = 0.5 * sqrt((fma((re / im), -2.0, 2.0) * im));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -4e+146) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= -2.8e-125) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(sqrt(fma(im, im, Float64(re * re))) - re)))); elseif (re <= 2.1e-35) tmp = Float64(0.5 * sqrt(Float64(fma(Float64(re / im), -2.0, 2.0) * im))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
code[re_, im_] := If[LessEqual[re, -4e+146], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, -2.8e-125], N[(0.5 * N[Sqrt[N[(2.0 * N[(N[Sqrt[N[(im * im + N[(re * re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] * -2.0 + 2.0), $MachinePrecision] * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -4 \cdot 10^{+146}:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq -2.8 \cdot 10^{-125}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(\sqrt{\mathsf{fma}\left(im, im, re \cdot re\right)} - re\right)}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im}, -2, 2\right) \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -3.99999999999999973e146Initial program 4.2%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6484.4
Applied rewrites84.4%
if -3.99999999999999973e146 < re < -2.8e-125Initial program 79.6%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6479.6
Applied rewrites79.6%
if -2.8e-125 < re < 2.1e-35Initial program 50.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites90.7%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6484.1
Applied rewrites84.1%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites76.2%
Applied rewrites76.3%
(FPCore (re im)
:precision binary64
(if (<= re -0.88)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re 2.1e-35)
(* 0.5 (sqrt (* (fma (/ re im) -2.0 2.0) im)))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -0.88) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 2.1e-35) {
tmp = 0.5 * sqrt((fma((re / im), -2.0, 2.0) * im));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
function code(re, im) tmp = 0.0 if (re <= -0.88) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 2.1e-35) tmp = Float64(0.5 * sqrt(Float64(fma(Float64(re / im), -2.0, 2.0) * im))); else tmp = Float64(Float64(im * 0.5) / sqrt(re)); end return tmp end
code[re_, im_] := If[LessEqual[re, -0.88], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(0.5 * N[Sqrt[N[(N[(N[(re / im), $MachinePrecision] * -2.0 + 2.0), $MachinePrecision] * im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(im * 0.5), $MachinePrecision] / N[Sqrt[re], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.88:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;0.5 \cdot \sqrt{\mathsf{fma}\left(\frac{re}{im}, -2, 2\right) \cdot im}\\
\mathbf{else}:\\
\;\;\;\;\frac{im \cdot 0.5}{\sqrt{re}}\\
\end{array}
\end{array}
if re < -0.880000000000000004Initial program 50.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -0.880000000000000004 < re < 2.1e-35Initial program 57.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites93.1%
Taylor expanded in im around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites76.2%
Applied rewrites76.3%
(FPCore (re im)
:precision binary64
(if (<= re -0.88)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re 2.1e-35)
(* 0.5 (sqrt (* 2.0 (- im re))))
(/ (* im 0.5) (sqrt re)))))
double code(double re, double im) {
double tmp;
if (re <= -0.88) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 2.1e-35) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (im * 0.5) / sqrt(re);
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.88d0)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 2.1d-35) 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 <= -0.88) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 2.1e-35) {
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 <= -0.88: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 2.1e-35: 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 <= -0.88) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 2.1e-35) 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 <= -0.88) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 2.1e-35) 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, -0.88], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], 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 -0.88:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;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 < -0.880000000000000004Initial program 50.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -0.880000000000000004 < re < 2.1e-35Initial program 57.4%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6481.1
Applied rewrites81.1%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites76.2%
Applied rewrites76.3%
(FPCore (re im)
:precision binary64
(if (<= re -0.88)
(* 0.5 (sqrt (* -4.0 re)))
(if (<= re 2.1e-35)
(* 0.5 (sqrt (* 2.0 (- im re))))
(* (/ 0.5 (sqrt re)) im))))
double code(double re, double im) {
double tmp;
if (re <= -0.88) {
tmp = 0.5 * sqrt((-4.0 * re));
} else if (re <= 2.1e-35) {
tmp = 0.5 * sqrt((2.0 * (im - re)));
} else {
tmp = (0.5 / sqrt(re)) * im;
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.88d0)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else if (re <= 2.1d-35) then
tmp = 0.5d0 * sqrt((2.0d0 * (im - re)))
else
tmp = (0.5d0 / sqrt(re)) * im
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.88) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else if (re <= 2.1e-35) {
tmp = 0.5 * Math.sqrt((2.0 * (im - re)));
} else {
tmp = (0.5 / Math.sqrt(re)) * im;
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.88: tmp = 0.5 * math.sqrt((-4.0 * re)) elif re <= 2.1e-35: tmp = 0.5 * math.sqrt((2.0 * (im - re))) else: tmp = (0.5 / math.sqrt(re)) * im return tmp
function code(re, im) tmp = 0.0 if (re <= -0.88) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); elseif (re <= 2.1e-35) tmp = Float64(0.5 * sqrt(Float64(2.0 * Float64(im - re)))); else tmp = Float64(Float64(0.5 / sqrt(re)) * im); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.88) tmp = 0.5 * sqrt((-4.0 * re)); elseif (re <= 2.1e-35) tmp = 0.5 * sqrt((2.0 * (im - re))); else tmp = (0.5 / sqrt(re)) * im; end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.88], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], If[LessEqual[re, 2.1e-35], N[(0.5 * N[Sqrt[N[(2.0 * N[(im - re), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(0.5 / N[Sqrt[re], $MachinePrecision]), $MachinePrecision] * im), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.88:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{elif}\;re \leq 2.1 \cdot 10^{-35}:\\
\;\;\;\;0.5 \cdot \sqrt{2 \cdot \left(im - re\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{\sqrt{re}} \cdot im\\
\end{array}
\end{array}
if re < -0.880000000000000004Initial program 50.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -0.880000000000000004 < re < 2.1e-35Initial program 57.4%
Taylor expanded in re around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f6481.1
Applied rewrites81.1%
if 2.1e-35 < re Initial program 10.5%
Taylor expanded in re around inf
associate-*r*N/A
lower-*.f64N/A
associate-*r*N/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-sqrt.f64N/A
lower-/.f6475.6
Applied rewrites75.6%
Applied rewrites76.2%
Applied rewrites76.1%
(FPCore (re im) :precision binary64 (if (<= re -0.88) (* 0.5 (sqrt (* -4.0 re))) (* 0.5 (sqrt (+ im im)))))
double code(double re, double im) {
double tmp;
if (re <= -0.88) {
tmp = 0.5 * sqrt((-4.0 * re));
} else {
tmp = 0.5 * sqrt((im + im));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (re <= (-0.88d0)) then
tmp = 0.5d0 * sqrt(((-4.0d0) * re))
else
tmp = 0.5d0 * sqrt((im + im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (re <= -0.88) {
tmp = 0.5 * Math.sqrt((-4.0 * re));
} else {
tmp = 0.5 * Math.sqrt((im + im));
}
return tmp;
}
def code(re, im): tmp = 0 if re <= -0.88: tmp = 0.5 * math.sqrt((-4.0 * re)) else: tmp = 0.5 * math.sqrt((im + im)) return tmp
function code(re, im) tmp = 0.0 if (re <= -0.88) tmp = Float64(0.5 * sqrt(Float64(-4.0 * re))); else tmp = Float64(0.5 * sqrt(Float64(im + im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (re <= -0.88) tmp = 0.5 * sqrt((-4.0 * re)); else tmp = 0.5 * sqrt((im + im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[re, -0.88], N[(0.5 * N[Sqrt[N[(-4.0 * re), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(0.5 * N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;re \leq -0.88:\\
\;\;\;\;0.5 \cdot \sqrt{-4 \cdot re}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im + im}\\
\end{array}
\end{array}
if re < -0.880000000000000004Initial program 50.4%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites100.0%
Taylor expanded in re around -inf
lower-*.f6477.7
Applied rewrites77.7%
if -0.880000000000000004 < re Initial program 39.8%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites72.6%
Taylor expanded in re around 0
lower-*.f6460.5
Applied rewrites60.5%
Applied rewrites60.5%
(FPCore (re im) :precision binary64 (if (<= im 2.5e-243) 0.0 (* 0.5 (sqrt (+ im im)))))
double code(double re, double im) {
double tmp;
if (im <= 2.5e-243) {
tmp = 0.0;
} else {
tmp = 0.5 * sqrt((im + im));
}
return tmp;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
real(8) :: tmp
if (im <= 2.5d-243) then
tmp = 0.0d0
else
tmp = 0.5d0 * sqrt((im + im))
end if
code = tmp
end function
public static double code(double re, double im) {
double tmp;
if (im <= 2.5e-243) {
tmp = 0.0;
} else {
tmp = 0.5 * Math.sqrt((im + im));
}
return tmp;
}
def code(re, im): tmp = 0 if im <= 2.5e-243: tmp = 0.0 else: tmp = 0.5 * math.sqrt((im + im)) return tmp
function code(re, im) tmp = 0.0 if (im <= 2.5e-243) tmp = 0.0; else tmp = Float64(0.5 * sqrt(Float64(im + im))); end return tmp end
function tmp_2 = code(re, im) tmp = 0.0; if (im <= 2.5e-243) tmp = 0.0; else tmp = 0.5 * sqrt((im + im)); end tmp_2 = tmp; end
code[re_, im_] := If[LessEqual[im, 2.5e-243], 0.0, N[(0.5 * N[Sqrt[N[(im + im), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;im \leq 2.5 \cdot 10^{-243}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \sqrt{im + im}\\
\end{array}
\end{array}
if im < 2.5e-243Initial program 47.0%
Applied rewrites27.6%
if 2.5e-243 < im Initial program 41.5%
lift-sqrt.f64N/A
lift-+.f64N/A
lift-*.f64N/A
sqr-abs-revN/A
fp-cancel-sign-sub-invN/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
fp-cancel-sub-sign-invN/A
lift-*.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
remove-double-negN/A
remove-double-negN/A
remove-double-negN/A
unpow1N/A
metadata-evalN/A
sqrt-pow1N/A
pow2N/A
rem-sqrt-square-revN/A
Applied rewrites78.4%
Taylor expanded in re around 0
lower-*.f6457.9
Applied rewrites57.9%
Applied rewrites57.9%
(FPCore (re im) :precision binary64 0.0)
double code(double re, double im) {
return 0.0;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
real(8) function code(re, im)
use fmin_fmax_functions
real(8), intent (in) :: re
real(8), intent (in) :: im
code = 0.0d0
end function
public static double code(double re, double im) {
return 0.0;
}
def code(re, im): return 0.0
function code(re, im) return 0.0 end
function tmp = code(re, im) tmp = 0.0; end
code[re_, im_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 42.1%
Applied rewrites6.1%
herbie shell --seed 2024360
(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)))))