FastMath test5

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

Specification

?
\[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
(FPCore (d1)
  :precision binary64
  (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))
double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
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(d1)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    code = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
end function
public static double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
def code(d1):
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
function code(d1)
	return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(d1 * Float64(d1 * d1)) * d1) * d1) * Float64(d1 * d1)) * d1)) * d1)
end
function tmp = code(d1)
	tmp = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1

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?

\[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
(FPCore (d1)
  :precision binary64
  (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))
double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
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(d1)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    code = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
end function
public static double code(double d1) {
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
}
def code(d1):
	return (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1
function code(d1)
	return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(d1 * Float64(d1 * d1)) * d1) * d1) * Float64(d1 * d1)) * d1)) * d1)
end
function tmp = code(d1)
	tmp = (d1 * (((((d1 * (d1 * d1)) * d1) * d1) * (d1 * d1)) * d1)) * d1;
end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(d1 * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * N[(d1 * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1

Alternative 1: 100.0% accurate, 0.5× speedup?

\[{d1}^{10} \]
(FPCore (d1)
  :precision binary64
  (pow d1 10))
double code(double d1) {
	return pow(d1, 10.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(d1)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    code = d1 ** 10.0d0
end function
public static double code(double d1) {
	return Math.pow(d1, 10.0);
}
def code(d1):
	return math.pow(d1, 10.0)
function code(d1)
	return d1 ^ 10.0
end
function tmp = code(d1)
	tmp = d1 ^ 10.0;
end
code[d1_] := N[Power[d1, 10], $MachinePrecision]
{d1}^{10}
Derivation
  1. Initial program 99.9%

    \[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1} \]
    2. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right)} \cdot d1 \]
    3. *-commutativeN/A

      \[\leadsto \color{blue}{\left(\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right)} \cdot d1 \]
    4. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)} \]
    5. lift-*.f64N/A

      \[\leadsto \color{blue}{\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)} \cdot \left(d1 \cdot d1\right) \]
    6. lift-*.f64N/A

      \[\leadsto \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot \color{blue}{\left(d1 \cdot d1\right)} \]
    7. associate-*l*N/A

      \[\leadsto \color{blue}{\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)} \]
  3. Applied rewrites100.0%

    \[\leadsto \color{blue}{{d1}^{10}} \]
  4. Add Preprocessing

Alternative 2: 99.9% accurate, 1.0× speedup?

\[\left(d1 \cdot \left(\left(\left(\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)\right) \cdot d1 \]
(FPCore (d1)
  :precision binary64
  (* (* d1 (* (* (* (* (* (* (* d1 d1) d1) d1) d1) d1) d1) d1)) d1))
double code(double d1) {
	return (d1 * (((((((d1 * d1) * d1) * d1) * d1) * d1) * d1) * d1)) * d1;
}
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(d1)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    code = (d1 * (((((((d1 * d1) * d1) * d1) * d1) * d1) * d1) * d1)) * d1
end function
public static double code(double d1) {
	return (d1 * (((((((d1 * d1) * d1) * d1) * d1) * d1) * d1) * d1)) * d1;
}
def code(d1):
	return (d1 * (((((((d1 * d1) * d1) * d1) * d1) * d1) * d1) * d1)) * d1
function code(d1)
	return Float64(Float64(d1 * Float64(Float64(Float64(Float64(Float64(Float64(Float64(d1 * d1) * d1) * d1) * d1) * d1) * d1) * d1)) * d1)
end
function tmp = code(d1)
	tmp = (d1 * (((((((d1 * d1) * d1) * d1) * d1) * d1) * d1) * d1)) * d1;
end
code[d1_] := N[(N[(d1 * N[(N[(N[(N[(N[(N[(N[(d1 * d1), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]
\left(d1 \cdot \left(\left(\left(\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)\right) \cdot d1
Derivation
  1. Initial program 99.9%

    \[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right)} \cdot d1\right)\right) \cdot d1 \]
    2. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \color{blue}{\left(d1 \cdot d1\right)}\right) \cdot d1\right)\right) \cdot d1 \]
    3. associate-*r*N/A

      \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)} \cdot d1\right)\right) \cdot d1 \]
    4. lower-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)} \cdot d1\right)\right) \cdot d1 \]
    5. lower-*.f6499.9%

      \[\leadsto \left(d1 \cdot \left(\left(\color{blue}{\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)} \cdot d1\right) \cdot d1\right)\right) \cdot d1 \]
    6. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(\color{blue}{\left(d1 \cdot \left(d1 \cdot d1\right)\right)} \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)\right) \cdot d1 \]
    7. *-commutativeN/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(\color{blue}{\left(\left(d1 \cdot d1\right) \cdot d1\right)} \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)\right) \cdot d1 \]
    8. lower-*.f6499.9%

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(\color{blue}{\left(\left(d1 \cdot d1\right) \cdot d1\right)} \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)\right) \cdot d1 \]
  3. Applied rewrites99.9%

    \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot d1\right)} \cdot d1\right)\right) \cdot d1 \]
  4. Add Preprocessing

Alternative 3: 99.9% accurate, 1.0× speedup?

\[\begin{array}{l} t_0 := \left(d1 \cdot d1\right) \cdot d1\\ \left(d1 \cdot \left(\left(\left(t\_0 \cdot d1\right) \cdot t\_0\right) \cdot d1\right)\right) \cdot d1 \end{array} \]
(FPCore (d1)
  :precision binary64
  (let* ((t_0 (* (* d1 d1) d1)))
  (* (* d1 (* (* (* t_0 d1) t_0) d1)) d1)))
double code(double d1) {
	double t_0 = (d1 * d1) * d1;
	return (d1 * (((t_0 * d1) * t_0) * d1)) * d1;
}
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(d1)
use fmin_fmax_functions
    real(8), intent (in) :: d1
    real(8) :: t_0
    t_0 = (d1 * d1) * d1
    code = (d1 * (((t_0 * d1) * t_0) * d1)) * d1
end function
public static double code(double d1) {
	double t_0 = (d1 * d1) * d1;
	return (d1 * (((t_0 * d1) * t_0) * d1)) * d1;
}
def code(d1):
	t_0 = (d1 * d1) * d1
	return (d1 * (((t_0 * d1) * t_0) * d1)) * d1
function code(d1)
	t_0 = Float64(Float64(d1 * d1) * d1)
	return Float64(Float64(d1 * Float64(Float64(Float64(t_0 * d1) * t_0) * d1)) * d1)
end
function tmp = code(d1)
	t_0 = (d1 * d1) * d1;
	tmp = (d1 * (((t_0 * d1) * t_0) * d1)) * d1;
end
code[d1_] := Block[{t$95$0 = N[(N[(d1 * d1), $MachinePrecision] * d1), $MachinePrecision]}, N[(N[(d1 * N[(N[(N[(t$95$0 * d1), $MachinePrecision] * t$95$0), $MachinePrecision] * d1), $MachinePrecision]), $MachinePrecision] * d1), $MachinePrecision]]
\begin{array}{l}
t_0 := \left(d1 \cdot d1\right) \cdot d1\\
\left(d1 \cdot \left(\left(\left(t\_0 \cdot d1\right) \cdot t\_0\right) \cdot d1\right)\right) \cdot d1
\end{array}
Derivation
  1. Initial program 99.9%

    \[\left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
  2. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right) \cdot \left(d1 \cdot d1\right)\right)} \cdot d1\right)\right) \cdot d1 \]
    2. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\left(\color{blue}{\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot d1\right)} \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right)\right) \cdot d1 \]
    3. associate-*l*N/A

      \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)} \cdot d1\right)\right) \cdot d1 \]
    4. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot \color{blue}{\left(d1 \cdot \left(d1 \cdot d1\right)\right)}\right) \cdot d1\right)\right) \cdot d1 \]
    5. lower-*.f6499.9%

      \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(d1 \cdot \left(d1 \cdot d1\right)\right) \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right)} \cdot d1\right)\right) \cdot d1 \]
    6. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\color{blue}{\left(d1 \cdot \left(d1 \cdot d1\right)\right)} \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right) \cdot d1\right)\right) \cdot d1 \]
    7. *-commutativeN/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\color{blue}{\left(\left(d1 \cdot d1\right) \cdot d1\right)} \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right) \cdot d1\right)\right) \cdot d1 \]
    8. lower-*.f6499.9%

      \[\leadsto \left(d1 \cdot \left(\left(\left(\color{blue}{\left(\left(d1 \cdot d1\right) \cdot d1\right)} \cdot d1\right) \cdot \left(d1 \cdot \left(d1 \cdot d1\right)\right)\right) \cdot d1\right)\right) \cdot d1 \]
    9. lift-*.f64N/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot \color{blue}{\left(d1 \cdot \left(d1 \cdot d1\right)\right)}\right) \cdot d1\right)\right) \cdot d1 \]
    10. *-commutativeN/A

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot \color{blue}{\left(\left(d1 \cdot d1\right) \cdot d1\right)}\right) \cdot d1\right)\right) \cdot d1 \]
    11. lower-*.f6499.9%

      \[\leadsto \left(d1 \cdot \left(\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot \color{blue}{\left(\left(d1 \cdot d1\right) \cdot d1\right)}\right) \cdot d1\right)\right) \cdot d1 \]
  3. Applied rewrites99.9%

    \[\leadsto \left(d1 \cdot \left(\color{blue}{\left(\left(\left(\left(d1 \cdot d1\right) \cdot d1\right) \cdot d1\right) \cdot \left(\left(d1 \cdot d1\right) \cdot d1\right)\right)} \cdot d1\right)\right) \cdot d1 \]
  4. Add Preprocessing

Reproduce

?
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (d1)
  :name "FastMath test5"
  :precision binary64
  (* (* d1 (* (* (* (* (* d1 (* d1 d1)) d1) d1) (* d1 d1)) d1)) d1))