| Alternative 1 | |
|---|---|
| Error | 4.5 |
| Cost | 836 |
\[\begin{array}{l}
\mathbf{if}\;x \cdot 2 \leq 5 \cdot 10^{-139}:\\
\;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{\frac{x}{y - t}}{z}\\
\end{array}
\]
(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (- (* y z) (* z t))) (t_2 (/ (/ (* x 2.0) z) (- y t))))
(if (<= t_1 -2e+256)
t_2
(if (<= t_1 -1e-100)
(/ x (/ (* z (- y t)) 2.0))
(if (<= t_1 4e-138)
t_2
(if (<= t_1 1e+15)
(* x (/ (/ 2.0 (- y t)) z))
(/ (* 2.0 (/ x (- y t))) z)))))))double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
double code(double x, double y, double z, double t) {
double t_1 = (y * z) - (z * t);
double t_2 = ((x * 2.0) / z) / (y - t);
double tmp;
if (t_1 <= -2e+256) {
tmp = t_2;
} else if (t_1 <= -1e-100) {
tmp = x / ((z * (y - t)) / 2.0);
} else if (t_1 <= 4e-138) {
tmp = t_2;
} else if (t_1 <= 1e+15) {
tmp = x * ((2.0 / (y - t)) / z);
} else {
tmp = (2.0 * (x / (y - t))) / z;
}
return tmp;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (x * 2.0d0) / ((y * z) - (t * z))
end function
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (y * z) - (z * t)
t_2 = ((x * 2.0d0) / z) / (y - t)
if (t_1 <= (-2d+256)) then
tmp = t_2
else if (t_1 <= (-1d-100)) then
tmp = x / ((z * (y - t)) / 2.0d0)
else if (t_1 <= 4d-138) then
tmp = t_2
else if (t_1 <= 1d+15) then
tmp = x * ((2.0d0 / (y - t)) / z)
else
tmp = (2.0d0 * (x / (y - t))) / z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return (x * 2.0) / ((y * z) - (t * z));
}
public static double code(double x, double y, double z, double t) {
double t_1 = (y * z) - (z * t);
double t_2 = ((x * 2.0) / z) / (y - t);
double tmp;
if (t_1 <= -2e+256) {
tmp = t_2;
} else if (t_1 <= -1e-100) {
tmp = x / ((z * (y - t)) / 2.0);
} else if (t_1 <= 4e-138) {
tmp = t_2;
} else if (t_1 <= 1e+15) {
tmp = x * ((2.0 / (y - t)) / z);
} else {
tmp = (2.0 * (x / (y - t))) / z;
}
return tmp;
}
def code(x, y, z, t): return (x * 2.0) / ((y * z) - (t * z))
def code(x, y, z, t): t_1 = (y * z) - (z * t) t_2 = ((x * 2.0) / z) / (y - t) tmp = 0 if t_1 <= -2e+256: tmp = t_2 elif t_1 <= -1e-100: tmp = x / ((z * (y - t)) / 2.0) elif t_1 <= 4e-138: tmp = t_2 elif t_1 <= 1e+15: tmp = x * ((2.0 / (y - t)) / z) else: tmp = (2.0 * (x / (y - t))) / z return tmp
function code(x, y, z, t) return Float64(Float64(x * 2.0) / Float64(Float64(y * z) - Float64(t * z))) end
function code(x, y, z, t) t_1 = Float64(Float64(y * z) - Float64(z * t)) t_2 = Float64(Float64(Float64(x * 2.0) / z) / Float64(y - t)) tmp = 0.0 if (t_1 <= -2e+256) tmp = t_2; elseif (t_1 <= -1e-100) tmp = Float64(x / Float64(Float64(z * Float64(y - t)) / 2.0)); elseif (t_1 <= 4e-138) tmp = t_2; elseif (t_1 <= 1e+15) tmp = Float64(x * Float64(Float64(2.0 / Float64(y - t)) / z)); else tmp = Float64(Float64(2.0 * Float64(x / Float64(y - t))) / z); end return tmp end
function tmp = code(x, y, z, t) tmp = (x * 2.0) / ((y * z) - (t * z)); end
function tmp_2 = code(x, y, z, t) t_1 = (y * z) - (z * t); t_2 = ((x * 2.0) / z) / (y - t); tmp = 0.0; if (t_1 <= -2e+256) tmp = t_2; elseif (t_1 <= -1e-100) tmp = x / ((z * (y - t)) / 2.0); elseif (t_1 <= 4e-138) tmp = t_2; elseif (t_1 <= 1e+15) tmp = x * ((2.0 / (y - t)) / z); else tmp = (2.0 * (x / (y - t))) / z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(N[(x * 2.0), $MachinePrecision] / N[(N[(y * z), $MachinePrecision] - N[(t * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(N[(x * 2.0), $MachinePrecision] / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+256], t$95$2, If[LessEqual[t$95$1, -1e-100], N[(x / N[(N[(z * N[(y - t), $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 4e-138], t$95$2, If[LessEqual[t$95$1, 1e+15], N[(x * N[(N[(2.0 / N[(y - t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
t_2 := \frac{\frac{x \cdot 2}{z}}{y - t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+256}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq -1 \cdot 10^{-100}:\\
\;\;\;\;\frac{x}{\frac{z \cdot \left(y - t\right)}{2}}\\
\mathbf{elif}\;t_1 \leq 4 \cdot 10^{-138}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 10^{+15}:\\
\;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot \frac{x}{y - t}}{z}\\
\end{array}
Results
| Original | 6.9 |
|---|---|
| Target | 2.1 |
| Herbie | 2.0 |
if (-.f64 (*.f64 y z) (*.f64 t z)) < -2.0000000000000001e256 or -1e-100 < (-.f64 (*.f64 y z) (*.f64 t z)) < 4.00000000000000027e-138Initial program 12.2
Simplified2.1
if -2.0000000000000001e256 < (-.f64 (*.f64 y z) (*.f64 t z)) < -1e-100Initial program 0.3
Simplified0.2
if 4.00000000000000027e-138 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1e15Initial program 0.3
Simplified0.3
Taylor expanded in x around 0 0.3
Simplified0.3
if 1e15 < (-.f64 (*.f64 y z) (*.f64 t z)) Initial program 10.0
Simplified6.8
Taylor expanded in x around 0 6.8
Simplified6.3
Applied egg-rr3.7
Final simplification2.0
| Alternative 1 | |
|---|---|
| Error | 4.5 |
| Cost | 836 |
| Alternative 2 | |
|---|---|
| Error | 4.5 |
| Cost | 836 |
| Alternative 3 | |
|---|---|
| Error | 4.6 |
| Cost | 836 |
| Alternative 4 | |
|---|---|
| Error | 16.9 |
| Cost | 713 |
| Alternative 5 | |
|---|---|
| Error | 16.6 |
| Cost | 713 |
| Alternative 6 | |
|---|---|
| Error | 16.6 |
| Cost | 713 |
| Alternative 7 | |
|---|---|
| Error | 16.6 |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Error | 5.6 |
| Cost | 576 |
| Alternative 9 | |
|---|---|
| Error | 31.5 |
| Cost | 448 |
herbie shell --seed 2022343
(FPCore (x y z t)
:name "Linear.Projection:infinitePerspective from linear-1.19.1.3, A"
:precision binary64
:herbie-target
(if (< (/ (* x 2.0) (- (* y z) (* t z))) -2.559141628295061e-13) (* (/ x (* (- y t) z)) 2.0) (if (< (/ (* x 2.0) (- (* y z) (* t z))) 1.045027827330126e-269) (/ (* (/ x z) 2.0) (- y t)) (* (/ x (* (- y t) z)) 2.0)))
(/ (* x 2.0) (- (* y z) (* t z))))