?

Average Error: 13.9 → 4.2
Time: 14.1s
Precision: binary64
Cost: 27977

?

\[\left(\left(-1 \leq a \land a \leq 1\right) \land \left(-1 \leq c \land c \leq 1\right)\right) \land \left(-1 \leq b \land b \leq 1\right)\]
\[\frac{a \cdot c - {b}^{2}}{\left(a + c\right) - 2 \cdot b} \]
\[\begin{array}{l} t_0 := a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}\\ \mathbf{if}\;b \leq -3.2 \cdot 10^{-184} \lor \neg \left(b \leq 2.85 \cdot 10^{-202}\right):\\ \;\;\;\;\left(\frac{a}{\frac{t_0}{c}} - \frac{b}{\frac{t_0}{b}}\right) \cdot \left(a + \left(b \cdot 2 - c\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \end{array} \]
(FPCore (a c b)
 :precision binary64
 (/ (- (* a c) (pow b 2.0)) (- (+ a c) (* 2.0 b))))
(FPCore (a c b)
 :precision binary64
 (let* ((t_0 (- (* a a) (pow (fma b -2.0 c) 2.0))))
   (if (or (<= b -3.2e-184) (not (<= b 2.85e-202)))
     (* (- (/ a (/ t_0 c)) (/ b (/ t_0 b))) (+ a (- (* b 2.0) c)))
     (* a (/ c (+ a c))))))
double code(double a, double c, double b) {
	return ((a * c) - pow(b, 2.0)) / ((a + c) - (2.0 * b));
}
double code(double a, double c, double b) {
	double t_0 = (a * a) - pow(fma(b, -2.0, c), 2.0);
	double tmp;
	if ((b <= -3.2e-184) || !(b <= 2.85e-202)) {
		tmp = ((a / (t_0 / c)) - (b / (t_0 / b))) * (a + ((b * 2.0) - c));
	} else {
		tmp = a * (c / (a + c));
	}
	return tmp;
}
function code(a, c, b)
	return Float64(Float64(Float64(a * c) - (b ^ 2.0)) / Float64(Float64(a + c) - Float64(2.0 * b)))
end
function code(a, c, b)
	t_0 = Float64(Float64(a * a) - (fma(b, -2.0, c) ^ 2.0))
	tmp = 0.0
	if ((b <= -3.2e-184) || !(b <= 2.85e-202))
		tmp = Float64(Float64(Float64(a / Float64(t_0 / c)) - Float64(b / Float64(t_0 / b))) * Float64(a + Float64(Float64(b * 2.0) - c)));
	else
		tmp = Float64(a * Float64(c / Float64(a + c)));
	end
	return tmp
end
code[a_, c_, b_] := N[(N[(N[(a * c), $MachinePrecision] - N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] / N[(N[(a + c), $MachinePrecision] - N[(2.0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[a_, c_, b_] := Block[{t$95$0 = N[(N[(a * a), $MachinePrecision] - N[Power[N[(b * -2.0 + c), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]}, If[Or[LessEqual[b, -3.2e-184], N[Not[LessEqual[b, 2.85e-202]], $MachinePrecision]], N[(N[(N[(a / N[(t$95$0 / c), $MachinePrecision]), $MachinePrecision] - N[(b / N[(t$95$0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a + N[(N[(b * 2.0), $MachinePrecision] - c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(a * N[(c / N[(a + c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\frac{a \cdot c - {b}^{2}}{\left(a + c\right) - 2 \cdot b}
\begin{array}{l}
t_0 := a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}\\
\mathbf{if}\;b \leq -3.2 \cdot 10^{-184} \lor \neg \left(b \leq 2.85 \cdot 10^{-202}\right):\\
\;\;\;\;\left(\frac{a}{\frac{t_0}{c}} - \frac{b}{\frac{t_0}{b}}\right) \cdot \left(a + \left(b \cdot 2 - c\right)\right)\\

\mathbf{else}:\\
\;\;\;\;a \cdot \frac{c}{a + c}\\


\end{array}

Error?

Derivation?

  1. Split input into 2 regimes
  2. if b < -3.2e-184 or 2.8500000000000002e-202 < b

    1. Initial program 5.3

      \[\frac{a \cdot c - {b}^{2}}{\left(a + c\right) - 2 \cdot b} \]
    2. Simplified5.3

      \[\leadsto \color{blue}{\frac{a \cdot c - b \cdot b}{\left(a + c\right) + -2 \cdot b}} \]
      Proof

      [Start]5.3

      \[ \frac{a \cdot c - {b}^{2}}{\left(a + c\right) - 2 \cdot b} \]

      unpow2 [=>]5.3

      \[ \frac{a \cdot c - \color{blue}{b \cdot b}}{\left(a + c\right) - 2 \cdot b} \]

      cancel-sign-sub-inv [=>]5.3

      \[ \frac{a \cdot c - b \cdot b}{\color{blue}{\left(a + c\right) + \left(-2\right) \cdot b}} \]

      metadata-eval [=>]5.3

      \[ \frac{a \cdot c - b \cdot b}{\left(a + c\right) + \color{blue}{-2} \cdot b} \]
    3. Applied egg-rr5.4

      \[\leadsto \color{blue}{\frac{a \cdot c - b \cdot b}{a \cdot a - \left(c + b \cdot -2\right) \cdot \left(c + b \cdot -2\right)} \cdot \left(a - \left(c + b \cdot -2\right)\right)} \]
    4. Applied egg-rr5.4

      \[\leadsto \color{blue}{\left(\frac{a \cdot c}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}} + \left(-\frac{b \cdot b}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}\right)\right)} \cdot \left(a - \left(c + b \cdot -2\right)\right) \]
    5. Simplified2.9

      \[\leadsto \color{blue}{\left(\frac{a}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{c}} - \frac{b}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{b}}\right)} \cdot \left(a - \left(c + b \cdot -2\right)\right) \]
      Proof

      [Start]5.4

      \[ \left(\frac{a \cdot c}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}} + \left(-\frac{b \cdot b}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}\right)\right) \cdot \left(a - \left(c + b \cdot -2\right)\right) \]

      sub-neg [<=]5.4

      \[ \color{blue}{\left(\frac{a \cdot c}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}} - \frac{b \cdot b}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}\right)} \cdot \left(a - \left(c + b \cdot -2\right)\right) \]

      associate-/l* [=>]4.5

      \[ \left(\color{blue}{\frac{a}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{c}}} - \frac{b \cdot b}{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}\right) \cdot \left(a - \left(c + b \cdot -2\right)\right) \]

      associate-/l* [=>]2.9

      \[ \left(\frac{a}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{c}} - \color{blue}{\frac{b}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{b}}}\right) \cdot \left(a - \left(c + b \cdot -2\right)\right) \]

    if -3.2e-184 < b < 2.8500000000000002e-202

    1. Initial program 28.2

      \[\frac{a \cdot c - {b}^{2}}{\left(a + c\right) - 2 \cdot b} \]
    2. Simplified28.2

      \[\leadsto \color{blue}{\frac{a \cdot c - b \cdot b}{\left(a + c\right) + -2 \cdot b}} \]
      Proof

      [Start]28.2

      \[ \frac{a \cdot c - {b}^{2}}{\left(a + c\right) - 2 \cdot b} \]

      unpow2 [=>]28.2

      \[ \frac{a \cdot c - \color{blue}{b \cdot b}}{\left(a + c\right) - 2 \cdot b} \]

      cancel-sign-sub-inv [=>]28.2

      \[ \frac{a \cdot c - b \cdot b}{\color{blue}{\left(a + c\right) + \left(-2\right) \cdot b}} \]

      metadata-eval [=>]28.2

      \[ \frac{a \cdot c - b \cdot b}{\left(a + c\right) + \color{blue}{-2} \cdot b} \]
    3. Taylor expanded in b around 0 28.2

      \[\leadsto \color{blue}{\frac{c \cdot a}{c + a}} \]
    4. Simplified6.2

      \[\leadsto \color{blue}{\frac{c}{c + a} \cdot a} \]
      Proof

      [Start]28.2

      \[ \frac{c \cdot a}{c + a} \]

      associate-/l* [=>]6.2

      \[ \color{blue}{\frac{c}{\frac{c + a}{a}}} \]

      associate-/r/ [=>]6.2

      \[ \color{blue}{\frac{c}{c + a} \cdot a} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification4.2

    \[\leadsto \begin{array}{l} \mathbf{if}\;b \leq -3.2 \cdot 10^{-184} \lor \neg \left(b \leq 2.85 \cdot 10^{-202}\right):\\ \;\;\;\;\left(\frac{a}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{c}} - \frac{b}{\frac{a \cdot a - {\left(\mathsf{fma}\left(b, -2, c\right)\right)}^{2}}{b}}\right) \cdot \left(a + \left(b \cdot 2 - c\right)\right)\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \end{array} \]

Alternatives

Alternative 1
Error5.0
Cost2116
\[\begin{array}{l} t_0 := b \cdot 2 - c\\ t_1 := a \cdot c - b \cdot b\\ \mathbf{if}\;b \leq -8.5 \cdot 10^{-163}:\\ \;\;\;\;\left(a + t_0\right) \cdot \frac{t_1}{a \cdot a + \left(c + b \cdot -2\right) \cdot t_0}\\ \mathbf{elif}\;b \leq 9.5 \cdot 10^{-167}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot b + \left(t_1 - b \cdot b\right)}{\left(a + c\right) + b \cdot -2}\\ \end{array} \]
Alternative 2
Error5.0
Cost1736
\[\begin{array}{l} t_0 := a \cdot c - b \cdot b\\ t_1 := \left(a + c\right) + b \cdot -2\\ \mathbf{if}\;b \leq -1.3 \cdot 10^{-162}:\\ \;\;\;\;\frac{t_0}{t_1}\\ \mathbf{elif}\;b \leq 1.2 \cdot 10^{-166}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \mathbf{else}:\\ \;\;\;\;\frac{b \cdot b + \left(t_0 - b \cdot b\right)}{t_1}\\ \end{array} \]
Alternative 3
Error5.0
Cost1225
\[\begin{array}{l} \mathbf{if}\;b \leq -1.55 \cdot 10^{-162} \lor \neg \left(b \leq 1.16 \cdot 10^{-166}\right):\\ \;\;\;\;\frac{a \cdot c - b \cdot b}{\left(a + c\right) + b \cdot -2}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \end{array} \]
Alternative 4
Error15.2
Cost905
\[\begin{array}{l} \mathbf{if}\;b \leq -7 \cdot 10^{-131} \lor \neg \left(b \leq 8.5 \cdot 10^{-160}\right):\\ \;\;\;\;\frac{-b}{\frac{c + b \cdot -2}{b}}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \end{array} \]
Alternative 5
Error32.2
Cost852
\[\begin{array}{l} \mathbf{if}\;b \leq -1.6 \cdot 10^{-142}:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{elif}\;b \leq -1.4 \cdot 10^{-162}:\\ \;\;\;\;a\\ \mathbf{elif}\;b \leq 1.36 \cdot 10^{-263}:\\ \;\;\;\;c\\ \mathbf{elif}\;b \leq 1.5 \cdot 10^{-246}:\\ \;\;\;\;a\\ \mathbf{elif}\;b \leq 2.5 \cdot 10^{-146}:\\ \;\;\;\;c\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5\\ \end{array} \]
Alternative 6
Error14.9
Cost713
\[\begin{array}{l} \mathbf{if}\;b \leq -7.4 \cdot 10^{-143} \lor \neg \left(b \leq 9 \cdot 10^{-144}\right):\\ \;\;\;\;\frac{b}{2 - \frac{a}{b}}\\ \mathbf{else}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \end{array} \]
Alternative 7
Error18.8
Cost712
\[\begin{array}{l} \mathbf{if}\;b \leq -1.2 \cdot 10^{-130}:\\ \;\;\;\;b \cdot 0.5\\ \mathbf{elif}\;b \leq 6.2 \cdot 10^{-143}:\\ \;\;\;\;a \cdot \frac{c}{a + c}\\ \mathbf{else}:\\ \;\;\;\;b \cdot 0.5\\ \end{array} \]
Alternative 8
Error43.2
Cost196
\[\begin{array}{l} \mathbf{if}\;c \leq 2.15 \cdot 10^{-92}:\\ \;\;\;\;c\\ \mathbf{else}:\\ \;\;\;\;a\\ \end{array} \]
Alternative 9
Error46.9
Cost64
\[a \]

Error

Reproduce?

herbie shell --seed 1 
(FPCore (a c b)
  :name "(a*c - b^2)/(a + c - 2*b)"
  :precision binary64
  :pre (and (and (and (<= -1.0 a) (<= a 1.0)) (and (<= -1.0 c) (<= c 1.0))) (and (<= -1.0 b) (<= b 1.0)))
  (/ (- (* a c) (pow b 2.0)) (- (+ a c) (* 2.0 b))))