Expression, p14

Percentage Accurate: 99.9% → 100.0%
Time: 2.4s
Alternatives: 4
Speedup: 1.0×

Specification

?
\[\left(\left(\left(56789 \leq a \land a \leq 98765\right) \land \left(0 \leq b \land b \leq 1\right)\right) \land \left(0 \leq c \land c \leq 0.0016773\right)\right) \land \left(0 \leq d \land d \leq 0.0016773\right)\]
\[\begin{array}{l} \\ a \cdot \left(\left(b + c\right) + d\right) \end{array} \]
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
double code(double a, double b, double c, double d) {
	return a * ((b + 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 = a * ((b + c) + d)
end function
public static double code(double a, double b, double c, double d) {
	return a * ((b + c) + d);
}
def code(a, b, c, d):
	return a * ((b + c) + d)
function code(a, b, c, d)
	return Float64(a * Float64(Float64(b + c) + d))
end
function tmp = code(a, b, c, d)
	tmp = a * ((b + c) + d);
end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
a \cdot \left(\left(b + c\right) + d\right)
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 4 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} \\ a \cdot \left(\left(b + c\right) + d\right) \end{array} \]
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
double code(double a, double b, double c, double d) {
	return a * ((b + 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 = a * ((b + c) + d)
end function
public static double code(double a, double b, double c, double d) {
	return a * ((b + c) + d);
}
def code(a, b, c, d):
	return a * ((b + c) + d)
function code(a, b, c, d)
	return Float64(a * Float64(Float64(b + c) + d))
end
function tmp = code(a, b, c, d)
	tmp = a * ((b + c) + d);
end
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
a \cdot \left(\left(b + c\right) + d\right)
\end{array}

Alternative 1: 100.0% accurate, 0.8× speedup?

\[\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ \mathsf{fma}\left(d + b, a, c \cdot a\right) \end{array} \]
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
(FPCore (a b c d) :precision binary64 (fma (+ d b) a (* c a)))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
	return fma((d + b), a, (c * a));
}
a, b, c, d = sort([a, b, c, d])
function code(a, b, c, d)
	return fma(Float64(d + b), a, Float64(c * a))
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
code[a_, b_, c_, d_] := N[(N[(d + b), $MachinePrecision] * a + N[(c * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
\mathsf{fma}\left(d + b, a, c \cdot a\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{a \cdot \left(\left(b + c\right) + d\right)} \]
    2. lift-+.f64N/A

      \[\leadsto a \cdot \color{blue}{\left(\left(b + c\right) + d\right)} \]
    3. lift-+.f64N/A

      \[\leadsto a \cdot \left(\color{blue}{\left(b + c\right)} + d\right) \]
    4. associate-+r+N/A

      \[\leadsto a \cdot \color{blue}{\left(b + \left(c + d\right)\right)} \]
    5. +-commutativeN/A

      \[\leadsto a \cdot \left(b + \color{blue}{\left(d + c\right)}\right) \]
    6. associate-+r+N/A

      \[\leadsto a \cdot \color{blue}{\left(\left(b + d\right) + c\right)} \]
    7. distribute-lft-outN/A

      \[\leadsto \color{blue}{a \cdot \left(b + d\right) + a \cdot c} \]
    8. *-commutativeN/A

      \[\leadsto \color{blue}{\left(b + d\right) \cdot a} + a \cdot c \]
    9. lower-fma.f64N/A

      \[\leadsto \color{blue}{\mathsf{fma}\left(b + d, a, a \cdot c\right)} \]
    10. +-commutativeN/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{d + b}, a, a \cdot c\right) \]
    11. lower-+.f64N/A

      \[\leadsto \mathsf{fma}\left(\color{blue}{d + b}, a, a \cdot c\right) \]
    12. *-commutativeN/A

      \[\leadsto \mathsf{fma}\left(d + b, a, \color{blue}{c \cdot a}\right) \]
    13. lower-*.f6499.9

      \[\leadsto \mathsf{fma}\left(d + b, a, \color{blue}{c \cdot a}\right) \]
  4. Applied rewrites99.9%

    \[\leadsto \color{blue}{\mathsf{fma}\left(d + b, a, c \cdot a\right)} \]
  5. Add Preprocessing

Alternative 2: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ a \cdot \left(\left(b + c\right) + d\right) \end{array} \]
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
(FPCore (a b c d) :precision binary64 (* a (+ (+ b c) d)))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
	return a * ((b + c) + d);
}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
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)
end function
assert a < b && b < c && c < d;
public static double code(double a, double b, double c, double d) {
	return a * ((b + c) + d);
}
[a, b, c, d] = sort([a, b, c, d])
def code(a, b, c, d):
	return a * ((b + c) + d)
a, b, c, d = sort([a, b, c, d])
function code(a, b, c, d)
	return Float64(a * Float64(Float64(b + c) + d))
end
a, b, c, d = num2cell(sort([a, b, c, d])){:}
function tmp = code(a, b, c, d)
	tmp = a * ((b + c) + d);
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
code[a_, b_, c_, d_] := N[(a * N[(N[(b + c), $MachinePrecision] + d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
a \cdot \left(\left(b + c\right) + d\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 3: 99.7% accurate, 1.3× speedup?

\[\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ a \cdot \left(c + d\right) \end{array} \]
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
(FPCore (a b c d) :precision binary64 (* a (+ c d)))
assert(a < b && b < c && c < d);
double code(double a, double b, double c, double d) {
	return a * (c + d);
}
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
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 + d)
end function
assert a < b && b < c && c < d;
public static double code(double a, double b, double c, double d) {
	return a * (c + d);
}
[a, b, c, d] = sort([a, b, c, d])
def code(a, b, c, d):
	return a * (c + d)
a, b, c, d = sort([a, b, c, d])
function code(a, b, c, d)
	return Float64(a * Float64(c + d))
end
a, b, c, d = num2cell(sort([a, b, c, d])){:}
function tmp = code(a, b, c, d)
	tmp = a * (c + d);
end
NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
code[a_, b_, c_, d_] := N[(a * N[(c + d), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
[a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
\\
a \cdot \left(c + d\right)
\end{array}
Derivation
  1. Initial program 99.9%

    \[a \cdot \left(\left(b + c\right) + d\right) \]
  2. Add Preprocessing
  3. Taylor expanded in b around 0

    \[\leadsto a \cdot \left(\color{blue}{c} + d\right) \]
  4. Step-by-step derivation
    1. Applied rewrites69.8%

      \[\leadsto a \cdot \left(\color{blue}{c} + d\right) \]
    2. Add Preprocessing

    Alternative 4: 93.9% accurate, 2.0× speedup?

    \[\begin{array}{l} [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\ \\ a \cdot d \end{array} \]
    NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
    (FPCore (a b c d) :precision binary64 (* a d))
    assert(a < b && b < c && c < d);
    double code(double a, double b, double c, double d) {
    	return a * d;
    }
    
    NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
    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 * d
    end function
    
    assert a < b && b < c && c < d;
    public static double code(double a, double b, double c, double d) {
    	return a * d;
    }
    
    [a, b, c, d] = sort([a, b, c, d])
    def code(a, b, c, d):
    	return a * d
    
    a, b, c, d = sort([a, b, c, d])
    function code(a, b, c, d)
    	return Float64(a * d)
    end
    
    a, b, c, d = num2cell(sort([a, b, c, d])){:}
    function tmp = code(a, b, c, d)
    	tmp = a * d;
    end
    
    NOTE: a, b, c, and d should be sorted in increasing order before calling this function.
    code[a_, b_, c_, d_] := N[(a * d), $MachinePrecision]
    
    \begin{array}{l}
    [a, b, c, d] = \mathsf{sort}([a, b, c, d])\\
    \\
    a \cdot d
    \end{array}
    
    Derivation
    1. Initial program 99.9%

      \[a \cdot \left(\left(b + c\right) + d\right) \]
    2. Add Preprocessing
    3. Taylor expanded in d around inf

      \[\leadsto a \cdot \color{blue}{d} \]
    4. Step-by-step derivation
      1. Applied rewrites44.0%

        \[\leadsto a \cdot \color{blue}{d} \]
      2. Add Preprocessing

      Developer Target 1: 99.9% accurate, 0.7× speedup?

      \[\begin{array}{l} \\ a \cdot b + a \cdot \left(c + d\right) \end{array} \]
      (FPCore (a b c d) :precision binary64 (+ (* a b) (* a (+ c d))))
      double code(double a, double b, double c, double d) {
      	return (a * b) + (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 = (a * b) + (a * (c + d))
      end function
      
      public static double code(double a, double b, double c, double d) {
      	return (a * b) + (a * (c + d));
      }
      
      def code(a, b, c, d):
      	return (a * b) + (a * (c + d))
      
      function code(a, b, c, d)
      	return Float64(Float64(a * b) + Float64(a * Float64(c + d)))
      end
      
      function tmp = code(a, b, c, d)
      	tmp = (a * b) + (a * (c + d));
      end
      
      code[a_, b_, c_, d_] := N[(N[(a * b), $MachinePrecision] + N[(a * N[(c + d), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
      
      \begin{array}{l}
      
      \\
      a \cdot b + a \cdot \left(c + d\right)
      \end{array}
      

      Reproduce

      ?
      herbie shell --seed 2025056 
      (FPCore (a b c d)
        :name "Expression, p14"
        :precision binary64
        :pre (and (and (and (and (<= 56789.0 a) (<= a 98765.0)) (and (<= 0.0 b) (<= b 1.0))) (and (<= 0.0 c) (<= c 0.0016773))) (and (<= 0.0 d) (<= d 0.0016773)))
      
        :alt
        (! :herbie-platform default (+ (* a b) (* a (+ c d))))
      
        (* a (+ (+ b c) d)))