?

Average Error: 61.8 → 0.4
Time: 13.1s
Precision: binary64
Cost: 7172

?

\[0.9 \leq t \land t \leq 1.1\]
\[\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) \]
\[\begin{array}{l} t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\ \mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\ \;\;\;\;\frac{1.6 \cdot 10^{-47} \cdot {t}^{3}}{t \cdot 4 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;t_1 \cdot t_1 + \left(-1 + t \cdot -4 \cdot 10^{-16}\right)\\ \end{array} \]
(FPCore (t)
 :precision binary64
 (+ (* (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16))) (- -1.0 (* 2.0 (* t 2e-16)))))
(FPCore (t)
 :precision binary64
 (let* ((t_1 (+ 1.0 (* t 2e-16))))
   (if (!= (* t 4e-16) 0.0)
     (/ (* 1.6e-47 (pow t 3.0)) (* t 4e-16))
     (+ (* t_1 t_1) (+ -1.0 (* t -4e-16))))))
double code(double t) {
	return ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)));
}
double code(double t) {
	double t_1 = 1.0 + (t * 2e-16);
	double tmp;
	if ((t * 4e-16) != 0.0) {
		tmp = (1.6e-47 * pow(t, 3.0)) / (t * 4e-16);
	} else {
		tmp = (t_1 * t_1) + (-1.0 + (t * -4e-16));
	}
	return tmp;
}
real(8) function code(t)
    real(8), intent (in) :: t
    code = ((1.0d0 + (t * 2d-16)) * (1.0d0 + (t * 2d-16))) + ((-1.0d0) - (2.0d0 * (t * 2d-16)))
end function
real(8) function code(t)
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = 1.0d0 + (t * 2d-16)
    if ((t * 4d-16) /= 0.0d0) then
        tmp = (1.6d-47 * (t ** 3.0d0)) / (t * 4d-16)
    else
        tmp = (t_1 * t_1) + ((-1.0d0) + (t * (-4d-16)))
    end if
    code = tmp
end function
public static double code(double t) {
	return ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)));
}
public static double code(double t) {
	double t_1 = 1.0 + (t * 2e-16);
	double tmp;
	if ((t * 4e-16) != 0.0) {
		tmp = (1.6e-47 * Math.pow(t, 3.0)) / (t * 4e-16);
	} else {
		tmp = (t_1 * t_1) + (-1.0 + (t * -4e-16));
	}
	return tmp;
}
def code(t):
	return ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)))
def code(t):
	t_1 = 1.0 + (t * 2e-16)
	tmp = 0
	if (t * 4e-16) != 0.0:
		tmp = (1.6e-47 * math.pow(t, 3.0)) / (t * 4e-16)
	else:
		tmp = (t_1 * t_1) + (-1.0 + (t * -4e-16))
	return tmp
function code(t)
	return Float64(Float64(Float64(1.0 + Float64(t * 2e-16)) * Float64(1.0 + Float64(t * 2e-16))) + Float64(-1.0 - Float64(2.0 * Float64(t * 2e-16))))
end
function code(t)
	t_1 = Float64(1.0 + Float64(t * 2e-16))
	tmp = 0.0
	if (Float64(t * 4e-16) != 0.0)
		tmp = Float64(Float64(1.6e-47 * (t ^ 3.0)) / Float64(t * 4e-16));
	else
		tmp = Float64(Float64(t_1 * t_1) + Float64(-1.0 + Float64(t * -4e-16)));
	end
	return tmp
end
function tmp = code(t)
	tmp = ((1.0 + (t * 2e-16)) * (1.0 + (t * 2e-16))) + (-1.0 - (2.0 * (t * 2e-16)));
end
function tmp_2 = code(t)
	t_1 = 1.0 + (t * 2e-16);
	tmp = 0.0;
	if ((t * 4e-16) ~= 0.0)
		tmp = (1.6e-47 * (t ^ 3.0)) / (t * 4e-16);
	else
		tmp = (t_1 * t_1) + (-1.0 + (t * -4e-16));
	end
	tmp_2 = tmp;
end
code[t_] := N[(N[(N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision] * N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(2.0 * N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[t_] := Block[{t$95$1 = N[(1.0 + N[(t * 2e-16), $MachinePrecision]), $MachinePrecision]}, If[Unequal[N[(t * 4e-16), $MachinePrecision], 0.0], N[(N[(1.6e-47 * N[Power[t, 3.0], $MachinePrecision]), $MachinePrecision] / N[(t * 4e-16), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 * t$95$1), $MachinePrecision] + N[(-1.0 + N[(t * -4e-16), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right)
\begin{array}{l}
t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\
\mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\
\;\;\;\;\frac{1.6 \cdot 10^{-47} \cdot {t}^{3}}{t \cdot 4 \cdot 10^{-16}}\\

\mathbf{else}:\\
\;\;\;\;t_1 \cdot t_1 + \left(-1 + t \cdot -4 \cdot 10^{-16}\right)\\


\end{array}

Error?

Target

Original61.8
Target50.6
Herbie0.4
\[\mathsf{fma}\left(1 + t \cdot 2 \cdot 10^{-16}, 1 + t \cdot 2 \cdot 10^{-16}, -1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) \]

Derivation?

  1. Initial program 61.8

    \[\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) \]
  2. Simplified61.8

    \[\leadsto \color{blue}{\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - t \cdot 4 \cdot 10^{-16}\right)} \]
    Proof

    [Start]61.8

    \[ \left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - 2 \cdot \left(t \cdot 2 \cdot 10^{-16}\right)\right) \]

    rational_best-simplify-113 [=>]61.8

    \[ \left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - \color{blue}{t \cdot \left(2 \cdot 2 \cdot 10^{-16}\right)}\right) \]

    metadata-eval [=>]61.8

    \[ \left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 - t \cdot \color{blue}{4 \cdot 10^{-16}}\right) \]
  3. Applied egg-rr57.6

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\ \;\;\;\;\frac{\left(t \cdot 4 \cdot 10^{-16}\right) \cdot \left(\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + -1\right) - t \cdot \left(t \cdot 1.6 \cdot 10^{-31}\right)}{t \cdot 4 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 + t \cdot -4 \cdot 10^{-16}\right)\\ } \end{array}} \]
  4. Taylor expanded in t around 0 0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\ \;\;\;\;\frac{\color{blue}{1.6 \cdot 10^{-47} \cdot {t}^{3}}}{t \cdot 4 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 + t \cdot -4 \cdot 10^{-16}\right)\\ \end{array} \]
  5. Final simplification0.4

    \[\leadsto \begin{array}{l} \mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\ \;\;\;\;\frac{1.6 \cdot 10^{-47} \cdot {t}^{3}}{t \cdot 4 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;\left(1 + t \cdot 2 \cdot 10^{-16}\right) \cdot \left(1 + t \cdot 2 \cdot 10^{-16}\right) + \left(-1 + t \cdot -4 \cdot 10^{-16}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost6656
\[4 \cdot 10^{-32} \cdot {t}^{2} \]
Alternative 2
Error53.8
Cost4696
\[\begin{array}{l} t_1 := \begin{array}{l} \mathbf{if}\;4 \cdot 10^{-16} \cdot t \ne 0:\\ \;\;\;\;\frac{\left(t \cdot t\right) \cdot 3.2 \cdot 10^{-31}}{t \cdot 8 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;0\\ \end{array}\\ \mathbf{if}\;t \cdot 2 \cdot 10^{-16} \leq 1.942 \cdot 10^{-16}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t \cdot -4 \cdot 10^{-16} - t_1 \ne 0:\\ \;\;\;\;\frac{t_1 \cdot t_1 + \left(t \cdot t\right) \cdot -1.6 \cdot 10^{-31}}{4 \cdot 10^{-16} \cdot t + t_1}\\ \mathbf{else}:\\ \;\;\;\;t_1 + t \cdot -4 \cdot 10^{-16}\\ \end{array}\\ \mathbf{else}:\\ \;\;\;\;\frac{t \cdot \left(4 \cdot 10^{-16} - t \cdot 1.6 \cdot 10^{-31}\right)}{1 + t \cdot -4 \cdot 10^{-16}} - t \cdot 4 \cdot 10^{-16}\\ \end{array} \]
Alternative 3
Error54.2
Cost1480
\[\begin{array}{l} \mathbf{if}\;t \cdot 2 \cdot 10^{-16} \leq 1.942 \cdot 10^{-16}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\ \;\;\;\;\frac{\frac{t \cdot 1.6 \cdot 10^{-31}}{\frac{1}{t}}}{t \cdot 4 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;t \cdot 4 \cdot 10^{-16}\\ \end{array} - t \cdot 4 \cdot 10^{-16}\\ \mathbf{else}:\\ \;\;\;\;\frac{t \cdot \left(4 \cdot 10^{-16} - t \cdot 1.6 \cdot 10^{-31}\right)}{1 + t \cdot -4 \cdot 10^{-16}} - t \cdot 4 \cdot 10^{-16}\\ \end{array} \]
Alternative 4
Error54.0
Cost1352
\[\begin{array}{l} \mathbf{if}\;t \cdot 2 \cdot 10^{-16} \leq 1.942 \cdot 10^{-16}:\\ \;\;\;\;\begin{array}{l} \mathbf{if}\;t \cdot 4 \cdot 10^{-16} \ne 0:\\ \;\;\;\;\frac{1.6 \cdot 10^{-31} \cdot \left(t \cdot t\right)}{t \cdot 4 \cdot 10^{-16}}\\ \mathbf{else}:\\ \;\;\;\;t \cdot 4 \cdot 10^{-16}\\ \end{array} - t \cdot 4 \cdot 10^{-16}\\ \mathbf{else}:\\ \;\;\;\;\frac{t \cdot \left(4 \cdot 10^{-16} - t \cdot 1.6 \cdot 10^{-31}\right)}{1 + t \cdot -4 \cdot 10^{-16}} - t \cdot 4 \cdot 10^{-16}\\ \end{array} \]
Alternative 5
Error55.0
Cost1220
\[\begin{array}{l} t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\ \mathbf{if}\;t \leq 0.9715:\\ \;\;\;\;\left(t_1 \cdot t_1 + -1\right) - t \cdot 4 \cdot 10^{-16}\\ \mathbf{else}:\\ \;\;\;\;\frac{t \cdot \left(4 \cdot 10^{-16} - t \cdot 1.6 \cdot 10^{-31}\right)}{1 + t \cdot -4 \cdot 10^{-16}} - t \cdot 4 \cdot 10^{-16}\\ \end{array} \]
Alternative 6
Error57.6
Cost1088
\[\begin{array}{l} t_1 := 1 + t \cdot 2 \cdot 10^{-16}\\ \left(t_1 \cdot t_1 + -1\right) - t \cdot 4 \cdot 10^{-16} \end{array} \]
Alternative 7
Error57.7
Cost192
\[4 \cdot 10^{-16} \cdot t \]
Alternative 8
Error61.8
Cost64
\[0 \]

Error

Reproduce?

herbie shell --seed 2023104 
(FPCore (t)
  :name "fma_test1"
  :precision binary64
  :pre (and (<= 0.9 t) (<= t 1.1))

  :herbie-target
  (fma (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16)) (- -1.0 (* 2.0 (* t 2e-16))))

  (+ (* (+ 1.0 (* t 2e-16)) (+ 1.0 (* t 2e-16))) (- -1.0 (* 2.0 (* t 2e-16)))))