Average Error: 7.7 → 0.9
Time: 4.0s
Precision: binary64
\[ \begin{array}{c}[y, t] = \mathsf{sort}([y, t])\\ \end{array} \]
\[\frac{x}{\left(y - z\right) \cdot \left(t - z\right)} \]
\[\begin{array}{l} t_1 := \left(y - z\right) \cdot \left(t - z\right)\\ \mathbf{if}\;t_1 \leq -2 \cdot 10^{+215}:\\ \;\;\;\;\frac{\frac{1}{z - y}}{\frac{z - t}{x}}\\ \mathbf{elif}\;t_1 \leq 2 \cdot 10^{+216}:\\ \;\;\;\;\frac{x}{t_1}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{x}{z - y}}{z - t}\\ \end{array} \]
(FPCore (x y z t) :precision binary64 (/ x (* (- y z) (- t z))))
(FPCore (x y z t)
 :precision binary64
 (let* ((t_1 (* (- y z) (- t z))))
   (if (<= t_1 -2e+215)
     (/ (/ 1.0 (- z y)) (/ (- z t) x))
     (if (<= t_1 2e+216) (/ x t_1) (/ (/ x (- z y)) (- z t))))))
double code(double x, double y, double z, double t) {
	return x / ((y - z) * (t - z));
}
double code(double x, double y, double z, double t) {
	double t_1 = (y - z) * (t - z);
	double tmp;
	if (t_1 <= -2e+215) {
		tmp = (1.0 / (z - y)) / ((z - t) / x);
	} else if (t_1 <= 2e+216) {
		tmp = x / t_1;
	} else {
		tmp = (x / (z - y)) / (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 - z) * (t - z))
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) * (t - z)
    if (t_1 <= (-2d+215)) then
        tmp = (1.0d0 / (z - y)) / ((z - t) / x)
    else if (t_1 <= 2d+216) then
        tmp = x / t_1
    else
        tmp = (x / (z - y)) / (z - t)
    end if
    code = tmp
end function
public static double code(double x, double y, double z, double t) {
	return x / ((y - z) * (t - z));
}
public static double code(double x, double y, double z, double t) {
	double t_1 = (y - z) * (t - z);
	double tmp;
	if (t_1 <= -2e+215) {
		tmp = (1.0 / (z - y)) / ((z - t) / x);
	} else if (t_1 <= 2e+216) {
		tmp = x / t_1;
	} else {
		tmp = (x / (z - y)) / (z - t);
	}
	return tmp;
}
def code(x, y, z, t):
	return x / ((y - z) * (t - z))
def code(x, y, z, t):
	t_1 = (y - z) * (t - z)
	tmp = 0
	if t_1 <= -2e+215:
		tmp = (1.0 / (z - y)) / ((z - t) / x)
	elif t_1 <= 2e+216:
		tmp = x / t_1
	else:
		tmp = (x / (z - y)) / (z - t)
	return tmp
function code(x, y, z, t)
	return Float64(x / Float64(Float64(y - z) * Float64(t - z)))
end
function code(x, y, z, t)
	t_1 = Float64(Float64(y - z) * Float64(t - z))
	tmp = 0.0
	if (t_1 <= -2e+215)
		tmp = Float64(Float64(1.0 / Float64(z - y)) / Float64(Float64(z - t) / x));
	elseif (t_1 <= 2e+216)
		tmp = Float64(x / t_1);
	else
		tmp = Float64(Float64(x / Float64(z - y)) / Float64(z - t));
	end
	return tmp
end
function tmp = code(x, y, z, t)
	tmp = x / ((y - z) * (t - z));
end
function tmp_2 = code(x, y, z, t)
	t_1 = (y - z) * (t - z);
	tmp = 0.0;
	if (t_1 <= -2e+215)
		tmp = (1.0 / (z - y)) / ((z - t) / x);
	elseif (t_1 <= 2e+216)
		tmp = x / t_1;
	else
		tmp = (x / (z - y)) / (z - t);
	end
	tmp_2 = tmp;
end
code[x_, y_, z_, t_] := N[(x / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+215], N[(N[(1.0 / N[(z - y), $MachinePrecision]), $MachinePrecision] / N[(N[(z - t), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+216], N[(x / t$95$1), $MachinePrecision], N[(N[(x / N[(z - y), $MachinePrecision]), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]]]]
\frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\begin{array}{l}
t_1 := \left(y - z\right) \cdot \left(t - z\right)\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+215}:\\
\;\;\;\;\frac{\frac{1}{z - y}}{\frac{z - t}{x}}\\

\mathbf{elif}\;t_1 \leq 2 \cdot 10^{+216}:\\
\;\;\;\;\frac{x}{t_1}\\

\mathbf{else}:\\
\;\;\;\;\frac{\frac{x}{z - y}}{z - t}\\


\end{array}

Error

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Target

Original7.7
Target8.4
Herbie0.9
\[\begin{array}{l} \mathbf{if}\;\frac{x}{\left(y - z\right) \cdot \left(t - z\right)} < 0:\\ \;\;\;\;\frac{\frac{x}{y - z}}{t - z}\\ \mathbf{else}:\\ \;\;\;\;x \cdot \frac{1}{\left(y - z\right) \cdot \left(t - z\right)}\\ \end{array} \]

Derivation

  1. Split input into 3 regimes
  2. if (*.f64 (-.f64 y z) (-.f64 t z)) < -1.99999999999999981e215

    1. Initial program 12.6

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

      \[\leadsto \color{blue}{\frac{\frac{x}{z - y}}{z - t}} \]
    3. Applied egg-rr0.8

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

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

    if -1.99999999999999981e215 < (*.f64 (-.f64 y z) (-.f64 t z)) < 2e216

    1. Initial program 1.6

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

    if 2e216 < (*.f64 (-.f64 y z) (-.f64 t z))

    1. Initial program 13.0

      \[\frac{x}{\left(y - z\right) \cdot \left(t - z\right)} \]
    2. Simplified0.2

      \[\leadsto \color{blue}{\frac{\frac{x}{z - y}}{z - t}} \]
  3. Recombined 3 regimes into one program.
  4. Final simplification0.9

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

Reproduce

herbie shell --seed 2022192 
(FPCore (x y z t)
  :name "Data.Random.Distribution.Triangular:triangularCDF from random-fu-0.2.6.2, B"
  :precision binary64

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

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