
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))
double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = ((a * c) + (b * d)) / ((c * c) + (d * d))
end function
public static double code(double a, double b, double c, double d) {
return ((a * c) + (b * d)) / ((c * c) + (d * d));
}
def code(a, b, c, d): return ((a * c) + (b * d)) / ((c * c) + (d * d))
function code(a, b, c, d) return Float64(Float64(Float64(a * c) + Float64(b * d)) / Float64(Float64(c * c) + Float64(d * d))) end
function tmp = code(a, b, c, d) tmp = ((a * c) + (b * d)) / ((c * c) + (d * d)); end
code[a_, b_, c_, d_] := N[(N[(N[(a * c), $MachinePrecision] + N[(b * d), $MachinePrecision]), $MachinePrecision] / N[(N[(c * c), $MachinePrecision] + N[(d * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{a \cdot c + b \cdot d}{c \cdot c + d \cdot d}
\end{array}
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma d d (* c c))))
(if (<= c -1.05e+128)
(/ a c)
(if (<= c -1.45e-26)
(fma a (/ c t_0) (* d (/ b t_0)))
(if (<= c 4.6e-145)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.3e+88)
(/ (fma d b (* c a)) t_0)
(/ (+ a (/ (* b d) c)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, (c * c));
double tmp;
if (c <= -1.05e+128) {
tmp = a / c;
} else if (c <= -1.45e-26) {
tmp = fma(a, (c / t_0), (d * (b / t_0)));
} else if (c <= 4.6e-145) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.3e+88) {
tmp = fma(d, b, (c * a)) / t_0;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = fma(d, d, Float64(c * c)) tmp = 0.0 if (c <= -1.05e+128) tmp = Float64(a / c); elseif (c <= -1.45e-26) tmp = fma(a, Float64(c / t_0), Float64(d * Float64(b / t_0))); elseif (c <= 4.6e-145) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.3e+88) tmp = Float64(fma(d, b, Float64(c * a)) / t_0); else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1.05e+128], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.45e-26], N[(a * N[(c / t$95$0), $MachinePrecision] + N[(d * N[(b / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[c, 4.6e-145], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.3e+88], N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / t$95$0), $MachinePrecision], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, c \cdot c\right)\\
\mathbf{if}\;c \leq -1.05 \cdot 10^{+128}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.45 \cdot 10^{-26}:\\
\;\;\;\;\mathsf{fma}\left(a, \frac{c}{t\_0}, d \cdot \frac{b}{t\_0}\right)\\
\mathbf{elif}\;c \leq 4.6 \cdot 10^{-145}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{+88}:\\
\;\;\;\;\frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if c < -1.05e128Initial program 35.6%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites7.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites4.5%
Taylor expanded in c around inf
lower-/.f6477.7
Applied rewrites77.7%
if -1.05e128 < c < -1.4499999999999999e-26Initial program 73.0%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
lift-*.f64N/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6480.1
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6480.1
Applied rewrites80.1%
if -1.4499999999999999e-26 < c < 4.60000000000000014e-145Initial program 71.7%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites28.6%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites24.0%
Taylor expanded in d around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f6486.9
Applied rewrites86.9%
if 4.60000000000000014e-145 < c < 2.3000000000000002e88Initial program 76.9%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6476.9
lift-*.f64N/A
*-commutativeN/A
lower-*.f6476.9
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6476.9
Applied rewrites76.9%
if 2.3000000000000002e88 < c Initial program 39.6%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites15.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites9.9%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-*.f6478.1
Applied rewrites78.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (/ (fma d b (* c a)) (fma d d (* c c)))))
(if (<= c -1e+114)
(/ a c)
(if (<= c -1.45e-26)
t_0
(if (<= c 4.6e-145)
(/ (+ b (/ (* a c) d)) d)
(if (<= c 2.3e+88) t_0 (/ (+ a (/ (* b d) c)) c)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, b, (c * a)) / fma(d, d, (c * c));
double tmp;
if (c <= -1e+114) {
tmp = a / c;
} else if (c <= -1.45e-26) {
tmp = t_0;
} else if (c <= 4.6e-145) {
tmp = (b + ((a * c) / d)) / d;
} else if (c <= 2.3e+88) {
tmp = t_0;
} else {
tmp = (a + ((b * d) / c)) / c;
}
return tmp;
}
function code(a, b, c, d) t_0 = Float64(fma(d, b, Float64(c * a)) / fma(d, d, Float64(c * c))) tmp = 0.0 if (c <= -1e+114) tmp = Float64(a / c); elseif (c <= -1.45e-26) tmp = t_0; elseif (c <= 4.6e-145) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); elseif (c <= 2.3e+88) tmp = t_0; else tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); end return tmp end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * b + N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(d * d + N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[c, -1e+114], N[(a / c), $MachinePrecision], If[LessEqual[c, -1.45e-26], t$95$0, If[LessEqual[c, 4.6e-145], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], If[LessEqual[c, 2.3e+88], t$95$0, N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\mathsf{fma}\left(d, b, c \cdot a\right)}{\mathsf{fma}\left(d, d, c \cdot c\right)}\\
\mathbf{if}\;c \leq -1 \cdot 10^{+114}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq -1.45 \cdot 10^{-26}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 4.6 \cdot 10^{-145}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{elif}\;c \leq 2.3 \cdot 10^{+88}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\end{array}
\end{array}
if c < -1e114Initial program 37.5%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites10.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites6.6%
Taylor expanded in c around inf
lower-/.f6476.7
Applied rewrites76.7%
if -1e114 < c < -1.4499999999999999e-26 or 4.60000000000000014e-145 < c < 2.3000000000000002e88Initial program 75.8%
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6475.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6475.8
lift-+.f64N/A
+-commutativeN/A
lift-*.f64N/A
lower-fma.f6475.8
Applied rewrites75.8%
if -1.4499999999999999e-26 < c < 4.60000000000000014e-145Initial program 71.7%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites28.6%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites24.0%
Taylor expanded in d around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f6486.9
Applied rewrites86.9%
if 2.3000000000000002e88 < c Initial program 39.6%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites15.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites9.9%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-*.f6478.1
Applied rewrites78.1%
(FPCore (a b c d) :precision binary64 (let* ((t_0 (/ (+ a (/ (* b d) c)) c))) (if (<= c -4.7e+58) t_0 (if (<= c 1.02e-8) (/ (+ b (/ (* a c) d)) d) t_0))))
double code(double a, double b, double c, double d) {
double t_0 = (a + ((b * d) / c)) / c;
double tmp;
if (c <= -4.7e+58) {
tmp = t_0;
} else if (c <= 1.02e-8) {
tmp = (b + ((a * c) / d)) / d;
} else {
tmp = t_0;
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: t_0
real(8) :: tmp
t_0 = (a + ((b * d) / c)) / c
if (c <= (-4.7d+58)) then
tmp = t_0
else if (c <= 1.02d-8) then
tmp = (b + ((a * c) / d)) / d
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double t_0 = (a + ((b * d) / c)) / c;
double tmp;
if (c <= -4.7e+58) {
tmp = t_0;
} else if (c <= 1.02e-8) {
tmp = (b + ((a * c) / d)) / d;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c, d): t_0 = (a + ((b * d) / c)) / c tmp = 0 if c <= -4.7e+58: tmp = t_0 elif c <= 1.02e-8: tmp = (b + ((a * c) / d)) / d else: tmp = t_0 return tmp
function code(a, b, c, d) t_0 = Float64(Float64(a + Float64(Float64(b * d) / c)) / c) tmp = 0.0 if (c <= -4.7e+58) tmp = t_0; elseif (c <= 1.02e-8) tmp = Float64(Float64(b + Float64(Float64(a * c) / d)) / d); else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c, d) t_0 = (a + ((b * d) / c)) / c; tmp = 0.0; if (c <= -4.7e+58) tmp = t_0; elseif (c <= 1.02e-8) tmp = (b + ((a * c) / d)) / d; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]}, If[LessEqual[c, -4.7e+58], t$95$0, If[LessEqual[c, 1.02e-8], N[(N[(b + N[(N[(a * c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision] / d), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{if}\;c \leq -4.7 \cdot 10^{+58}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;c \leq 1.02 \cdot 10^{-8}:\\
\;\;\;\;\frac{b + \frac{a \cdot c}{d}}{d}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if c < -4.69999999999999972e58 or 1.02000000000000003e-8 < c Initial program 47.0%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites21.9%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites15.4%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-*.f6473.6
Applied rewrites73.6%
if -4.69999999999999972e58 < c < 1.02000000000000003e-8Initial program 74.0%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites32.4%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites27.8%
Taylor expanded in d around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lift-*.f6478.4
Applied rewrites78.4%
(FPCore (a b c d) :precision binary64 (if (<= d -0.013) (/ b d) (if (<= d 4.2e+25) (/ (+ a (/ (* b d) c)) c) (/ b d))))
double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.013) {
tmp = b / d;
} else if (d <= 4.2e+25) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = b / d;
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (d <= (-0.013d0)) then
tmp = b / d
else if (d <= 4.2d+25) then
tmp = (a + ((b * d) / c)) / c
else
tmp = b / d
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (d <= -0.013) {
tmp = b / d;
} else if (d <= 4.2e+25) {
tmp = (a + ((b * d) / c)) / c;
} else {
tmp = b / d;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if d <= -0.013: tmp = b / d elif d <= 4.2e+25: tmp = (a + ((b * d) / c)) / c else: tmp = b / d return tmp
function code(a, b, c, d) tmp = 0.0 if (d <= -0.013) tmp = Float64(b / d); elseif (d <= 4.2e+25) tmp = Float64(Float64(a + Float64(Float64(b * d) / c)) / c); else tmp = Float64(b / d); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (d <= -0.013) tmp = b / d; elseif (d <= 4.2e+25) tmp = (a + ((b * d) / c)) / c; else tmp = b / d; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[d, -0.013], N[(b / d), $MachinePrecision], If[LessEqual[d, 4.2e+25], N[(N[(a + N[(N[(b * d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision], N[(b / d), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;d \leq -0.013:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{elif}\;d \leq 4.2 \cdot 10^{+25}:\\
\;\;\;\;\frac{a + \frac{b \cdot d}{c}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{d}\\
\end{array}
\end{array}
if d < -0.0129999999999999994 or 4.1999999999999998e25 < d Initial program 48.0%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites22.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites16.3%
Taylor expanded in c around 0
lower-/.f6465.4
Applied rewrites65.4%
if -0.0129999999999999994 < d < 4.1999999999999998e25Initial program 73.3%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites32.0%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites27.1%
Taylor expanded in c around inf
lower-/.f64N/A
lower-+.f64N/A
lower-/.f64N/A
lower-*.f6480.2
Applied rewrites80.2%
(FPCore (a b c d) :precision binary64 (if (<= c -4.7e+58) (/ a c) (if (<= c 22000.0) (/ b d) (/ a c))))
double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.7e+58) {
tmp = a / c;
} else if (c <= 22000.0) {
tmp = b / d;
} else {
tmp = a / c;
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (c <= (-4.7d+58)) then
tmp = a / c
else if (c <= 22000.0d0) then
tmp = b / d
else
tmp = a / c
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (c <= -4.7e+58) {
tmp = a / c;
} else if (c <= 22000.0) {
tmp = b / d;
} else {
tmp = a / c;
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if c <= -4.7e+58: tmp = a / c elif c <= 22000.0: tmp = b / d else: tmp = a / c return tmp
function code(a, b, c, d) tmp = 0.0 if (c <= -4.7e+58) tmp = Float64(a / c); elseif (c <= 22000.0) tmp = Float64(b / d); else tmp = Float64(a / c); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (c <= -4.7e+58) tmp = a / c; elseif (c <= 22000.0) tmp = b / d; else tmp = a / c; end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[LessEqual[c, -4.7e+58], N[(a / c), $MachinePrecision], If[LessEqual[c, 22000.0], N[(b / d), $MachinePrecision], N[(a / c), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;c \leq -4.7 \cdot 10^{+58}:\\
\;\;\;\;\frac{a}{c}\\
\mathbf{elif}\;c \leq 22000:\\
\;\;\;\;\frac{b}{d}\\
\mathbf{else}:\\
\;\;\;\;\frac{a}{c}\\
\end{array}
\end{array}
if c < -4.69999999999999972e58 or 22000 < c Initial program 46.4%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites21.3%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites14.8%
Taylor expanded in c around inf
lower-/.f6467.6
Applied rewrites67.6%
if -4.69999999999999972e58 < c < 22000Initial program 74.0%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites32.7%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites28.1%
Taylor expanded in c around 0
lower-/.f6461.1
Applied rewrites61.1%
(FPCore (a b c d) :precision binary64 (/ a c))
double code(double a, double b, double c, double d) {
return a / c;
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
code = a / c
end function
public static double code(double a, double b, double c, double d) {
return a / c;
}
def code(a, b, c, d): return a / c
function code(a, b, c, d) return Float64(a / c) end
function tmp = code(a, b, c, d) tmp = a / c; end
code[a_, b_, c_, d_] := N[(a / c), $MachinePrecision]
\begin{array}{l}
\\
\frac{a}{c}
\end{array}
Initial program 61.3%
lift-/.f64N/A
lift-+.f64N/A
div-addN/A
flip-+N/A
lower-/.f64N/A
Applied rewrites27.5%
lift--.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lift-*.f64N/A
associate-*r/N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
*-commutativeN/A
Applied rewrites22.0%
Taylor expanded in c around inf
lower-/.f6443.7
Applied rewrites43.7%
(FPCore (a b c d) :precision binary64 (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
double code(double a, double b, double c, double d) {
double tmp;
if (fabs(d) < fabs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
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(a, b, c, d)
use fmin_fmax_functions
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8), intent (in) :: d
real(8) :: tmp
if (abs(d) < abs(c)) then
tmp = (a + (b * (d / c))) / (c + (d * (d / c)))
else
tmp = (b + (a * (c / d))) / (d + (c * (c / d)))
end if
code = tmp
end function
public static double code(double a, double b, double c, double d) {
double tmp;
if (Math.abs(d) < Math.abs(c)) {
tmp = (a + (b * (d / c))) / (c + (d * (d / c)));
} else {
tmp = (b + (a * (c / d))) / (d + (c * (c / d)));
}
return tmp;
}
def code(a, b, c, d): tmp = 0 if math.fabs(d) < math.fabs(c): tmp = (a + (b * (d / c))) / (c + (d * (d / c))) else: tmp = (b + (a * (c / d))) / (d + (c * (c / d))) return tmp
function code(a, b, c, d) tmp = 0.0 if (abs(d) < abs(c)) tmp = Float64(Float64(a + Float64(b * Float64(d / c))) / Float64(c + Float64(d * Float64(d / c)))); else tmp = Float64(Float64(b + Float64(a * Float64(c / d))) / Float64(d + Float64(c * Float64(c / d)))); end return tmp end
function tmp_2 = code(a, b, c, d) tmp = 0.0; if (abs(d) < abs(c)) tmp = (a + (b * (d / c))) / (c + (d * (d / c))); else tmp = (b + (a * (c / d))) / (d + (c * (c / d))); end tmp_2 = tmp; end
code[a_, b_, c_, d_] := If[Less[N[Abs[d], $MachinePrecision], N[Abs[c], $MachinePrecision]], N[(N[(a + N[(b * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(c + N[(d * N[(d / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + N[(a * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(d + N[(c * N[(c / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|d\right| < \left|c\right|:\\
\;\;\;\;\frac{a + b \cdot \frac{d}{c}}{c + d \cdot \frac{d}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + a \cdot \frac{c}{d}}{d + c \cdot \frac{c}{d}}\\
\end{array}
\end{array}
herbie shell --seed 2025107
(FPCore (a b c d)
:name "Complex division, real part"
:precision binary64
:alt
(! :herbie-platform default (if (< (fabs d) (fabs c)) (/ (+ a (* b (/ d c))) (+ c (* d (/ d c)))) (/ (+ b (* a (/ c d))) (+ d (* c (/ c d))))))
(/ (+ (* a c) (* b d)) (+ (* c c) (* d d))))