| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 968 |
(FPCore (x y z) :precision binary64 (/ (* x (+ (- y z) 1.0)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (- (+ (/ 1.0 z) (/ y z)) 1.0) x)))
(if (<= x -1e+45)
t_0
(if (<= x 2.5e-59) (+ (/ (* x y) z) (+ (/ x z) (- x))) t_0))))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 = (((1.0 / z) + (y / z)) - 1.0) * x;
double tmp;
if (x <= -1e+45) {
tmp = t_0;
} else if (x <= 2.5e-59) {
tmp = ((x * y) / z) + ((x / z) + -x);
} 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) + 1.0d0)) / 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 = (((1.0d0 / z) + (y / z)) - 1.0d0) * x
if (x <= (-1d+45)) then
tmp = t_0
else if (x <= 2.5d-59) then
tmp = ((x * y) / z) + ((x / z) + -x)
else
tmp = t_0
end if
code = tmp
end function
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 = (((1.0 / z) + (y / z)) - 1.0) * x;
double tmp;
if (x <= -1e+45) {
tmp = t_0;
} else if (x <= 2.5e-59) {
tmp = ((x * y) / z) + ((x / z) + -x);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): return (x * ((y - z) + 1.0)) / z
def code(x, y, z): t_0 = (((1.0 / z) + (y / z)) - 1.0) * x tmp = 0 if x <= -1e+45: tmp = t_0 elif x <= 2.5e-59: tmp = ((x * y) / z) + ((x / z) + -x) else: tmp = t_0 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(Float64(Float64(1.0 / z) + Float64(y / z)) - 1.0) * x) tmp = 0.0 if (x <= -1e+45) tmp = t_0; elseif (x <= 2.5e-59) tmp = Float64(Float64(Float64(x * y) / z) + Float64(Float64(x / z) + Float64(-x))); else tmp = t_0; 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 = (((1.0 / z) + (y / z)) - 1.0) * x; tmp = 0.0; if (x <= -1e+45) tmp = t_0; elseif (x <= 2.5e-59) tmp = ((x * y) / z) + ((x / z) + -x); else tmp = t_0; 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[(N[(N[(1.0 / z), $MachinePrecision] + N[(y / z), $MachinePrecision]), $MachinePrecision] - 1.0), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1e+45], t$95$0, If[LessEqual[x, 2.5e-59], N[(N[(N[(x * y), $MachinePrecision] / z), $MachinePrecision] + N[(N[(x / z), $MachinePrecision] + (-x)), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\begin{array}{l}
t_0 := \left(\left(\frac{1}{z} + \frac{y}{z}\right) - 1\right) \cdot x\\
\mathbf{if}\;x \leq -1 \cdot 10^{+45}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-59}:\\
\;\;\;\;\frac{x \cdot y}{z} + \left(\frac{x}{z} + \left(-x\right)\right)\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 10.1 |
|---|---|
| Target | 0.4 |
| Herbie | 0.3 |
if x < -9.9999999999999993e44 or 2.5000000000000001e-59 < x Initial program 24.4
Simplified24.4
[Start]24.4 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-37 [=>]24.4 | \[ \frac{\color{blue}{\left(y - z\right) \cdot x + x \cdot 1}}{z}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]24.4 | \[ \frac{\color{blue}{x \cdot 1 + \left(y - z\right) \cdot x}}{z}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]24.4 | \[ \frac{\color{blue}{x} + \left(y - z\right) \cdot x}{z}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]24.4 | \[ \frac{x + \color{blue}{x \cdot \left(y - z\right)}}{z}
\] |
Taylor expanded in y around 0 8.3
Simplified8.3
[Start]8.3 | \[ \frac{y \cdot x}{z} + \left(-1 \cdot x + \frac{x}{z}\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.3 | \[ \frac{\color{blue}{x \cdot y}}{z} + \left(-1 \cdot x + \frac{x}{z}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]8.3 | \[ \frac{x \cdot y}{z} + \color{blue}{\left(\frac{x}{z} + -1 \cdot x\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]8.3 | \[ \frac{x \cdot y}{z} + \left(\frac{x}{z} + \color{blue}{x \cdot -1}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-94 [<=]8.3 | \[ \frac{x \cdot y}{z} + \left(\frac{x}{z} + \color{blue}{\left(-x\right)}\right)
\] |
Taylor expanded in x around 0 0.4
if -9.9999999999999993e44 < x < 2.5000000000000001e-59Initial program 0.4
Simplified0.4
[Start]0.4 | \[ \frac{x \cdot \left(\left(y - z\right) + 1\right)}{z}
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-37 [=>]0.4 | \[ \frac{\color{blue}{\left(y - z\right) \cdot x + x \cdot 1}}{z}
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.4 | \[ \frac{\color{blue}{x \cdot 1 + \left(y - z\right) \cdot x}}{z}
\] |
rational_best_oopsla_all_46_json_45_simplify-52 [=>]0.4 | \[ \frac{\color{blue}{x} + \left(y - z\right) \cdot x}{z}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.4 | \[ \frac{x + \color{blue}{x \cdot \left(y - z\right)}}{z}
\] |
Taylor expanded in y around 0 0.2
Simplified0.2
[Start]0.2 | \[ \frac{y \cdot x}{z} + \left(-1 \cdot x + \frac{x}{z}\right)
\] |
|---|---|
rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2 | \[ \frac{\color{blue}{x \cdot y}}{z} + \left(-1 \cdot x + \frac{x}{z}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-35 [=>]0.2 | \[ \frac{x \cdot y}{z} + \color{blue}{\left(\frac{x}{z} + -1 \cdot x\right)}
\] |
rational_best_oopsla_all_46_json_45_simplify-74 [=>]0.2 | \[ \frac{x \cdot y}{z} + \left(\frac{x}{z} + \color{blue}{x \cdot -1}\right)
\] |
rational_best_oopsla_all_46_json_45_simplify-94 [<=]0.2 | \[ \frac{x \cdot y}{z} + \left(\frac{x}{z} + \color{blue}{\left(-x\right)}\right)
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.3 |
| Cost | 968 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 904 |
| Alternative 3 | |
|---|---|
| Error | 12.2 |
| Cost | 848 |
| Alternative 4 | |
|---|---|
| Error | 1.0 |
| Cost | 840 |
| Alternative 5 | |
|---|---|
| Error | 0.1 |
| Cost | 840 |
| Alternative 6 | |
|---|---|
| Error | 0.1 |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Error | 4.3 |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 4.3 |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Error | 1.0 |
| Cost | 712 |
| Alternative 10 | |
|---|---|
| Error | 19.5 |
| Cost | 456 |
| Alternative 11 | |
|---|---|
| Error | 18.7 |
| Cost | 320 |
| Alternative 12 | |
|---|---|
| Error | 33.7 |
| Cost | 128 |
herbie shell --seed 2023090
(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))