Average Error: 0.0 → 9.1
Time: 3.8s
Precision: binary64
Cost: 7108
\[\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t \]
\[\begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+121}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot -0.5, 0.125 \cdot x\right)\\ \mathbf{elif}\;y \cdot z \leq 10^{+24}:\\ \;\;\;\;0.125 \cdot x + t\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot x + \left(y \cdot z\right) \cdot -0.5\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))
(FPCore (x y z t)
 :precision binary64
 (if (<= (* y z) -5e+121)
   (fma y (* z -0.5) (* 0.125 x))
   (if (<= (* y z) 1e+24) (+ (* 0.125 x) t) (+ (* 0.125 x) (* (* y z) -0.5)))))
double code(double x, double y, double z, double t) {
	return (((1.0 / 8.0) * x) - ((y * z) / 2.0)) + t;
}
double code(double x, double y, double z, double t) {
	double tmp;
	if ((y * z) <= -5e+121) {
		tmp = fma(y, (z * -0.5), (0.125 * x));
	} else if ((y * z) <= 1e+24) {
		tmp = (0.125 * x) + t;
	} else {
		tmp = (0.125 * x) + ((y * z) * -0.5);
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(Float64(Float64(1.0 / 8.0) * x) - Float64(Float64(y * z) / 2.0)) + t)
end
function code(x, y, z, t)
	tmp = 0.0
	if (Float64(y * z) <= -5e+121)
		tmp = fma(y, Float64(z * -0.5), Float64(0.125 * x));
	elseif (Float64(y * z) <= 1e+24)
		tmp = Float64(Float64(0.125 * x) + t);
	else
		tmp = Float64(Float64(0.125 * x) + Float64(Float64(y * z) * -0.5));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(N[(N[(1.0 / 8.0), $MachinePrecision] * x), $MachinePrecision] - N[(N[(y * z), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] + t), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(y * z), $MachinePrecision], -5e+121], N[(y * N[(z * -0.5), $MachinePrecision] + N[(0.125 * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y * z), $MachinePrecision], 1e+24], N[(N[(0.125 * x), $MachinePrecision] + t), $MachinePrecision], N[(N[(0.125 * x), $MachinePrecision] + N[(N[(y * z), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]]
\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t
\begin{array}{l}
\mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+121}:\\
\;\;\;\;\mathsf{fma}\left(y, z \cdot -0.5, 0.125 \cdot x\right)\\

\mathbf{elif}\;y \cdot z \leq 10^{+24}:\\
\;\;\;\;0.125 \cdot x + t\\

\mathbf{else}:\\
\;\;\;\;0.125 \cdot x + \left(y \cdot z\right) \cdot -0.5\\


\end{array}

Error

Target

Original0.0
Target0.0
Herbie9.1
\[\left(\frac{x}{8} + t\right) - \frac{z}{2} \cdot y \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 y z) < -5.00000000000000007e121

    1. Initial program 0.0

      \[\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t \]
    2. Taylor expanded in t around 0 10.0

      \[\leadsto \color{blue}{0.125 \cdot x - 0.5 \cdot \left(y \cdot z\right)} \]
    3. Simplified9.9

      \[\leadsto \color{blue}{\mathsf{fma}\left(y, z \cdot -0.5, 0.125 \cdot x\right)} \]

    if -5.00000000000000007e121 < (*.f64 y z) < 9.9999999999999998e23

    1. Initial program 0.0

      \[\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t \]
    2. Taylor expanded in y around 0 7.7

      \[\leadsto \color{blue}{0.125 \cdot x + t} \]

    if 9.9999999999999998e23 < (*.f64 y z)

    1. Initial program 0.1

      \[\left(\frac{1}{8} \cdot x - \frac{y \cdot z}{2}\right) + t \]
    2. Taylor expanded in t around 0 13.5

      \[\leadsto \color{blue}{0.125 \cdot x - 0.5 \cdot \left(y \cdot z\right)} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification9.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+121}:\\ \;\;\;\;\mathsf{fma}\left(y, z \cdot -0.5, 0.125 \cdot x\right)\\ \mathbf{elif}\;y \cdot z \leq 10^{+24}:\\ \;\;\;\;0.125 \cdot x + t\\ \mathbf{else}:\\ \;\;\;\;0.125 \cdot x + \left(y \cdot z\right) \cdot -0.5\\ \end{array} \]

Alternatives

Alternative 1
Error9.1
Cost1096
\[\begin{array}{l} t_1 := 0.125 \cdot x + \left(y \cdot z\right) \cdot -0.5\\ \mathbf{if}\;y \cdot z \leq -5 \cdot 10^{+121}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \cdot z \leq 10^{+24}:\\ \;\;\;\;0.125 \cdot x + t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error9.5
Cost968
\[\begin{array}{l} t_1 := t + \left(y \cdot z\right) \cdot -0.5\\ \mathbf{if}\;y \cdot z \leq -2.0915082795430662 \cdot 10^{+77}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \cdot z \leq 1.0761491174801814 \cdot 10^{+124}:\\ \;\;\;\;0.125 \cdot x + t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error11.8
Cost840
\[\begin{array}{l} t_1 := \left(y \cdot z\right) \cdot -0.5\\ \mathbf{if}\;y \cdot z \leq -7.20243854477268 \cdot 10^{+124}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \cdot z \leq 1.0761491174801814 \cdot 10^{+124}:\\ \;\;\;\;0.125 \cdot x + t\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 4
Error28.6
Cost720
\[\begin{array}{l} \mathbf{if}\;t \leq -1.7296732402236914 \cdot 10^{+81}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq -3.353267083893106 \cdot 10^{-6}:\\ \;\;\;\;\left(y \cdot z\right) \cdot -0.5\\ \mathbf{elif}\;t \leq -1.7350310241546463 \cdot 10^{-56}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 4.111892382606937 \cdot 10^{+94}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 5
Error28.4
Cost456
\[\begin{array}{l} \mathbf{if}\;t \leq -1.7350310241546463 \cdot 10^{-56}:\\ \;\;\;\;t\\ \mathbf{elif}\;t \leq 4.111892382606937 \cdot 10^{+94}:\\ \;\;\;\;0.125 \cdot x\\ \mathbf{else}:\\ \;\;\;\;t\\ \end{array} \]
Alternative 6
Error39.9
Cost64
\[t \]

Error

Reproduce

herbie shell --seed 2022228 
(FPCore (x y z t)
  :name "Diagrams.Solve.Polynomial:quartForm  from diagrams-solve-0.1, B"
  :precision binary64

  :herbie-target
  (- (+ (/ x 8.0) t) (* (/ z 2.0) y))

  (+ (- (* (/ 1.0 8.0) x) (/ (* y z) 2.0)) t))