| Alternative 1 | |
|---|---|
| Error | 31.31% |
| Cost | 585 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-44} \lor \neg \left(y \leq 1.1 \cdot 10^{-50}\right):\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x (+ y z)) z)))
(if (or (<= t_0 -4e+306)
(and (not (<= t_0 -2e+183))
(or (<= t_0 1e-125) (not (<= t_0 2e+221)))))
(+ x (* x (/ y z)))
t_0)))double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if ((t_0 <= -4e+306) || (!(t_0 <= -2e+183) && ((t_0 <= 1e-125) || !(t_0 <= 2e+221)))) {
tmp = x + (x * (y / z));
} else {
tmp = t_0;
}
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)) / z
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)) / z
if ((t_0 <= (-4d+306)) .or. (.not. (t_0 <= (-2d+183))) .and. (t_0 <= 1d-125) .or. (.not. (t_0 <= 2d+221))) then
tmp = x + (x * (y / z))
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
public static double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double tmp;
if ((t_0 <= -4e+306) || (!(t_0 <= -2e+183) && ((t_0 <= 1e-125) || !(t_0 <= 2e+221)))) {
tmp = x + (x * (y / z));
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): return (x * (y + z)) / z
def code(x, y, z): t_0 = (x * (y + z)) / z tmp = 0 if (t_0 <= -4e+306) or (not (t_0 <= -2e+183) and ((t_0 <= 1e-125) or not (t_0 <= 2e+221))): tmp = x + (x * (y / z)) else: tmp = t_0 return tmp
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function code(x, y, z) t_0 = Float64(Float64(x * Float64(y + z)) / z) tmp = 0.0 if ((t_0 <= -4e+306) || (!(t_0 <= -2e+183) && ((t_0 <= 1e-125) || !(t_0 <= 2e+221)))) tmp = Float64(x + Float64(x * Float64(y / z))); else tmp = t_0; end return tmp end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
function tmp_2 = code(x, y, z) t_0 = (x * (y + z)) / z; tmp = 0.0; if ((t_0 <= -4e+306) || (~((t_0 <= -2e+183)) && ((t_0 <= 1e-125) || ~((t_0 <= 2e+221))))) tmp = x + (x * (y / z)); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Or[LessEqual[t$95$0, -4e+306], And[N[Not[LessEqual[t$95$0, -2e+183]], $MachinePrecision], Or[LessEqual[t$95$0, 1e-125], N[Not[LessEqual[t$95$0, 2e+221]], $MachinePrecision]]]], N[(x + N[(x * N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
\mathbf{if}\;t_0 \leq -4 \cdot 10^{+306} \lor \neg \left(t_0 \leq -2 \cdot 10^{+183}\right) \land \left(t_0 \leq 10^{-125} \lor \neg \left(t_0 \leq 2 \cdot 10^{+221}\right)\right):\\
\;\;\;\;x + x \cdot \frac{y}{z}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 19.34% |
|---|---|
| Target | 5.17% |
| Herbie | 2.53% |
if (/.f64 (*.f64 x (+.f64 y z)) z) < -4.00000000000000007e306 or -1.99999999999999989e183 < (/.f64 (*.f64 x (+.f64 y z)) z) < 1.00000000000000001e-125 or 2.0000000000000001e221 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 28.85
Simplified3.64
[Start]28.85 | \[ \frac{x \cdot \left(y + z\right)}{z}
\] |
|---|---|
associate-*r/ [<=]3.64 | \[ \color{blue}{x \cdot \frac{y + z}{z}}
\] |
Taylor expanded in x around 0 28.85
Simplified3.62
[Start]28.85 | \[ \frac{\left(y + z\right) \cdot x}{z}
\] |
|---|---|
associate-*l/ [<=]3.64 | \[ \color{blue}{\frac{y + z}{z} \cdot x}
\] |
*-lft-identity [<=]3.64 | \[ \frac{\color{blue}{1 \cdot \left(y + z\right)}}{z} \cdot x
\] |
associate-*l/ [<=]3.83 | \[ \color{blue}{\left(\frac{1}{z} \cdot \left(y + z\right)\right)} \cdot x
\] |
distribute-lft-in [=>]3.83 | \[ \color{blue}{\left(\frac{1}{z} \cdot y + \frac{1}{z} \cdot z\right)} \cdot x
\] |
lft-mult-inverse [=>]3.67 | \[ \left(\frac{1}{z} \cdot y + \color{blue}{1}\right) \cdot x
\] |
distribute-rgt1-in [<=]3.66 | \[ \color{blue}{x + \left(\frac{1}{z} \cdot y\right) \cdot x}
\] |
associate-*l/ [=>]3.62 | \[ x + \color{blue}{\frac{1 \cdot y}{z}} \cdot x
\] |
*-lft-identity [=>]3.62 | \[ x + \frac{\color{blue}{y}}{z} \cdot x
\] |
if -4.00000000000000007e306 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1.99999999999999989e183 or 1.00000000000000001e-125 < (/.f64 (*.f64 x (+.f64 y z)) z) < 2.0000000000000001e221Initial program 0.37
Final simplification2.53
| Alternative 1 | |
|---|---|
| Error | 31.31% |
| Cost | 585 |
| Alternative 2 | |
|---|---|
| Error | 5.8% |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 5.78% |
| Cost | 448 |
| Alternative 4 | |
|---|---|
| Error | 5.17% |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Error | 40.66% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))