| Alternative 1 | |
|---|---|
| Error | 0.46% |
| Cost | 1865 |
(FPCore (x y z) :precision binary64 (/ (+ x y) (- 1.0 (/ y z))))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (- 1.0 (/ y z))) (t_1 (/ (+ x y) t_0)))
(if (<= t_1 -5e-262)
t_1
(if (<= t_1 0.0) (* z (- -1.0 (/ x y))) (+ (/ y t_0) (/ x t_0))))))double code(double x, double y, double z) {
return (x + y) / (1.0 - (y / z));
}
double code(double x, double y, double z) {
double t_0 = 1.0 - (y / z);
double t_1 = (x + y) / t_0;
double tmp;
if (t_1 <= -5e-262) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = z * (-1.0 - (x / y));
} else {
tmp = (y / t_0) + (x / 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) / (1.0d0 - (y / 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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (y / z)
t_1 = (x + y) / t_0
if (t_1 <= (-5d-262)) then
tmp = t_1
else if (t_1 <= 0.0d0) then
tmp = z * ((-1.0d0) - (x / y))
else
tmp = (y / t_0) + (x / t_0)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x + y) / (1.0 - (y / z));
}
public static double code(double x, double y, double z) {
double t_0 = 1.0 - (y / z);
double t_1 = (x + y) / t_0;
double tmp;
if (t_1 <= -5e-262) {
tmp = t_1;
} else if (t_1 <= 0.0) {
tmp = z * (-1.0 - (x / y));
} else {
tmp = (y / t_0) + (x / t_0);
}
return tmp;
}
def code(x, y, z): return (x + y) / (1.0 - (y / z))
def code(x, y, z): t_0 = 1.0 - (y / z) t_1 = (x + y) / t_0 tmp = 0 if t_1 <= -5e-262: tmp = t_1 elif t_1 <= 0.0: tmp = z * (-1.0 - (x / y)) else: tmp = (y / t_0) + (x / t_0) return tmp
function code(x, y, z) return Float64(Float64(x + y) / Float64(1.0 - Float64(y / z))) end
function code(x, y, z) t_0 = Float64(1.0 - Float64(y / z)) t_1 = Float64(Float64(x + y) / t_0) tmp = 0.0 if (t_1 <= -5e-262) tmp = t_1; elseif (t_1 <= 0.0) tmp = Float64(z * Float64(-1.0 - Float64(x / y))); else tmp = Float64(Float64(y / t_0) + Float64(x / t_0)); end return tmp end
function tmp = code(x, y, z) tmp = (x + y) / (1.0 - (y / z)); end
function tmp_2 = code(x, y, z) t_0 = 1.0 - (y / z); t_1 = (x + y) / t_0; tmp = 0.0; if (t_1 <= -5e-262) tmp = t_1; elseif (t_1 <= 0.0) tmp = z * (-1.0 - (x / y)); else tmp = (y / t_0) + (x / t_0); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x + y), $MachinePrecision] / N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 - N[(y / z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x + y), $MachinePrecision] / t$95$0), $MachinePrecision]}, If[LessEqual[t$95$1, -5e-262], t$95$1, If[LessEqual[t$95$1, 0.0], N[(z * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / t$95$0), $MachinePrecision] + N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x + y}{1 - \frac{y}{z}}
\begin{array}{l}
t_0 := 1 - \frac{y}{z}\\
t_1 := \frac{x + y}{t_0}\\
\mathbf{if}\;t_1 \leq -5 \cdot 10^{-262}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;z \cdot \left(-1 - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{t_0} + \frac{x}{t_0}\\
\end{array}
Results
| Original | 11.83% |
|---|---|
| Target | 6.27% |
| Herbie | 0.45% |
if (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -4.99999999999999992e-262Initial program 0.16
if -4.99999999999999992e-262 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) < -0.0Initial program 87.56
Simplified87.56
[Start]87.56 | \[ \frac{x + y}{1 - \frac{y}{z}}
\] |
|---|---|
+-commutative [=>]87.56 | \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}}
\] |
Applied egg-rr87.56
Taylor expanded in y around inf 84.45
Simplified84.45
[Start]84.45 | \[ \left(-1 \cdot \frac{z}{y}\right) \cdot \left(y + x\right)
\] |
|---|---|
associate-*r/ [=>]84.45 | \[ \color{blue}{\frac{-1 \cdot z}{y}} \cdot \left(y + x\right)
\] |
mul-1-neg [=>]84.45 | \[ \frac{\color{blue}{-z}}{y} \cdot \left(y + x\right)
\] |
Taylor expanded in z around 0 5.09
Simplified2.44
[Start]5.09 | \[ -1 \cdot \frac{\left(y + x\right) \cdot z}{y}
\] |
|---|---|
*-commutative [=>]5.09 | \[ -1 \cdot \frac{\color{blue}{z \cdot \left(y + x\right)}}{y}
\] |
associate-*l/ [<=]84.45 | \[ -1 \cdot \color{blue}{\left(\frac{z}{y} \cdot \left(y + x\right)\right)}
\] |
distribute-lft-in [=>]84.45 | \[ -1 \cdot \color{blue}{\left(\frac{z}{y} \cdot y + \frac{z}{y} \cdot x\right)}
\] |
associate-/r/ [<=]71.43 | \[ -1 \cdot \left(\frac{z}{y} \cdot y + \color{blue}{\frac{z}{\frac{y}{x}}}\right)
\] |
associate-/l* [<=]71.78 | \[ -1 \cdot \left(\frac{z}{y} \cdot y + \color{blue}{\frac{z \cdot x}{y}}\right)
\] |
*-commutative [=>]71.78 | \[ -1 \cdot \left(\frac{z}{y} \cdot y + \frac{\color{blue}{x \cdot z}}{y}\right)
\] |
associate-*l/ [<=]71.42 | \[ -1 \cdot \left(\frac{z}{y} \cdot y + \color{blue}{\frac{x}{y} \cdot z}\right)
\] |
*-commutative [<=]71.42 | \[ -1 \cdot \left(\color{blue}{y \cdot \frac{z}{y}} + \frac{x}{y} \cdot z\right)
\] |
associate-*r/ [=>]4.92 | \[ -1 \cdot \left(\color{blue}{\frac{y \cdot z}{y}} + \frac{x}{y} \cdot z\right)
\] |
associate-*l/ [<=]2.43 | \[ -1 \cdot \left(\color{blue}{\frac{y}{y} \cdot z} + \frac{x}{y} \cdot z\right)
\] |
*-inverses [=>]2.43 | \[ -1 \cdot \left(\color{blue}{1} \cdot z + \frac{x}{y} \cdot z\right)
\] |
*-lft-identity [=>]2.43 | \[ -1 \cdot \left(\color{blue}{z} + \frac{x}{y} \cdot z\right)
\] |
distribute-lft-out [<=]2.43 | \[ \color{blue}{-1 \cdot z + -1 \cdot \left(\frac{x}{y} \cdot z\right)}
\] |
mul-1-neg [=>]2.43 | \[ -1 \cdot z + \color{blue}{\left(-\frac{x}{y} \cdot z\right)}
\] |
unsub-neg [=>]2.43 | \[ \color{blue}{-1 \cdot z - \frac{x}{y} \cdot z}
\] |
distribute-rgt-out-- [=>]2.44 | \[ \color{blue}{z \cdot \left(-1 - \frac{x}{y}\right)}
\] |
if -0.0 < (/.f64 (+.f64 x y) (-.f64 1 (/.f64 y z))) Initial program 0.14
Simplified0.14
[Start]0.14 | \[ \frac{x + y}{1 - \frac{y}{z}}
\] |
|---|---|
+-commutative [=>]0.14 | \[ \frac{\color{blue}{y + x}}{1 - \frac{y}{z}}
\] |
Taylor expanded in x around 0 0.14
Simplified0.14
[Start]0.14 | \[ \frac{x}{1 - \frac{y}{z}} + \frac{y}{1 - \frac{y}{z}}
\] |
|---|---|
+-commutative [=>]0.14 | \[ \color{blue}{\frac{y}{1 - \frac{y}{z}} + \frac{x}{1 - \frac{y}{z}}}
\] |
Final simplification0.45
| Alternative 1 | |
|---|---|
| Error | 0.46% |
| Cost | 1865 |
| Alternative 2 | |
|---|---|
| Error | 27.26% |
| Cost | 1108 |
| Alternative 3 | |
|---|---|
| Error | 27.24% |
| Cost | 1108 |
| Alternative 4 | |
|---|---|
| Error | 27.3% |
| Cost | 978 |
| Alternative 5 | |
|---|---|
| Error | 25.75% |
| Cost | 977 |
| Alternative 6 | |
|---|---|
| Error | 36.29% |
| Cost | 853 |
| Alternative 7 | |
|---|---|
| Error | 34.7% |
| Cost | 853 |
| Alternative 8 | |
|---|---|
| Error | 33.55% |
| Cost | 721 |
| Alternative 9 | |
|---|---|
| Error | 42.25% |
| Cost | 392 |
| Alternative 10 | |
|---|---|
| Error | 60.69% |
| Cost | 328 |
| Alternative 11 | |
|---|---|
| Error | 66.53% |
| Cost | 64 |
herbie shell --seed 2023090
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, A"
:precision binary64
:herbie-target
(if (< y -3.7429310762689856e+171) (* (/ (+ y x) (- y)) z) (if (< y 3.5534662456086734e+168) (/ (+ x y) (- 1.0 (/ y z))) (* (/ (+ y x) (- y)) z)))
(/ (+ x y) (- 1.0 (/ y z))))