(FPCore (x) :precision binary64 (+ (* (* (- 1.0 (cos x)) (sin x)) (exp x)) (sin (+ x 10.0))))
double code(double x) { return (((1.0 - cos(x)) * sin(x)) * exp(x)) + sin((x + 10.0)); }
real(8) function code(x) real(8), intent (in) :: x code = (((1.0d0 - cos(x)) * sin(x)) * exp(x)) + sin((x + 10.0d0)) end function
public static double code(double x) { return (((1.0 - Math.cos(x)) * Math.sin(x)) * Math.exp(x)) + Math.sin((x + 10.0)); }
def code(x): return (((1.0 - math.cos(x)) * math.sin(x)) * math.exp(x)) + math.sin((x + 10.0))
function code(x) return Float64(Float64(Float64(Float64(1.0 - cos(x)) * sin(x)) * exp(x)) + sin(Float64(x + 10.0))) end
function tmp = code(x) tmp = (((1.0 - cos(x)) * sin(x)) * exp(x)) + sin((x + 10.0)); end
code[x_] := N[(N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] * N[Exp[x], $MachinePrecision]), $MachinePrecision] + N[Sin[N[(x + 10.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(1 - \cos x\right) \cdot \sin x\right) \cdot e^{x} + \sin \left(x + 10\right) \end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (x) :precision binary64 (+ (* (* (- 1.0 (cos x)) (sin x)) (exp x)) (sin (+ x 10.0))))
double code(double x) { return (((1.0 - cos(x)) * sin(x)) * exp(x)) + sin((x + 10.0)); }
real(8) function code(x) real(8), intent (in) :: x code = (((1.0d0 - cos(x)) * sin(x)) * exp(x)) + sin((x + 10.0d0)) end function
public static double code(double x) { return (((1.0 - Math.cos(x)) * Math.sin(x)) * Math.exp(x)) + Math.sin((x + 10.0)); }
def code(x): return (((1.0 - math.cos(x)) * math.sin(x)) * math.exp(x)) + math.sin((x + 10.0))
function code(x) return Float64(Float64(Float64(Float64(1.0 - cos(x)) * sin(x)) * exp(x)) + sin(Float64(x + 10.0))) end
function tmp = code(x) tmp = (((1.0 - cos(x)) * sin(x)) * exp(x)) + sin((x + 10.0)); end
code[x_] := N[(N[(N[(N[(1.0 - N[Cos[x], $MachinePrecision]), $MachinePrecision] * N[Sin[x], $MachinePrecision]), $MachinePrecision] * N[Exp[x], $MachinePrecision]), $MachinePrecision] + N[Sin[N[(x + 10.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(1 - \cos x\right) \cdot \sin x\right) \cdot e^{x} + \sin \left(x + 10\right) \end{array}
(FPCore (x) :precision binary64 (let* ((t_0 (* (cos 10.0) x))) (pow (/ (- t_0 (sin 10.0)) (- (pow t_0 2.0) (pow (sin 10.0) 2.0))) -1.0)))
double code(double x) { double t_0 = cos(10.0) * x; return pow(((t_0 - sin(10.0)) / (pow(t_0, 2.0) - pow(sin(10.0), 2.0))), -1.0); }
real(8) function code(x) real(8), intent (in) :: x real(8) :: t_0 t_0 = cos(10.0d0) * x code = ((t_0 - sin(10.0d0)) / ((t_0 ** 2.0d0) - (sin(10.0d0) ** 2.0d0))) ** (-1.0d0) end function
public static double code(double x) { double t_0 = Math.cos(10.0) * x; return Math.pow(((t_0 - Math.sin(10.0)) / (Math.pow(t_0, 2.0) - Math.pow(Math.sin(10.0), 2.0))), -1.0); }
def code(x): t_0 = math.cos(10.0) * x return math.pow(((t_0 - math.sin(10.0)) / (math.pow(t_0, 2.0) - math.pow(math.sin(10.0), 2.0))), -1.0)
function code(x) t_0 = Float64(cos(10.0) * x) return Float64(Float64(t_0 - sin(10.0)) / Float64((t_0 ^ 2.0) - (sin(10.0) ^ 2.0))) ^ -1.0 end
function tmp = code(x) t_0 = cos(10.0) * x; tmp = ((t_0 - sin(10.0)) / ((t_0 ^ 2.0) - (sin(10.0) ^ 2.0))) ^ -1.0; end
code[x_] := Block[{t$95$0 = N[(N[Cos[10.0], $MachinePrecision] * x), $MachinePrecision]}, N[Power[N[(N[(t$95$0 - N[Sin[10.0], $MachinePrecision]), $MachinePrecision] / N[(N[Power[t$95$0, 2.0], $MachinePrecision] - N[Power[N[Sin[10.0], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision]]
\begin{array}{l} \\ \begin{array}{l} t_0 := \cos 10 \cdot x\\ {\left(\frac{t\_0 - \sin 10}{{t\_0}^{2} - {\sin 10}^{2}}\right)}^{-1} \end{array} \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
lower-cos.f64
N/A
lower-sin.f64
100.0
Applied rewrites100.0%
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (fma 0.5 (fma (+ (cos -10.0) (cos 10.0)) x (sin -10.0)) (* 1.5 (sin 10.0))))
double code(double x) { return fma(0.5, fma((cos(-10.0) + cos(10.0)), x, sin(-10.0)), (1.5 * sin(10.0))); }
function code(x) return fma(0.5, fma(Float64(cos(-10.0) + cos(10.0)), x, sin(-10.0)), Float64(1.5 * sin(10.0))) end
code[x_] := N[(0.5 * N[(N[(N[Cos[-10.0], $MachinePrecision] + N[Cos[10.0], $MachinePrecision]), $MachinePrecision] * x + N[Sin[-10.0], $MachinePrecision]), $MachinePrecision] + N[(1.5 * N[Sin[10.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(0.5, \mathsf{fma}\left(\cos -10 + \cos 10, x, \sin -10\right), 1.5 \cdot \sin 10\right) \end{array}
Initial program 100.0%
lift-+.f64
N/A
+-commutative
N/A
lift-sin.f64
N/A
lift-+.f64
N/A
sin-sum
N/A
associate-+l+
N/A
sin-cos-mult
N/A
div-inv
N/A
metadata-eval
N/A
lower-fma.f64
N/A
Applied rewrites100.0%
Taylor expanded in x around 0
+-commutative
N/A
distribute-lft-in
N/A
associate-+r+
N/A
*-commutative
N/A
associate-+l+
N/A
*-commutative
N/A
distribute-lft-out
N/A
+-commutative
N/A
lower-fma.f64
N/A
Applied rewrites100.0%
(FPCore (x) :precision binary64 (fma (cos 10.0) x (sin 10.0)))
double code(double x) { return fma(cos(10.0), x, sin(10.0)); }
function code(x) return fma(cos(10.0), x, sin(10.0)) end
code[x_] := N[(N[Cos[10.0], $MachinePrecision] * x + N[Sin[10.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \mathsf{fma}\left(\cos 10, x, \sin 10\right) \end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
lower-cos.f64
N/A
lower-sin.f64
100.0
Applied rewrites100.0%
(FPCore (x) :precision binary64 (+ (* (* (* x x) x) 0.5) (sin (+ x 10.0))))
double code(double x) { return (((x * x) * x) * 0.5) + sin((x + 10.0)); }
real(8) function code(x) real(8), intent (in) :: x code = (((x * x) * x) * 0.5d0) + sin((x + 10.0d0)) end function
public static double code(double x) { return (((x * x) * x) * 0.5) + Math.sin((x + 10.0)); }
def code(x): return (((x * x) * x) * 0.5) + math.sin((x + 10.0))
function code(x) return Float64(Float64(Float64(Float64(x * x) * x) * 0.5) + sin(Float64(x + 10.0))) end
function tmp = code(x) tmp = (((x * x) * x) * 0.5) + sin((x + 10.0)); end
code[x_] := N[(N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * 0.5), $MachinePrecision] + N[Sin[N[(x + 10.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l} \\ \left(\left(x \cdot x\right) \cdot x\right) \cdot 0.5 + \sin \left(x + 10\right) \end{array}
Initial program 100.0%
Taylor expanded in x around 0
*-commutative
N/A
lower-*.f64
N/A
lower-pow.f64
100.0
Applied rewrites100.0%
Applied rewrites100.0%
(FPCore (x) :precision binary64 (sin 10.0))
double code(double x) { return sin(10.0); }
real(8) function code(x) real(8), intent (in) :: x code = sin(10.0d0) end function
public static double code(double x) { return Math.sin(10.0); }
def code(x): return math.sin(10.0)
function code(x) return sin(10.0) end
function tmp = code(x) tmp = sin(10.0); end
code[x_] := N[Sin[10.0], $MachinePrecision]
\begin{array}{l} \\ \sin 10 \end{array}
Initial program 100.0%
Taylor expanded in x around 0
lower-sin.f64
99.6
Applied rewrites99.6%
herbie shell --seed 1
(FPCore (x)
:name "(1-cos(x))* sin(x)*exp(x) + sin(x+10)"
:precision binary64
:pre (and (<= -1e-9 x) (<= x 0.0))
(+ (* (* (- 1.0 (cos x)) (sin x)) (exp x)) (sin (+ x 10.0))))