Average Error: 0.2 → 0.2
Time: 25.4s
Precision: binary64
Cost: 26304
\[\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t \]
\[\log \left(x + y\right) + \left(\log z - \mathsf{fma}\left(\log t, 0.5 - a, t\right)\right) \]
(FPCore (x y z t a)
 :precision binary64
 (+ (- (+ (log (+ x y)) (log z)) t) (* (- a 0.5) (log t))))
(FPCore (x y z t a)
 :precision binary64
 (+ (log (+ x y)) (- (log z) (fma (log t) (- 0.5 a) t))))
double code(double x, double y, double z, double t, double a) {
	return ((log((x + y)) + log(z)) - t) + ((a - 0.5) * log(t));
}
double code(double x, double y, double z, double t, double a) {
	return log((x + y)) + (log(z) - fma(log(t), (0.5 - a), t));
}
function code(x, y, z, t, a)
	return Float64(Float64(Float64(log(Float64(x + y)) + log(z)) - t) + Float64(Float64(a - 0.5) * log(t)))
end
function code(x, y, z, t, a)
	return Float64(log(Float64(x + y)) + Float64(log(z) - fma(log(t), Float64(0.5 - a), t)))
end
code[x_, y_, z_, t_, a_] := N[(N[(N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[Log[z], $MachinePrecision]), $MachinePrecision] - t), $MachinePrecision] + N[(N[(a - 0.5), $MachinePrecision] * N[Log[t], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := N[(N[Log[N[(x + y), $MachinePrecision]], $MachinePrecision] + N[(N[Log[z], $MachinePrecision] - N[(N[Log[t], $MachinePrecision] * N[(0.5 - a), $MachinePrecision] + t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t
\log \left(x + y\right) + \left(\log z - \mathsf{fma}\left(\log t, 0.5 - a, t\right)\right)

Error

Target

Original0.2
Target0.3
Herbie0.2
\[\log \left(x + y\right) + \left(\left(\log z - t\right) + \left(a - 0.5\right) \cdot \log t\right) \]

Derivation

  1. Initial program 0.2

    \[\left(\left(\log \left(x + y\right) + \log z\right) - t\right) + \left(a - 0.5\right) \cdot \log t \]
  2. Simplified0.2

    \[\leadsto \color{blue}{\log \left(x + y\right) + \left(\log z - \mathsf{fma}\left(\log t, 0.5 - a, t\right)\right)} \]
    Proof
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (fma.f64 (log.f64 t) (-.f64 1/2 a) t))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (fma.f64 (log.f64 t) (Rewrite<= unsub-neg_binary64 (+.f64 1/2 (neg.f64 a))) t))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (fma.f64 (log.f64 t) (Rewrite=> +-commutative_binary64 (+.f64 (neg.f64 a) 1/2)) t))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (fma.f64 (log.f64 t) (+.f64 (Rewrite=> neg-sub0_binary64 (-.f64 0 a)) 1/2) t))): 16 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (fma.f64 (log.f64 t) (Rewrite<= associate--r-_binary64 (-.f64 0 (-.f64 a 1/2))) t))): 0 points increase in error, 16 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (fma.f64 (log.f64 t) (Rewrite<= neg-sub0_binary64 (neg.f64 (-.f64 a 1/2))) t))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (log.f64 t) (neg.f64 (-.f64 a 1/2))) t)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (+.f64 (Rewrite<= *-commutative_binary64 (*.f64 (neg.f64 (-.f64 a 1/2)) (log.f64 t))) t))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (-.f64 (log.f64 z) (Rewrite<= +-commutative_binary64 (+.f64 t (*.f64 (neg.f64 (-.f64 a 1/2)) (log.f64 t)))))): 10 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (Rewrite=> associate--r+_binary64 (-.f64 (-.f64 (log.f64 z) t) (*.f64 (neg.f64 (-.f64 a 1/2)) (log.f64 t))))): 6 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (Rewrite=> cancel-sign-sub_binary64 (+.f64 (-.f64 (log.f64 z) t) (*.f64 (-.f64 a 1/2) (log.f64 t))))): 0 points increase in error, 0 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (+.f64 (Rewrite=> sub-neg_binary64 (+.f64 (log.f64 z) (neg.f64 t))) (*.f64 (-.f64 a 1/2) (log.f64 t)))): 0 points increase in error, 16 points decrease in error
    (+.f64 (log.f64 (+.f64 x y)) (Rewrite=> associate-+l+_binary64 (+.f64 (log.f64 z) (+.f64 (neg.f64 t) (*.f64 (-.f64 a 1/2) (log.f64 t)))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (log.f64 (+.f64 x y)) (log.f64 z)) (+.f64 (neg.f64 t) (*.f64 (-.f64 a 1/2) (log.f64 t))))): 0 points increase in error, 0 points decrease in error
    (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 (+.f64 (log.f64 (+.f64 x y)) (log.f64 z)) (neg.f64 t)) (*.f64 (-.f64 a 1/2) (log.f64 t)))): 0 points increase in error, 0 points decrease in error
    (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 (+.f64 (log.f64 (+.f64 x y)) (log.f64 z)) t)) (*.f64 (-.f64 a 1/2) (log.f64 t))): 0 points increase in error, 0 points decrease in error
  3. Final simplification0.2

    \[\leadsto \log \left(x + y\right) + \left(\log z - \mathsf{fma}\left(\log t, 0.5 - a, t\right)\right) \]

Alternatives

Alternative 1
Error20.1
Cost46152
\[\begin{array}{l} t_1 := \log t \cdot a\\ t_2 := \log \left(x + y\right) + \log z\\ \mathbf{if}\;t_2 \leq -800:\\ \;\;\;\;t_1 - t\\ \mathbf{elif}\;t_2 \leq 695:\\ \;\;\;\;\log \left(y \cdot z\right) - \mathsf{fma}\left(0.5 - a, \log t, t\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\log z - t\right) + t_1\\ \end{array} \]
Alternative 2
Error19.2
Cost26176
\[\left(\log z + \log y\right) - \mathsf{fma}\left(0.5 - a, \log t, t\right) \]
Alternative 3
Error0.9
Cost20424
\[\begin{array}{l} \mathbf{if}\;a + -0.5 \leq -100000000:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right) - t\\ \mathbf{elif}\;a + -0.5 \leq -0.4:\\ \;\;\;\;\left(\log \left(x + y\right) + \left(\log z + \log t \cdot -0.5\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log t, a + -0.5, -t\right)\\ \end{array} \]
Alternative 4
Error12.1
Cost20296
\[\begin{array}{l} \mathbf{if}\;a + -0.5 \leq -100000000:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right) - t\\ \mathbf{elif}\;a + -0.5 \leq -0.4:\\ \;\;\;\;\left(\log z + \log y\right) + \left(\log t \cdot -0.5 - t\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log t, a + -0.5, -t\right)\\ \end{array} \]
Alternative 5
Error12.1
Cost20296
\[\begin{array}{l} \mathbf{if}\;a + -0.5 \leq -100000000:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right) - t\\ \mathbf{elif}\;a + -0.5 \leq -0.4:\\ \;\;\;\;\left(\log z + \left(\log y + \log t \cdot -0.5\right)\right) - t\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log t, a + -0.5, -t\right)\\ \end{array} \]
Alternative 6
Error0.3
Cost20032
\[\left(\log \left(x + y\right) + \left(\log z - t\right)\right) + \log t \cdot \left(a + -0.5\right) \]
Alternative 7
Error16.6
Cost13512
\[\begin{array}{l} \mathbf{if}\;a \leq 1.6 \cdot 10^{-160}:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right) - t\\ \mathbf{elif}\;a \leq 1.12 \cdot 10^{-45}:\\ \;\;\;\;\log t \cdot -0.5 + \log \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(\log t, a + -0.5, -t\right)\\ \end{array} \]
Alternative 8
Error15.9
Cost13508
\[\begin{array}{l} \mathbf{if}\;t \leq 8.6 \cdot 10^{-43}:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right) + \log \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;\left(\log z - t\right) + \log t \cdot a\\ \end{array} \]
Alternative 9
Error14.2
Cost13184
\[\mathsf{fma}\left(\log t, a + -0.5, -t\right) \]
Alternative 10
Error14.2
Cost6980
\[\begin{array}{l} \mathbf{if}\;t \leq 0.14:\\ \;\;\;\;t + \log t \cdot \left(a + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\log t \cdot a - t\\ \end{array} \]
Alternative 11
Error22.0
Cost6852
\[\begin{array}{l} \mathbf{if}\;t \leq 2.2 \cdot 10^{+39}:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 12
Error14.2
Cost6852
\[\begin{array}{l} \mathbf{if}\;t \leq 0.31:\\ \;\;\;\;\log t \cdot \left(a + -0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\log t \cdot a - t\\ \end{array} \]
Alternative 13
Error14.2
Cost6848
\[\log t \cdot \left(a + -0.5\right) - t \]
Alternative 14
Error38.3
Cost6724
\[\begin{array}{l} \mathbf{if}\;t \leq 310:\\ \;\;\;\;\log \left(y \cdot z\right)\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 15
Error23.8
Cost6724
\[\begin{array}{l} \mathbf{if}\;t \leq 1.35 \cdot 10^{+39}:\\ \;\;\;\;\log t \cdot a\\ \mathbf{else}:\\ \;\;\;\;-t\\ \end{array} \]
Alternative 16
Error39.1
Cost128
\[-t \]

Error

Reproduce

herbie shell --seed 2022343 
(FPCore (x y z t a)
  :name "Numeric.SpecFunctions:logGammaL from math-functions-0.1.5.2"
  :precision binary64

  :herbie-target
  (+ (log (+ x y)) (+ (- (log z) t) (* (- a 0.5) (log t))))

  (+ (- (+ (log (+ x y)) (log z)) t) (* (- a 0.5) (log t))))