(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 (* 2.0 (/ (/ x (- y t)) z))))
(if (<= t_1 -3.913792715055396e+151)
t_2
(if (<= t_1 -1.2691724707153681e-107)
(/ (* 2.0 x) t_1)
(if (<= t_1 0.0)
(* 2.0 (/ (/ x z) (- y t)))
(if (<= t_1 1.4516736965324895e+90)
(/ (* 2.0 x) (* z (- y t)))
t_2))))))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 = 2.0 * ((x / (y - t)) / z);
double tmp;
if (t_1 <= -3.913792715055396e+151) {
tmp = t_2;
} else if (t_1 <= -1.2691724707153681e-107) {
tmp = (2.0 * x) / t_1;
} else if (t_1 <= 0.0) {
tmp = 2.0 * ((x / z) / (y - t));
} else if (t_1 <= 1.4516736965324895e+90) {
tmp = (2.0 * x) / (z * (y - t));
} else {
tmp = t_2;
}
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 = 2.0d0 * ((x / (y - t)) / z)
if (t_1 <= (-3.913792715055396d+151)) then
tmp = t_2
else if (t_1 <= (-1.2691724707153681d-107)) then
tmp = (2.0d0 * x) / t_1
else if (t_1 <= 0.0d0) then
tmp = 2.0d0 * ((x / z) / (y - t))
else if (t_1 <= 1.4516736965324895d+90) then
tmp = (2.0d0 * x) / (z * (y - t))
else
tmp = t_2
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 = 2.0 * ((x / (y - t)) / z);
double tmp;
if (t_1 <= -3.913792715055396e+151) {
tmp = t_2;
} else if (t_1 <= -1.2691724707153681e-107) {
tmp = (2.0 * x) / t_1;
} else if (t_1 <= 0.0) {
tmp = 2.0 * ((x / z) / (y - t));
} else if (t_1 <= 1.4516736965324895e+90) {
tmp = (2.0 * x) / (z * (y - t));
} else {
tmp = t_2;
}
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 = 2.0 * ((x / (y - t)) / z) tmp = 0 if t_1 <= -3.913792715055396e+151: tmp = t_2 elif t_1 <= -1.2691724707153681e-107: tmp = (2.0 * x) / t_1 elif t_1 <= 0.0: tmp = 2.0 * ((x / z) / (y - t)) elif t_1 <= 1.4516736965324895e+90: tmp = (2.0 * x) / (z * (y - t)) else: tmp = t_2 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(2.0 * Float64(Float64(x / Float64(y - t)) / z)) tmp = 0.0 if (t_1 <= -3.913792715055396e+151) tmp = t_2; elseif (t_1 <= -1.2691724707153681e-107) tmp = Float64(Float64(2.0 * x) / t_1); elseif (t_1 <= 0.0) tmp = Float64(2.0 * Float64(Float64(x / z) / Float64(y - t))); elseif (t_1 <= 1.4516736965324895e+90) tmp = Float64(Float64(2.0 * x) / Float64(z * Float64(y - t))); else tmp = t_2; 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 = 2.0 * ((x / (y - t)) / z); tmp = 0.0; if (t_1 <= -3.913792715055396e+151) tmp = t_2; elseif (t_1 <= -1.2691724707153681e-107) tmp = (2.0 * x) / t_1; elseif (t_1 <= 0.0) tmp = 2.0 * ((x / z) / (y - t)); elseif (t_1 <= 1.4516736965324895e+90) tmp = (2.0 * x) / (z * (y - t)); else tmp = t_2; 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[(2.0 * N[(N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -3.913792715055396e+151], t$95$2, If[LessEqual[t$95$1, -1.2691724707153681e-107], N[(N[(2.0 * x), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[t$95$1, 0.0], N[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 1.4516736965324895e+90], N[(N[(2.0 * x), $MachinePrecision] / N[(z * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - z \cdot t\\
t_2 := 2 \cdot \frac{\frac{x}{y - t}}{z}\\
\mathbf{if}\;t_1 \leq -3.913792715055396 \cdot 10^{+151}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq -1.2691724707153681 \cdot 10^{-107}:\\
\;\;\;\;\frac{2 \cdot x}{t_1}\\
\mathbf{elif}\;t_1 \leq 0:\\
\;\;\;\;2 \cdot \frac{\frac{x}{z}}{y - t}\\
\mathbf{elif}\;t_1 \leq 1.4516736965324895 \cdot 10^{+90}:\\
\;\;\;\;\frac{2 \cdot x}{z \cdot \left(y - t\right)}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}




Bits error versus x




Bits error versus y




Bits error versus z




Bits error versus t
Results
| Original | 6.8 |
|---|---|
| Target | 2.1 |
| Herbie | 1.3 |
if (-.f64 (*.f64 y z) (*.f64 t z)) < -3.9137927150553962e151 or 1.4516736965324895e90 < (-.f64 (*.f64 y z) (*.f64 t z)) Initial program 11.2
Simplified1.9
Applied egg-rr1.9
Applied egg-rr1.6
if -3.9137927150553962e151 < (-.f64 (*.f64 y z) (*.f64 t z)) < -1.26917247071536813e-107Initial program 0.3
if -1.26917247071536813e-107 < (-.f64 (*.f64 y z) (*.f64 t z)) < -0.0Initial program 12.6
Simplified4.2
Applied egg-rr4.3
Applied egg-rr4.2
Taylor expanded in x around 0 12.6
Simplified4.2
if -0.0 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1.4516736965324895e90Initial program 0.5
Simplified10.4
Applied egg-rr0.5
Final simplification1.3
herbie shell --seed 2022150
(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))))