| Alternative 1 | |
|---|---|
| Error | 1.7 |
| Cost | 2512 |
(FPCore (x y z) :precision binary64 (/ (* x (- y z)) y))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x (- y z)) y)))
(if (<= t_0 -5e+289)
(* (- 1.0 (/ z y)) x)
(if (<= t_0 -5e+57)
t_0
(if (<= t_0 0.0)
(- x (* x (/ z y)))
(if (<= t_0 5e+282) (+ x (- (/ (* z x) y))) x))))))double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
double code(double x, double y, double z) {
double t_0 = (x * (y - z)) / y;
double tmp;
if (t_0 <= -5e+289) {
tmp = (1.0 - (z / y)) * x;
} else if (t_0 <= -5e+57) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = x - (x * (z / y));
} else if (t_0 <= 5e+282) {
tmp = x + -((z * x) / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (y - z)) / y
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = (x * (y - z)) / y
if (t_0 <= (-5d+289)) then
tmp = (1.0d0 - (z / y)) * x
else if (t_0 <= (-5d+57)) then
tmp = t_0
else if (t_0 <= 0.0d0) then
tmp = x - (x * (z / y))
else if (t_0 <= 5d+282) then
tmp = x + -((z * x) / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * (y - z)) / y;
}
public static double code(double x, double y, double z) {
double t_0 = (x * (y - z)) / y;
double tmp;
if (t_0 <= -5e+289) {
tmp = (1.0 - (z / y)) * x;
} else if (t_0 <= -5e+57) {
tmp = t_0;
} else if (t_0 <= 0.0) {
tmp = x - (x * (z / y));
} else if (t_0 <= 5e+282) {
tmp = x + -((z * x) / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): return (x * (y - z)) / y
def code(x, y, z): t_0 = (x * (y - z)) / y tmp = 0 if t_0 <= -5e+289: tmp = (1.0 - (z / y)) * x elif t_0 <= -5e+57: tmp = t_0 elif t_0 <= 0.0: tmp = x - (x * (z / y)) elif t_0 <= 5e+282: tmp = x + -((z * x) / y) else: tmp = x return tmp
function code(x, y, z) return Float64(Float64(x * Float64(y - z)) / y) end
function code(x, y, z) t_0 = Float64(Float64(x * Float64(y - z)) / y) tmp = 0.0 if (t_0 <= -5e+289) tmp = Float64(Float64(1.0 - Float64(z / y)) * x); elseif (t_0 <= -5e+57) tmp = t_0; elseif (t_0 <= 0.0) tmp = Float64(x - Float64(x * Float64(z / y))); elseif (t_0 <= 5e+282) tmp = Float64(x + Float64(-Float64(Float64(z * x) / y))); else tmp = x; end return tmp end
function tmp = code(x, y, z) tmp = (x * (y - z)) / y; end
function tmp_2 = code(x, y, z) t_0 = (x * (y - z)) / y; tmp = 0.0; if (t_0 <= -5e+289) tmp = (1.0 - (z / y)) * x; elseif (t_0 <= -5e+57) tmp = t_0; elseif (t_0 <= 0.0) tmp = x - (x * (z / y)); elseif (t_0 <= 5e+282) tmp = x + -((z * x) / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y - z), $MachinePrecision]), $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[t$95$0, -5e+289], N[(N[(1.0 - N[(z / y), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$0, -5e+57], t$95$0, If[LessEqual[t$95$0, 0.0], N[(x - N[(x * N[(z / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+282], N[(x + (-N[(N[(z * x), $MachinePrecision] / y), $MachinePrecision])), $MachinePrecision], x]]]]]
\frac{x \cdot \left(y - z\right)}{y}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y - z\right)}{y}\\
\mathbf{if}\;t_0 \leq -5 \cdot 10^{+289}:\\
\;\;\;\;\left(1 - \frac{z}{y}\right) \cdot x\\
\mathbf{elif}\;t_0 \leq -5 \cdot 10^{+57}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 0:\\
\;\;\;\;x - x \cdot \frac{z}{y}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+282}:\\
\;\;\;\;x + \left(-\frac{z \cdot x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
Results
| Original | 12.8 |
|---|---|
| Target | 3.3 |
| Herbie | 1.6 |
if (/.f64 (*.f64 x (-.f64 y z)) y) < -5.00000000000000031e289Initial program 57.3
Taylor expanded in y around 0 19.0
Simplified19.0
[Start]19.0 | \[ -1 \cdot \frac{z \cdot x}{y} + x
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]19.0 | \[ \color{blue}{x + -1 \cdot \frac{z \cdot x}{y}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]19.0 | \[ x + \color{blue}{\frac{z \cdot x}{y} \cdot -1}
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]19.0 | \[ x + \color{blue}{\left(-\frac{z \cdot x}{y}\right)}
\] |
Taylor expanded in x around 0 1.4
if -5.00000000000000031e289 < (/.f64 (*.f64 x (-.f64 y z)) y) < -4.99999999999999972e57Initial program 0.2
if -4.99999999999999972e57 < (/.f64 (*.f64 x (-.f64 y z)) y) < -0.0Initial program 9.7
Taylor expanded in y around 0 5.1
Simplified5.1
[Start]5.1 | \[ -1 \cdot \frac{z \cdot x}{y} + x
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]5.1 | \[ \color{blue}{x + -1 \cdot \frac{z \cdot x}{y}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]5.1 | \[ x + \color{blue}{\frac{z \cdot x}{y} \cdot -1}
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]5.1 | \[ x + \color{blue}{\left(-\frac{z \cdot x}{y}\right)}
\] |
Taylor expanded in x around 0 0.2
Simplified0.2
[Start]0.2 | \[ \left(1 - \frac{z}{y}\right) \cdot x
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2 | \[ \color{blue}{x \cdot \left(1 - \frac{z}{y}\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-13 [=>]0.2 | \[ \color{blue}{1 \cdot x - x \cdot \frac{z}{y}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [<=]0.2 | \[ \color{blue}{x \cdot 1} - x \cdot \frac{z}{y}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.2 | \[ \color{blue}{x} - x \cdot \frac{z}{y}
\] |
if -0.0 < (/.f64 (*.f64 x (-.f64 y z)) y) < 4.99999999999999978e282Initial program 0.4
Taylor expanded in y around 0 0.2
Simplified0.2
[Start]0.2 | \[ -1 \cdot \frac{z \cdot x}{y} + x
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.2 | \[ \color{blue}{x + -1 \cdot \frac{z \cdot x}{y}}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2 | \[ x + \color{blue}{\frac{z \cdot x}{y} \cdot -1}
\] |
rational_best_oopsla_all_46_json_45_simplify-92 [=>]0.2 | \[ x + \color{blue}{\left(-\frac{z \cdot x}{y}\right)}
\] |
if 4.99999999999999978e282 < (/.f64 (*.f64 x (-.f64 y z)) y) Initial program 55.8
Taylor expanded in y around inf 15.4
Final simplification1.6
| Alternative 1 | |
|---|---|
| Error | 1.7 |
| Cost | 2512 |
| Alternative 2 | |
|---|---|
| Error | 18.7 |
| Cost | 648 |
| Alternative 3 | |
|---|---|
| Error | 3.2 |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Error | 3.2 |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Error | 25.0 |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x y z)
:name "Diagrams.Backend.Cairo.Internal:setTexture from diagrams-cairo-1.3.0.3"
:precision binary64
:herbie-target
(if (< z -2.060202331921739e+104) (- x (/ (* z x) y)) (if (< z 1.6939766013828526e+213) (/ x (/ y (- y z))) (* (- y z) (/ x y))))
(/ (* x (- y z)) y))