
(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.1%
Final simplification99.1%
(FPCore (x y z t) :precision binary64 (if (<= y -9.8e-40) 1.0 (if (<= y 1.7e-105) (- 1.0 (/ x (* z t))) (+ 1.0 (/ (/ x y) (- t y))))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -9.8e-40) {
tmp = 1.0;
} else if (y <= 1.7e-105) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0 + ((x / y) / (t - y));
}
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 <= (-9.8d-40)) then
tmp = 1.0d0
else if (y <= 1.7d-105) then
tmp = 1.0d0 - (x / (z * t))
else
tmp = 1.0d0 + ((x / y) / (t - y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -9.8e-40) {
tmp = 1.0;
} else if (y <= 1.7e-105) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0 + ((x / y) / (t - y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -9.8e-40: tmp = 1.0 elif y <= 1.7e-105: tmp = 1.0 - (x / (z * t)) else: tmp = 1.0 + ((x / y) / (t - y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -9.8e-40) tmp = 1.0; elseif (y <= 1.7e-105) tmp = Float64(1.0 - Float64(x / Float64(z * t))); else tmp = Float64(1.0 + Float64(Float64(x / y) / Float64(t - y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -9.8e-40) tmp = 1.0; elseif (y <= 1.7e-105) tmp = 1.0 - (x / (z * t)); else tmp = 1.0 + ((x / y) / (t - y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -9.8e-40], 1.0, If[LessEqual[y, 1.7e-105], N[(1.0 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x / y), $MachinePrecision] / N[(t - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{-40}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-105}:\\
\;\;\;\;1 - \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{x}{y}}{t - y}\\
\end{array}
\end{array}
if y < -9.7999999999999995e-40Initial program 99.9%
Taylor expanded in x around 0 89.9%
if -9.7999999999999995e-40 < y < 1.69999999999999996e-105Initial program 97.4%
Taylor expanded in y around 0 79.0%
if 1.69999999999999996e-105 < y Initial program 100.0%
Taylor expanded in z around 0 89.4%
sub-neg89.4%
associate-/r*89.4%
distribute-neg-frac289.4%
neg-sub089.4%
sub-neg89.4%
+-commutative89.4%
associate--r+89.4%
neg-sub089.4%
remove-double-neg89.4%
Simplified89.4%
Final simplification85.9%
(FPCore (x y z t) :precision binary64 (if (<= y -4.6e-35) 1.0 (if (<= y 2.7e-46) (- 1.0 (/ x (* z t))) 1.0)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -4.6e-35) {
tmp = 1.0;
} else if (y <= 2.7e-46) {
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 <= (-4.6d-35)) then
tmp = 1.0d0
else if (y <= 2.7d-46) 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 <= -4.6e-35) {
tmp = 1.0;
} else if (y <= 2.7e-46) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -4.6e-35: tmp = 1.0 elif y <= 2.7e-46: tmp = 1.0 - (x / (z * t)) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -4.6e-35) tmp = 1.0; elseif (y <= 2.7e-46) 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 <= -4.6e-35) tmp = 1.0; elseif (y <= 2.7e-46) tmp = 1.0 - (x / (z * t)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -4.6e-35], 1.0, If[LessEqual[y, 2.7e-46], N[(1.0 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{-35}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.7 \cdot 10^{-46}:\\
\;\;\;\;1 - \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.5999999999999998e-35 or 2.7e-46 < y Initial program 100.0%
Taylor expanded in x around 0 92.6%
if -4.5999999999999998e-35 < y < 2.7e-46Initial program 97.7%
Taylor expanded in y around 0 74.9%
Final simplification85.7%
(FPCore (x y z t) :precision binary64 (if (<= z -9.4e-126) (+ 1.0 (/ (/ x z) (- y t))) (+ 1.0 (/ (/ x y) (- t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.4e-126) {
tmp = 1.0 + ((x / z) / (y - t));
} else {
tmp = 1.0 + ((x / y) / (t - y));
}
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 (z <= (-9.4d-126)) then
tmp = 1.0d0 + ((x / z) / (y - t))
else
tmp = 1.0d0 + ((x / y) / (t - y))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.4e-126) {
tmp = 1.0 + ((x / z) / (y - t));
} else {
tmp = 1.0 + ((x / y) / (t - y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -9.4e-126: tmp = 1.0 + ((x / z) / (y - t)) else: tmp = 1.0 + ((x / y) / (t - y)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -9.4e-126) tmp = Float64(1.0 + Float64(Float64(x / z) / Float64(y - t))); else tmp = Float64(1.0 + Float64(Float64(x / y) / Float64(t - y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -9.4e-126) tmp = 1.0 + ((x / z) / (y - t)); else tmp = 1.0 + ((x / y) / (t - y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -9.4e-126], N[(1.0 + N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x / y), $MachinePrecision] / N[(t - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.4 \cdot 10^{-126}:\\
\;\;\;\;1 + \frac{\frac{x}{z}}{y - t}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{x}{y}}{t - y}\\
\end{array}
\end{array}
if z < -9.40000000000000035e-126Initial program 99.9%
Taylor expanded in z around inf 90.9%
associate-/r*90.9%
Simplified90.9%
if -9.40000000000000035e-126 < z Initial program 98.6%
Taylor expanded in z around 0 75.8%
sub-neg75.8%
associate-/r*75.4%
distribute-neg-frac275.4%
neg-sub075.4%
sub-neg75.4%
+-commutative75.4%
associate--r+75.4%
neg-sub075.4%
remove-double-neg75.4%
Simplified75.4%
(FPCore (x y z t) :precision binary64 (if (<= t 1.9e-131) (+ 1.0 (/ x (* y z))) 1.0))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= 1.9e-131) {
tmp = 1.0 + (x / (y * z));
} 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 (t <= 1.9d-131) then
tmp = 1.0d0 + (x / (y * z))
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 (t <= 1.9e-131) {
tmp = 1.0 + (x / (y * z));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= 1.9e-131: tmp = 1.0 + (x / (y * z)) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= 1.9e-131) tmp = Float64(1.0 + Float64(x / Float64(y * z))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= 1.9e-131) tmp = 1.0 + (x / (y * z)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, 1.9e-131], N[(1.0 + N[(x / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 1.9 \cdot 10^{-131}:\\
\;\;\;\;1 + \frac{x}{y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if t < 1.89999999999999997e-131Initial program 98.6%
Taylor expanded in t around 0 74.6%
Taylor expanded in z around inf 62.1%
*-commutative62.1%
Simplified62.1%
if 1.89999999999999997e-131 < t Initial program 100.0%
Taylor expanded in x around 0 82.7%
Final simplification68.8%
(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.1%
Taylor expanded in x around 0 76.6%
herbie shell --seed 2024165
(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)))))