ENA, Section 1.4, Exercise 1

Percentage Accurate: 94.5% → 97.6%
Time: 35.6s
Alternatives: 9
Speedup: 1.0×

Specification

?
\[\frac{199}{100} \leq x \land x \leq \frac{201}{100}\]
\[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (exp (* 10 (* x x)))))
double code(double x) {
	return cos(x) * exp((10.0 * (x * x)));
}
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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * exp((10.0d0 * (x * x)))
end function
public static double code(double x) {
	return Math.cos(x) * Math.exp((10.0 * (x * x)));
}
def code(x):
	return math.cos(x) * math.exp((10.0 * (x * x)))
function code(x)
	return Float64(cos(x) * exp(Float64(10.0 * Float64(x * x))))
end
function tmp = code(x)
	tmp = cos(x) * exp((10.0 * (x * x)));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Exp[N[(10 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}

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 9 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: 94.5% accurate, 1.0× speedup?

\[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (exp (* 10 (* x x)))))
double code(double x) {
	return cos(x) * exp((10.0 * (x * x)));
}
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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * exp((10.0d0 * (x * x)))
end function
public static double code(double x) {
	return Math.cos(x) * Math.exp((10.0 * (x * x)));
}
def code(x):
	return math.cos(x) * math.exp((10.0 * (x * x)))
function code(x)
	return Float64(cos(x) * exp(Float64(10.0 * Float64(x * x))))
end
function tmp = code(x)
	tmp = cos(x) * exp((10.0 * (x * x)));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Exp[N[(10 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}

Alternative 1: 97.6% accurate, 0.5× speedup?

\[\cos x \cdot {\left({\left(e^{x + x}\right)}^{x}\right)}^{5} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (pow (pow (exp (+ x x)) x) 5)))
double code(double x) {
	return cos(x) * pow(pow(exp((x + x)), x), 5.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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * ((exp((x + x)) ** x) ** 5.0d0)
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.pow(Math.exp((x + x)), x), 5.0);
}
def code(x):
	return math.cos(x) * math.pow(math.pow(math.exp((x + x)), x), 5.0)
function code(x)
	return Float64(cos(x) * ((exp(Float64(x + x)) ^ x) ^ 5.0))
end
function tmp = code(x)
	tmp = cos(x) * ((exp((x + x)) ^ x) ^ 5.0);
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Power[N[Exp[N[(x + x), $MachinePrecision]], $MachinePrecision], x], $MachinePrecision], 5], $MachinePrecision]), $MachinePrecision]
\cos x \cdot {\left({\left(e^{x + x}\right)}^{x}\right)}^{5}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot e^{\color{blue}{10 \cdot \left(x \cdot x\right)}} \]
    3. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(x \cdot x\right) \cdot 10}} \]
    4. exp-prodN/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    5. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    6. lower-exp.f6495.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
  3. Applied rewrites95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
  4. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    2. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
    3. exp-fabsN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(\left|e^{x \cdot x}\right|\right)}}^{10} \]
    4. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left(\left|\color{blue}{e^{x \cdot x}}\right|\right)}^{10} \]
    5. rem-sqrt-square-revN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(\sqrt{e^{x \cdot x} \cdot e^{x \cdot x}}\right)}}^{10} \]
    6. sqrt-pow2N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x} \cdot e^{x \cdot x}\right)}^{\left(\frac{10}{2}\right)}} \]
    7. metadata-evalN/A

      \[\leadsto \cos x \cdot {\left(e^{x \cdot x} \cdot e^{x \cdot x}\right)}^{\color{blue}{5}} \]
    8. metadata-evalN/A

      \[\leadsto \cos x \cdot {\left(e^{x \cdot x} \cdot e^{x \cdot x}\right)}^{\color{blue}{\left(3 + 2\right)}} \]
    9. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x} \cdot e^{x \cdot x}\right)}^{\left(3 + 2\right)}} \]
    10. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left(\color{blue}{e^{x \cdot x}} \cdot e^{x \cdot x}\right)}^{\left(3 + 2\right)} \]
    11. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{x \cdot x} \cdot \color{blue}{e^{x \cdot x}}\right)}^{\left(3 + 2\right)} \]
    12. exp-lft-sqr-revN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\left(x \cdot x\right) \cdot 2}\right)}}^{\left(3 + 2\right)} \]
    13. lower-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\left(x \cdot x\right) \cdot 2}\right)}}^{\left(3 + 2\right)} \]
    14. lower-*.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{\left(x \cdot x\right) \cdot 2}}\right)}^{\left(3 + 2\right)} \]
    15. metadata-eval95.3%

      \[\leadsto \cos x \cdot {\left(e^{\left(x \cdot x\right) \cdot 2}\right)}^{\color{blue}{5}} \]
  5. Applied rewrites95.3%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{\left(x \cdot x\right) \cdot 2}\right)}^{5}} \]
  6. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\left(x \cdot x\right) \cdot 2}\right)}}^{5} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{\left(x \cdot x\right) \cdot 2}}\right)}^{5} \]
    3. exp-lft-sqrN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x} \cdot e^{x \cdot x}\right)}}^{5} \]
    4. lift-*.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{x \cdot x}} \cdot e^{x \cdot x}\right)}^{5} \]
    5. exp-prodN/A

      \[\leadsto \cos x \cdot {\left(\color{blue}{{\left(e^{x}\right)}^{x}} \cdot e^{x \cdot x}\right)}^{5} \]
    6. lift-*.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{x}\right)}^{x} \cdot e^{\color{blue}{x \cdot x}}\right)}^{5} \]
    7. exp-prodN/A

      \[\leadsto \cos x \cdot {\left({\left(e^{x}\right)}^{x} \cdot \color{blue}{{\left(e^{x}\right)}^{x}}\right)}^{5} \]
    8. pow-prod-downN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x} \cdot e^{x}\right)}^{x}\right)}}^{5} \]
    9. lower-pow.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x} \cdot e^{x}\right)}^{x}\right)}}^{5} \]
    10. prod-expN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{x + x}\right)}}^{x}\right)}^{5} \]
    11. lower-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{x + x}\right)}}^{x}\right)}^{5} \]
    12. lower-+.f6497.6%

      \[\leadsto \cos x \cdot {\left({\left(e^{\color{blue}{x + x}}\right)}^{x}\right)}^{5} \]
  7. Applied rewrites97.6%

    \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x + x}\right)}^{x}\right)}}^{5} \]
  8. Add Preprocessing

Alternative 2: 96.7% accurate, 0.5× speedup?

\[\cos x \cdot {\left({\left(e^{x}\right)}^{x}\right)}^{10} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (pow (pow (exp x) x) 10)))
double code(double x) {
	return cos(x) * pow(pow(exp(x), x), 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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * ((exp(x) ** x) ** 10.0d0)
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.pow(Math.exp(x), x), 10.0);
}
def code(x):
	return math.cos(x) * math.pow(math.pow(math.exp(x), x), 10.0)
function code(x)
	return Float64(cos(x) * ((exp(x) ^ x) ^ 10.0))
end
function tmp = code(x)
	tmp = cos(x) * ((exp(x) ^ x) ^ 10.0);
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Power[N[Exp[x], $MachinePrecision], x], $MachinePrecision], 10], $MachinePrecision]), $MachinePrecision]
\cos x \cdot {\left({\left(e^{x}\right)}^{x}\right)}^{10}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot e^{\color{blue}{10 \cdot \left(x \cdot x\right)}} \]
    3. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(x \cdot x\right) \cdot 10}} \]
    4. exp-prodN/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    5. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    6. lower-exp.f6495.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
  3. Applied rewrites95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
  4. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{x \cdot x}}\right)}^{10} \]
    3. sqr-neg-revN/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)}}\right)}^{10} \]
    4. lift-neg.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{\left(-x\right)} \cdot \left(\mathsf{neg}\left(x\right)\right)}\right)}^{10} \]
    5. lift-neg.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\left(-x\right) \cdot \color{blue}{\left(-x\right)}}\right)}^{10} \]
    6. exp-prodN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{-x}\right)}^{\left(-x\right)}\right)}}^{10} \]
    7. exp-fabsN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(\left|e^{-x}\right|\right)}}^{\left(-x\right)}\right)}^{10} \]
    8. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(\left|\color{blue}{e^{-x}}\right|\right)}^{\left(-x\right)}\right)}^{10} \]
    9. rem-sqrt-square-revN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(\sqrt{e^{-x} \cdot e^{-x}}\right)}}^{\left(-x\right)}\right)}^{10} \]
    10. sqrt-pow2N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{-x} \cdot e^{-x}\right)}^{\left(\frac{-x}{2}\right)}\right)}}^{10} \]
    11. lower-pow.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{-x} \cdot e^{-x}\right)}^{\left(\frac{-x}{2}\right)}\right)}}^{10} \]
    12. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(\color{blue}{e^{-x}} \cdot e^{-x}\right)}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    13. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{-x} \cdot \color{blue}{e^{-x}}\right)}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    14. exp-lft-sqr-revN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{\left(-x\right) \cdot 2}\right)}}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    15. lower-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{\left(-x\right) \cdot 2}\right)}}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    16. lower-*.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{\color{blue}{\left(-x\right) \cdot 2}}\right)}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    17. mult-flip-revN/A

      \[\leadsto \cos x \cdot {\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\color{blue}{\left(\left(-x\right) \cdot \frac{1}{2}\right)}}\right)}^{10} \]
    18. lower-*.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\color{blue}{\left(\left(-x\right) \cdot \frac{1}{2}\right)}}\right)}^{10} \]
    19. metadata-eval97.0%

      \[\leadsto \cos x \cdot {\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\left(\left(-x\right) \cdot \color{blue}{\frac{1}{2}}\right)}\right)}^{10} \]
  5. Applied rewrites97.0%

    \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\left(\left(-x\right) \cdot \frac{1}{2}\right)}\right)}}^{10} \]
  6. Applied rewrites96.7%

    \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{x}\right)}^{x}\right)}}^{10} \]
  7. Add Preprocessing

Alternative 3: 95.2% accurate, 0.7× speedup?

\[\cos x \cdot {\left(e^{x \cdot x}\right)}^{10} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (pow (exp (* x x)) 10)))
double code(double x) {
	return cos(x) * pow(exp((x * x)), 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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * (exp((x * x)) ** 10.0d0)
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.exp((x * x)), 10.0);
}
def code(x):
	return math.cos(x) * math.pow(math.exp((x * x)), 10.0)
function code(x)
	return Float64(cos(x) * (exp(Float64(x * x)) ^ 10.0))
end
function tmp = code(x)
	tmp = cos(x) * (exp((x * x)) ^ 10.0);
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision], 10], $MachinePrecision]), $MachinePrecision]
\cos x \cdot {\left(e^{x \cdot x}\right)}^{10}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot e^{\color{blue}{10 \cdot \left(x \cdot x\right)}} \]
    3. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(x \cdot x\right) \cdot 10}} \]
    4. exp-prodN/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    5. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    6. lower-exp.f6495.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
  3. Applied rewrites95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
  4. Add Preprocessing

Alternative 4: 95.2% accurate, 0.7× speedup?

\[\cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (pow (exp 10) (* x x))))
double code(double x) {
	return cos(x) * pow(exp(10.0), (x * x));
}
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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * (exp(10.0d0) ** (x * x))
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow(Math.exp(10.0), (x * x));
}
def code(x):
	return math.cos(x) * math.pow(math.exp(10.0), (x * x))
function code(x)
	return Float64(cos(x) * (exp(10.0) ^ Float64(x * x)))
end
function tmp = code(x)
	tmp = cos(x) * (exp(10.0) ^ (x * x));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Exp[10], $MachinePrecision], N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot e^{\color{blue}{10 \cdot \left(x \cdot x\right)}} \]
    3. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(x \cdot x\right) \cdot 10}} \]
    4. exp-prodN/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    5. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    6. lower-exp.f6495.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
  3. Applied rewrites95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
  4. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{x \cdot x}}\right)}^{10} \]
    3. sqr-neg-revN/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{\left(\mathsf{neg}\left(x\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)}}\right)}^{10} \]
    4. lift-neg.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\color{blue}{\left(-x\right)} \cdot \left(\mathsf{neg}\left(x\right)\right)}\right)}^{10} \]
    5. lift-neg.f64N/A

      \[\leadsto \cos x \cdot {\left(e^{\left(-x\right) \cdot \color{blue}{\left(-x\right)}}\right)}^{10} \]
    6. exp-prodN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{-x}\right)}^{\left(-x\right)}\right)}}^{10} \]
    7. exp-fabsN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(\left|e^{-x}\right|\right)}}^{\left(-x\right)}\right)}^{10} \]
    8. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(\left|\color{blue}{e^{-x}}\right|\right)}^{\left(-x\right)}\right)}^{10} \]
    9. rem-sqrt-square-revN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(\sqrt{e^{-x} \cdot e^{-x}}\right)}}^{\left(-x\right)}\right)}^{10} \]
    10. sqrt-pow2N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{-x} \cdot e^{-x}\right)}^{\left(\frac{-x}{2}\right)}\right)}}^{10} \]
    11. lower-pow.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{-x} \cdot e^{-x}\right)}^{\left(\frac{-x}{2}\right)}\right)}}^{10} \]
    12. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(\color{blue}{e^{-x}} \cdot e^{-x}\right)}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    13. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{-x} \cdot \color{blue}{e^{-x}}\right)}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    14. exp-lft-sqr-revN/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{\left(-x\right) \cdot 2}\right)}}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    15. lower-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{\left(-x\right) \cdot 2}\right)}}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    16. lower-*.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{\color{blue}{\left(-x\right) \cdot 2}}\right)}^{\left(\frac{-x}{2}\right)}\right)}^{10} \]
    17. mult-flip-revN/A

      \[\leadsto \cos x \cdot {\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\color{blue}{\left(\left(-x\right) \cdot \frac{1}{2}\right)}}\right)}^{10} \]
    18. lower-*.f64N/A

      \[\leadsto \cos x \cdot {\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\color{blue}{\left(\left(-x\right) \cdot \frac{1}{2}\right)}}\right)}^{10} \]
    19. metadata-eval97.0%

      \[\leadsto \cos x \cdot {\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\left(\left(-x\right) \cdot \color{blue}{\frac{1}{2}}\right)}\right)}^{10} \]
  5. Applied rewrites97.0%

    \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\left(\left(-x\right) \cdot \frac{1}{2}\right)}\right)}}^{10} \]
  6. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\left(\left(-x\right) \cdot \frac{1}{2}\right)}\right)}^{10}} \]
    2. lift-pow.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left({\left(e^{\left(-x\right) \cdot 2}\right)}^{\left(\left(-x\right) \cdot \frac{1}{2}\right)}\right)}}^{10} \]
    3. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\left({\color{blue}{\left(e^{\left(-x\right) \cdot 2}\right)}}^{\left(\left(-x\right) \cdot \frac{1}{2}\right)}\right)}^{10} \]
    4. pow-expN/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{\left(\left(-x\right) \cdot 2\right) \cdot \left(\left(-x\right) \cdot \frac{1}{2}\right)}\right)}}^{10} \]
    5. pow-expN/A

      \[\leadsto \cos x \cdot \color{blue}{e^{\left(\left(\left(-x\right) \cdot 2\right) \cdot \left(\left(-x\right) \cdot \frac{1}{2}\right)\right) \cdot 10}} \]
    6. sinh-+-cosh-revN/A

      \[\leadsto \cos x \cdot \color{blue}{\left(\cosh \left(\left(\left(\left(-x\right) \cdot 2\right) \cdot \left(\left(-x\right) \cdot \frac{1}{2}\right)\right) \cdot 10\right) + \sinh \left(\left(\left(\left(-x\right) \cdot 2\right) \cdot \left(\left(-x\right) \cdot \frac{1}{2}\right)\right) \cdot 10\right)\right)} \]
  7. Applied rewrites95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{10}\right)}^{\left(x \cdot x\right)}} \]
  8. Add Preprocessing

Alternative 5: 94.5% accurate, 1.0× speedup?

\[\sin \left(\frac{1}{2} \cdot \pi + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)} \]
(FPCore (x)
  :precision binary64
  (* (sin (+ (* 1/2 PI) x)) (exp (* 10 (* x x)))))
double code(double x) {
	return sin(((0.5 * ((double) M_PI)) + x)) * exp((10.0 * (x * x)));
}
public static double code(double x) {
	return Math.sin(((0.5 * Math.PI) + x)) * Math.exp((10.0 * (x * x)));
}
def code(x):
	return math.sin(((0.5 * math.pi) + x)) * math.exp((10.0 * (x * x)))
function code(x)
	return Float64(sin(Float64(Float64(0.5 * pi) + x)) * exp(Float64(10.0 * Float64(x * x))))
end
function tmp = code(x)
	tmp = sin(((0.5 * pi) + x)) * exp((10.0 * (x * x)));
end
code[x_] := N[(N[Sin[N[(N[(1/2 * Pi), $MachinePrecision] + x), $MachinePrecision]], $MachinePrecision] * N[Exp[N[(10 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\sin \left(\frac{1}{2} \cdot \pi + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-cos.f64N/A

      \[\leadsto \color{blue}{\cos x} \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    2. sin-+PI/2-revN/A

      \[\leadsto \color{blue}{\sin \left(x + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    3. lower-sin.f64N/A

      \[\leadsto \color{blue}{\sin \left(x + \frac{\mathsf{PI}\left(\right)}{2}\right)} \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    4. +-commutativeN/A

      \[\leadsto \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + x\right)} \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    5. lower-+.f64N/A

      \[\leadsto \sin \color{blue}{\left(\frac{\mathsf{PI}\left(\right)}{2} + x\right)} \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    6. mult-flipN/A

      \[\leadsto \sin \left(\color{blue}{\mathsf{PI}\left(\right) \cdot \frac{1}{2}} + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    7. *-commutativeN/A

      \[\leadsto \sin \left(\color{blue}{\frac{1}{2} \cdot \mathsf{PI}\left(\right)} + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    8. lower-*.f64N/A

      \[\leadsto \sin \left(\color{blue}{\frac{1}{2} \cdot \mathsf{PI}\left(\right)} + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    9. metadata-evalN/A

      \[\leadsto \sin \left(\color{blue}{\frac{1}{2}} \cdot \mathsf{PI}\left(\right) + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)} \]
    10. lower-PI.f6494.5%

      \[\leadsto \sin \left(\frac{1}{2} \cdot \color{blue}{\pi} + x\right) \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  3. Applied rewrites94.5%

    \[\leadsto \color{blue}{\sin \left(\frac{1}{2} \cdot \pi + x\right)} \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  4. Add Preprocessing

Alternative 6: 11.4% accurate, 1.0× speedup?

\[\cos x \cdot {\left(1 + x\right)}^{\left(10 \cdot x\right)} \]
(FPCore (x)
  :precision binary64
  (* (cos x) (pow (+ 1 x) (* 10 x))))
double code(double x) {
	return cos(x) * pow((1.0 + x), (10.0 * x));
}
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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * ((1.0d0 + x) ** (10.0d0 * x))
end function
public static double code(double x) {
	return Math.cos(x) * Math.pow((1.0 + x), (10.0 * x));
}
def code(x):
	return math.cos(x) * math.pow((1.0 + x), (10.0 * x))
function code(x)
	return Float64(cos(x) * (Float64(1.0 + x) ^ Float64(10.0 * x)))
end
function tmp = code(x)
	tmp = cos(x) * ((1.0 + x) ^ (10.0 * x));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[(1 + x), $MachinePrecision], N[(10 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\cos x \cdot {\left(1 + x\right)}^{\left(10 \cdot x\right)}
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Step-by-step derivation
    1. lift-exp.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{e^{10 \cdot \left(x \cdot x\right)}} \]
    2. lift-*.f64N/A

      \[\leadsto \cos x \cdot e^{\color{blue}{10 \cdot \left(x \cdot x\right)}} \]
    3. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(x \cdot x\right) \cdot 10}} \]
    4. exp-prodN/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    5. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    6. lower-exp.f6495.2%

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
  3. Applied rewrites95.2%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
  4. Step-by-step derivation
    1. lift-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x \cdot x}\right)}^{10}} \]
    2. lift-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x \cdot x}\right)}}^{10} \]
    3. pow-expN/A

      \[\leadsto \cos x \cdot \color{blue}{e^{\left(x \cdot x\right) \cdot 10}} \]
    4. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{10 \cdot \left(x \cdot x\right)}} \]
    5. lift-*.f64N/A

      \[\leadsto \cos x \cdot e^{10 \cdot \color{blue}{\left(x \cdot x\right)}} \]
    6. associate-*r*N/A

      \[\leadsto \cos x \cdot e^{\color{blue}{\left(10 \cdot x\right) \cdot x}} \]
    7. *-commutativeN/A

      \[\leadsto \cos x \cdot e^{\color{blue}{x \cdot \left(10 \cdot x\right)}} \]
    8. exp-prodN/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x}\right)}^{\left(10 \cdot x\right)}} \]
    9. lower-pow.f64N/A

      \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x}\right)}^{\left(10 \cdot x\right)}} \]
    10. lower-exp.f64N/A

      \[\leadsto \cos x \cdot {\color{blue}{\left(e^{x}\right)}}^{\left(10 \cdot x\right)} \]
    11. lower-*.f6494.7%

      \[\leadsto \cos x \cdot {\left(e^{x}\right)}^{\color{blue}{\left(10 \cdot x\right)}} \]
  5. Applied rewrites94.7%

    \[\leadsto \cos x \cdot \color{blue}{{\left(e^{x}\right)}^{\left(10 \cdot x\right)}} \]
  6. Taylor expanded in x around 0

    \[\leadsto \cos x \cdot {\color{blue}{\left(1 + x\right)}}^{\left(10 \cdot x\right)} \]
  7. Step-by-step derivation
    1. lower-+.f6411.4%

      \[\leadsto \cos x \cdot {\left(1 + \color{blue}{x}\right)}^{\left(10 \cdot x\right)} \]
  8. Applied rewrites11.4%

    \[\leadsto \cos x \cdot {\color{blue}{\left(1 + x\right)}}^{\left(10 \cdot x\right)} \]
  9. Add Preprocessing

Alternative 7: 9.8% accurate, 1.0× speedup?

\[\cos x \cdot \left(1 + 10 \cdot {x}^{2}\right) \]
(FPCore (x)
  :precision binary64
  (* (cos x) (+ 1 (* 10 (pow x 2)))))
double code(double x) {
	return cos(x) * (1.0 + (10.0 * pow(x, 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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = cos(x) * (1.0d0 + (10.0d0 * (x ** 2.0d0)))
end function
public static double code(double x) {
	return Math.cos(x) * (1.0 + (10.0 * Math.pow(x, 2.0)));
}
def code(x):
	return math.cos(x) * (1.0 + (10.0 * math.pow(x, 2.0)))
function code(x)
	return Float64(cos(x) * Float64(1.0 + Float64(10.0 * (x ^ 2.0))))
end
function tmp = code(x)
	tmp = cos(x) * (1.0 + (10.0 * (x ^ 2.0)));
end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[(1 + N[(10 * N[Power[x, 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\cos x \cdot \left(1 + 10 \cdot {x}^{2}\right)
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Taylor expanded in x around 0

    \[\leadsto \cos x \cdot \color{blue}{\left(1 + 10 \cdot {x}^{2}\right)} \]
  3. Step-by-step derivation
    1. lower-+.f64N/A

      \[\leadsto \cos x \cdot \left(1 + \color{blue}{10 \cdot {x}^{2}}\right) \]
    2. lower-*.f64N/A

      \[\leadsto \cos x \cdot \left(1 + 10 \cdot \color{blue}{{x}^{2}}\right) \]
    3. lower-pow.f649.8%

      \[\leadsto \cos x \cdot \left(1 + 10 \cdot {x}^{\color{blue}{2}}\right) \]
  4. Applied rewrites9.8%

    \[\leadsto \cos x \cdot \color{blue}{\left(1 + 10 \cdot {x}^{2}\right)} \]
  5. Add Preprocessing

Alternative 8: 1.5% accurate, 15.4× speedup?

\[1 + \left(\frac{19}{2} \cdot x\right) \cdot x \]
(FPCore (x)
  :precision binary64
  (+ 1 (* (* 19/2 x) x)))
double code(double x) {
	return 1.0 + ((9.5 * x) * x);
}
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(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = 1.0d0 + ((9.5d0 * x) * x)
end function
public static double code(double x) {
	return 1.0 + ((9.5 * x) * x);
}
def code(x):
	return 1.0 + ((9.5 * x) * x)
function code(x)
	return Float64(1.0 + Float64(Float64(9.5 * x) * x))
end
function tmp = code(x)
	tmp = 1.0 + ((9.5 * x) * x);
end
code[x_] := N[(1 + N[(N[(19/2 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
1 + \left(\frac{19}{2} \cdot x\right) \cdot x
Derivation
  1. Initial program 94.5%

    \[\cos x \cdot e^{10 \cdot \left(x \cdot x\right)} \]
  2. Taylor expanded in x around 0

    \[\leadsto \color{blue}{1 + \frac{19}{2} \cdot {x}^{2}} \]
  3. Step-by-step derivation
    1. lower-+.f64N/A

      \[\leadsto 1 + \color{blue}{\frac{19}{2} \cdot {x}^{2}} \]
    2. lower-*.f64N/A

      \[\leadsto 1 + \frac{19}{2} \cdot \color{blue}{{x}^{2}} \]
    3. lower-pow.f641.5%

      \[\leadsto 1 + \frac{19}{2} \cdot {x}^{\color{blue}{2}} \]
  4. Applied rewrites1.5%

    \[\leadsto \color{blue}{1 + \frac{19}{2} \cdot {x}^{2}} \]
  5. Step-by-step derivation
    1. lift-*.f64N/A

      \[\leadsto 1 + \frac{19}{2} \cdot \color{blue}{{x}^{2}} \]
    2. lift-pow.f64N/A

      \[\leadsto 1 + \frac{19}{2} \cdot {x}^{\color{blue}{2}} \]
    3. pow2N/A

      \[\leadsto 1 + \frac{19}{2} \cdot \left(x \cdot \color{blue}{x}\right) \]
    4. associate-*r*N/A

      \[\leadsto 1 + \left(\frac{19}{2} \cdot x\right) \cdot \color{blue}{x} \]
    5. metadata-evalN/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\frac{-19}{2}\right)\right) \cdot x\right) \cdot x \]
    6. metadata-evalN/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right)\right)\right) \cdot x\right) \cdot x \]
    7. distribute-lft-neg-outN/A

      \[\leadsto 1 + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right) \cdot x\right)\right) \cdot x \]
    8. distribute-rgt-neg-outN/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)\right) \cdot x \]
    9. lift-neg.f64N/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right) \cdot \left(-x\right)\right) \cdot x \]
    10. lower-*.f64N/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right) \cdot \left(-x\right)\right) \cdot \color{blue}{x} \]
    11. lift-neg.f64N/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right) \cdot \left(\mathsf{neg}\left(x\right)\right)\right) \cdot x \]
    12. distribute-rgt-neg-outN/A

      \[\leadsto 1 + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right) \cdot x\right)\right) \cdot x \]
    13. distribute-lft-neg-outN/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\frac{19}{2}\right)\right)\right)\right) \cdot x\right) \cdot x \]
    14. metadata-evalN/A

      \[\leadsto 1 + \left(\left(\mathsf{neg}\left(\frac{-19}{2}\right)\right) \cdot x\right) \cdot x \]
    15. metadata-evalN/A

      \[\leadsto 1 + \left(\frac{19}{2} \cdot x\right) \cdot x \]
    16. lower-*.f641.5%

      \[\leadsto 1 + \left(\frac{19}{2} \cdot x\right) \cdot x \]
  6. Applied rewrites1.5%

    \[\leadsto 1 + \left(\frac{19}{2} \cdot x\right) \cdot \color{blue}{x} \]
  7. Add Preprocessing

Reproduce

?
herbie shell --seed 2025271 -o generate:evaluate
(FPCore (x)
  :name "ENA, Section 1.4, Exercise 1"
  :precision binary64
  :pre (and (<= 199/100 x) (<= x 201/100))
  (* (cos x) (exp (* 10 (* x x)))))