
(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 13 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 (* (cos x) (* (pow (pow (pow (exp 5.0) 2.0) x) (/ x 2.0)) (pow (pow (exp 10.0) x) (/ x 2.0)))))
double code(double x) {
return cos(x) * (pow(pow(pow(exp(5.0), 2.0), x), (x / 2.0)) * pow(pow(exp(10.0), x), (x / 2.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = cos(x) * ((((exp(5.0d0) ** 2.0d0) ** x) ** (x / 2.0d0)) * ((exp(10.0d0) ** x) ** (x / 2.0d0)))
end function
public static double code(double x) {
return Math.cos(x) * (Math.pow(Math.pow(Math.pow(Math.exp(5.0), 2.0), x), (x / 2.0)) * Math.pow(Math.pow(Math.exp(10.0), x), (x / 2.0)));
}
def code(x): return math.cos(x) * (math.pow(math.pow(math.pow(math.exp(5.0), 2.0), x), (x / 2.0)) * math.pow(math.pow(math.exp(10.0), x), (x / 2.0)))
function code(x) return Float64(cos(x) * Float64((((exp(5.0) ^ 2.0) ^ x) ^ Float64(x / 2.0)) * ((exp(10.0) ^ x) ^ Float64(x / 2.0)))) end
function tmp = code(x) tmp = cos(x) * ((((exp(5.0) ^ 2.0) ^ x) ^ (x / 2.0)) * ((exp(10.0) ^ x) ^ (x / 2.0))); end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[(N[Power[N[Power[N[Power[N[Exp[5.0], $MachinePrecision], 2.0], $MachinePrecision], x], $MachinePrecision], N[(x / 2.0), $MachinePrecision]], $MachinePrecision] * N[Power[N[Power[N[Exp[10.0], $MachinePrecision], x], $MachinePrecision], N[(x / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \left({\left({\left({\left(e^{5}\right)}^{2}\right)}^{x}\right)}^{\left(\frac{x}{2}\right)} \cdot {\left({\left(e^{10}\right)}^{x}\right)}^{\left(\frac{x}{2}\right)}\right)
\end{array}
Initial program 94.6%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
lift-*.f64N/A
pow-unpowN/A
sqr-powN/A
pow-prod-upN/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites98.0%
unpow1N/A
sqr-powN/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-pow.f6499.0
Applied rewrites99.0%
lift-*.f64N/A
pow2N/A
lower-pow.f6499.0
lift-pow.f64N/A
lift-exp.f64N/A
pow-expN/A
lower-exp.f64N/A
metadata-eval99.0
Applied rewrites99.0%
lift-*.f64N/A
*-rgt-identity99.0
Applied rewrites99.0%
Final simplification99.0%
(FPCore (x) :precision binary64 (let* ((t_0 (pow (pow (exp 10.0) x) (/ x 2.0)))) (* (cos x) (* t_0 t_0))))
double code(double x) {
double t_0 = pow(pow(exp(10.0), x), (x / 2.0));
return cos(x) * (t_0 * t_0);
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
t_0 = (exp(10.0d0) ** x) ** (x / 2.0d0)
code = cos(x) * (t_0 * t_0)
end function
public static double code(double x) {
double t_0 = Math.pow(Math.pow(Math.exp(10.0), x), (x / 2.0));
return Math.cos(x) * (t_0 * t_0);
}
def code(x): t_0 = math.pow(math.pow(math.exp(10.0), x), (x / 2.0)) return math.cos(x) * (t_0 * t_0)
function code(x) t_0 = (exp(10.0) ^ x) ^ Float64(x / 2.0) return Float64(cos(x) * Float64(t_0 * t_0)) end
function tmp = code(x) t_0 = (exp(10.0) ^ x) ^ (x / 2.0); tmp = cos(x) * (t_0 * t_0); end
code[x_] := Block[{t$95$0 = N[Power[N[Power[N[Exp[10.0], $MachinePrecision], x], $MachinePrecision], N[(x / 2.0), $MachinePrecision]], $MachinePrecision]}, N[(N[Cos[x], $MachinePrecision] * N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := {\left({\left(e^{10}\right)}^{x}\right)}^{\left(\frac{x}{2}\right)}\\
\cos x \cdot \left(t\_0 \cdot t\_0\right)
\end{array}
\end{array}
Initial program 94.6%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
lift-*.f64N/A
pow-unpowN/A
sqr-powN/A
pow-prod-upN/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites98.0%
lift-*.f64N/A
*-rgt-identity98.0
Applied rewrites98.0%
Final simplification98.0%
(FPCore (x) :precision binary64 (* (cos x) (pow (pow (exp 10.0) (* (- x) x)) -1.0)))
double code(double x) {
return cos(x) * pow(pow(exp(10.0), (-x * x)), -1.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = cos(x) * ((exp(10.0d0) ** (-x * x)) ** (-1.0d0))
end function
public static double code(double x) {
return Math.cos(x) * Math.pow(Math.pow(Math.exp(10.0), (-x * x)), -1.0);
}
def code(x): return math.cos(x) * math.pow(math.pow(math.exp(10.0), (-x * x)), -1.0)
function code(x) return Float64(cos(x) * ((exp(10.0) ^ Float64(Float64(-x) * x)) ^ -1.0)) end
function tmp = code(x) tmp = cos(x) * ((exp(10.0) ^ (-x * x)) ^ -1.0); end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Power[N[Exp[10.0], $MachinePrecision], N[((-x) * x), $MachinePrecision]], $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot {\left({\left(e^{10}\right)}^{\left(\left(-x\right) \cdot x\right)}\right)}^{-1}
\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.4%
Final simplification95.4%
(FPCore (x) :precision binary64 (* (cos x) (pow (pow (exp 10.0) x) x)))
double code(double x) {
return cos(x) * pow(pow(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.pow(Math.pow(Math.exp(10.0), x), x);
}
def code(x): return math.cos(x) * math.pow(math.pow(math.exp(10.0), x), x)
function code(x) return Float64(cos(x) * ((exp(10.0) ^ 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[Power[N[Exp[10.0], $MachinePrecision], x], $MachinePrecision], x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot {\left({\left(e^{10}\right)}^{x}\right)}^{x}
\end{array}
Initial program 94.6%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
lift-*.f64N/A
pow-unpowN/A
lower-pow.f64N/A
lower-pow.f64N/A
lower-exp.f6498.0
Applied rewrites98.0%
(FPCore (x) :precision binary64 (* (cos x) (pow (pow (exp x) 10.0) x)))
double code(double x) {
return cos(x) * pow(pow(exp(x), 10.0), x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = cos(x) * ((exp(x) ** 10.0d0) ** x)
end function
public static double code(double x) {
return Math.cos(x) * Math.pow(Math.pow(Math.exp(x), 10.0), x);
}
def code(x): return math.cos(x) * math.pow(math.pow(math.exp(x), 10.0), x)
function code(x) return Float64(cos(x) * ((exp(x) ^ 10.0) ^ x)) end
function tmp = code(x) tmp = cos(x) * ((exp(x) ^ 10.0) ^ x); end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[Power[N[Power[N[Exp[x], $MachinePrecision], 10.0], $MachinePrecision], x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot {\left({\left(e^{x}\right)}^{10}\right)}^{x}
\end{array}
Initial program 94.6%
Taylor expanded in x around inf
unpow2N/A
associate-*r*N/A
exp-prodN/A
lower-pow.f64N/A
*-commutativeN/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f6496.8
Applied rewrites96.8%
Final simplification96.8%
(FPCore (x) :precision binary64 (* (cos x) (pow (exp 10.0) (* x x))))
double code(double x) {
return cos(x) * pow(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.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.0], $MachinePrecision], N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot {\left(e^{10}\right)}^{\left(x \cdot x\right)}
\end{array}
Initial program 94.6%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
lower-pow.f64N/A
lower-exp.f6495.4
Applied rewrites95.4%
(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}
Initial program 94.6%
(FPCore (x) :precision binary64 (* (fma (fma (fma -0.001388888888888889 (* x x) 0.041666666666666664) (* x x) -0.5) (* x x) 1.0) (exp (* 10.0 (* x x)))))
double code(double x) {
return fma(fma(fma(-0.001388888888888889, (x * x), 0.041666666666666664), (x * x), -0.5), (x * x), 1.0) * exp((10.0 * (x * x)));
}
function code(x) return Float64(fma(fma(fma(-0.001388888888888889, Float64(x * x), 0.041666666666666664), Float64(x * x), -0.5), Float64(x * x), 1.0) * exp(Float64(10.0 * Float64(x * x)))) end
code[x_] := N[(N[(N[(N[(-0.001388888888888889 * N[(x * x), $MachinePrecision] + 0.041666666666666664), $MachinePrecision] * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(-0.001388888888888889, x \cdot x, 0.041666666666666664\right), x \cdot x, -0.5\right), x \cdot x, 1\right) \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}
Initial program 94.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6427.6
Applied rewrites27.6%
(FPCore (x) :precision binary64 (* (fma (fma 0.041666666666666664 (* x x) -0.5) (* x x) 1.0) (exp (* 10.0 (* x x)))))
double code(double x) {
return fma(fma(0.041666666666666664, (x * x), -0.5), (x * x), 1.0) * exp((10.0 * (x * x)));
}
function code(x) return Float64(fma(fma(0.041666666666666664, Float64(x * x), -0.5), Float64(x * x), 1.0) * exp(Float64(10.0 * Float64(x * x)))) end
code[x_] := N[(N[(N[(0.041666666666666664 * N[(x * x), $MachinePrecision] + -0.5), $MachinePrecision] * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(0.041666666666666664, x \cdot x, -0.5\right), x \cdot x, 1\right) \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}
Initial program 94.6%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
sub-negN/A
metadata-evalN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6421.3
Applied rewrites21.3%
(FPCore (x) :precision binary64 (* (fma -0.5 (* x x) 1.0) (exp (* 10.0 (* x x)))))
double code(double x) {
return fma(-0.5, (x * x), 1.0) * exp((10.0 * (x * x)));
}
function code(x) return Float64(fma(-0.5, Float64(x * x), 1.0) * exp(Float64(10.0 * Float64(x * x)))) end
code[x_] := N[(N[(-0.5 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision] * N[Exp[N[(10.0 * N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(-0.5, x \cdot x, 1\right) \cdot e^{10 \cdot \left(x \cdot x\right)}
\end{array}
Initial program 94.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6418.2
Applied rewrites18.2%
(FPCore (x) :precision binary64 (* (cos x) (fma 10.0 (* x x) 1.0)))
double code(double x) {
return cos(x) * fma(10.0, (x * x), 1.0);
}
function code(x) return Float64(cos(x) * fma(10.0, Float64(x * x), 1.0)) end
code[x_] := N[(N[Cos[x], $MachinePrecision] * N[(10.0 * N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos x \cdot \mathsf{fma}\left(10, x \cdot x, 1\right)
\end{array}
Initial program 94.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f649.8
Applied rewrites9.8%
Final simplification9.8%
(FPCore (x) :precision binary64 (* (* -0.5 (* x x)) 1.0))
double code(double x) {
return (-0.5 * (x * x)) * 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((-0.5d0) * (x * x)) * 1.0d0
end function
public static double code(double x) {
return (-0.5 * (x * x)) * 1.0;
}
def code(x): return (-0.5 * (x * x)) * 1.0
function code(x) return Float64(Float64(-0.5 * Float64(x * x)) * 1.0) end
function tmp = code(x) tmp = (-0.5 * (x * x)) * 1.0; end
code[x_] := N[(N[(-0.5 * N[(x * x), $MachinePrecision]), $MachinePrecision] * 1.0), $MachinePrecision]
\begin{array}{l}
\\
\left(-0.5 \cdot \left(x \cdot x\right)\right) \cdot 1
\end{array}
Initial program 94.6%
lift-exp.f64N/A
lift-*.f64N/A
exp-prodN/A
lift-*.f64N/A
pow-unpowN/A
sqr-powN/A
pow-prod-upN/A
sqr-powN/A
lower-*.f64N/A
Applied rewrites98.0%
Taylor expanded in x around 0
Applied rewrites9.6%
Taylor expanded in x around 0
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f649.7
Applied rewrites9.7%
Taylor expanded in x around inf
Applied rewrites9.7%
(FPCore (x) :precision binary64 1.0)
double code(double x) {
return 1.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double x) {
return 1.0;
}
def code(x): return 1.0
function code(x) return 1.0 end
function tmp = code(x) tmp = 1.0; end
code[x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 94.6%
Taylor expanded in x around 0
Applied rewrites1.5%
herbie shell --seed 2024324
(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)))))