| Alternative 1 | |
|---|---|
| Error | 12.5 |
| Cost | 1112 |
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (+ (- y z) 1.0)) (t_1 (/ (* x t_0) z)))
(if (<= t_1 (- INFINITY))
(* (- (/ y z) 1.0) x)
(if (<= t_1 5e+146) (+ (/ (* x (- y -1.0)) z) (- x)) (* t_0 (/ x z))))))double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
double code(double x, double y, double z) {
double t_0 = (y - z) + 1.0;
double t_1 = (x * t_0) / z;
double tmp;
if (t_1 <= -((double) INFINITY)) {
tmp = ((y / z) - 1.0) * x;
} else if (t_1 <= 5e+146) {
tmp = ((x * (y - -1.0)) / z) + -x;
} else {
tmp = t_0 * (x / z);
}
return tmp;
}
public static double code(double x, double y, double z) {
return (x * ((y - z) + 1.0)) / z;
}
public static double code(double x, double y, double z) {
double t_0 = (y - z) + 1.0;
double t_1 = (x * t_0) / z;
double tmp;
if (t_1 <= -Double.POSITIVE_INFINITY) {
tmp = ((y / z) - 1.0) * x;
} else if (t_1 <= 5e+146) {
tmp = ((x * (y - -1.0)) / z) + -x;
} else {
tmp = t_0 * (x / z);
}
return tmp;
}
def code(x, y, z): return (x * ((y - z) + 1.0)) / z
def code(x, y, z): t_0 = (y - z) + 1.0 t_1 = (x * t_0) / z tmp = 0 if t_1 <= -math.inf: tmp = ((y / z) - 1.0) * x elif t_1 <= 5e+146: tmp = ((x * (y - -1.0)) / z) + -x else: tmp = t_0 * (x / z) return tmp
function code(x, y, z) return Float64(Float64(x * Float64(Float64(y - z) + 1.0)) / z) end
function code(x, y, z) t_0 = Float64(Float64(y - z) + 1.0) t_1 = Float64(Float64(x * t_0) / z) tmp = 0.0 if (t_1 <= Float64(-Inf)) tmp = Float64(Float64(Float64(y / z) - 1.0) * x); elseif (t_1 <= 5e+146) tmp = Float64(Float64(Float64(x * Float64(y - -1.0)) / z) + Float64(-x)); else tmp = Float64(t_0 * Float64(x / z)); end return tmp end
function tmp = code(x, y, z) tmp = (x * ((y - z) + 1.0)) / z; end
function tmp_2 = code(x, y, z) t_0 = (y - z) + 1.0; t_1 = (x * t_0) / z; tmp = 0.0; if (t_1 <= -Inf) tmp = ((y / z) - 1.0) * x; elseif (t_1 <= 5e+146) tmp = ((x * (y - -1.0)) / z) + -x; else tmp = t_0 * (x / z); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(y - z), $MachinePrecision] + 1.0), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision]}, If[LessEqual[t$95$1, (-Infinity)], N[(N[(N[(y / z), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision], If[LessEqual[t$95$1, 5e+146], N[(N[(N[(x * N[(y - -1.0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision] + (-x)), $MachinePrecision], N[(t$95$0 * N[(x / z), $MachinePrecision]), $MachinePrecision]]]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \left(y - z\right) + 1\\
t_1 := \frac{x \cdot t_0}{z}\\
\mathbf{if}\;t_1 \leq -\infty:\\
\;\;\;\;\left(\frac{y}{z} - 1\right) \cdot x\\
\mathbf{elif}\;t_1 \leq 5 \cdot 10^{+146}:\\
\;\;\;\;\frac{x \cdot \left(y - -1\right)}{z} + \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{x}{z}\\
\end{array}
Results
| Original | 10.2 |
|---|---|
| Target | 0.5 |
| Herbie | 0.1 |
if (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < -inf.0Initial program 64.0
Simplified0.2
[Start]64.0 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
rational.json-simplify-49 [=>]0.2 | \[ \color{blue}{\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}}
\] |
Taylor expanded in z around 0 22.4
Simplified22.4
[Start]22.4 | \[ -1 \cdot x + \frac{\left(1 + y\right) \cdot x}{z}
\] |
|---|---|
rational.json-simplify-1 [=>]22.4 | \[ \color{blue}{\frac{\left(1 + y\right) \cdot x}{z} + -1 \cdot x}
\] |
rational.json-simplify-2 [=>]22.4 | \[ \frac{\color{blue}{x \cdot \left(1 + y\right)}}{z} + -1 \cdot x
\] |
rational.json-simplify-17 [=>]22.4 | \[ \frac{x \cdot \color{blue}{\left(y - -1\right)}}{z} + -1 \cdot x
\] |
rational.json-simplify-2 [=>]22.4 | \[ \frac{x \cdot \left(y - -1\right)}{z} + \color{blue}{x \cdot -1}
\] |
rational.json-simplify-8 [<=]22.4 | \[ \frac{x \cdot \left(y - -1\right)}{z} + \color{blue}{\left(-x\right)}
\] |
Taylor expanded in y around inf 22.4
Simplified0.0
[Start]22.4 | \[ \frac{y \cdot x}{z} + \left(-x\right)
\] |
|---|---|
rational.json-simplify-49 [=>]0.0 | \[ \color{blue}{x \cdot \frac{y}{z}} + \left(-x\right)
\] |
Taylor expanded in x around 0 0.1
if -inf.0 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) < 4.9999999999999999e146Initial program 0.2
Simplified11.8
[Start]0.2 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
rational.json-simplify-49 [=>]11.8 | \[ \color{blue}{\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}}
\] |
Taylor expanded in z around 0 0.1
Simplified0.1
[Start]0.1 | \[ -1 \cdot x + \frac{\left(1 + y\right) \cdot x}{z}
\] |
|---|---|
rational.json-simplify-1 [=>]0.1 | \[ \color{blue}{\frac{\left(1 + y\right) \cdot x}{z} + -1 \cdot x}
\] |
rational.json-simplify-2 [=>]0.1 | \[ \frac{\color{blue}{x \cdot \left(1 + y\right)}}{z} + -1 \cdot x
\] |
rational.json-simplify-17 [=>]0.1 | \[ \frac{x \cdot \color{blue}{\left(y - -1\right)}}{z} + -1 \cdot x
\] |
rational.json-simplify-2 [=>]0.1 | \[ \frac{x \cdot \left(y - -1\right)}{z} + \color{blue}{x \cdot -1}
\] |
rational.json-simplify-8 [<=]0.1 | \[ \frac{x \cdot \left(y - -1\right)}{z} + \color{blue}{\left(-x\right)}
\] |
if 4.9999999999999999e146 < (/.f64 (*.f64 x (+.f64 (-.f64 y z) 1)) z) Initial program 28.3
Simplified0.1
[Start]28.3 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
rational.json-simplify-49 [=>]0.1 | \[ \color{blue}{\left(\left(y - z\right) + 1\right) \cdot \frac{x}{z}}
\] |
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 12.5 |
| Cost | 1112 |
| Alternative 2 | |
|---|---|
| Error | 12.2 |
| Cost | 848 |
| Alternative 3 | |
|---|---|
| Error | 0.2 |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Error | 0.2 |
| Cost | 840 |
| Alternative 5 | |
|---|---|
| Error | 0.2 |
| Cost | 840 |
| Alternative 6 | |
|---|---|
| Error | 8.8 |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Error | 0.9 |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 19.1 |
| Cost | 456 |
| Alternative 9 | |
|---|---|
| Error | 33.7 |
| Cost | 128 |
herbie shell --seed 2023064
(FPCore (x y z)
:name "Diagrams.TwoD.Segment.Bernstein:evaluateBernstein from diagrams-lib-1.3.0.3"
:precision binary64
:herbie-target
(if (< x -2.71483106713436e-162) (- (* (+ 1.0 y) (/ x z)) x) (if (< x 3.874108816439546e-197) (* (* x (+ (- y z) 1.0)) (/ 1.0 z)) (- (* (+ 1.0 y) (/ x z)) x)))
(/ (* x (+ (- y z) 1.0)) z))