?

Average Error: 3.8 → 2.3
Time: 14.6s
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 := \frac{y}{z \cdot 3}\\ \mathbf{if}\;z \cdot 3 \leq -4 \cdot 10^{-160}:\\ \;\;\;\;\left(\left(x + x\right) - \left(x + t_1\right)\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-178}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y + 0.3333333333333333 \cdot \frac{t}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;\left(x - t_1\right) + \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 (/ y (* z 3.0))))
   (if (<= (* z 3.0) -4e-160)
     (+ (- (+ x x) (+ x t_1)) (/ t (* (* z 3.0) y)))
     (if (<= (* z 3.0) 5e-178)
       (/ (+ (* -0.3333333333333333 y) (* 0.3333333333333333 (/ t y))) z)
       (+ (- x 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 = y / (z * 3.0);
	double tmp;
	if ((z * 3.0) <= -4e-160) {
		tmp = ((x + x) - (x + t_1)) + (t / ((z * 3.0) * y));
	} else if ((z * 3.0) <= 5e-178) {
		tmp = ((-0.3333333333333333 * y) + (0.3333333333333333 * (t / y))) / z;
	} else {
		tmp = (x - 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 = y / (z * 3.0d0)
    if ((z * 3.0d0) <= (-4d-160)) then
        tmp = ((x + x) - (x + t_1)) + (t / ((z * 3.0d0) * y))
    else if ((z * 3.0d0) <= 5d-178) then
        tmp = (((-0.3333333333333333d0) * y) + (0.3333333333333333d0 * (t / y))) / z
    else
        tmp = (x - 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 = y / (z * 3.0);
	double tmp;
	if ((z * 3.0) <= -4e-160) {
		tmp = ((x + x) - (x + t_1)) + (t / ((z * 3.0) * y));
	} else if ((z * 3.0) <= 5e-178) {
		tmp = ((-0.3333333333333333 * y) + (0.3333333333333333 * (t / y))) / z;
	} else {
		tmp = (x - 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 = y / (z * 3.0)
	tmp = 0
	if (z * 3.0) <= -4e-160:
		tmp = ((x + x) - (x + t_1)) + (t / ((z * 3.0) * y))
	elif (z * 3.0) <= 5e-178:
		tmp = ((-0.3333333333333333 * y) + (0.3333333333333333 * (t / y))) / z
	else:
		tmp = (x - 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(y / Float64(z * 3.0))
	tmp = 0.0
	if (Float64(z * 3.0) <= -4e-160)
		tmp = Float64(Float64(Float64(x + x) - Float64(x + t_1)) + Float64(t / Float64(Float64(z * 3.0) * y)));
	elseif (Float64(z * 3.0) <= 5e-178)
		tmp = Float64(Float64(Float64(-0.3333333333333333 * y) + Float64(0.3333333333333333 * Float64(t / y))) / z);
	else
		tmp = Float64(Float64(x - 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 = y / (z * 3.0);
	tmp = 0.0;
	if ((z * 3.0) <= -4e-160)
		tmp = ((x + x) - (x + t_1)) + (t / ((z * 3.0) * y));
	elseif ((z * 3.0) <= 5e-178)
		tmp = ((-0.3333333333333333 * y) + (0.3333333333333333 * (t / y))) / z;
	else
		tmp = (x - 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[(y / N[(z * 3.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(z * 3.0), $MachinePrecision], -4e-160], N[(N[(N[(x + x), $MachinePrecision] - N[(x + t$95$1), $MachinePrecision]), $MachinePrecision] + N[(t / N[(N[(z * 3.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(z * 3.0), $MachinePrecision], 5e-178], N[(N[(N[(-0.3333333333333333 * y), $MachinePrecision] + N[(0.3333333333333333 * N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], N[(N[(x - t$95$1), $MachinePrecision] + 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 := \frac{y}{z \cdot 3}\\
\mathbf{if}\;z \cdot 3 \leq -4 \cdot 10^{-160}:\\
\;\;\;\;\left(\left(x + x\right) - \left(x + t_1\right)\right) + \frac{t}{\left(z \cdot 3\right) \cdot y}\\

\mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-178}:\\
\;\;\;\;\frac{-0.3333333333333333 \cdot y + 0.3333333333333333 \cdot \frac{t}{y}}{z}\\

\mathbf{else}:\\
\;\;\;\;\left(x - t_1\right) + \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.8
Target2.0
Herbie2.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) < -4e-160

    1. Initial program 1.4

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

      \[\leadsto \color{blue}{\frac{1}{x - \frac{y}{z \cdot 3}} \cdot \left(\left(x - \frac{y}{z \cdot 3}\right) \cdot \left(x - \frac{y}{z \cdot 3}\right)\right)} + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
    3. Applied egg-rr1.4

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

    if -4e-160 < (*.f64 z 3) < 4.99999999999999976e-178

    1. Initial program 27.9

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

      \[\leadsto \left(x - \frac{y}{z \cdot 3}\right) + \color{blue}{0.3333333333333333 \cdot \frac{t}{y \cdot z}} \]
    3. Taylor expanded in x around 0 32.8

      \[\leadsto \color{blue}{-0.3333333333333333 \cdot \frac{y}{z}} + 0.3333333333333333 \cdot \frac{t}{y \cdot z} \]
    4. Simplified32.8

      \[\leadsto \color{blue}{\frac{y}{z} \cdot -0.3333333333333333} + 0.3333333333333333 \cdot \frac{t}{y \cdot z} \]
      Proof

      [Start]32.8

      \[ -0.3333333333333333 \cdot \frac{y}{z} + 0.3333333333333333 \cdot \frac{t}{y \cdot z} \]

      rational_best-simplify-2 [=>]32.8

      \[ \color{blue}{\frac{y}{z} \cdot -0.3333333333333333} + 0.3333333333333333 \cdot \frac{t}{y \cdot z} \]
    5. Taylor expanded in z around 0 9.2

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

    if 4.99999999999999976e-178 < (*.f64 z 3)

    1. Initial program 2.1

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

      \[\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 simplification2.3

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

Alternatives

Alternative 1
Error2.4
Cost1480
\[\begin{array}{l} t_1 := \left(x - \frac{y}{z \cdot 3}\right) + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\\ \mathbf{if}\;z \cdot 3 \leq -4 \cdot 10^{-160}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-178}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y + 0.3333333333333333 \cdot \frac{t}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 2
Error2.3
Cost1480
\[\begin{array}{l} t_1 := x - \frac{y}{z \cdot 3}\\ \mathbf{if}\;z \cdot 3 \leq -4 \cdot 10^{-160}:\\ \;\;\;\;t_1 + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\\ \mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-178}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y + 0.3333333333333333 \cdot \frac{t}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1 + \frac{t}{3 \cdot \left(y \cdot z\right)}\\ \end{array} \]
Alternative 3
Error2.3
Cost1480
\[\begin{array}{l} t_1 := x - \frac{y}{z \cdot 3}\\ \mathbf{if}\;z \cdot 3 \leq -4 \cdot 10^{-160}:\\ \;\;\;\;t_1 + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{elif}\;z \cdot 3 \leq 5 \cdot 10^{-178}:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y + 0.3333333333333333 \cdot \frac{t}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;t_1 + \frac{t}{3 \cdot \left(y \cdot z\right)}\\ \end{array} \]
Alternative 4
Error13.9
Cost1224
\[\begin{array}{l} \mathbf{if}\;x \leq -1.9 \cdot 10^{+23}:\\ \;\;\;\;x + \frac{t}{z \cdot \left(y \cdot 3\right)}\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{+14}:\\ \;\;\;\;0.1111111111111111 \cdot \left(\frac{\frac{t}{y \cdot z}}{0.3333333333333333} + \frac{\frac{y}{z}}{-0.3333333333333333}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \end{array} \]
Alternative 5
Error13.9
Cost1096
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{+24}:\\ \;\;\;\;x + \frac{t}{z \cdot \left(y \cdot 3\right)}\\ \mathbf{elif}\;x \leq 5.2 \cdot 10^{+14}:\\ \;\;\;\;\frac{y}{z} \cdot -0.3333333333333333 + 0.3333333333333333 \cdot \frac{t}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \end{array} \]
Alternative 6
Error13.9
Cost1096
\[\begin{array}{l} t_1 := \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \mathbf{if}\;x \leq -6.9 \cdot 10^{+22}:\\ \;\;\;\;x + \frac{t}{z \cdot \left(y \cdot 3\right)}\\ \mathbf{elif}\;x \leq 5000000000000:\\ \;\;\;\;\frac{y}{z} \cdot -0.3333333333333333 + t_1\\ \mathbf{else}:\\ \;\;\;\;x + t_1\\ \end{array} \]
Alternative 7
Error13.7
Cost968
\[\begin{array}{l} \mathbf{if}\;x \leq -2.25 \cdot 10^{+24}:\\ \;\;\;\;x + \frac{t}{z \cdot \left(y \cdot 3\right)}\\ \mathbf{elif}\;x \leq 11000000000000:\\ \;\;\;\;\frac{-0.3333333333333333 \cdot y + 0.3333333333333333 \cdot \frac{t}{y}}{z}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{t}{\left(z \cdot 3\right) \cdot y}\\ \end{array} \]
Alternative 8
Error30.6
Cost712
\[\begin{array}{l} \mathbf{if}\;x \leq -1.25 \cdot 10^{-23}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2200000000:\\ \;\;\;\;0.3333333333333333 \cdot \frac{t}{y \cdot z}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 9
Error23.1
Cost576
\[x + \frac{t}{3 \cdot \left(y \cdot z\right)} \]
Alternative 10
Error23.1
Cost576
\[x + \frac{t}{\left(z \cdot 3\right) \cdot y} \]
Alternative 11
Error37.4
Cost64
\[x \]

Error

Reproduce?

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