?

Average Error: 5.77% → 1.5%
Time: 15.2s
Precision: binary64
Cost: 7492

?

\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
\[\begin{array}{l} t_1 := \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{if}\;z \cdot 3 \leq -2 \cdot 10^{+139}:\\ \;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + t_1\\ \mathbf{elif}\;z \cdot 3 \leq 2 \cdot 10^{-11}:\\ \;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;t_1 + \left(x - \frac{y}{z \cdot 3}\right)\\ \end{array} \]
(FPCore (x y z t)
 :precision binary64
 (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (/ t (* (* z 3.0) y))))
   (if (<= (* z 3.0) -2e+139)
     (+ (fma -0.3333333333333333 (/ y z) x) t_1)
     (if (<= (* z 3.0) 2e-11)
       (+ x (/ (- y (/ t y)) (* z -3.0)))
       (+ t_1 (- x (/ y (* z 3.0))))))))
double code(double x, double y, double z, double t) {
	return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
double code(double x, double y, double z, double t) {
	double t_1 = t / ((z * 3.0) * y);
	double tmp;
	if ((z * 3.0) <= -2e+139) {
		tmp = fma(-0.3333333333333333, (y / z), x) + t_1;
	} else if ((z * 3.0) <= 2e-11) {
		tmp = x + ((y - (t / y)) / (z * -3.0));
	} else {
		tmp = t_1 + (x - (y / (z * 3.0)));
	}
	return tmp;
}
function code(x, y, z, t)
	return Float64(Float64(x - Float64(y / Float64(z * 3.0))) + Float64(t / Float64(Float64(z * 3.0) * y)))
end
function code(x, y, z, t)
	t_1 = Float64(t / Float64(Float64(z * 3.0) * y))
	tmp = 0.0
	if (Float64(z * 3.0) <= -2e+139)
		tmp = Float64(fma(-0.3333333333333333, Float64(y / z), x) + t_1);
	elseif (Float64(z * 3.0) <= 2e-11)
		tmp = Float64(x + Float64(Float64(y - Float64(t / y)) / Float64(z * -3.0)));
	else
		tmp = Float64(t_1 + Float64(x - Float64(y / Float64(z * 3.0))));
	end
	return tmp
end
code[x_, y_, z_, t_] := N[(N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * 3.0), $MachinePrecision], -2e+139], N[(N[(-0.3333333333333333 * N[(y / z), $MachinePrecision] + x), $MachinePrecision] + t$95$1), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 2e-11], N[(x + N[(N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision] / N[(z * -3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}
\begin{array}{l}
t_1 := \frac{t}{\left(z \cdot 3\right) \cdot y}\\
\mathbf{if}\;z \cdot 3 \leq -2 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + t_1\\

\mathbf{elif}\;z \cdot 3 \leq 2 \cdot 10^{-11}:\\
\;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\

\mathbf{else}:\\
\;\;\;\;t_1 + \left(x - \frac{y}{z \cdot 3}\right)\\


\end{array}

Error?

Target

Original5.77%
Target2.81%
Herbie1.5%
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{\frac{t}{z \cdot 3}}{y} \]

Derivation?

  1. Split input into 3 regimes
  2. if (*.f64 z 3) < -2.00000000000000007e139

    1. Initial program 1.1

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    2. Simplified1.08

      \[\leadsto \color{blue}{\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}} \]
      Proof

      [Start]1.1

      \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      sub-neg [=>]1.1

      \[ \color{blue}{\left(x + \left(-\frac{y}{z \cdot 3}\right)\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      +-commutative [=>]1.1

      \[ \color{blue}{\left(\left(-\frac{y}{z \cdot 3}\right) + x\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      neg-mul-1 [=>]1.1

      \[ \left(\color{blue}{-1 \cdot \frac{y}{z \cdot 3}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      associate-*r/ [=>]1.1

      \[ \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      *-commutative [=>]1.1

      \[ \left(\frac{-1 \cdot y}{\color{blue}{3 \cdot z}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      times-frac [=>]1.08

      \[ \left(\color{blue}{\frac{-1}{3} \cdot \frac{y}{z}} + x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      fma-def [=>]1.08

      \[ \color{blue}{\mathsf{fma}\left(\frac{-1}{3}, \frac{y}{z}, x\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      metadata-eval [=>]1.08

      \[ \mathsf{fma}\left(\color{blue}{-0.3333333333333333}, \frac{y}{z}, x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      *-commutative [=>]1.08

      \[ \mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{\color{blue}{y \cdot \left(z \cdot 3\right)}} \]

    if -2.00000000000000007e139 < (*.f64 z 3) < 1.99999999999999988e-11

    1. Initial program 11.47

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    2. Simplified2.48

      \[\leadsto \color{blue}{x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)} \]
      Proof

      [Start]11.47

      \[ \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]

      associate-+l- [=>]11.47

      \[ \color{blue}{x - \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)} \]

      sub-neg [=>]11.47

      \[ \color{blue}{x + \left(-\left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)\right)} \]

      neg-mul-1 [=>]11.47

      \[ x + \color{blue}{-1 \cdot \left(\frac{y}{z \cdot 3} - \frac{t}{\left(z \cdot 3\right) \cdot y}\right)} \]

      distribute-lft-out-- [<=]11.47

      \[ x + \color{blue}{\left(-1 \cdot \frac{y}{z \cdot 3} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right)} \]

      associate-*r/ [=>]11.47

      \[ x + \left(\color{blue}{\frac{-1 \cdot y}{z \cdot 3}} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right) \]

      associate-*l/ [<=]11.53

      \[ x + \left(\color{blue}{\frac{-1}{z \cdot 3} \cdot y} - -1 \cdot \frac{t}{\left(z \cdot 3\right) \cdot y}\right) \]

      associate-*r/ [=>]11.53

      \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1 \cdot t}{\left(z \cdot 3\right) \cdot y}}\right) \]

      times-frac [=>]2.44

      \[ x + \left(\frac{-1}{z \cdot 3} \cdot y - \color{blue}{\frac{-1}{z \cdot 3} \cdot \frac{t}{y}}\right) \]

      distribute-lft-out-- [=>]2.43

      \[ x + \color{blue}{\frac{-1}{z \cdot 3} \cdot \left(y - \frac{t}{y}\right)} \]

      *-commutative [=>]2.43

      \[ x + \frac{-1}{\color{blue}{3 \cdot z}} \cdot \left(y - \frac{t}{y}\right) \]

      associate-/r* [=>]2.48

      \[ x + \color{blue}{\frac{\frac{-1}{3}}{z}} \cdot \left(y - \frac{t}{y}\right) \]

      metadata-eval [=>]2.48

      \[ x + \frac{\color{blue}{-0.3333333333333333}}{z} \cdot \left(y - \frac{t}{y}\right) \]
    3. Applied egg-rr2.35

      \[\leadsto x + \color{blue}{\frac{y - \frac{t}{y}}{z \cdot -3}} \]

    if 1.99999999999999988e-11 < (*.f64 z 3)

    1. Initial program 0.56

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification1.5

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot 3 \leq -2 \cdot 10^{+139}:\\ \;\;\;\;\mathsf{fma}\left(-0.3333333333333333, \frac{y}{z}, x\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{elif}\;z \cdot 3 \leq 2 \cdot 10^{-11}:\\ \;\;\;\;x + \frac{y - \frac{t}{y}}{z \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;\frac{t}{\left(z \cdot 3\right) \cdot y} + \left(x - \frac{y}{z \cdot 3}\right)\\ \end{array} \]

Alternatives

Alternative 1
Error0.63%
Cost1481
\[\begin{array}{l} \mathbf{if}\;z \cdot 3 \leq -3 \cdot 10^{-18} \lor \neg \left(z \cdot 3 \leq 2 \cdot 10^{-11}\right):\\ \;\;\;\;\frac{t}{\left(z \cdot 3\right) \cdot y} + \left(x - \frac{y}{z \cdot 3}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\frac{y - \frac{t}{y}}{z}}{-3}\\ \end{array} \]
Alternative 2
Error48.26%
Cost1245
\[\begin{array}{l} t_1 := 0.3333333333333333 \cdot \frac{\frac{t}{z}}{y}\\ \mathbf{if}\;y \leq -3.6 \cdot 10^{+41}:\\ \;\;\;\;\frac{y}{z \cdot -3}\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-25}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -1 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -3.1 \cdot 10^{-181}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 160000000:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 1.35 \cdot 10^{+59} \lor \neg \left(y \leq 1.8 \cdot 10^{+103}\right):\\ \;\;\;\;\frac{-0.3333333333333333}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error45.57%
Cost1112
\[\begin{array}{l} t_1 := 0.3333333333333333 \cdot \frac{t}{z \cdot y}\\ \mathbf{if}\;x \leq -1.65 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.2 \cdot 10^{-11}:\\ \;\;\;\;y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;x \leq -2.4 \cdot 10^{-74}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -5.2 \cdot 10^{-217}:\\ \;\;\;\;\frac{-0.3333333333333333}{\frac{z}{y}}\\ \mathbf{elif}\;x \leq 3.2 \cdot 10^{-269}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.5 \cdot 10^{+68}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 4
Error45.82%
Cost1112
\[\begin{array}{l} \mathbf{if}\;x \leq -1.3 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.1 \cdot 10^{-10}:\\ \;\;\;\;y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;x \leq -7.2 \cdot 10^{-75}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\frac{t}{y}}{z}\\ \mathbf{elif}\;x \leq -4.8 \cdot 10^{-216}:\\ \;\;\;\;\frac{-0.3333333333333333}{\frac{z}{y}}\\ \mathbf{elif}\;x \leq 9.8 \cdot 10^{-261}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{t}{z \cdot y}\\ \mathbf{elif}\;x \leq 2.8 \cdot 10^{+67}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error25.83%
Cost976
\[\begin{array}{l} t_1 := 0.3333333333333333 \cdot \frac{\frac{t}{z}}{y}\\ t_2 := x + y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{if}\;y \leq -9.8 \cdot 10^{-60}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;y \leq -7 \cdot 10^{-142}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -6.4 \cdot 10^{-181}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.9 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 6
Error25.76%
Cost976
\[\begin{array}{l} t_1 := 0.3333333333333333 \cdot \frac{\frac{t}{z}}{y}\\ \mathbf{if}\;y \leq -5.5 \cdot 10^{-62}:\\ \;\;\;\;x + y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;y \leq -1.45 \cdot 10^{-141}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq -1.7 \cdot 10^{-181}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-102}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z \cdot -3}\\ \end{array} \]
Alternative 7
Error25.8%
Cost976
\[\begin{array}{l} \mathbf{if}\;y \leq -1.8 \cdot 10^{-60}:\\ \;\;\;\;x + y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;y \leq -7.5 \cdot 10^{-142}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\frac{t}{z}}{y}\\ \mathbf{elif}\;y \leq -8 \cdot 10^{-187}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 3.6 \cdot 10^{-102}:\\ \;\;\;\;\frac{0.3333333333333333}{y \cdot \frac{z}{t}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z \cdot -3}\\ \end{array} \]
Alternative 8
Error2.62%
Cost969
\[\begin{array}{l} \mathbf{if}\;y \leq -2.3 \cdot 10^{-133} \lor \neg \left(y \leq 1.9 \cdot 10^{-102}\right):\\ \;\;\;\;x + \left(y - \frac{t}{y}\right) \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\frac{t}{z \cdot 3}}{y}\\ \end{array} \]
Alternative 9
Error2.65%
Cost968
\[\begin{array}{l} t_1 := y - \frac{t}{y}\\ \mathbf{if}\;y \leq -7.8 \cdot 10^{-134}:\\ \;\;\;\;x + t_1 \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;y \leq 5 \cdot 10^{-101}:\\ \;\;\;\;x + \frac{\frac{t}{z \cdot 3}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{t_1}}\\ \end{array} \]
Alternative 10
Error2.58%
Cost968
\[\begin{array}{l} t_1 := y - \frac{t}{y}\\ \mathbf{if}\;y \leq -2.3 \cdot 10^{-133}:\\ \;\;\;\;x + \frac{t_1}{z \cdot -3}\\ \mathbf{elif}\;y \leq 7 \cdot 10^{-101}:\\ \;\;\;\;x + \frac{\frac{t}{z \cdot 3}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{t_1}}\\ \end{array} \]
Alternative 11
Error14.05%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -2 \cdot 10^{-5} \lor \neg \left(y \leq 520000\right):\\ \;\;\;\;x + \frac{y}{z \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{t}{y} \cdot \frac{0.3333333333333333}{z}\\ \end{array} \]
Alternative 12
Error13%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -1.45 \cdot 10^{-8} \lor \neg \left(y \leq 5500000\right):\\ \;\;\;\;x + \frac{y}{z \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{t \cdot 0.3333333333333333}{z \cdot y}\\ \end{array} \]
Alternative 13
Error9.18%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -0.6 \lor \neg \left(y \leq 700000\right):\\ \;\;\;\;x + \frac{y}{z \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{\frac{t}{z \cdot 3}}{y}\\ \end{array} \]
Alternative 14
Error18.57%
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -1.05 \cdot 10^{-26}:\\ \;\;\;\;x + y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;x \leq 8.6 \cdot 10^{+32}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{y - \frac{t}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{z \cdot -3}\\ \end{array} \]
Alternative 15
Error44.53%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.8 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.5 \cdot 10^{+68}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 16
Error44.65%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -9.5 \cdot 10^{+35}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{+70}:\\ \;\;\;\;y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 17
Error44.54%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.65 \cdot 10^{+36}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3 \cdot 10^{+67}:\\ \;\;\;\;\frac{-0.3333333333333333}{\frac{z}{y}}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 18
Error44.5%
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -6.8 \cdot 10^{+35}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8.8 \cdot 10^{+67}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y}{z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 19
Error58.49%
Cost64
\[x \]

Error

Reproduce?

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

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

  (+ (- x (/ y (* z 3.0))) (/ t (* (* z 3.0) y))))