| Alternative 1 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 1101 |
(FPCore (x y z t) :precision binary64 (* x (/ (* (/ y z) t) t)))
(FPCore (x y z t)
:precision binary64
(if (<= (/ y z) (- INFINITY))
(/ y (/ z x))
(if (<= (/ y z) -5e-58)
(* (/ y z) x)
(if (<= (/ y z) 0.0) (* y (* x (/ 1.0 z))) (/ x (/ z y))))))double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -((double) INFINITY)) {
tmp = y / (z / x);
} else if ((y / z) <= -5e-58) {
tmp = (y / z) * x;
} else if ((y / z) <= 0.0) {
tmp = y * (x * (1.0 / z));
} else {
tmp = x / (z / y);
}
return tmp;
}
public static double code(double x, double y, double z, double t) {
return x * (((y / z) * t) / t);
}
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y / z) <= -Double.POSITIVE_INFINITY) {
tmp = y / (z / x);
} else if ((y / z) <= -5e-58) {
tmp = (y / z) * x;
} else if ((y / z) <= 0.0) {
tmp = y * (x * (1.0 / z));
} else {
tmp = x / (z / y);
}
return tmp;
}
def code(x, y, z, t): return x * (((y / z) * t) / t)
def code(x, y, z, t): tmp = 0 if (y / z) <= -math.inf: tmp = y / (z / x) elif (y / z) <= -5e-58: tmp = (y / z) * x elif (y / z) <= 0.0: tmp = y * (x * (1.0 / z)) else: tmp = x / (z / y) return tmp
function code(x, y, z, t) return Float64(x * Float64(Float64(Float64(y / z) * t) / t)) end
function code(x, y, z, t) tmp = 0.0 if (Float64(y / z) <= Float64(-Inf)) tmp = Float64(y / Float64(z / x)); elseif (Float64(y / z) <= -5e-58) tmp = Float64(Float64(y / z) * x); elseif (Float64(y / z) <= 0.0) tmp = Float64(y * Float64(x * Float64(1.0 / z))); else tmp = Float64(x / Float64(z / y)); end return tmp end
function tmp = code(x, y, z, t) tmp = x * (((y / z) * t) / t); end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y / z) <= -Inf) tmp = y / (z / x); elseif ((y / z) <= -5e-58) tmp = (y / z) * x; elseif ((y / z) <= 0.0) tmp = y * (x * (1.0 / z)); else tmp = x / (z / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(x * N[(N[(N[(y / z), $MachinePrecision] * t), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[N[(y / z), $MachinePrecision], (-Infinity)], N[(y / N[(z / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], -5e-58], N[(N[(y / z), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[N[(y / z), $MachinePrecision], 0.0], N[(y * N[(x * N[(1.0 / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x / N[(z / y), $MachinePrecision]), $MachinePrecision]]]]
x \cdot \frac{\frac{y}{z} \cdot t}{t}
\begin{array}{l}
\mathbf{if}\;\frac{y}{z} \leq -\infty:\\
\;\;\;\;\frac{y}{\frac{z}{x}}\\
\mathbf{elif}\;\frac{y}{z} \leq -5 \cdot 10^{-58}:\\
\;\;\;\;\frac{y}{z} \cdot x\\
\mathbf{elif}\;\frac{y}{z} \leq 0:\\
\;\;\;\;y \cdot \left(x \cdot \frac{1}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\frac{z}{y}}\\
\end{array}
Results
| Original | 77.1% |
|---|---|
| Target | 97.5% |
| Herbie | 95.3% |
if (/.f64 y z) < -inf.0Initial program 0.0%
Simplified99.6%
[Start]0.0 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
*-commutative [=>]0.0 | \[ \color{blue}{\frac{\frac{y}{z} \cdot t}{t} \cdot x}
\] |
associate-/l* [=>]0.0 | \[ \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}} \cdot x
\] |
*-inverses [=>]0.0 | \[ \frac{\frac{y}{z}}{\color{blue}{1}} \cdot x
\] |
/-rgt-identity [=>]0.0 | \[ \color{blue}{\frac{y}{z}} \cdot x
\] |
associate-*l/ [=>]99.5 | \[ \color{blue}{\frac{y \cdot x}{z}}
\] |
associate-*r/ [<=]99.6 | \[ \color{blue}{y \cdot \frac{x}{z}}
\] |
Applied egg-rr99.7%
[Start]99.6 | \[ y \cdot \frac{x}{z}
\] |
|---|---|
clear-num [=>]99.5 | \[ y \cdot \color{blue}{\frac{1}{\frac{z}{x}}}
\] |
un-div-inv [=>]99.7 | \[ \color{blue}{\frac{y}{\frac{z}{x}}}
\] |
if -inf.0 < (/.f64 y z) < -4.99999999999999977e-58Initial program 83.4%
Simplified99.6%
[Start]83.4 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
associate-/l* [=>]99.6 | \[ x \cdot \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}}
\] |
*-inverses [=>]99.6 | \[ x \cdot \frac{\frac{y}{z}}{\color{blue}{1}}
\] |
/-rgt-identity [=>]99.6 | \[ x \cdot \color{blue}{\frac{y}{z}}
\] |
if -4.99999999999999977e-58 < (/.f64 y z) < -0.0Initial program 77.8%
Simplified95.6%
[Start]77.8 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
*-commutative [=>]77.8 | \[ \color{blue}{\frac{\frac{y}{z} \cdot t}{t} \cdot x}
\] |
associate-/l* [=>]86.6 | \[ \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}} \cdot x
\] |
*-inverses [=>]86.6 | \[ \frac{\frac{y}{z}}{\color{blue}{1}} \cdot x
\] |
/-rgt-identity [=>]86.6 | \[ \color{blue}{\frac{y}{z}} \cdot x
\] |
associate-*l/ [=>]95.6 | \[ \color{blue}{\frac{y \cdot x}{z}}
\] |
associate-*r/ [<=]95.6 | \[ \color{blue}{y \cdot \frac{x}{z}}
\] |
Applied egg-rr94.6%
[Start]95.6 | \[ y \cdot \frac{x}{z}
\] |
|---|---|
associate-*r/ [=>]95.6 | \[ \color{blue}{\frac{y \cdot x}{z}}
\] |
clear-num [=>]94.6 | \[ \color{blue}{\frac{1}{\frac{z}{y \cdot x}}}
\] |
Applied egg-rr95.5%
[Start]94.6 | \[ \frac{1}{\frac{z}{y \cdot x}}
\] |
|---|---|
associate-/r/ [=>]95.6 | \[ \color{blue}{\frac{1}{z} \cdot \left(y \cdot x\right)}
\] |
*-commutative [=>]95.6 | \[ \frac{1}{z} \cdot \color{blue}{\left(x \cdot y\right)}
\] |
associate-*r* [=>]95.5 | \[ \color{blue}{\left(\frac{1}{z} \cdot x\right) \cdot y}
\] |
if -0.0 < (/.f64 y z) Initial program 77.0%
Simplified92.6%
[Start]77.0 | \[ x \cdot \frac{\frac{y}{z} \cdot t}{t}
\] |
|---|---|
associate-/l* [=>]92.6 | \[ x \cdot \color{blue}{\frac{\frac{y}{z}}{\frac{t}{t}}}
\] |
*-inverses [=>]92.6 | \[ x \cdot \frac{\frac{y}{z}}{\color{blue}{1}}
\] |
/-rgt-identity [=>]92.6 | \[ x \cdot \color{blue}{\frac{y}{z}}
\] |
Taylor expanded in x around 0 89.1%
Simplified92.6%
[Start]89.1 | \[ \frac{y \cdot x}{z}
\] |
|---|---|
*-commutative [=>]89.1 | \[ \frac{\color{blue}{x \cdot y}}{z}
\] |
associate-/l* [=>]92.6 | \[ \color{blue}{\frac{x}{\frac{z}{y}}}
\] |
Final simplification95.3%
| Alternative 1 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 1101 |
| Alternative 2 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 1100 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.6% |
| Cost | 1100 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 320 |
herbie shell --seed 2023151
(FPCore (x y z t)
:name "Graphics.Rendering.Chart.Backend.Diagrams:calcFontMetrics from Chart-diagrams-1.5.1, B"
:precision binary64
:herbie-target
(if (< (/ (* (/ y z) t) t) -1.20672205123045e+245) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) -5.907522236933906e-275) (* x (/ y z)) (if (< (/ (* (/ y z) t) t) 5.658954423153415e-65) (/ y (/ z x)) (if (< (/ (* (/ y z) t) t) 2.0087180502407133e+217) (* x (/ y z)) (/ (* y x) z)))))
(* x (/ (* (/ y z) t) t)))