| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 1609 |
(FPCore (x y z t) :precision binary64 (/ x (* (- y z) (- t z))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- y z) (- t z))) (t_2 (/ x (- z t))))
(if (<= t_1 -4e+139)
(* t_2 (/ 1.0 (- z y)))
(if (<= t_1 40000000000000.0)
(/ 1.0 (/ (* (- z t) (- z y)) x))
(/ t_2 (- z y))))))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 = (y - z) * (t - z);
double t_2 = x / (z - t);
double tmp;
if (t_1 <= -4e+139) {
tmp = t_2 * (1.0 / (z - y));
} else if (t_1 <= 40000000000000.0) {
tmp = 1.0 / (((z - t) * (z - y)) / x);
} else {
tmp = t_2 / (z - 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
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) :: t_2
real(8) :: tmp
t_1 = (y - z) * (t - z)
t_2 = x / (z - t)
if (t_1 <= (-4d+139)) then
tmp = t_2 * (1.0d0 / (z - y))
else if (t_1 <= 40000000000000.0d0) then
tmp = 1.0d0 / (((z - t) * (z - y)) / x)
else
tmp = t_2 / (z - y)
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 = (y - z) * (t - z);
double t_2 = x / (z - t);
double tmp;
if (t_1 <= -4e+139) {
tmp = t_2 * (1.0 / (z - y));
} else if (t_1 <= 40000000000000.0) {
tmp = 1.0 / (((z - t) * (z - y)) / x);
} else {
tmp = t_2 / (z - y);
}
return tmp;
}
def code(x, y, z, t): return x / ((y - z) * (t - z))
def code(x, y, z, t): t_1 = (y - z) * (t - z) t_2 = x / (z - t) tmp = 0 if t_1 <= -4e+139: tmp = t_2 * (1.0 / (z - y)) elif t_1 <= 40000000000000.0: tmp = 1.0 / (((z - t) * (z - y)) / x) else: tmp = t_2 / (z - y) 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(Float64(y - z) * Float64(t - z)) t_2 = Float64(x / Float64(z - t)) tmp = 0.0 if (t_1 <= -4e+139) tmp = Float64(t_2 * Float64(1.0 / Float64(z - y))); elseif (t_1 <= 40000000000000.0) tmp = Float64(1.0 / Float64(Float64(Float64(z - t) * Float64(z - y)) / x)); else tmp = Float64(t_2 / Float64(z - y)); 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 = (y - z) * (t - z); t_2 = x / (z - t); tmp = 0.0; if (t_1 <= -4e+139) tmp = t_2 * (1.0 / (z - y)); elseif (t_1 <= 40000000000000.0) tmp = 1.0 / (((z - t) * (z - y)) / x); else tmp = t_2 / (z - y); 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[(N[(y - z), $MachinePrecision] * N[(t - z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x / N[(z - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -4e+139], N[(t$95$2 * N[(1.0 / N[(z - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 40000000000000.0], N[(1.0 / N[(N[(N[(z - t), $MachinePrecision] * N[(z - y), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision], N[(t$95$2 / N[(z - y), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\begin{array}{l}
t_1 := \left(y - z\right) \cdot \left(t - z\right)\\
t_2 := \frac{x}{z - t}\\
\mathbf{if}\;t_1 \leq -4 \cdot 10^{+139}:\\
\;\;\;\;t_2 \cdot \frac{1}{z - y}\\
\mathbf{elif}\;t_1 \leq 40000000000000:\\
\;\;\;\;\frac{1}{\frac{\left(z - t\right) \cdot \left(z - y\right)}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_2}{z - y}\\
\end{array}
Results
| Original | 7.2 |
|---|---|
| Target | 7.8 |
| Herbie | 1.6 |
if (*.f64 (-.f64 y z) (-.f64 t z)) < -4.00000000000000013e139Initial program 10.7
Simplified0.9
[Start]10.7 | \[ \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\] |
|---|---|
sub-neg [=>]10.7 | \[ \frac{x}{\color{blue}{\left(y + \left(-z\right)\right)} \cdot \left(t - z\right)}
\] |
+-commutative [=>]10.7 | \[ \frac{x}{\color{blue}{\left(\left(-z\right) + y\right)} \cdot \left(t - z\right)}
\] |
neg-sub0 [=>]10.7 | \[ \frac{x}{\left(\color{blue}{\left(0 - z\right)} + y\right) \cdot \left(t - z\right)}
\] |
associate-+l- [=>]10.7 | \[ \frac{x}{\color{blue}{\left(0 - \left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
sub0-neg [=>]10.7 | \[ \frac{x}{\color{blue}{\left(-\left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
distribute-lft-neg-out [=>]10.7 | \[ \frac{x}{\color{blue}{-\left(z - y\right) \cdot \left(t - z\right)}}
\] |
distribute-rgt-neg-in [=>]10.7 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot \left(-\left(t - z\right)\right)}}
\] |
neg-sub0 [=>]10.7 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(0 - \left(t - z\right)\right)}}
\] |
associate-+l- [<=]10.7 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(\left(0 - t\right) + z\right)}}
\] |
neg-sub0 [<=]10.7 | \[ \frac{x}{\left(z - y\right) \cdot \left(\color{blue}{\left(-t\right)} + z\right)}
\] |
+-commutative [<=]10.7 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z + \left(-t\right)\right)}}
\] |
sub-neg [<=]10.7 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z - t\right)}}
\] |
associate-/l/ [<=]0.9 | \[ \color{blue}{\frac{\frac{x}{z - t}}{z - y}}
\] |
Applied egg-rr1.0
if -4.00000000000000013e139 < (*.f64 (-.f64 y z) (-.f64 t z)) < 4e13Initial program 2.8
Simplified5.2
[Start]2.8 | \[ \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\] |
|---|---|
sub-neg [=>]2.8 | \[ \frac{x}{\color{blue}{\left(y + \left(-z\right)\right)} \cdot \left(t - z\right)}
\] |
+-commutative [=>]2.8 | \[ \frac{x}{\color{blue}{\left(\left(-z\right) + y\right)} \cdot \left(t - z\right)}
\] |
neg-sub0 [=>]2.8 | \[ \frac{x}{\left(\color{blue}{\left(0 - z\right)} + y\right) \cdot \left(t - z\right)}
\] |
associate-+l- [=>]2.8 | \[ \frac{x}{\color{blue}{\left(0 - \left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
sub0-neg [=>]2.8 | \[ \frac{x}{\color{blue}{\left(-\left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
distribute-lft-neg-out [=>]2.8 | \[ \frac{x}{\color{blue}{-\left(z - y\right) \cdot \left(t - z\right)}}
\] |
distribute-rgt-neg-in [=>]2.8 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot \left(-\left(t - z\right)\right)}}
\] |
neg-sub0 [=>]2.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(0 - \left(t - z\right)\right)}}
\] |
associate-+l- [<=]2.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(\left(0 - t\right) + z\right)}}
\] |
neg-sub0 [<=]2.8 | \[ \frac{x}{\left(z - y\right) \cdot \left(\color{blue}{\left(-t\right)} + z\right)}
\] |
+-commutative [<=]2.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z + \left(-t\right)\right)}}
\] |
sub-neg [<=]2.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z - t\right)}}
\] |
associate-/l/ [<=]5.2 | \[ \color{blue}{\frac{\frac{x}{z - t}}{z - y}}
\] |
Applied egg-rr5.3
Applied egg-rr3.1
if 4e13 < (*.f64 (-.f64 y z) (-.f64 t z)) Initial program 7.8
Simplified1.2
[Start]7.8 | \[ \frac{x}{\left(y - z\right) \cdot \left(t - z\right)}
\] |
|---|---|
sub-neg [=>]7.8 | \[ \frac{x}{\color{blue}{\left(y + \left(-z\right)\right)} \cdot \left(t - z\right)}
\] |
+-commutative [=>]7.8 | \[ \frac{x}{\color{blue}{\left(\left(-z\right) + y\right)} \cdot \left(t - z\right)}
\] |
neg-sub0 [=>]7.8 | \[ \frac{x}{\left(\color{blue}{\left(0 - z\right)} + y\right) \cdot \left(t - z\right)}
\] |
associate-+l- [=>]7.8 | \[ \frac{x}{\color{blue}{\left(0 - \left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
sub0-neg [=>]7.8 | \[ \frac{x}{\color{blue}{\left(-\left(z - y\right)\right)} \cdot \left(t - z\right)}
\] |
distribute-lft-neg-out [=>]7.8 | \[ \frac{x}{\color{blue}{-\left(z - y\right) \cdot \left(t - z\right)}}
\] |
distribute-rgt-neg-in [=>]7.8 | \[ \frac{x}{\color{blue}{\left(z - y\right) \cdot \left(-\left(t - z\right)\right)}}
\] |
neg-sub0 [=>]7.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(0 - \left(t - z\right)\right)}}
\] |
associate-+l- [<=]7.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(\left(0 - t\right) + z\right)}}
\] |
neg-sub0 [<=]7.8 | \[ \frac{x}{\left(z - y\right) \cdot \left(\color{blue}{\left(-t\right)} + z\right)}
\] |
+-commutative [<=]7.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z + \left(-t\right)\right)}}
\] |
sub-neg [<=]7.8 | \[ \frac{x}{\left(z - y\right) \cdot \color{blue}{\left(z - t\right)}}
\] |
associate-/l/ [<=]1.2 | \[ \color{blue}{\frac{\frac{x}{z - t}}{z - y}}
\] |
Final simplification1.6
| Alternative 1 | |
|---|---|
| Error | 0.8 |
| Cost | 1609 |
| Alternative 2 | |
|---|---|
| Error | 0.8 |
| Cost | 1608 |
| Alternative 3 | |
|---|---|
| Error | 28.7 |
| Cost | 1572 |
| Alternative 4 | |
|---|---|
| Error | 16.2 |
| Cost | 1372 |
| Alternative 5 | |
|---|---|
| Error | 15.3 |
| Cost | 1240 |
| Alternative 6 | |
|---|---|
| Error | 20.8 |
| Cost | 976 |
| Alternative 7 | |
|---|---|
| Error | 15.6 |
| Cost | 976 |
| Alternative 8 | |
|---|---|
| Error | 14.1 |
| Cost | 976 |
| Alternative 9 | |
|---|---|
| Error | 14.1 |
| Cost | 976 |
| Alternative 10 | |
|---|---|
| Error | 14.1 |
| Cost | 976 |
| Alternative 11 | |
|---|---|
| Error | 10.7 |
| Cost | 844 |
| Alternative 12 | |
|---|---|
| Error | 4.5 |
| Cost | 840 |
| Alternative 13 | |
|---|---|
| Error | 35.2 |
| Cost | 585 |
| Alternative 14 | |
|---|---|
| Error | 24.6 |
| Cost | 585 |
| Alternative 15 | |
|---|---|
| Error | 23.3 |
| Cost | 585 |
| Alternative 16 | |
|---|---|
| Error | 23.4 |
| Cost | 585 |
| Alternative 17 | |
|---|---|
| Error | 21.3 |
| Cost | 585 |
| Alternative 18 | |
|---|---|
| Error | 40.1 |
| Cost | 320 |
herbie shell --seed 2023016
(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))))