| Alternative 1 | |
|---|---|
| Error | 1.6 |
| Cost | 1864 |
(FPCore (x y z t) :precision binary64 (/ x (* (- y z) (- t z))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ x (* (- y z) (- t z)))))
(if (<= t_1 -2e+140)
(* (/ 1.0 (/ (- z y) x)) (/ 1.0 (- z t)))
(if (<= t_1 2e-305)
(/ (/ x (- z t)) (- z y))
(/ x (- (* (- y z) t) (* z (- y z))))))))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 = x / ((y - z) * (t - z));
double tmp;
if (t_1 <= -2e+140) {
tmp = (1.0 / ((z - y) / x)) * (1.0 / (z - t));
} else if (t_1 <= 2e-305) {
tmp = (x / (z - t)) / (z - y);
} else {
tmp = x / (((y - z) * t) - (z * (y - z)));
}
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 = x / ((y - z) * (t - z))
if (t_1 <= (-2d+140)) then
tmp = (1.0d0 / ((z - y) / x)) * (1.0d0 / (z - t))
else if (t_1 <= 2d-305) then
tmp = (x / (z - t)) / (z - y)
else
tmp = x / (((y - z) * t) - (z * (y - z)))
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 = x / ((y - z) * (t - z));
double tmp;
if (t_1 <= -2e+140) {
tmp = (1.0 / ((z - y) / x)) * (1.0 / (z - t));
} else if (t_1 <= 2e-305) {
tmp = (x / (z - t)) / (z - y);
} else {
tmp = x / (((y - z) * t) - (z * (y - z)));
}
return tmp;
}
def code(x, y, z, t): return x / ((y - z) * (t - z))
def code(x, y, z, t): t_1 = x / ((y - z) * (t - z)) tmp = 0 if t_1 <= -2e+140: tmp = (1.0 / ((z - y) / x)) * (1.0 / (z - t)) elif t_1 <= 2e-305: tmp = (x / (z - t)) / (z - y) else: tmp = x / (((y - z) * t) - (z * (y - z))) 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(x / Float64(Float64(y - z) * Float64(t - z))) tmp = 0.0 if (t_1 <= -2e+140) tmp = Float64(Float64(1.0 / Float64(Float64(z - y) / x)) * Float64(1.0 / Float64(z - t))); elseif (t_1 <= 2e-305) tmp = Float64(Float64(x / Float64(z - t)) / Float64(z - y)); else tmp = Float64(x / Float64(Float64(Float64(y - z) * t) - Float64(z * Float64(y - z)))); 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 = x / ((y - z) * (t - z)); tmp = 0.0; if (t_1 <= -2e+140) tmp = (1.0 / ((z - y) / x)) * (1.0 / (z - t)); elseif (t_1 <= 2e-305) tmp = (x / (z - t)) / (z - y); else tmp = x / (((y - z) * t) - (z * (y - z))); 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[(x / N[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+140], N[(N[(1.0 / N[(N[(z - y), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e-305], N[(N[(x / N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - y), $MachinePrecision]), $MachinePrecision], N[(x / N[(N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision] - N[(z * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\begin{array}{l}
t_1 := \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+140}:\\
\;\;\;\;\frac{1}{\frac{z - y}{x}} \cdot \frac{1}{z - t}\\
\mathbf{elif}\;t_1 \leq 2 \cdot 10^{-305}:\\
\;\;\;\;\frac{\frac{x}{z - t}}{z - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\left(y - z\right) \cdot t - z \cdot \left(y - z\right)}\\
\end{array}
Results
| Original | 8.0 |
|---|---|
| Target | 8.8 |
| Herbie | 1.6 |
if (/.f64 x (*.f64 (-.f64 y z) (-.f64 t z))) < -2.00000000000000012e140Initial program 7.5
Simplified6.6
[Start]7.5 | \[ \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\] |
|---|---|
sub-neg [=>]7.5 | \[ \frac{x}{\color{blue}{\left(y + \left(-z\right)\right)} \cdot \left(t - z\right)}
\] |
+-commutative [=>]7.5 | \[ \frac{x}{\color{blue}{\left(\left(-z\right) + y\right)} \cdot \left(t - z\right)}
\] |
neg-sub0 [=>]7.5 | \[ \frac{x}{\left(\color{blue}{\left(0 - z\right)} + y\right) \cdot \left(t - z\right)}
\] |
associate-+l- [=>]7.5 | \[ \frac{x}{\color{blue}{\left(0 - \left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
sub0-neg [=>]7.5 | \[ \frac{x}{\color{blue}{\left(-\left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
distribute-lft-neg-out [=>]7.5 | \[ \frac{x}{\color{blue}{-\left(z - y\right) \cdot \left(t - z\right)}}
\] |
distribute-rgt-neg-in [=>]7.5 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot \left(-\left(t - z\right)\right)}}
\] |
neg-sub0 [=>]7.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(0 - \left(t - z\right)\right)}}
\] |
associate-+l- [<=]7.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(\left(0 - t\right) + z\right)}}
\] |
neg-sub0 [<=]7.5 | \[ \frac{x}{\left(z - y\right) \cdot \left(\color{blue}{\left(-t\right)} + z\right)}
\] |
+-commutative [<=]7.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z + \left(-t\right)\right)}}
\] |
sub-neg [<=]7.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z - t\right)}}
\] |
associate-/l/ [<=]6.6 | \[ \color{blue}{\frac{\frac{x}{z - t}}{z - y}}
\] |
Applied egg-rr8.8
if -2.00000000000000012e140 < (/.f64 x (*.f64 (-.f64 y z) (-.f64 t z))) < 1.99999999999999999e-305Initial program 10.1
Simplified1.1
[Start]10.1 | \[ \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\] |
|---|---|
sub-neg [=>]10.1 | \[ \frac{x}{\color{blue}{\left(y + \left(-z\right)\right)} \cdot \left(t - z\right)}
\] |
+-commutative [=>]10.1 | \[ \frac{x}{\color{blue}{\left(\left(-z\right) + y\right)} \cdot \left(t - z\right)}
\] |
neg-sub0 [=>]10.1 | \[ \frac{x}{\left(\color{blue}{\left(0 - z\right)} + y\right) \cdot \left(t - z\right)}
\] |
associate-+l- [=>]10.1 | \[ \frac{x}{\color{blue}{\left(0 - \left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
sub0-neg [=>]10.1 | \[ \frac{x}{\color{blue}{\left(-\left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
distribute-lft-neg-out [=>]10.1 | \[ \frac{x}{\color{blue}{-\left(z - y\right) \cdot \left(t - z\right)}}
\] |
distribute-rgt-neg-in [=>]10.1 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot \left(-\left(t - z\right)\right)}}
\] |
neg-sub0 [=>]10.1 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(0 - \left(t - z\right)\right)}}
\] |
associate-+l- [<=]10.1 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(\left(0 - t\right) + z\right)}}
\] |
neg-sub0 [<=]10.1 | \[ \frac{x}{\left(z - y\right) \cdot \left(\color{blue}{\left(-t\right)} + z\right)}
\] |
+-commutative [<=]10.1 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z + \left(-t\right)\right)}}
\] |
sub-neg [<=]10.1 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z - t\right)}}
\] |
associate-/l/ [<=]1.1 | \[ \color{blue}{\frac{\frac{x}{z - t}}{z - y}}
\] |
if 1.99999999999999999e-305 < (/.f64 x (*.f64 (-.f64 y z) (-.f64 t z))) Initial program 1.5
Simplified1.5
[Start]1.5 | \[ \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\] |
|---|---|
sub-neg [=>]1.5 | \[ \frac{x}{\color{blue}{\left(y + \left(-z\right)\right)} \cdot \left(t - z\right)}
\] |
+-commutative [=>]1.5 | \[ \frac{x}{\color{blue}{\left(\left(-z\right) + y\right)} \cdot \left(t - z\right)}
\] |
neg-sub0 [=>]1.5 | \[ \frac{x}{\left(\color{blue}{\left(0 - z\right)} + y\right) \cdot \left(t - z\right)}
\] |
associate-+l- [=>]1.5 | \[ \frac{x}{\color{blue}{\left(0 - \left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
sub0-neg [=>]1.5 | \[ \frac{x}{\color{blue}{\left(-\left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
distribute-lft-neg-out [=>]1.5 | \[ \frac{x}{\color{blue}{-\left(z - y\right) \cdot \left(t - z\right)}}
\] |
distribute-rgt-neg-in [=>]1.5 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot \left(-\left(t - z\right)\right)}}
\] |
neg-sub0 [=>]1.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(0 - \left(t - z\right)\right)}}
\] |
associate-+l- [<=]1.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(\left(0 - t\right) + z\right)}}
\] |
neg-sub0 [<=]1.5 | \[ \frac{x}{\left(z - y\right) \cdot \left(\color{blue}{\left(-t\right)} + z\right)}
\] |
+-commutative [<=]1.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z + \left(-t\right)\right)}}
\] |
sub-neg [<=]1.5 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z - t\right)}}
\] |
Applied egg-rr1.5
Taylor expanded in x around 0 1.5
Simplified1.5
[Start]1.5 | \[ \frac{x}{-1 \cdot \left(\left(z - y\right) \cdot t\right) + \left(z - y\right) \cdot z}
\] |
|---|---|
+-commutative [=>]1.5 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot z + -1 \cdot \left(\left(z - y\right) \cdot t\right)}}
\] |
*-commutative [<=]1.5 | \[ \frac{x}{\color{blue}{z \cdot \left(z - y\right)} + -1 \cdot \left(\left(z - y\right) \cdot t\right)}
\] |
mul-1-neg [=>]1.5 | \[ \frac{x}{z \cdot \left(z - y\right) + \color{blue}{\left(-\left(z - y\right) \cdot t\right)}}
\] |
sub-neg [<=]1.5 | \[ \frac{x}{\color{blue}{z \cdot \left(z - y\right) - \left(z - y\right) \cdot t}}
\] |
Final simplification1.6
| Alternative 1 | |
|---|---|
| Error | 1.6 |
| Cost | 1864 |
| Alternative 2 | |
|---|---|
| Error | 4.6 |
| Cost | 1608 |
| Alternative 3 | |
|---|---|
| Error | 1.9 |
| Cost | 1608 |
| Alternative 4 | |
|---|---|
| Error | 27.8 |
| Cost | 1108 |
| Alternative 5 | |
|---|---|
| Error | 27.8 |
| Cost | 1108 |
| Alternative 6 | |
|---|---|
| Error | 27.8 |
| Cost | 1044 |
| Alternative 7 | |
|---|---|
| Error | 27.8 |
| Cost | 1044 |
| Alternative 8 | |
|---|---|
| Error | 20.1 |
| Cost | 976 |
| Alternative 9 | |
|---|---|
| Error | 18.2 |
| Cost | 976 |
| Alternative 10 | |
|---|---|
| Error | 12.2 |
| Cost | 972 |
| Alternative 11 | |
|---|---|
| Error | 12.2 |
| Cost | 972 |
| Alternative 12 | |
|---|---|
| Error | 14.3 |
| Cost | 844 |
| Alternative 13 | |
|---|---|
| Error | 11.9 |
| Cost | 844 |
| Alternative 14 | |
|---|---|
| Error | 12.2 |
| Cost | 844 |
| Alternative 15 | |
|---|---|
| Error | 15.8 |
| Cost | 712 |
| Alternative 16 | |
|---|---|
| Error | 15.7 |
| Cost | 712 |
| Alternative 17 | |
|---|---|
| Error | 36.0 |
| Cost | 585 |
| Alternative 18 | |
|---|---|
| Error | 25.8 |
| Cost | 585 |
| Alternative 19 | |
|---|---|
| Error | 24.8 |
| Cost | 585 |
| Alternative 20 | |
|---|---|
| Error | 25.1 |
| Cost | 585 |
| Alternative 21 | |
|---|---|
| Error | 22.5 |
| Cost | 585 |
| Alternative 22 | |
|---|---|
| Error | 50.4 |
| Cost | 320 |
herbie shell --seed 2023018
(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))))