Average Error: 3.7 → 1.3
Time: 13.9s
Precision: binary64
Cost: 1480
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
\[\begin{array}{l} t_1 := x - \frac{y}{z \cdot 3}\\ \mathbf{if}\;z \cdot 3 \leq -5 \cdot 10^{+138}:\\ \;\;\;\;t_1 + t \cdot \frac{\frac{0.3333333333333333}{z}}{y}\\ \mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-143}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1 + \frac{t}{3 \cdot \left(y \cdot z\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 (- x (/ y (* z 3.0)))))
   (if (<= (* z 3.0) -5e+138)
     (+ t_1 (* t (/ (/ 0.3333333333333333 z) y)))
     (if (<= (* z 3.0) 5e-143)
       (+ x (* (/ -0.3333333333333333 z) (- y (/ t y))))
       (+ t_1 (/ t (* 3.0 (* y z))))))))
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 = x - (y / (z * 3.0));
	double tmp;
	if ((z * 3.0) <= -5e+138) {
		tmp = t_1 + (t * ((0.3333333333333333 / z) / y));
	} else if ((z * 3.0) <= 5e-143) {
		tmp = x + ((-0.3333333333333333 / z) * (y - (t / y)));
	} else {
		tmp = t_1 + (t / (3.0 * (y * z)));
	}
	return tmp;
}
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    code = (x - (y / (z * 3.0d0))) + (t / ((z * 3.0d0) * y))
end function
real(8) function code(x, y, z, t)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8) :: t_1
    real(8) :: tmp
    t_1 = x - (y / (z * 3.0d0))
    if ((z * 3.0d0) <= (-5d+138)) then
        tmp = t_1 + (t * ((0.3333333333333333d0 / z) / y))
    else if ((z * 3.0d0) <= 5d-143) then
        tmp = x + (((-0.3333333333333333d0) / z) * (y - (t / y)))
    else
        tmp = t_1 + (t / (3.0d0 * (y * z)))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = x - (y / (z * 3.0));
	double tmp;
	if ((z * 3.0) <= -5e+138) {
		tmp = t_1 + (t * ((0.3333333333333333 / z) / y));
	} else if ((z * 3.0) <= 5e-143) {
		tmp = x + ((-0.3333333333333333 / z) * (y - (t / y)));
	} else {
		tmp = t_1 + (t / (3.0 * (y * z)));
	}
	return tmp;
}
def code(x, y, z, t):
	return (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y))
def code(x, y, z, t):
	t_1 = x - (y / (z * 3.0))
	tmp = 0
	if (z * 3.0) <= -5e+138:
		tmp = t_1 + (t * ((0.3333333333333333 / z) / y))
	elif (z * 3.0) <= 5e-143:
		tmp = x + ((-0.3333333333333333 / z) * (y - (t / y)))
	else:
		tmp = t_1 + (t / (3.0 * (y * z)))
	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(x - Float64(y / Float64(z * 3.0)))
	tmp = 0.0
	if (Float64(z * 3.0) <= -5e+138)
		tmp = Float64(t_1 + Float64(t * Float64(Float64(0.3333333333333333 / z) / y)));
	elseif (Float64(z * 3.0) <= 5e-143)
		tmp = Float64(x + Float64(Float64(-0.3333333333333333 / z) * Float64(y - Float64(t / y))));
	else
		tmp = Float64(t_1 + Float64(t / Float64(3.0 * Float64(y * z))));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = (x - (y / (z * 3.0))) + (t / ((z * 3.0) * y));
end
function tmp_2 = code(x, y, z, t)
	t_1 = x - (y / (z * 3.0));
	tmp = 0.0;
	if ((z * 3.0) <= -5e+138)
		tmp = t_1 + (t * ((0.3333333333333333 / z) / y));
	elseif ((z * 3.0) <= 5e-143)
		tmp = x + ((-0.3333333333333333 / z) * (y - (t / y)));
	else
		tmp = t_1 + (t / (3.0 * (y * z)));
	end
	tmp_2 = 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[(x - N[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * 3.0), $MachinePrecision], -5e+138], N[(t$95$1 + N[(t * N[(N[(0.3333333333333333 / z), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 5e-143], N[(x + N[(N[(-0.3333333333333333 / z), $MachinePrecision] * N[(y - N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t$95$1 + N[(t / N[(3.0 * N[(y * z), $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 := x - \frac{y}{z \cdot 3}\\
\mathbf{if}\;z \cdot 3 \leq -5 \cdot 10^{+138}:\\
\;\;\;\;t_1 + t \cdot \frac{\frac{0.3333333333333333}{z}}{y}\\

\mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-143}:\\
\;\;\;\;x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\

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


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original3.7
Target1.8
Herbie1.3
\[\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) < -5.00000000000000016e138

    1. Initial program 0.7

      \[\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    2. Applied egg-rr0.7

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

    if -5.00000000000000016e138 < (*.f64 z 3) < 5.0000000000000002e-143

    1. Initial program 8.2

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

      \[\leadsto \color{blue}{\mathsf{fma}\left(\frac{-0.3333333333333333}{z}, y - \frac{t}{y}, x\right)} \]
      Proof
      (fma.f64 (/.f64 -1/3 z) (-.f64 y (/.f64 t y)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (/.f64 (Rewrite<= metadata-eval (/.f64 -1 3)) z) (-.f64 y (/.f64 t y)) x): 0 points increase in error, 0 points decrease in error
      (fma.f64 (Rewrite<= associate-/r*_binary64 (/.f64 -1 (*.f64 3 z))) (-.f64 y (/.f64 t y)) x): 29 points increase in error, 13 points decrease in error
      (fma.f64 (/.f64 -1 (Rewrite<= *-commutative_binary64 (*.f64 z 3))) (-.f64 y (/.f64 t y)) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= fma-def_binary64 (+.f64 (*.f64 (/.f64 -1 (*.f64 z 3)) (-.f64 y (/.f64 t y))) x)): 3 points increase in error, 1 points decrease in error
      (+.f64 (Rewrite<= distribute-lft-out--_binary64 (-.f64 (*.f64 (/.f64 -1 (*.f64 z 3)) y) (*.f64 (/.f64 -1 (*.f64 z 3)) (/.f64 t y)))) x): 2 points increase in error, 1 points decrease in error
      (+.f64 (-.f64 (Rewrite=> associate-*l/_binary64 (/.f64 (*.f64 -1 y) (*.f64 z 3))) (*.f64 (/.f64 -1 (*.f64 z 3)) (/.f64 t y))) x): 5 points increase in error, 15 points decrease in error
      (+.f64 (-.f64 (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 y)) (*.f64 z 3)) (*.f64 (/.f64 -1 (*.f64 z 3)) (/.f64 t y))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 y (*.f64 z 3)))) (*.f64 (/.f64 -1 (*.f64 z 3)) (/.f64 t y))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (neg.f64 (/.f64 y (*.f64 z 3))) (Rewrite<= times-frac_binary64 (/.f64 (*.f64 -1 t) (*.f64 (*.f64 z 3) y)))) x): 19 points increase in error, 24 points decrease in error
      (+.f64 (-.f64 (neg.f64 (/.f64 y (*.f64 z 3))) (/.f64 (Rewrite<= neg-mul-1_binary64 (neg.f64 t)) (*.f64 (*.f64 z 3) y))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (-.f64 (neg.f64 (/.f64 y (*.f64 z 3))) (Rewrite<= distribute-neg-frac_binary64 (neg.f64 (/.f64 t (*.f64 (*.f64 z 3) y))))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= unsub-neg_binary64 (+.f64 (neg.f64 (/.f64 y (*.f64 z 3))) (neg.f64 (neg.f64 (/.f64 t (*.f64 (*.f64 z 3) y)))))) x): 0 points increase in error, 0 points decrease in error
      (+.f64 (+.f64 (neg.f64 (/.f64 y (*.f64 z 3))) (Rewrite=> remove-double-neg_binary64 (/.f64 t (*.f64 (*.f64 z 3) y)))) x): 0 points increase in error, 0 points decrease in error
      (Rewrite<= +-commutative_binary64 (+.f64 x (+.f64 (neg.f64 (/.f64 y (*.f64 z 3))) (/.f64 t (*.f64 (*.f64 z 3) y))))): 0 points increase in error, 0 points decrease in error
      (Rewrite<= associate-+l+_binary64 (+.f64 (+.f64 x (neg.f64 (/.f64 y (*.f64 z 3)))) (/.f64 t (*.f64 (*.f64 z 3) y)))): 0 points increase in error, 0 points decrease in error
      (+.f64 (Rewrite<= sub-neg_binary64 (-.f64 x (/.f64 y (*.f64 z 3)))) (/.f64 t (*.f64 (*.f64 z 3) y))): 0 points increase in error, 0 points decrease in error
    3. Applied egg-rr1.7

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

    if 5.0000000000000002e-143 < (*.f64 z 3)

    1. Initial program 1.3

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

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;z \cdot 3 \leq -5 \cdot 10^{+138}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + t \cdot \frac{\frac{0.3333333333333333}{z}}{y}\\ \mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-143}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{3 \cdot \left(y \cdot z\right)}\\ \end{array} \]

Alternatives

Alternative 1
Error0.4
Cost1224
\[\begin{array}{l} t_1 := \left(x - \frac{\frac{y}{z}}{3}\right) + \frac{t}{y \cdot \left(z \cdot 3\right)}\\ \mathbf{if}\;t \leq -1 \cdot 10^{+22}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 8.2 \cdot 10^{-16}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error0.5
Cost1224
\[\begin{array}{l} t_1 := \left(x - \frac{y}{z \cdot 3}\right) + \frac{t}{3 \cdot \left(y \cdot z\right)}\\ \mathbf{if}\;t \leq -1.2794547621366762 \cdot 10^{-88}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.174005024285197 \cdot 10^{-16}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 3
Error31.2
Cost1112
\[\begin{array}{l} \mathbf{if}\;y \leq -1.938126799837756 \cdot 10^{+99}:\\ \;\;\;\;y \cdot \frac{-0.3333333333333333}{z}\\ \mathbf{elif}\;y \leq -2.2677817758631396 \cdot 10^{+54}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq -3.0975825467504145 \cdot 10^{-8}:\\ \;\;\;\;\frac{y}{z \cdot -3}\\ \mathbf{elif}\;y \leq 3.8 \cdot 10^{-208}:\\ \;\;\;\;x\\ \mathbf{elif}\;y \leq 1.367593831153133 \cdot 10^{-92}:\\ \;\;\;\;\frac{t \cdot \frac{0.3333333333333333}{z}}{y}\\ \mathbf{elif}\;y \leq 3.876819769016031 \cdot 10^{+72}:\\ \;\;\;\;x\\ \mathbf{else}:\\ \;\;\;\;\frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 4
Error1.8
Cost1088
\[\left(x - \frac{y}{z \cdot 3}\right) + \frac{1}{y} \cdot \left(t \cdot \frac{0.3333333333333333}{z}\right) \]
Alternative 5
Error6.4
Cost972
\[\begin{array}{l} \mathbf{if}\;y \leq -5.133301751857722 \cdot 10^{+35}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -6.16280358870359 \cdot 10^{-11}:\\ \;\;\;\;\frac{0.3333333333333333}{\frac{z}{\frac{t}{y} - y}}\\ \mathbf{elif}\;y \leq 2.151754503387541 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{t}{z} \cdot \frac{0.3333333333333333}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 6
Error6.4
Cost972
\[\begin{array}{l} \mathbf{if}\;y \leq -5.133301751857722 \cdot 10^{+35}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -6.16280358870359 \cdot 10^{-11}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\frac{t}{y} - y}{z}\\ \mathbf{elif}\;y \leq 2.151754503387541 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{t}{z} \cdot \frac{0.3333333333333333}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 7
Error6.4
Cost972
\[\begin{array}{l} \mathbf{if}\;y \leq -5.133301751857722 \cdot 10^{+35}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -6.16280358870359 \cdot 10^{-11}:\\ \;\;\;\;0.3333333333333333 \cdot \frac{\frac{t}{y} - y}{z}\\ \mathbf{elif}\;y \leq 2.151754503387541 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{\frac{t \cdot 0.3333333333333333}{z}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 8
Error6.4
Cost972
\[\begin{array}{l} \mathbf{if}\;y \leq -5.133301751857722 \cdot 10^{+35}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -6.16280358870359 \cdot 10^{-11}:\\ \;\;\;\;\frac{0.3333333333333333}{z} \cdot \left(\frac{t}{y} - y\right)\\ \mathbf{elif}\;y \leq 2.151754503387541 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{\frac{t \cdot 0.3333333333333333}{z}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 9
Error6.4
Cost972
\[\begin{array}{l} \mathbf{if}\;y \leq -5.133301751857722 \cdot 10^{+35}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{elif}\;y \leq -6.16280358870359 \cdot 10^{-11}:\\ \;\;\;\;\frac{0.3333333333333333 \cdot \frac{t}{y} + y \cdot -0.3333333333333333}{z}\\ \mathbf{elif}\;y \leq 2.151754503387541 \cdot 10^{-39}:\\ \;\;\;\;x + \frac{\frac{t \cdot 0.3333333333333333}{z}}{y}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 10
Error1.6
Cost968
\[\begin{array}{l} t_1 := x + \frac{-0.3333333333333333}{z} \cdot \left(y - \frac{t}{y}\right)\\ \mathbf{if}\;y \leq -4.215015821444856 \cdot 10^{-123}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;y \leq 9.039753357728365 \cdot 10^{-119}:\\ \;\;\;\;x + \frac{\frac{t \cdot 0.3333333333333333}{z}}{y}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 11
Error18.9
Cost844
\[\begin{array}{l} t_1 := x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ t_2 := \frac{t}{z} \cdot \frac{0.3333333333333333}{y}\\ \mathbf{if}\;t \leq -5.7 \cdot 10^{+208}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+171}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5.6 \cdot 10^{+195}:\\ \;\;\;\;t_2\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 12
Error18.9
Cost844
\[\begin{array}{l} t_1 := \frac{t}{z} \cdot \frac{0.3333333333333333}{y}\\ \mathbf{if}\;t \leq -5.7 \cdot 10^{+208}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t \leq 5 \cdot 10^{+171}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \mathbf{elif}\;t \leq 5.6 \cdot 10^{+195}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \end{array} \]
Alternative 13
Error11.5
Cost840
\[\begin{array}{l} \mathbf{if}\;x \leq -2.9315551022217165 \cdot 10^{-84}:\\ \;\;\;\;x + -0.3333333333333333 \cdot \frac{y}{z}\\ \mathbf{elif}\;x \leq 2.6972815645362105:\\ \;\;\;\;\frac{0.3333333333333333}{\frac{z}{\frac{t}{y} - y}}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{-0.3333333333333333}{\frac{z}{y}}\\ \end{array} \]
Alternative 14
Error27.6
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -1.1308609991500697 \cdot 10^{-42}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 196.0029005101179:\\ \;\;\;\;\frac{y}{z \cdot -3}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 15
Error37.2
Cost64
\[x \]

Error

Reproduce

herbie shell --seed 2022291 
(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))))