
(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 8 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 98.5%
Final simplification98.5%
(FPCore (x y z t) :precision binary64 (if (or (<= z -4.7e-132) (not (<= z 5.5e-128))) (- 1.0 (/ (/ x z) (- t y))) (+ 1.0 (/ (/ x y) (- t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -4.7e-132) || !(z <= 5.5e-128)) {
tmp = 1.0 - ((x / z) / (t - y));
} 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 <= (-4.7d-132)) .or. (.not. (z <= 5.5d-128))) then
tmp = 1.0d0 - ((x / z) / (t - y))
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 <= -4.7e-132) || !(z <= 5.5e-128)) {
tmp = 1.0 - ((x / z) / (t - y));
} else {
tmp = 1.0 + ((x / y) / (t - y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -4.7e-132) or not (z <= 5.5e-128): tmp = 1.0 - ((x / z) / (t - y)) else: tmp = 1.0 + ((x / y) / (t - y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -4.7e-132) || !(z <= 5.5e-128)) tmp = Float64(1.0 - Float64(Float64(x / z) / Float64(t - y))); 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 <= -4.7e-132) || ~((z <= 5.5e-128))) tmp = 1.0 - ((x / z) / (t - y)); else tmp = 1.0 + ((x / y) / (t - y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -4.7e-132], N[Not[LessEqual[z, 5.5e-128]], $MachinePrecision]], N[(1.0 - N[(N[(x / z), $MachinePrecision] / N[(t - y), $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 -4.7 \cdot 10^{-132} \lor \neg \left(z \leq 5.5 \cdot 10^{-128}\right):\\
\;\;\;\;1 - \frac{\frac{x}{z}}{t - y}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{\frac{x}{y}}{t - y}\\
\end{array}
\end{array}
if z < -4.7000000000000002e-132 or 5.5000000000000004e-128 < z Initial program 99.2%
Taylor expanded in z around inf 96.4%
associate-/r*95.4%
Simplified95.4%
if -4.7000000000000002e-132 < z < 5.5000000000000004e-128Initial program 97.0%
Taylor expanded in z around 0 88.7%
sub-neg88.7%
associate-/r*87.2%
distribute-neg-frac287.2%
neg-sub087.2%
sub-neg87.2%
+-commutative87.2%
associate--r+87.2%
neg-sub087.2%
remove-double-neg87.2%
Simplified87.2%
Final simplification92.6%
(FPCore (x y z t) :precision binary64 (if (<= z -5.3e-20) 1.0 (if (<= z 6.2e-109) (+ 1.0 (/ (/ x y) (- t y))) (- 1.0 (/ x (* z t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.3e-20) {
tmp = 1.0;
} else if (z <= 6.2e-109) {
tmp = 1.0 + ((x / y) / (t - y));
} else {
tmp = 1.0 - (x / (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
real(8) :: tmp
if (z <= (-5.3d-20)) then
tmp = 1.0d0
else if (z <= 6.2d-109) then
tmp = 1.0d0 + ((x / y) / (t - y))
else
tmp = 1.0d0 - (x / (z * t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5.3e-20) {
tmp = 1.0;
} else if (z <= 6.2e-109) {
tmp = 1.0 + ((x / y) / (t - y));
} else {
tmp = 1.0 - (x / (z * t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -5.3e-20: tmp = 1.0 elif z <= 6.2e-109: tmp = 1.0 + ((x / y) / (t - y)) else: tmp = 1.0 - (x / (z * t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -5.3e-20) tmp = 1.0; elseif (z <= 6.2e-109) tmp = Float64(1.0 + Float64(Float64(x / y) / Float64(t - y))); else tmp = Float64(1.0 - Float64(x / Float64(z * t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -5.3e-20) tmp = 1.0; elseif (z <= 6.2e-109) tmp = 1.0 + ((x / y) / (t - y)); else tmp = 1.0 - (x / (z * t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -5.3e-20], 1.0, If[LessEqual[z, 6.2e-109], N[(1.0 + N[(N[(x / y), $MachinePrecision] / N[(t - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.3 \cdot 10^{-20}:\\
\;\;\;\;1\\
\mathbf{elif}\;z \leq 6.2 \cdot 10^{-109}:\\
\;\;\;\;1 + \frac{\frac{x}{y}}{t - y}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{x}{z \cdot t}\\
\end{array}
\end{array}
if z < -5.3000000000000002e-20Initial program 100.0%
Taylor expanded in x around 0 88.5%
if -5.3000000000000002e-20 < z < 6.1999999999999999e-109Initial program 96.7%
Taylor expanded in z around 0 82.5%
sub-neg82.5%
associate-/r*81.3%
distribute-neg-frac281.3%
neg-sub081.3%
sub-neg81.3%
+-commutative81.3%
associate--r+81.3%
neg-sub081.3%
remove-double-neg81.3%
Simplified81.3%
if 6.1999999999999999e-109 < z Initial program 99.6%
Taylor expanded in y around 0 70.9%
Final simplification79.6%
(FPCore (x y z t) :precision binary64 (if (<= y -7.5e-77) 1.0 (if (<= y 1.65e-80) (- 1.0 (/ x (* z t))) (- 1.0 (/ (/ x y) y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -7.5e-77) {
tmp = 1.0;
} else if (y <= 1.65e-80) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0 - ((x / y) / 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 <= (-7.5d-77)) then
tmp = 1.0d0
else if (y <= 1.65d-80) then
tmp = 1.0d0 - (x / (z * t))
else
tmp = 1.0d0 - ((x / y) / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -7.5e-77) {
tmp = 1.0;
} else if (y <= 1.65e-80) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0 - ((x / y) / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -7.5e-77: tmp = 1.0 elif y <= 1.65e-80: tmp = 1.0 - (x / (z * t)) else: tmp = 1.0 - ((x / y) / y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -7.5e-77) tmp = 1.0; elseif (y <= 1.65e-80) tmp = Float64(1.0 - Float64(x / Float64(z * t))); else tmp = Float64(1.0 - Float64(Float64(x / y) / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -7.5e-77) tmp = 1.0; elseif (y <= 1.65e-80) tmp = 1.0 - (x / (z * t)); else tmp = 1.0 - ((x / y) / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -7.5e-77], 1.0, If[LessEqual[y, 1.65e-80], N[(1.0 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[(N[(x / y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-77}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.65 \cdot 10^{-80}:\\
\;\;\;\;1 - \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;1 - \frac{\frac{x}{y}}{y}\\
\end{array}
\end{array}
if y < -7.5000000000000006e-77Initial program 99.9%
Taylor expanded in x around 0 89.6%
if -7.5000000000000006e-77 < y < 1.65e-80Initial program 96.3%
Taylor expanded in y around 0 70.5%
if 1.65e-80 < y Initial program 100.0%
Taylor expanded in z around 0 93.6%
sub-neg93.6%
associate-/r*92.2%
distribute-neg-frac292.2%
neg-sub092.2%
sub-neg92.2%
+-commutative92.2%
associate--r+92.2%
neg-sub092.2%
remove-double-neg92.2%
Simplified92.2%
Taylor expanded in t around 0 87.9%
neg-mul-187.9%
Simplified87.9%
Final simplification81.3%
(FPCore (x y z t) :precision binary64 (if (<= y -3e-79) 1.0 (if (<= y 2.45e-45) (- 1.0 (/ x (* z t))) 1.0)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3e-79) {
tmp = 1.0;
} else if (y <= 2.45e-45) {
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 <= (-3d-79)) then
tmp = 1.0d0
else if (y <= 2.45d-45) 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 <= -3e-79) {
tmp = 1.0;
} else if (y <= 2.45e-45) {
tmp = 1.0 - (x / (z * t));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3e-79: tmp = 1.0 elif y <= 2.45e-45: tmp = 1.0 - (x / (z * t)) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3e-79) tmp = 1.0; elseif (y <= 2.45e-45) 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 <= -3e-79) tmp = 1.0; elseif (y <= 2.45e-45) tmp = 1.0 - (x / (z * t)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3e-79], 1.0, If[LessEqual[y, 2.45e-45], N[(1.0 - N[(x / N[(z * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{-79}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{-45}:\\
\;\;\;\;1 - \frac{x}{z \cdot t}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3e-79 or 2.4499999999999999e-45 < y Initial program 99.9%
Taylor expanded in x around 0 89.0%
if -3e-79 < y < 2.4499999999999999e-45Initial program 96.5%
Taylor expanded in y around 0 69.2%
Final simplification80.5%
(FPCore (x y z t) :precision binary64 (if (<= t -3e-221) 1.0 (if (<= t 1.65e-159) (+ 1.0 (/ x (* y z))) 1.0)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -3e-221) {
tmp = 1.0;
} else if (t <= 1.65e-159) {
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 <= (-3d-221)) then
tmp = 1.0d0
else if (t <= 1.65d-159) 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 <= -3e-221) {
tmp = 1.0;
} else if (t <= 1.65e-159) {
tmp = 1.0 + (x / (y * z));
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -3e-221: tmp = 1.0 elif t <= 1.65e-159: tmp = 1.0 + (x / (y * z)) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -3e-221) tmp = 1.0; elseif (t <= 1.65e-159) 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 <= -3e-221) tmp = 1.0; elseif (t <= 1.65e-159) tmp = 1.0 + (x / (y * z)); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -3e-221], 1.0, If[LessEqual[t, 1.65e-159], N[(1.0 + N[(x / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -3 \cdot 10^{-221}:\\
\;\;\;\;1\\
\mathbf{elif}\;t \leq 1.65 \cdot 10^{-159}:\\
\;\;\;\;1 + \frac{x}{y \cdot z}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if t < -3.0000000000000002e-221 or 1.6500000000000001e-159 < t Initial program 99.9%
Taylor expanded in x around 0 77.2%
if -3.0000000000000002e-221 < t < 1.6500000000000001e-159Initial program 93.5%
Taylor expanded in z around inf 72.4%
associate-/r*74.4%
Simplified74.4%
Taylor expanded in y around inf 70.7%
(FPCore (x y z t) :precision binary64 (if (<= x -5.5e+168) (/ x (* z (- t))) 1.0))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -5.5e+168) {
tmp = 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 (x <= (-5.5d+168)) then
tmp = 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 (x <= -5.5e+168) {
tmp = x / (z * -t);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -5.5e+168: tmp = x / (z * -t) else: tmp = 1.0 return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -5.5e+168) tmp = Float64(x / Float64(z * Float64(-t))); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -5.5e+168) tmp = x / (z * -t); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -5.5e+168], N[(x / N[(z * (-t)), $MachinePrecision]), $MachinePrecision], 1.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+168}:\\
\;\;\;\;\frac{x}{z \cdot \left(-t\right)}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -5.5000000000000001e168Initial program 99.8%
Taylor expanded in x around inf 73.6%
mul-1-neg73.6%
*-commutative73.6%
distribute-neg-frac273.6%
distribute-rgt-neg-out73.6%
neg-sub073.6%
sub-neg73.6%
+-commutative73.6%
associate--r+73.6%
neg-sub073.6%
remove-double-neg73.6%
Simplified73.6%
Taylor expanded in y around 0 42.0%
associate-*r/42.0%
neg-mul-142.0%
Simplified42.0%
if -5.5000000000000001e168 < x Initial program 98.3%
Taylor expanded in x around 0 76.3%
Final simplification72.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 98.5%
Taylor expanded in x around 0 70.7%
herbie shell --seed 2024145
(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)))))