Data.Random.Distribution.Triangular:triangularCDF from random-fu-0.2.6.2, A

?

Percentage Accurate: 99.1% → 98.5%
Time: 10.1s
Precision: binary64
Cost: 704

?

\[1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)} \]
\[\begin{array}{l} [z, t] = \mathsf{sort}([z, t])\\ \end{array} 1 - \frac{\frac{x}{y - z}}{y - t} \]
(FPCore (x y z t) :precision binary64 (- 1.0 (/ x (* (- y z) (- y t)))))
;; Ensure these are sorted, for example in Racket, do
(match-define (list z t) (sort (z t) <))

(FPCore (x y z t) :precision binary64 (- 1.0 (/ (/ x (- y z)) (- y t))))
double code(double x, double y, double z, double t) {
	return 1.0 - (x / ((y - z) * (y - t)));
}
// Ensure these are sorted
assert(z < t);

double code(double x, double y, double z, double t) {
	return 1.0 - ((x / (y - z)) / (y - t));
}
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 = 1.0d0 - (x / ((y - z) * (y - t)))
end function
NOTE: z and t should be sorted in increasing order before calling this 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
    code = 1.0d0 - ((x / (y - z)) / (y - t))
end function
public static double code(double x, double y, double z, double t) {
	return 1.0 - (x / ((y - z) * (y - t)));
}
// Ensure these are sorted
assert z < t;

public static double code(double x, double y, double z, double t) {
	return 1.0 - ((x / (y - z)) / (y - t));
}
def code(x, y, z, t):
	return 1.0 - (x / ((y - z) * (y - t)))
[z, t] = sort([z, t])

def code(x, y, z, t):
	return 1.0 - ((x / (y - z)) / (y - t))
function code(x, y, z, t)
	return Float64(1.0 - Float64(x / Float64(Float64(y - z) * Float64(y - t))))
end
z, t = sort([z, t])

function code(x, y, z, t)
	return Float64(1.0 - Float64(Float64(x / Float64(y - z)) / Float64(y - t)))
end
function tmp = code(x, y, z, t)
	tmp = 1.0 - (x / ((y - z) * (y - t)));
end
z, t = num2cell(sort([z, t])){:}

function tmp = code(x, y, z, t)
	tmp = 1.0 - ((x / (y - z)) / (y - t));
end
code[x_, y_, z_, t_] := N[(1.0 - N[(x / N[(N[(y - z), $MachinePrecision] * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
NOTE: z and t should be sorted in increasing order before calling this function.

code[x_, y_, z_, t_] := N[(1.0 - N[(N[(x / N[(y - z), $MachinePrecision]), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)}
\begin{array}{l}
[z, t] = \mathsf{sort}([z, t])\\
\end{array}
1 - \frac{\frac{x}{y - z}}{y - t}

Local Percentage Accuracy?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 98.8%

    \[1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)} \]
  2. Simplified98.8%

    \[\leadsto \color{blue}{1 - \frac{\frac{x}{y - t}}{y - z}} \]
    Step-by-step derivation

    [Start]98.8

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

    associate-/l/ [<=]98.8

    \[ 1 - \color{blue}{\frac{\frac{x}{y - t}}{y - z}} \]
  3. Taylor expanded in x around 0 98.8%

    \[\leadsto 1 - \color{blue}{\frac{x}{\left(y - t\right) \cdot \left(y - z\right)}} \]
  4. Simplified99.5%

    \[\leadsto 1 - \color{blue}{\frac{\frac{x}{y - z}}{y - t}} \]
    Step-by-step derivation

    [Start]98.8

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

    associate-/l/ [<=]99.5

    \[ 1 - \color{blue}{\frac{\frac{x}{y - z}}{y - t}} \]
  5. Final simplification99.5%

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

Alternatives

Alternative 1
Accuracy85.5%
Cost841
\[\begin{array}{l} \mathbf{if}\;y \leq -2.1 \cdot 10^{-50} \lor \neg \left(y \leq 2.9 \cdot 10^{-93}\right):\\ \;\;\;\;1 - \frac{x}{y \cdot \left(y - z\right)}\\ \mathbf{else}:\\ \;\;\;\;1 - x \cdot \frac{\frac{1}{t}}{z}\\ \end{array} \]
Alternative 2
Accuracy81.4%
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -8.8 \cdot 10^{-41}:\\ \;\;\;\;1 - \frac{x}{y \cdot y}\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-181}:\\ \;\;\;\;1 - x \cdot \frac{\frac{1}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 3
Accuracy85.5%
Cost840
\[\begin{array}{l} \mathbf{if}\;y \leq -1.15 \cdot 10^{-50}:\\ \;\;\;\;1 - \frac{x}{y \cdot \left(y - z\right)}\\ \mathbf{elif}\;y \leq 6.5 \cdot 10^{-101}:\\ \;\;\;\;1 - x \cdot \frac{\frac{1}{t}}{z}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{y \cdot \left(y - t\right)}\\ \end{array} \]
Alternative 4
Accuracy90.0%
Cost840
\[\begin{array}{l} \mathbf{if}\;z \leq -7.2 \cdot 10^{-75}:\\ \;\;\;\;1 + \frac{\frac{x}{y - t}}{z}\\ \mathbf{elif}\;z \leq 1.22 \cdot 10^{-307}:\\ \;\;\;\;1 - \frac{\frac{x}{y}}{y - t}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{t \cdot \left(z - y\right)}\\ \end{array} \]
Alternative 5
Accuracy82.6%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -1.46 \cdot 10^{-96}:\\ \;\;\;\;1\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-181}:\\ \;\;\;\;1 - \frac{x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 6
Accuracy81.5%
Cost712
\[\begin{array}{l} \mathbf{if}\;y \leq -2.9 \cdot 10^{-42}:\\ \;\;\;\;1 - \frac{x}{y \cdot y}\\ \mathbf{elif}\;y \leq 1.85 \cdot 10^{-181}:\\ \;\;\;\;1 - \frac{x}{z \cdot t}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 7
Accuracy89.1%
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq 450000000000:\\ \;\;\;\;1 - \frac{x}{y \cdot \left(y - z\right)}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{t \cdot \left(z - y\right)}\\ \end{array} \]
Alternative 8
Accuracy88.7%
Cost708
\[\begin{array}{l} \mathbf{if}\;t \leq 500000000000:\\ \;\;\;\;1 - \frac{\frac{x}{y}}{y - z}\\ \mathbf{else}:\\ \;\;\;\;1 - \frac{x}{t \cdot \left(z - y\right)}\\ \end{array} \]
Alternative 9
Accuracy99.1%
Cost704
\[1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)} \]
Alternative 10
Accuracy75.2%
Cost580
\[\begin{array}{l} \mathbf{if}\;t \leq 2.4 \cdot 10^{-91}:\\ \;\;\;\;1 + \frac{\frac{x}{z}}{y}\\ \mathbf{else}:\\ \;\;\;\;1\\ \end{array} \]
Alternative 11
Accuracy75.1%
Cost64
\[1 \]

Error

Reproduce?

herbie shell --seed 2023160 
(FPCore (x y z t)
  :name "Data.Random.Distribution.Triangular:triangularCDF from random-fu-0.2.6.2, A"
  :precision binary64
  (- 1.0 (/ x (* (- y z) (- y t)))))