
(FPCore (x) :precision binary64 (* (cos x) (exp (* 10.0 (* x x)))))
double code(double x) {
return cos(x) * exp((10.0 * (x * x)));
}
real(8) function code(x)
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.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 20 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (* (cos x) (exp (* 10.0 (* x x)))))
double code(double x) {
return cos(x) * exp((10.0 * (x * x)));
}
real(8) function code(x)
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.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}
(FPCore (x) :precision binary64 (* (/ 1.0 (pow (pow (exp 20.0) x) (* -0.5 x))) (cos x)))
double code(double x) {
return (1.0 / pow(pow(exp(20.0), x), (-0.5 * x))) * cos(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / ((exp(20.0d0) ** x) ** ((-0.5d0) * x))) * cos(x)
end function
public static double code(double x) {
return (1.0 / Math.pow(Math.pow(Math.exp(20.0), x), (-0.5 * x))) * Math.cos(x);
}
def code(x): return (1.0 / math.pow(math.pow(math.exp(20.0), x), (-0.5 * x))) * math.cos(x)
function code(x) return Float64(Float64(1.0 / ((exp(20.0) ^ x) ^ Float64(-0.5 * x))) * cos(x)) end
function tmp = code(x) tmp = (1.0 / ((exp(20.0) ^ x) ^ (-0.5 * x))) * cos(x); end
code[x_] := N[(N[(1.0 / N[Power[N[Power[N[Exp[20.0], $MachinePrecision], x], $MachinePrecision], N[(-0.5 * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{{\left({\left(e^{20}\right)}^{x}\right)}^{\left(-0.5 \cdot x\right)}} \cdot \cos x
\end{array}
Initial program 94.6%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
sqr-powN/A
pow-prod-upN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
associate-/l/N/A
+-inversesN/A
+-inversesN/A
flip-+N/A
count-2N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
metadata-evalN/A
*-rgt-identityN/A
frac-2negN/A
distribute-frac-negN/A
Applied rewrites95.2%
lift-pow.f64N/A
sqr-powN/A
pow-prod-downN/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
pow-unpowN/A
lift-neg.f64N/A
neg-mul-1N/A
*-commutativeN/A
associate-/l*N/A
metadata-evalN/A
lower-pow.f64N/A
lower-pow.f64N/A
lift-exp.f64N/A
lift-exp.f64N/A
prod-expN/A
lower-exp.f64N/A
metadata-evalN/A
*-commutativeN/A
lower-*.f6499.3
Applied rewrites99.3%
Final simplification99.3%
(FPCore (x) :precision binary64 (* (/ 1.0 (pow (pow (exp 10.0) x) (- x))) (cos x)))
double code(double x) {
return (1.0 / pow(pow(exp(10.0), x), -x)) * cos(x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / ((exp(10.0d0) ** x) ** -x)) * cos(x)
end function
public static double code(double x) {
return (1.0 / Math.pow(Math.pow(Math.exp(10.0), x), -x)) * Math.cos(x);
}
def code(x): return (1.0 / math.pow(math.pow(math.exp(10.0), x), -x)) * math.cos(x)
function code(x) return Float64(Float64(1.0 / ((exp(10.0) ^ x) ^ Float64(-x))) * cos(x)) end
function tmp = code(x) tmp = (1.0 / ((exp(10.0) ^ x) ^ -x)) * cos(x); end
code[x_] := N[(N[(1.0 / N[Power[N[Power[N[Exp[10.0], $MachinePrecision], x], $MachinePrecision], (-x)], $MachinePrecision]), $MachinePrecision] * N[Cos[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{{\left({\left(e^{10}\right)}^{x}\right)}^{\left(-x\right)}} \cdot \cos x
\end{array}
Initial program 94.5%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
sqr-powN/A
pow-prod-upN/A
flip-+N/A
+-inversesN/A
+-inversesN/A
metadata-evalN/A
associate-/l/N/A
+-inversesN/A
+-inversesN/A
flip-+N/A
count-2N/A
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
metadata-evalN/A
*-rgt-identityN/A
frac-2negN/A
distribute-frac-negN/A
Applied rewrites95.2%
lift-pow.f64N/A
lift-*.f64N/A
*-commutativeN/A
pow-unpowN/A
lift-exp.f64N/A
exp-prodN/A
*-commutativeN/A
pow-expN/A
lift-exp.f64N/A
lower-pow.f64N/A
lift-exp.f64N/A
pow-expN/A
*-commutativeN/A
lift-*.f64N/A
lower-exp.f6495.0
Applied rewrites95.0%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f6498.0
Applied rewrites98.0%
Final simplification98.0%
herbie shell --seed 2024230
(FPCore (x)
:name "ENA, Section 1.4, Exercise 1"
:precision binary64
:pre (and (<= 1.99 x) (<= x 2.01))
(* (cos x) (exp (* 10.0 (* x x)))))