?

Average Error: 6.1 → 0.5
Time: 29.4s
Precision: binary64
Cost: 1672

?

\[x + \frac{y \cdot \left(z - t\right)}{a} \]
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ t_2 := \left(\frac{z}{a} - \frac{t}{a}\right) \cdot y + x\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+169}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+238}:\\ \;\;\;\;\left(-\frac{y \cdot t}{a}\right) + \left(\frac{y \cdot z}{a} + x\right)\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) a)))
(FPCore (x y z t a)
 :precision binary64
 (let* ((t_1 (* y (- z t))) (t_2 (+ (* (- (/ z a) (/ t a)) y) x)))
   (if (<= t_1 -1e+169)
     t_2
     (if (<= t_1 1e+238) (+ (- (/ (* y t) a)) (+ (/ (* y z) a) x)) t_2))))
double code(double x, double y, double z, double t, double a) {
	return x + ((y * (z - t)) / a);
}
double code(double x, double y, double z, double t, double a) {
	double t_1 = y * (z - t);
	double t_2 = (((z / a) - (t / a)) * y) + x;
	double tmp;
	if (t_1 <= -1e+169) {
		tmp = t_2;
	} else if (t_1 <= 1e+238) {
		tmp = -((y * t) / a) + (((y * z) / a) + x);
	} else {
		tmp = t_2;
	}
	return tmp;
}
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    code = x + ((y * (z - t)) / a)
end function
real(8) function code(x, y, z, t, a)
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    real(8), intent (in) :: z
    real(8), intent (in) :: t
    real(8), intent (in) :: a
    real(8) :: t_1
    real(8) :: t_2
    real(8) :: tmp
    t_1 = y * (z - t)
    t_2 = (((z / a) - (t / a)) * y) + x
    if (t_1 <= (-1d+169)) then
        tmp = t_2
    else if (t_1 <= 1d+238) then
        tmp = -((y * t) / a) + (((y * z) / a) + x)
    else
        tmp = t_2
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
	return x + ((y * (z - t)) / a);
}
public static double code(double x, double y, double z, double t, double a) {
	double t_1 = y * (z - t);
	double t_2 = (((z / a) - (t / a)) * y) + x;
	double tmp;
	if (t_1 <= -1e+169) {
		tmp = t_2;
	} else if (t_1 <= 1e+238) {
		tmp = -((y * t) / a) + (((y * z) / a) + x);
	} else {
		tmp = t_2;
	}
	return tmp;
}
def code(x, y, z, t, a):
	return x + ((y * (z - t)) / a)
def code(x, y, z, t, a):
	t_1 = y * (z - t)
	t_2 = (((z / a) - (t / a)) * y) + x
	tmp = 0
	if t_1 <= -1e+169:
		tmp = t_2
	elif t_1 <= 1e+238:
		tmp = -((y * t) / a) + (((y * z) / a) + x)
	else:
		tmp = t_2
	return tmp
function code(x, y, z, t, a)
	return Float64(x + Float64(Float64(y * Float64(z - t)) / a))
end
function code(x, y, z, t, a)
	t_1 = Float64(y * Float64(z - t))
	t_2 = Float64(Float64(Float64(Float64(z / a) - Float64(t / a)) * y) + x)
	tmp = 0.0
	if (t_1 <= -1e+169)
		tmp = t_2;
	elseif (t_1 <= 1e+238)
		tmp = Float64(Float64(-Float64(Float64(y * t) / a)) + Float64(Float64(Float64(y * z) / a) + x));
	else
		tmp = t_2;
	end
	return tmp
end
function tmp = code(x, y, z, t, a)
	tmp = x + ((y * (z - t)) / a);
end
function tmp_2 = code(x, y, z, t, a)
	t_1 = y * (z - t);
	t_2 = (((z / a) - (t / a)) * y) + x;
	tmp = 0.0;
	if (t_1 <= -1e+169)
		tmp = t_2;
	elseif (t_1 <= 1e+238)
		tmp = -((y * t) / a) + (((y * z) / a) + x);
	else
		tmp = t_2;
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(N[(z / a), $MachinePrecision] - N[(t / a), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] + x), $MachinePrecision]}, If[LessEqual[t$95$1, -1e+169], t$95$2, If[LessEqual[t$95$1, 1e+238], N[((-N[(N[(y * t), $MachinePrecision] / a), $MachinePrecision]) + N[(N[(N[(y * z), $MachinePrecision] / a), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
x + \frac{y \cdot \left(z - t\right)}{a}
\begin{array}{l}
t_1 := y \cdot \left(z - t\right)\\
t_2 := \left(\frac{z}{a} - \frac{t}{a}\right) \cdot y + x\\
\mathbf{if}\;t_1 \leq -1 \cdot 10^{+169}:\\
\;\;\;\;t_2\\

\mathbf{elif}\;t_1 \leq 10^{+238}:\\
\;\;\;\;\left(-\frac{y \cdot t}{a}\right) + \left(\frac{y \cdot z}{a} + x\right)\\

\mathbf{else}:\\
\;\;\;\;t_2\\


\end{array}

Error?

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original6.1
Target0.8
Herbie0.5
\[\begin{array}{l} \mathbf{if}\;y < -1.0761266216389975 \cdot 10^{-10}:\\ \;\;\;\;x + \frac{1}{\frac{\frac{a}{z - t}}{y}}\\ \mathbf{elif}\;y < 2.894426862792089 \cdot 10^{-49}:\\ \;\;\;\;x + \frac{y \cdot \left(z - t\right)}{a}\\ \mathbf{else}:\\ \;\;\;\;x + \frac{y}{\frac{a}{z - t}}\\ \end{array} \]

Derivation?

  1. Split input into 2 regimes
  2. if (*.f64 y (-.f64 z t)) < -9.99999999999999934e168 or 1e238 < (*.f64 y (-.f64 z t))

    1. Initial program 27.4

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

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

    if -9.99999999999999934e168 < (*.f64 y (-.f64 z t)) < 1e238

    1. Initial program 0.4

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

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

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

      [Start]0.4

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

      rational_best.json-simplify-1 [=>]0.4

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

      rational_best.json-simplify-43 [=>]0.4

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

      rational_best.json-simplify-2 [=>]0.4

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

      rational_best.json-simplify-12 [=>]0.4

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

      rational_best.json-simplify-1 [<=]0.4

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

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

Alternatives

Alternative 1
Error14.6
Cost2512
\[\begin{array}{l} t_1 := \frac{y \cdot z}{a} + x\\ t_2 := \frac{y \cdot \left(z - t\right)}{a}\\ t_3 := \frac{z - t}{a} \cdot y\\ \mathbf{if}\;t_2 \leq -1 \cdot 10^{+193}:\\ \;\;\;\;t_3\\ \mathbf{elif}\;t_2 \leq 4 \cdot 10^{+81}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;t_2 \leq 5 \cdot 10^{+166}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_2 \leq 10^{+263}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;t_3\\ \end{array} \]
Alternative 2
Error0.5
Cost1480
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ t_2 := \left(\frac{z}{a} - \frac{t}{a}\right) \cdot y + x\\ \mathbf{if}\;t_1 \leq -1 \cdot 10^{+169}:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 10^{+238}:\\ \;\;\;\;x + \frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 3
Error1.5
Cost1352
\[\begin{array}{l} t_1 := y \cdot \left(z - t\right)\\ t_2 := \frac{z - t}{a} \cdot y\\ \mathbf{if}\;t_1 \leq -\infty:\\ \;\;\;\;t_2\\ \mathbf{elif}\;t_1 \leq 4 \cdot 10^{+290}:\\ \;\;\;\;x + \frac{t_1}{a}\\ \mathbf{else}:\\ \;\;\;\;t_2\\ \end{array} \]
Alternative 4
Error21.3
Cost976
\[\begin{array}{l} t_1 := \frac{z - t}{a} \cdot y\\ \mathbf{if}\;x \leq -1.6 \cdot 10^{+40}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq -2.15 \cdot 10^{-91}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq -2.5 \cdot 10^{-168}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 3.6 \cdot 10^{-10}:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 5
Error29.2
Cost848
\[\begin{array}{l} t_1 := \frac{z}{a} \cdot y\\ \mathbf{if}\;x \leq -3.3 \cdot 10^{-177}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 7.7 \cdot 10^{-178}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 1.3 \cdot 10^{-79}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 0.185:\\ \;\;\;\;t_1\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 6
Error29.1
Cost848
\[\begin{array}{l} \mathbf{if}\;x \leq -1.55 \cdot 10^{-167}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 8 \cdot 10^{-177}:\\ \;\;\;\;\frac{y \cdot z}{a}\\ \mathbf{elif}\;x \leq 1.5 \cdot 10^{-83}:\\ \;\;\;\;x\\ \mathbf{elif}\;x \leq 0.16:\\ \;\;\;\;\frac{z}{a} \cdot y\\ \mathbf{else}:\\ \;\;\;\;x\\ \end{array} \]
Alternative 7
Error12.6
Cost776
\[\begin{array}{l} t_1 := \frac{z}{a} \cdot y + x\\ \mathbf{if}\;z \leq -3 \cdot 10^{-112}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 1.75 \cdot 10^{-9}:\\ \;\;\;\;\left(-\frac{y \cdot t}{a}\right) + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 8
Error12.7
Cost776
\[\begin{array}{l} t_1 := \frac{z}{a} \cdot y + x\\ \mathbf{if}\;z \leq -1.42 \cdot 10^{-95}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;z \leq 3.3 \cdot 10^{-19}:\\ \;\;\;\;\left(-\frac{t}{a}\right) \cdot y + x\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 9
Error16.7
Cost712
\[\begin{array}{l} t_1 := \frac{z}{a} \cdot y + x\\ \mathbf{if}\;x \leq -1.1 \cdot 10^{-212}:\\ \;\;\;\;t_1\\ \mathbf{elif}\;x \leq 2.7 \cdot 10^{-175}:\\ \;\;\;\;\frac{z - t}{a} \cdot y\\ \mathbf{else}:\\ \;\;\;\;t_1\\ \end{array} \]
Alternative 10
Error31.2
Cost64
\[x \]

Error

Reproduce?

herbie shell --seed 2023088 
(FPCore (x y z t a)
  :name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, E"
  :precision binary64

  :herbie-target
  (if (< y -1.0761266216389975e-10) (+ x (/ 1.0 (/ (/ a (- z t)) y))) (if (< y 2.894426862792089e-49) (+ x (/ (* y (- z t)) a)) (+ x (/ y (/ a (- z t))))))

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