
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.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(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 + (b + (c + d))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
function code(a, b, c, d) return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (a + (b + (c + d))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c d) :precision binary64 (* (+ a (+ b (+ c d))) 2.0))
double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.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(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 + (b + (c + d))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (a + (b + (c + d))) * 2.0;
}
def code(a, b, c, d): return (a + (b + (c + d))) * 2.0
function code(a, b, c, d) return Float64(Float64(a + Float64(b + Float64(c + d))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (a + (b + (c + d))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(a + N[(b + N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(a + \left(b + \left(c + d\right)\right)\right) \cdot 2
\end{array}
(FPCore (a b c d) :precision binary64 (* (+ b (* c (+ 1.0 (/ (+ a d) c)))) 2.0))
double code(double a, double b, double c, double d) {
return (b + (c * (1.0 + ((a + d) / c)))) * 2.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(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 = (b + (c * (1.0d0 + ((a + d) / c)))) * 2.0d0
end function
public static double code(double a, double b, double c, double d) {
return (b + (c * (1.0 + ((a + d) / c)))) * 2.0;
}
def code(a, b, c, d): return (b + (c * (1.0 + ((a + d) / c)))) * 2.0
function code(a, b, c, d) return Float64(Float64(b + Float64(c * Float64(1.0 + Float64(Float64(a + d) / c)))) * 2.0) end
function tmp = code(a, b, c, d) tmp = (b + (c * (1.0 + ((a + d) / c)))) * 2.0; end
code[a_, b_, c_, d_] := N[(N[(b + N[(c * N[(1.0 + N[(N[(a + d), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision]
\begin{array}{l}
\\
\left(b + c \cdot \left(1 + \frac{a + d}{c}\right)\right) \cdot 2
\end{array}
Initial program 94.3%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f64N/A
div-add-revN/A
div-addN/A
+-commutativeN/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
metadata-evalN/A
lower--.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6495.2
Applied rewrites95.2%
Taylor expanded in b around 0
lower-+.f64N/A
lower-*.f64N/A
lower-+.f64N/A
div-add-revN/A
lower-/.f64N/A
lower-+.f6499.4
Applied rewrites99.4%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (- (fma d d (pow (+ a b) 2.0)) (* d (+ a b))))
(t_1 (/ (* d d) t_0)))
(fma
2.0
(*
c
(-
(fma 2.0 t_1 t_1)
(/
(* (+ (pow d 3.0) (pow (+ a b) 3.0)) (- (* 2.0 d) (+ a b)))
(pow t_0 2.0))))
(* b (+ 2.0 (* 2.0 (/ (+ a d) b)))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(d, d, pow((a + b), 2.0)) - (d * (a + b));
double t_1 = (d * d) / t_0;
return fma(2.0, (c * (fma(2.0, t_1, t_1) - (((pow(d, 3.0) + pow((a + b), 3.0)) * ((2.0 * d) - (a + b))) / pow(t_0, 2.0)))), (b * (2.0 + (2.0 * ((a + d) / b)))));
}
function code(a, b, c, d) t_0 = Float64(fma(d, d, (Float64(a + b) ^ 2.0)) - Float64(d * Float64(a + b))) t_1 = Float64(Float64(d * d) / t_0) return fma(2.0, Float64(c * Float64(fma(2.0, t_1, t_1) - Float64(Float64(Float64((d ^ 3.0) + (Float64(a + b) ^ 3.0)) * Float64(Float64(2.0 * d) - Float64(a + b))) / (t_0 ^ 2.0)))), Float64(b * Float64(2.0 + Float64(2.0 * Float64(Float64(a + d) / b))))) end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(N[(d * d + N[Power[N[(a + b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] - N[(d * N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(d * d), $MachinePrecision] / t$95$0), $MachinePrecision]}, N[(2.0 * N[(c * N[(N[(2.0 * t$95$1 + t$95$1), $MachinePrecision] - N[(N[(N[(N[Power[d, 3.0], $MachinePrecision] + N[Power[N[(a + b), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] * N[(N[(2.0 * d), $MachinePrecision] - N[(a + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[t$95$0, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * N[(2.0 + N[(2.0 * N[(N[(a + d), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(d, d, {\left(a + b\right)}^{2}\right) - d \cdot \left(a + b\right)\\
t_1 := \frac{d \cdot d}{t\_0}\\
\mathsf{fma}\left(2, c \cdot \left(\mathsf{fma}\left(2, t\_1, t\_1\right) - \frac{\left({d}^{3} + {\left(a + b\right)}^{3}\right) \cdot \left(2 \cdot d - \left(a + b\right)\right)}{{t\_0}^{2}}\right), b \cdot \left(2 + 2 \cdot \frac{a + d}{b}\right)\right)
\end{array}
\end{array}
Initial program 94.3%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+r+N/A
flip3-+N/A
lower-/.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in c around 0
Applied rewrites94.8%
Taylor expanded in b around inf
lower-*.f64N/A
lower-+.f64N/A
lower-*.f64N/A
lower-/.f64N/A
lift-+.f6497.1
Applied rewrites97.1%
(FPCore (a b c d)
:precision binary64
(let* ((t_0 (fma 2.0 (* a a) (* a a)))
(t_1 (+ (pow a 3.0) (pow d 3.0)))
(t_2 (- (* 2.0 a) d))
(t_3 (- (* 2.0 d) a))
(t_4 (- (fma a a (* d d)) (* a d)))
(t_5 (pow t_4 2.0))
(t_6 (/ (* d d) t_4))
(t_7 (pow t_4 3.0))
(t_8 (/ t_1 t_5))
(t_9 (/ (* t_0 t_3) t_5))
(t_10 (/ (pow (* d t_2) 2.0) t_7))
(t_11 (/ (* (* d d) t_2) t_5))
(t_12 (/ (* d d) t_5))
(t_13 (* 2.0 (/ (* t_1 (* t_2 t_3)) t_7)))
(t_14 (/ (* a a) t_4))
(t_15 (- (fma 2.0 t_14 t_14) (/ (* t_1 t_2) t_5)))
(t_16 (/ a t_4)))
(fma
2.0
(* c (- (fma 2.0 t_6 t_6) (/ (* t_1 t_3) t_5)))
(fma
2.0
(/ t_1 t_4)
(*
b
(fma
2.0
(* c (- (fma -2.0 t_11 t_13) (fma -1.0 t_8 (+ t_9 t_11))))
(fma
2.0
t_15
(*
b
(fma
2.0
(*
c
(-
(fma
-2.0
(fma -1.0 t_10 t_12)
(fma
2.0
(/ (* t_2 (- (fma -1.0 t_8 t_9) t_13)) t_4)
(/
(*
t_1
(*
t_3
(-
(fma 2.0 (* a a) (fma 2.0 (* d d) (pow t_2 2.0)))
(* 2.0 (* a d)))))
(pow t_4 4.0))))
(fma
-1.0
t_10
(fma -1.0 (/ t_0 t_5) (+ (/ (* (+ a (* 2.0 a)) t_3) t_5) t_12)))))
(*
2.0
(-
(fma 2.0 t_16 t_16)
(+
(/ (* t_2 t_15) t_4)
(+ (/ (pow a 3.0) t_5) (/ (pow d 3.0) t_5))))))))))))))
double code(double a, double b, double c, double d) {
double t_0 = fma(2.0, (a * a), (a * a));
double t_1 = pow(a, 3.0) + pow(d, 3.0);
double t_2 = (2.0 * a) - d;
double t_3 = (2.0 * d) - a;
double t_4 = fma(a, a, (d * d)) - (a * d);
double t_5 = pow(t_4, 2.0);
double t_6 = (d * d) / t_4;
double t_7 = pow(t_4, 3.0);
double t_8 = t_1 / t_5;
double t_9 = (t_0 * t_3) / t_5;
double t_10 = pow((d * t_2), 2.0) / t_7;
double t_11 = ((d * d) * t_2) / t_5;
double t_12 = (d * d) / t_5;
double t_13 = 2.0 * ((t_1 * (t_2 * t_3)) / t_7);
double t_14 = (a * a) / t_4;
double t_15 = fma(2.0, t_14, t_14) - ((t_1 * t_2) / t_5);
double t_16 = a / t_4;
return fma(2.0, (c * (fma(2.0, t_6, t_6) - ((t_1 * t_3) / t_5))), fma(2.0, (t_1 / t_4), (b * fma(2.0, (c * (fma(-2.0, t_11, t_13) - fma(-1.0, t_8, (t_9 + t_11)))), fma(2.0, t_15, (b * fma(2.0, (c * (fma(-2.0, fma(-1.0, t_10, t_12), fma(2.0, ((t_2 * (fma(-1.0, t_8, t_9) - t_13)) / t_4), ((t_1 * (t_3 * (fma(2.0, (a * a), fma(2.0, (d * d), pow(t_2, 2.0))) - (2.0 * (a * d))))) / pow(t_4, 4.0)))) - fma(-1.0, t_10, fma(-1.0, (t_0 / t_5), ((((a + (2.0 * a)) * t_3) / t_5) + t_12))))), (2.0 * (fma(2.0, t_16, t_16) - (((t_2 * t_15) / t_4) + ((pow(a, 3.0) / t_5) + (pow(d, 3.0) / t_5))))))))))));
}
function code(a, b, c, d) t_0 = fma(2.0, Float64(a * a), Float64(a * a)) t_1 = Float64((a ^ 3.0) + (d ^ 3.0)) t_2 = Float64(Float64(2.0 * a) - d) t_3 = Float64(Float64(2.0 * d) - a) t_4 = Float64(fma(a, a, Float64(d * d)) - Float64(a * d)) t_5 = t_4 ^ 2.0 t_6 = Float64(Float64(d * d) / t_4) t_7 = t_4 ^ 3.0 t_8 = Float64(t_1 / t_5) t_9 = Float64(Float64(t_0 * t_3) / t_5) t_10 = Float64((Float64(d * t_2) ^ 2.0) / t_7) t_11 = Float64(Float64(Float64(d * d) * t_2) / t_5) t_12 = Float64(Float64(d * d) / t_5) t_13 = Float64(2.0 * Float64(Float64(t_1 * Float64(t_2 * t_3)) / t_7)) t_14 = Float64(Float64(a * a) / t_4) t_15 = Float64(fma(2.0, t_14, t_14) - Float64(Float64(t_1 * t_2) / t_5)) t_16 = Float64(a / t_4) return fma(2.0, Float64(c * Float64(fma(2.0, t_6, t_6) - Float64(Float64(t_1 * t_3) / t_5))), fma(2.0, Float64(t_1 / t_4), Float64(b * fma(2.0, Float64(c * Float64(fma(-2.0, t_11, t_13) - fma(-1.0, t_8, Float64(t_9 + t_11)))), fma(2.0, t_15, Float64(b * fma(2.0, Float64(c * Float64(fma(-2.0, fma(-1.0, t_10, t_12), fma(2.0, Float64(Float64(t_2 * Float64(fma(-1.0, t_8, t_9) - t_13)) / t_4), Float64(Float64(t_1 * Float64(t_3 * Float64(fma(2.0, Float64(a * a), fma(2.0, Float64(d * d), (t_2 ^ 2.0))) - Float64(2.0 * Float64(a * d))))) / (t_4 ^ 4.0)))) - fma(-1.0, t_10, fma(-1.0, Float64(t_0 / t_5), Float64(Float64(Float64(Float64(a + Float64(2.0 * a)) * t_3) / t_5) + t_12))))), Float64(2.0 * Float64(fma(2.0, t_16, t_16) - Float64(Float64(Float64(t_2 * t_15) / t_4) + Float64(Float64((a ^ 3.0) / t_5) + Float64((d ^ 3.0) / t_5)))))))))))) end
code[a_, b_, c_, d_] := Block[{t$95$0 = N[(2.0 * N[(a * a), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Power[a, 3.0], $MachinePrecision] + N[Power[d, 3.0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * a), $MachinePrecision] - d), $MachinePrecision]}, Block[{t$95$3 = N[(N[(2.0 * d), $MachinePrecision] - a), $MachinePrecision]}, Block[{t$95$4 = N[(N[(a * a + N[(d * d), $MachinePrecision]), $MachinePrecision] - N[(a * d), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$5 = N[Power[t$95$4, 2.0], $MachinePrecision]}, Block[{t$95$6 = N[(N[(d * d), $MachinePrecision] / t$95$4), $MachinePrecision]}, Block[{t$95$7 = N[Power[t$95$4, 3.0], $MachinePrecision]}, Block[{t$95$8 = N[(t$95$1 / t$95$5), $MachinePrecision]}, Block[{t$95$9 = N[(N[(t$95$0 * t$95$3), $MachinePrecision] / t$95$5), $MachinePrecision]}, Block[{t$95$10 = N[(N[Power[N[(d * t$95$2), $MachinePrecision], 2.0], $MachinePrecision] / t$95$7), $MachinePrecision]}, Block[{t$95$11 = N[(N[(N[(d * d), $MachinePrecision] * t$95$2), $MachinePrecision] / t$95$5), $MachinePrecision]}, Block[{t$95$12 = N[(N[(d * d), $MachinePrecision] / t$95$5), $MachinePrecision]}, Block[{t$95$13 = N[(2.0 * N[(N[(t$95$1 * N[(t$95$2 * t$95$3), $MachinePrecision]), $MachinePrecision] / t$95$7), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$14 = N[(N[(a * a), $MachinePrecision] / t$95$4), $MachinePrecision]}, Block[{t$95$15 = N[(N[(2.0 * t$95$14 + t$95$14), $MachinePrecision] - N[(N[(t$95$1 * t$95$2), $MachinePrecision] / t$95$5), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$16 = N[(a / t$95$4), $MachinePrecision]}, N[(2.0 * N[(c * N[(N[(2.0 * t$95$6 + t$95$6), $MachinePrecision] - N[(N[(t$95$1 * t$95$3), $MachinePrecision] / t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(t$95$1 / t$95$4), $MachinePrecision] + N[(b * N[(2.0 * N[(c * N[(N[(-2.0 * t$95$11 + t$95$13), $MachinePrecision] - N[(-1.0 * t$95$8 + N[(t$95$9 + t$95$11), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * t$95$15 + N[(b * N[(2.0 * N[(c * N[(N[(-2.0 * N[(-1.0 * t$95$10 + t$95$12), $MachinePrecision] + N[(2.0 * N[(N[(t$95$2 * N[(N[(-1.0 * t$95$8 + t$95$9), $MachinePrecision] - t$95$13), $MachinePrecision]), $MachinePrecision] / t$95$4), $MachinePrecision] + N[(N[(t$95$1 * N[(t$95$3 * N[(N[(2.0 * N[(a * a), $MachinePrecision] + N[(2.0 * N[(d * d), $MachinePrecision] + N[Power[t$95$2, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(2.0 * N[(a * d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Power[t$95$4, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(-1.0 * t$95$10 + N[(-1.0 * N[(t$95$0 / t$95$5), $MachinePrecision] + N[(N[(N[(N[(a + N[(2.0 * a), $MachinePrecision]), $MachinePrecision] * t$95$3), $MachinePrecision] / t$95$5), $MachinePrecision] + t$95$12), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(N[(2.0 * t$95$16 + t$95$16), $MachinePrecision] - N[(N[(N[(t$95$2 * t$95$15), $MachinePrecision] / t$95$4), $MachinePrecision] + N[(N[(N[Power[a, 3.0], $MachinePrecision] / t$95$5), $MachinePrecision] + N[(N[Power[d, 3.0], $MachinePrecision] / t$95$5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]]]]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(2, a \cdot a, a \cdot a\right)\\
t_1 := {a}^{3} + {d}^{3}\\
t_2 := 2 \cdot a - d\\
t_3 := 2 \cdot d - a\\
t_4 := \mathsf{fma}\left(a, a, d \cdot d\right) - a \cdot d\\
t_5 := {t\_4}^{2}\\
t_6 := \frac{d \cdot d}{t\_4}\\
t_7 := {t\_4}^{3}\\
t_8 := \frac{t\_1}{t\_5}\\
t_9 := \frac{t\_0 \cdot t\_3}{t\_5}\\
t_10 := \frac{{\left(d \cdot t\_2\right)}^{2}}{t\_7}\\
t_11 := \frac{\left(d \cdot d\right) \cdot t\_2}{t\_5}\\
t_12 := \frac{d \cdot d}{t\_5}\\
t_13 := 2 \cdot \frac{t\_1 \cdot \left(t\_2 \cdot t\_3\right)}{t\_7}\\
t_14 := \frac{a \cdot a}{t\_4}\\
t_15 := \mathsf{fma}\left(2, t\_14, t\_14\right) - \frac{t\_1 \cdot t\_2}{t\_5}\\
t_16 := \frac{a}{t\_4}\\
\mathsf{fma}\left(2, c \cdot \left(\mathsf{fma}\left(2, t\_6, t\_6\right) - \frac{t\_1 \cdot t\_3}{t\_5}\right), \mathsf{fma}\left(2, \frac{t\_1}{t\_4}, b \cdot \mathsf{fma}\left(2, c \cdot \left(\mathsf{fma}\left(-2, t\_11, t\_13\right) - \mathsf{fma}\left(-1, t\_8, t\_9 + t\_11\right)\right), \mathsf{fma}\left(2, t\_15, b \cdot \mathsf{fma}\left(2, c \cdot \left(\mathsf{fma}\left(-2, \mathsf{fma}\left(-1, t\_10, t\_12\right), \mathsf{fma}\left(2, \frac{t\_2 \cdot \left(\mathsf{fma}\left(-1, t\_8, t\_9\right) - t\_13\right)}{t\_4}, \frac{t\_1 \cdot \left(t\_3 \cdot \left(\mathsf{fma}\left(2, a \cdot a, \mathsf{fma}\left(2, d \cdot d, {t\_2}^{2}\right)\right) - 2 \cdot \left(a \cdot d\right)\right)\right)}{{t\_4}^{4}}\right)\right) - \mathsf{fma}\left(-1, t\_10, \mathsf{fma}\left(-1, \frac{t\_0}{t\_5}, \frac{\left(a + 2 \cdot a\right) \cdot t\_3}{t\_5} + t\_12\right)\right)\right), 2 \cdot \left(\mathsf{fma}\left(2, t\_16, t\_16\right) - \left(\frac{t\_2 \cdot t\_15}{t\_4} + \left(\frac{{a}^{3}}{t\_5} + \frac{{d}^{3}}{t\_5}\right)\right)\right)\right)\right)\right)\right)\right)
\end{array}
\end{array}
Initial program 94.3%
lift-+.f64N/A
lift-+.f64N/A
lift-+.f64N/A
associate-+r+N/A
flip3-+N/A
lower-/.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
lower-+.f64N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fma.f64N/A
lower-+.f64N/A
lower-+.f64N/A
lower--.f64N/A
pow2N/A
lower-pow.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-*.f64N/A
Applied rewrites93.6%
Taylor expanded in c around 0
Applied rewrites94.8%
Taylor expanded in b around 0
Applied rewrites96.4%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ c (+ (+ d b) a))))
double code(double a, double b, double c, double d) {
return 2.0 * (c + ((d + b) + a));
}
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 = 2.0d0 * (c + ((d + b) + a))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (c + ((d + b) + a));
}
def code(a, b, c, d): return 2.0 * (c + ((d + b) + a))
function code(a, b, c, d) return Float64(2.0 * Float64(c + Float64(Float64(d + b) + a))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (c + ((d + b) + a)); end
code[a_, b_, c_, d_] := N[(2.0 * N[(c + N[(N[(d + b), $MachinePrecision] + a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(c + \left(\left(d + b\right) + a\right)\right)
\end{array}
Initial program 94.3%
Taylor expanded in c around 0
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6495.7
Applied rewrites95.7%
(FPCore (a b c d) :precision binary64 (* 2.0 (+ b (* d (+ 1.0 (/ (+ a c) d))))))
double code(double a, double b, double c, double d) {
return 2.0 * (b + (d * (1.0 + ((a + c) / 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 = 2.0d0 * (b + (d * (1.0d0 + ((a + c) / d))))
end function
public static double code(double a, double b, double c, double d) {
return 2.0 * (b + (d * (1.0 + ((a + c) / d))));
}
def code(a, b, c, d): return 2.0 * (b + (d * (1.0 + ((a + c) / d))))
function code(a, b, c, d) return Float64(2.0 * Float64(b + Float64(d * Float64(1.0 + Float64(Float64(a + c) / d))))) end
function tmp = code(a, b, c, d) tmp = 2.0 * (b + (d * (1.0 + ((a + c) / d)))); end
code[a_, b_, c_, d_] := N[(2.0 * N[(b + N[(d * N[(1.0 + N[(N[(a + c), $MachinePrecision] / d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(b + d \cdot \left(1 + \frac{a + c}{d}\right)\right)
\end{array}
Initial program 94.3%
Taylor expanded in b around 0
distribute-lft-outN/A
lower-*.f64N/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f6494.5
Applied rewrites94.5%
Taylor expanded in d around inf
lower-*.f64N/A
lower-+.f64N/A
div-add-revN/A
lower-/.f64N/A
lower-+.f6495.2
Applied rewrites95.2%
herbie shell --seed 2025057
(FPCore (a b c d)
:name "Expression, p6"
:precision binary64
:pre (and (and (and (and (<= -14.0 a) (<= a -13.0)) (and (<= -3.0 b) (<= b -2.0))) (and (<= 3.0 c) (<= c 3.5))) (and (<= 12.5 d) (<= d 13.5)))
:alt
(! :herbie-platform default (let ((e 2)) (+ (* (+ a b) e) (* (+ c d) e))))
(* (+ a (+ b (+ c d))) 2.0))