
(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)));
}
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)));
}
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
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]
\begin{array}{l}
\\
1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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)));
}
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)));
}
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
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]
\begin{array}{l}
\\
1 - \frac{x}{\left(y - z\right) \cdot \left(y - t\right)}
\end{array}
(FPCore (x y z t) :precision binary64 (+ 1.0 (/ x (* (- y z) (- t y)))))
double code(double x, double y, double z, double t) {
return 1.0 + (x / ((y - z) * (t - y)));
}
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) * (t - y)))
end function
public static double code(double x, double y, double z, double t) {
return 1.0 + (x / ((y - z) * (t - y)));
}
def code(x, y, z, t): return 1.0 + (x / ((y - z) * (t - y)))
function code(x, y, z, t) return Float64(1.0 + Float64(x / Float64(Float64(y - z) * Float64(t - y)))) end
function tmp = code(x, y, z, t) tmp = 1.0 + (x / ((y - z) * (t - y))); end
code[x_, y_, z_, t_] := N[(1.0 + N[(x / N[(N[(y - z), $MachinePrecision] * N[(t - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 + \frac{x}{\left(y - z\right) \cdot \left(t - y\right)}
\end{array}
Initial program 99.6%
Final simplification99.6%
(FPCore (x y z t)
:precision binary64
(if (<= y -1.15e-15)
1.0
(if (<= y -9.4e-88)
(+ 1.0 (/ x (* y t)))
(if (<= y 3e-160) (+ 1.0 (* (/ x z) (/ -1.0 t))) 1.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.15e-15) {
tmp = 1.0;
} else if (y <= -9.4e-88) {
tmp = 1.0 + (x / (y * t));
} else if (y <= 3e-160) {
tmp = 1.0 + ((x / z) * (-1.0 / t));
} else {
tmp = 1.0;
}
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
real(8) :: tmp
if (y <= (-1.15d-15)) then
tmp = 1.0d0
else if (y <= (-9.4d-88)) then
tmp = 1.0d0 + (x / (y * t))
else if (y <= 3d-160) then
tmp = 1.0d0 + ((x / z) * ((-1.0d0) / t))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -1.15e-15) {
tmp = 1.0;
} else if (y <= -9.4e-88) {
tmp = 1.0 + (x / (y * t));
} else if (y <= 3e-160) {
tmp = 1.0 + ((x / z) * (-1.0 / t));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -1.15e-15: tmp = 1.0 elif y <= -9.4e-88: tmp = 1.0 + (x / (y * t)) elif y <= 3e-160: tmp = 1.0 + ((x / z) * (-1.0 / t)) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -1.15e-15) tmp = 1.0; elseif (y <= -9.4e-88) tmp = Float64(1.0 + Float64(x / Float64(y * t))); elseif (y <= 3e-160) tmp = Float64(1.0 + Float64(Float64(x / z) * Float64(-1.0 / t))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -1.15e-15) tmp = 1.0; elseif (y <= -9.4e-88) tmp = 1.0 + (x / (y * t)); elseif (y <= 3e-160) tmp = 1.0 + ((x / z) * (-1.0 / t)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -1.15e-15], 1.0, If[LessEqual[y, -9.4e-88], N[(1.0 + N[(x / N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3e-160], N[(1.0 + N[(N[(x / z), $MachinePrecision] * N[(-1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.15 \cdot 10^{-15}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -9.4 \cdot 10^{-88}:\\
\;\;\;\;1 + \frac{x}{y \cdot t}\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-160}:\\
\;\;\;\;1 + \frac{x}{z} \cdot \frac{-1}{t}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.14999999999999995e-15 or 2.99999999999999997e-160 < y Initial program 100.0%
Taylor expanded in z around inf 66.8%
mul-1-neg66.8%
associate-/r*66.7%
distribute-neg-frac66.7%
Simplified66.7%
Taylor expanded in x around 0 84.9%
if -1.14999999999999995e-15 < y < -9.4e-88Initial program 100.0%
Taylor expanded in t around inf 82.8%
associate-*r/82.8%
neg-mul-182.8%
Simplified82.8%
Taylor expanded in y around inf 72.2%
+-commutative72.2%
*-commutative72.2%
Simplified72.2%
if -9.4e-88 < y < 2.99999999999999997e-160Initial program 98.8%
Taylor expanded in y around 0 87.7%
*-un-lft-identity87.7%
times-frac87.8%
Applied egg-rr87.8%
Final simplification85.0%
(FPCore (x y z t)
:precision binary64
(if (<= y -6e-13)
1.0
(if (<= y -8e-87)
(+ 1.0 (/ x (* y t)))
(if (<= y 2.8e-160) (- 1.0 (/ x (* z t))) 1.0))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6e-13) {
tmp = 1.0;
} else if (y <= -8e-87) {
tmp = 1.0 + (x / (y * t));
} else if (y <= 2.8e-160) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0;
}
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
real(8) :: tmp
if (y <= (-6d-13)) then
tmp = 1.0d0
else if (y <= (-8d-87)) then
tmp = 1.0d0 + (x / (y * t))
else if (y <= 2.8d-160) then
tmp = 1.0d0 - (x / (z * t))
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -6e-13) {
tmp = 1.0;
} else if (y <= -8e-87) {
tmp = 1.0 + (x / (y * t));
} else if (y <= 2.8e-160) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -6e-13: tmp = 1.0 elif y <= -8e-87: tmp = 1.0 + (x / (y * t)) elif y <= 2.8e-160: tmp = 1.0 - (x / (z * t)) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -6e-13) tmp = 1.0; elseif (y <= -8e-87) tmp = Float64(1.0 + Float64(x / Float64(y * t))); elseif (y <= 2.8e-160) tmp = Float64(1.0 - Float64(x / Float64(z * t))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -6e-13) tmp = 1.0; elseif (y <= -8e-87) tmp = 1.0 + (x / (y * t)); elseif (y <= 2.8e-160) tmp = 1.0 - (x / (z * t)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -6e-13], 1.0, If[LessEqual[y, -8e-87], N[(1.0 + N[(x / N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.8e-160], N[(1.0 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{-13}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -8 \cdot 10^{-87}:\\
\;\;\;\;1 + \frac{x}{y \cdot t}\\
\mathbf{elif}\;y \leq 2.8 \cdot 10^{-160}:\\
\;\;\;\;1 - \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.99999999999999968e-13 or 2.80000000000000016e-160 < y Initial program 100.0%
Taylor expanded in z around inf 66.8%
mul-1-neg66.8%
associate-/r*66.7%
distribute-neg-frac66.7%
Simplified66.7%
Taylor expanded in x around 0 84.9%
if -5.99999999999999968e-13 < y < -8.00000000000000014e-87Initial program 100.0%
Taylor expanded in t around inf 82.8%
associate-*r/82.8%
neg-mul-182.8%
Simplified82.8%
Taylor expanded in y around inf 72.2%
+-commutative72.2%
*-commutative72.2%
Simplified72.2%
if -8.00000000000000014e-87 < y < 2.80000000000000016e-160Initial program 98.8%
Taylor expanded in y around 0 87.7%
Final simplification85.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.9e-141) (not (<= y 3.3e-104))) (- 1.0 (/ x (* y (- y t)))) (+ 1.0 (* (/ x z) (/ -1.0 t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.9e-141) || !(y <= 3.3e-104)) {
tmp = 1.0 - (x / (y * (y - t)));
} else {
tmp = 1.0 + ((x / z) * (-1.0 / 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
real(8) :: tmp
if ((y <= (-4.9d-141)) .or. (.not. (y <= 3.3d-104))) then
tmp = 1.0d0 - (x / (y * (y - t)))
else
tmp = 1.0d0 + ((x / z) * ((-1.0d0) / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.9e-141) || !(y <= 3.3e-104)) {
tmp = 1.0 - (x / (y * (y - t)));
} else {
tmp = 1.0 + ((x / z) * (-1.0 / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.9e-141) or not (y <= 3.3e-104): tmp = 1.0 - (x / (y * (y - t))) else: tmp = 1.0 + ((x / z) * (-1.0 / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.9e-141) || !(y <= 3.3e-104)) tmp = Float64(1.0 - Float64(x / Float64(y * Float64(y - t)))); else tmp = Float64(1.0 + Float64(Float64(x / z) * Float64(-1.0 / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4.9e-141) || ~((y <= 3.3e-104))) tmp = 1.0 - (x / (y * (y - t))); else tmp = 1.0 + ((x / z) * (-1.0 / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.9e-141], N[Not[LessEqual[y, 3.3e-104]], $MachinePrecision]], N[(1.0 - N[(x / N[(y * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x / z), $MachinePrecision] * N[(-1.0 / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{-141} \lor \neg \left(y \leq 3.3 \cdot 10^{-104}\right):\\
\;\;\;\;1 - \frac{x}{y \cdot \left(y - t\right)}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{x}{z} \cdot \frac{-1}{t}\\
\end{array}
\end{array}
if y < -4.90000000000000006e-141 or 3.30000000000000002e-104 < y Initial program 100.0%
Taylor expanded in z around 0 89.0%
if -4.90000000000000006e-141 < y < 3.30000000000000002e-104Initial program 98.8%
Taylor expanded in y around 0 87.5%
*-un-lft-identity87.5%
times-frac87.5%
Applied egg-rr87.5%
Final simplification88.5%
(FPCore (x y z t) :precision binary64 (if (<= y -0.12) (+ 1.0 (/ (/ x y) (- z y))) (if (<= y 0.03) (+ 1.0 (/ x (* (- y z) t))) (- 1.0 (/ x (* y (- y t)))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -0.12) {
tmp = 1.0 + ((x / y) / (z - y));
} else if (y <= 0.03) {
tmp = 1.0 + (x / ((y - z) * t));
} else {
tmp = 1.0 - (x / (y * (y - 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
real(8) :: tmp
if (y <= (-0.12d0)) then
tmp = 1.0d0 + ((x / y) / (z - y))
else if (y <= 0.03d0) then
tmp = 1.0d0 + (x / ((y - z) * t))
else
tmp = 1.0d0 - (x / (y * (y - t)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -0.12) {
tmp = 1.0 + ((x / y) / (z - y));
} else if (y <= 0.03) {
tmp = 1.0 + (x / ((y - z) * t));
} else {
tmp = 1.0 - (x / (y * (y - t)));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -0.12: tmp = 1.0 + ((x / y) / (z - y)) elif y <= 0.03: tmp = 1.0 + (x / ((y - z) * t)) else: tmp = 1.0 - (x / (y * (y - t))) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -0.12) tmp = Float64(1.0 + Float64(Float64(x / y) / Float64(z - y))); elseif (y <= 0.03) tmp = Float64(1.0 + Float64(x / Float64(Float64(y - z) * t))); else tmp = Float64(1.0 - Float64(x / Float64(y * Float64(y - t)))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -0.12) tmp = 1.0 + ((x / y) / (z - y)); elseif (y <= 0.03) tmp = 1.0 + (x / ((y - z) * t)); else tmp = 1.0 - (x / (y * (y - t))); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -0.12], N[(1.0 + N[(N[(x / y), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.03], N[(1.0 + N[(x / N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(x / N[(y * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.12:\\
\;\;\;\;1 + \frac{\frac{x}{y}}{z - y}\\
\mathbf{elif}\;y \leq 0.03:\\
\;\;\;\;1 + \frac{x}{\left(y - z\right) \cdot t}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{y \cdot \left(y - t\right)}\\
\end{array}
\end{array}
if y < -0.12Initial program 99.9%
Taylor expanded in t around 0 93.8%
associate-/r*93.7%
Simplified93.7%
if -0.12 < y < 0.029999999999999999Initial program 99.2%
Taylor expanded in t around inf 87.8%
associate-*r/87.8%
neg-mul-187.8%
Simplified87.8%
if 0.029999999999999999 < y Initial program 100.0%
Taylor expanded in z around 0 96.9%
Final simplification91.4%
(FPCore (x y z t) :precision binary64 1.0)
double code(double x, double y, double z, double t) {
return 1.0;
}
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
end function
public static double code(double x, double y, double z, double t) {
return 1.0;
}
def code(x, y, z, t): return 1.0
function code(x, y, z, t) return 1.0 end
function tmp = code(x, y, z, t) tmp = 1.0; end
code[x_, y_, z_, t_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 99.6%
Taylor expanded in z around inf 76.0%
mul-1-neg76.0%
associate-/r*75.9%
distribute-neg-frac75.9%
Simplified75.9%
Taylor expanded in x around 0 76.0%
herbie shell --seed 2024108
(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)))))