(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (/ x (- y t)))
(t_2 (- (* y z) (* z t)))
(t_3 (* 2.0 (/ x (* z (- y t))))))
(if (<= t_2 -1e+230)
(* 2.0 (/ 1.0 (/ z t_1)))
(if (<= t_2 -1e-244)
t_3
(if (<= t_2 2e-106)
(* 2.0 (/ t_1 z))
(if (<= t_2 5e+264) t_3 (* 2.0 (* (/ 1.0 (- y t)) (/ x 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 = x / (y - t);
double t_2 = (y * z) - (z * t);
double t_3 = 2.0 * (x / (z * (y - t)));
double tmp;
if (t_2 <= -1e+230) {
tmp = 2.0 * (1.0 / (z / t_1));
} else if (t_2 <= -1e-244) {
tmp = t_3;
} else if (t_2 <= 2e-106) {
tmp = 2.0 * (t_1 / z);
} else if (t_2 <= 5e+264) {
tmp = t_3;
} else {
tmp = 2.0 * ((1.0 / (y - t)) * (x / 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) :: t_3
real(8) :: tmp
t_1 = x / (y - t)
t_2 = (y * z) - (z * t)
t_3 = 2.0d0 * (x / (z * (y - t)))
if (t_2 <= (-1d+230)) then
tmp = 2.0d0 * (1.0d0 / (z / t_1))
else if (t_2 <= (-1d-244)) then
tmp = t_3
else if (t_2 <= 2d-106) then
tmp = 2.0d0 * (t_1 / z)
else if (t_2 <= 5d+264) then
tmp = t_3
else
tmp = 2.0d0 * ((1.0d0 / (y - t)) * (x / 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 = x / (y - t);
double t_2 = (y * z) - (z * t);
double t_3 = 2.0 * (x / (z * (y - t)));
double tmp;
if (t_2 <= -1e+230) {
tmp = 2.0 * (1.0 / (z / t_1));
} else if (t_2 <= -1e-244) {
tmp = t_3;
} else if (t_2 <= 2e-106) {
tmp = 2.0 * (t_1 / z);
} else if (t_2 <= 5e+264) {
tmp = t_3;
} else {
tmp = 2.0 * ((1.0 / (y - t)) * (x / 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 = x / (y - t) t_2 = (y * z) - (z * t) t_3 = 2.0 * (x / (z * (y - t))) tmp = 0 if t_2 <= -1e+230: tmp = 2.0 * (1.0 / (z / t_1)) elif t_2 <= -1e-244: tmp = t_3 elif t_2 <= 2e-106: tmp = 2.0 * (t_1 / z) elif t_2 <= 5e+264: tmp = t_3 else: tmp = 2.0 * ((1.0 / (y - t)) * (x / 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(x / Float64(y - t)) t_2 = Float64(Float64(y * z) - Float64(z * t)) t_3 = Float64(2.0 * Float64(x / Float64(z * Float64(y - t)))) tmp = 0.0 if (t_2 <= -1e+230) tmp = Float64(2.0 * Float64(1.0 / Float64(z / t_1))); elseif (t_2 <= -1e-244) tmp = t_3; elseif (t_2 <= 2e-106) tmp = Float64(2.0 * Float64(t_1 / z)); elseif (t_2 <= 5e+264) tmp = t_3; else tmp = Float64(2.0 * Float64(Float64(1.0 / Float64(y - t)) * Float64(x / 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 = x / (y - t); t_2 = (y * z) - (z * t); t_3 = 2.0 * (x / (z * (y - t))); tmp = 0.0; if (t_2 <= -1e+230) tmp = 2.0 * (1.0 / (z / t_1)); elseif (t_2 <= -1e-244) tmp = t_3; elseif (t_2 <= 2e-106) tmp = 2.0 * (t_1 / z); elseif (t_2 <= 5e+264) tmp = t_3; else tmp = 2.0 * ((1.0 / (y - t)) * (x / 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[(x / N[(y - t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(2.0 * N[(x / N[(z * N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -1e+230], N[(2.0 * N[(1.0 / N[(z / t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, -1e-244], t$95$3, If[LessEqual[t$95$2, 2e-106], N[(2.0 * N[(t$95$1 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$2, 5e+264], t$95$3, N[(2.0 * N[(N[(1.0 / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(x / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := \frac{x}{y - t}\\
t_2 := y \cdot z - z \cdot t\\
t_3 := 2 \cdot \frac{x}{z \cdot \left(y - t\right)}\\
\mathbf{if}\;t_2 \leq -1 \cdot 10^{+230}:\\
\;\;\;\;2 \cdot \frac{1}{\frac{z}{t_1}}\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-244}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 \leq 2 \cdot 10^{-106}:\\
\;\;\;\;2 \cdot \frac{t_1}{z}\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+264}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(\frac{1}{y - t} \cdot \frac{x}{z}\right)\\
\end{array}
Results
| Original | 7.1 |
|---|---|
| Target | 2.1 |
| Herbie | 0.6 |
if (-.f64 (*.f64 y z) (*.f64 t z)) < -1.0000000000000001e230Initial program 13.2
Simplified0.2
Applied egg-rr0.2
Applied egg-rr0.8
if -1.0000000000000001e230 < (-.f64 (*.f64 y z) (*.f64 t z)) < -9.9999999999999993e-245 or 1.99999999999999988e-106 < (-.f64 (*.f64 y z) (*.f64 t z)) < 5.00000000000000033e264Initial program 0.2
Simplified8.7
Applied egg-rr0.4
Taylor expanded in x around 0 0.2
if -9.9999999999999993e-245 < (-.f64 (*.f64 y z) (*.f64 t z)) < 1.99999999999999988e-106Initial program 11.8
Simplified3.0
Applied egg-rr3.1
Applied egg-rr3.4
if 5.00000000000000033e264 < (-.f64 (*.f64 y z) (*.f64 t z)) Initial program 23.6
Simplified0.2
Applied egg-rr0.3
Final simplification0.6
herbie shell --seed 2022210
(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))))