| Alternative 1 | |
|---|---|
| Error | 19.2 |
| Cost | 584 |
\[\begin{array}{l}
\mathbf{if}\;z \leq -1.55 \cdot 10^{-9}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 2.3 \cdot 10^{-106}:\\
\;\;\;\;\frac{y \cdot 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 (* (+ 1.0 (/ y z)) x))) (if (<= x -5e-42) t_0 (if (<= x 1e-104) (+ (/ (* y x) z) x) 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 = (1.0 + (y / z)) * x;
double tmp;
if (x <= -5e-42) {
tmp = t_0;
} else if (x <= 1e-104) {
tmp = ((y * 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)) / 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 + (y / z)) * x
if (x <= (-5d-42)) then
tmp = t_0
else if (x <= 1d-104) then
tmp = ((y * 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)) / z;
}
public static double code(double x, double y, double z) {
double t_0 = (1.0 + (y / z)) * x;
double tmp;
if (x <= -5e-42) {
tmp = t_0;
} else if (x <= 1e-104) {
tmp = ((y * x) / z) + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): return (x * (y + z)) / z
def code(x, y, z): t_0 = (1.0 + (y / z)) * x tmp = 0 if x <= -5e-42: tmp = t_0 elif x <= 1e-104: tmp = ((y * x) / z) + x 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(1.0 + Float64(y / z)) * x) tmp = 0.0 if (x <= -5e-42) tmp = t_0; elseif (x <= 1e-104) tmp = Float64(Float64(Float64(y * x) / z) + x); 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 = (1.0 + (y / z)) * x; tmp = 0.0; if (x <= -5e-42) tmp = t_0; elseif (x <= 1e-104) tmp = ((y * x) / z) + x; 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[(1.0 + N[(y / z), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -5e-42], t$95$0, If[LessEqual[x, 1e-104], N[(N[(N[(y * x), $MachinePrecision] / z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \left(1 + \frac{y}{z}\right) \cdot x\\
\mathbf{if}\;x \leq -5 \cdot 10^{-42}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 10^{-104}:\\
\;\;\;\;\frac{y \cdot x}{z} + x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
Results
| Original | 12.6 |
|---|---|
| Target | 3.0 |
| Herbie | 1.7 |
if x < -5.00000000000000003e-42 or 9.99999999999999927e-105 < x Initial program 17.5
Taylor expanded in y around 0 6.0
Taylor expanded in x around 0 0.5
if -5.00000000000000003e-42 < x < 9.99999999999999927e-105Initial program 6.4
Taylor expanded in y around 0 3.3
Final simplification1.7
| Alternative 1 | |
|---|---|
| Error | 19.2 |
| Cost | 584 |
| Alternative 2 | |
|---|---|
| Error | 3.3 |
| Cost | 448 |
| Alternative 3 | |
|---|---|
| Error | 25.6 |
| Cost | 64 |
herbie shell --seed 2023077
(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))