?

Average Error: 2.1 → 2.0
Time: 12.3s
Precision: binary64
Cost: 1096

?

\[x + \left(y - x\right) \cdot \frac{z}{t} \]
\[\begin{array}{l} \mathbf{if}\;z \leq -1.85 \cdot 10^{-80}:\\ \;\;\;\;\frac{y - x}{t} \cdot z + x\\ \mathbf{elif}\;z \leq 5 \cdot 10^{-176}:\\ \;\;\;\;\frac{z \cdot y}{t} + x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{else}:\\ \;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
(FPCore (x y z t)
 :precision binary64
 (if (<= z -1.85e-80)
   (+ (* (/ (- y x) t) z) x)
   (if (<= z 5e-176)
     (+ (/ (* z y) t) (* x (- 1.0 (/ z t))))
     (+ x (* (- y x) (/ z t))))))
double code(double x, double y, double z, double t) {
	return x + ((y - x) * (z / t));
}
double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -1.85e-80) {
		tmp = (((y - x) / t) * z) + x;
	} else if (z <= 5e-176) {
		tmp = ((z * y) / t) + (x * (1.0 - (z / t)));
	} else {
		tmp = x + ((y - x) * (z / t));
	}
	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 - x) * (z / t))
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) :: tmp
    if (z <= (-1.85d-80)) then
        tmp = (((y - x) / t) * z) + x
    else if (z <= 5d-176) then
        tmp = ((z * y) / t) + (x * (1.0d0 - (z / t)))
    else
        tmp = x + ((y - x) * (z / t))
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x + ((y - x) * (z / t));
}
public static double code(double x, double y, double z, double t) {
	double tmp;
	if (z <= -1.85e-80) {
		tmp = (((y - x) / t) * z) + x;
	} else if (z <= 5e-176) {
		tmp = ((z * y) / t) + (x * (1.0 - (z / t)));
	} else {
		tmp = x + ((y - x) * (z / t));
	}
	return tmp;
}
def code(x, y, z, t):
	return x + ((y - x) * (z / t))
def code(x, y, z, t):
	tmp = 0
	if z <= -1.85e-80:
		tmp = (((y - x) / t) * z) + x
	elif z <= 5e-176:
		tmp = ((z * y) / t) + (x * (1.0 - (z / t)))
	else:
		tmp = x + ((y - x) * (z / t))
	return tmp
function code(x, y, z, t)
	return Float64(x + Float64(Float64(y - x) * Float64(z / t)))
end
function code(x, y, z, t)
	tmp = 0.0
	if (z <= -1.85e-80)
		tmp = Float64(Float64(Float64(Float64(y - x) / t) * z) + x);
	elseif (z <= 5e-176)
		tmp = Float64(Float64(Float64(z * y) / t) + Float64(x * Float64(1.0 - Float64(z / t))));
	else
		tmp = Float64(x + Float64(Float64(y - x) * Float64(z / t)));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x + ((y - x) * (z / t));
end
function tmp_2 = code(x, y, z, t)
	tmp = 0.0;
	if (z <= -1.85e-80)
		tmp = (((y - x) / t) * z) + x;
	elseif (z <= 5e-176)
		tmp = ((z * y) / t) + (x * (1.0 - (z / t)));
	else
		tmp = x + ((y - x) * (z / t));
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[z, -1.85e-80], N[(N[(N[(N[(y - x), $MachinePrecision] / t), $MachinePrecision] * z), $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 5e-176], N[(N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision] + N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \left(y - x\right) \cdot \frac{z}{t}
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{-80}:\\
\;\;\;\;\frac{y - x}{t} \cdot z + x\\

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

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


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original2.1
Target2.2
Herbie2.0
\[\begin{array}{l} \mathbf{if}\;\left(y - x\right) \cdot \frac{z}{t} < -1013646692435.8867:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \mathbf{elif}\;\left(y - x\right) \cdot \frac{z}{t} < 0:\\ \;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y - x}{\frac{t}{z}}\\ \end{array} \]

Derivation?

  1. Split input into 3 regimes
  2. if z < -1.85000000000000016e-80

    1. Initial program 2.6

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

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

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

    if -1.85000000000000016e-80 < z < 5e-176

    1. Initial program 1.3

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

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

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

      [Start]1.2

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

      rational.json-simplify-2 [=>]1.2

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

      rational.json-simplify-2 [=>]1.2

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

      rational.json-simplify-17 [=>]1.2

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

      rational.json-simplify-2 [=>]1.2

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

      rational.json-simplify-9 [=>]1.2

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

      rational.json-simplify-12 [=>]1.2

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

      rational.json-simplify-46 [<=]1.2

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

      rational.json-simplify-1 [=>]1.2

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

      rational.json-simplify-46 [=>]1.2

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

      metadata-eval [=>]1.2

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

    if 5e-176 < z

    1. Initial program 2.6

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

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

Alternatives

Alternative 1
Error27.5
Cost1176
\[\begin{array}{l} t_1 := -\frac{z \cdot x}{t}\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{+87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{+56}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -6.5 \cdot 10^{-100}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 2.05 \cdot 10^{-185}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;x \leq 4.1 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{+36}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 2
Error27.5
Cost1176
\[\begin{array}{l} \mathbf{if}\;x \leq -3.3 \cdot 10^{+87}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -1.85 \cdot 10^{+56}:\\ \;\;\;\;\left(-\frac{x}{t}\right) \cdot z\\ \mathbf{elif}\;x \leq -1.05 \cdot 10^{-98}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-185}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{elif}\;x \leq 4.8 \cdot 10^{-19}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.7 \cdot 10^{+36}:\\ \;\;\;\;-\frac{z \cdot x}{t}\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 3
Error16.7
Cost1108
\[\begin{array}{l} t_1 := \frac{y - x}{t} \cdot z\\ t_2 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -0.62:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -1.7 \cdot 10^{-42}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.35 \cdot 10^{-132}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;x \leq -5 \cdot 10^{-148}:\\ \;\;\;\;\frac{z \cdot y}{t}\\ \mathbf{elif}\;x \leq 5.1 \cdot 10^{-185}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error5.9
Cost1096
\[\begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -100:\\ \;\;\;\;\frac{y - x}{t} \cdot z\\ \mathbf{elif}\;\frac{z}{t} \leq 10^{-10}:\\ \;\;\;\;\frac{y}{t} \cdot z + x\\ \mathbf{else}:\\ \;\;\;\;\left(\frac{y}{t} - \frac{x}{t}\right) \cdot z\\ \end{array} \]
Alternative 5
Error6.1
Cost968
\[\begin{array}{l} t_1 := \frac{y - x}{t} \cdot z\\ \mathbf{if}\;\frac{z}{t} \leq -5 \cdot 10^{-12}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 10^{-10}:\\ \;\;\;\;x + \frac{z \cdot y}{t}\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 6
Error5.9
Cost968
\[\begin{array}{l} t_1 := \frac{y - x}{t} \cdot z\\ \mathbf{if}\;\frac{z}{t} \leq -100:\\ \;\;\;\;t_1\\ \mathbf{elif}\;\frac{z}{t} \leq 10^{-10}:\\ \;\;\;\;\frac{y}{t} \cdot z + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 7
Error1.4
Cost836
\[\begin{array}{l} \mathbf{if}\;\frac{z}{t} \leq -2 \cdot 10^{+213}:\\ \;\;\;\;\frac{y - x}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x + \left(y - x\right) \cdot \frac{z}{t}\\ \end{array} \]
Alternative 8
Error17.5
Cost712
\[\begin{array}{l} t_1 := x \cdot \left(1 - \frac{z}{t}\right)\\ \mathbf{if}\;x \leq -4.5 \cdot 10^{-104}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-185}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error26.2
Cost584
\[\begin{array}{l} \mathbf{if}\;x \leq -3.1 \cdot 10^{-100}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 5.3 \cdot 10^{-185}:\\ \;\;\;\;\frac{y}{t} \cdot z\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 10
Error32.0
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023077 
(FPCore (x y z t)
  :name "Graphics.Rendering.Plot.Render.Plot.Axis:tickPosition from plot-0.2.3.4"
  :precision binary64

  :herbie-target
  (if (< (* (- y x) (/ z t)) -1013646692435.8867) (+ x (/ (- y x) (/ t z))) (if (< (* (- y x) (/ z t)) 0.0) (+ x (/ (* (- y x) z) t)) (+ x (/ (- y x) (/ t z)))))

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