(FPCore (x y z t) :precision binary64 (/ (* x 2.0) (- (* y z) (* t z))))
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* 2.0 (/ (/ x z) (- y t))))
(t_2 (- (* y z) (* z t)))
(t_3 (/ x (* z (* (- y t) 0.5)))))
(if (<= t_2 -2e+270)
t_1
(if (<= t_2 -1e-123)
t_3
(if (<= t_2 1e-274)
(/ (/ (* 2.0 x) (- y t)) z)
(if (<= t_2 5e+238) t_3 t_1))))))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 = 2.0 * ((x / z) / (y - t));
double t_2 = (y * z) - (z * t);
double t_3 = x / (z * ((y - t) * 0.5));
double tmp;
if (t_2 <= -2e+270) {
tmp = t_1;
} else if (t_2 <= -1e-123) {
tmp = t_3;
} else if (t_2 <= 1e-274) {
tmp = ((2.0 * x) / (y - t)) / z;
} else if (t_2 <= 5e+238) {
tmp = t_3;
} else {
tmp = t_1;
}
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 = 2.0d0 * ((x / z) / (y - t))
t_2 = (y * z) - (z * t)
t_3 = x / (z * ((y - t) * 0.5d0))
if (t_2 <= (-2d+270)) then
tmp = t_1
else if (t_2 <= (-1d-123)) then
tmp = t_3
else if (t_2 <= 1d-274) then
tmp = ((2.0d0 * x) / (y - t)) / z
else if (t_2 <= 5d+238) then
tmp = t_3
else
tmp = t_1
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 = 2.0 * ((x / z) / (y - t));
double t_2 = (y * z) - (z * t);
double t_3 = x / (z * ((y - t) * 0.5));
double tmp;
if (t_2 <= -2e+270) {
tmp = t_1;
} else if (t_2 <= -1e-123) {
tmp = t_3;
} else if (t_2 <= 1e-274) {
tmp = ((2.0 * x) / (y - t)) / z;
} else if (t_2 <= 5e+238) {
tmp = t_3;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): return (x * 2.0) / ((y * z) - (t * z))
def code(x, y, z, t): t_1 = 2.0 * ((x / z) / (y - t)) t_2 = (y * z) - (z * t) t_3 = x / (z * ((y - t) * 0.5)) tmp = 0 if t_2 <= -2e+270: tmp = t_1 elif t_2 <= -1e-123: tmp = t_3 elif t_2 <= 1e-274: tmp = ((2.0 * x) / (y - t)) / z elif t_2 <= 5e+238: tmp = t_3 else: tmp = t_1 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(2.0 * Float64(Float64(x / z) / Float64(y - t))) t_2 = Float64(Float64(y * z) - Float64(z * t)) t_3 = Float64(x / Float64(z * Float64(Float64(y - t) * 0.5))) tmp = 0.0 if (t_2 <= -2e+270) tmp = t_1; elseif (t_2 <= -1e-123) tmp = t_3; elseif (t_2 <= 1e-274) tmp = Float64(Float64(Float64(2.0 * x) / Float64(y - t)) / z); elseif (t_2 <= 5e+238) tmp = t_3; else tmp = t_1; 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 = 2.0 * ((x / z) / (y - t)); t_2 = (y * z) - (z * t); t_3 = x / (z * ((y - t) * 0.5)); tmp = 0.0; if (t_2 <= -2e+270) tmp = t_1; elseif (t_2 <= -1e-123) tmp = t_3; elseif (t_2 <= 1e-274) tmp = ((2.0 * x) / (y - t)) / z; elseif (t_2 <= 5e+238) tmp = t_3; else tmp = t_1; 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[(2.0 * N[(N[(x / z), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(y * z), $MachinePrecision] - N[(z * t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$3 = N[(x / N[(z * N[(N[(y - t), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$2, -2e+270], t$95$1, If[LessEqual[t$95$2, -1e-123], t$95$3, If[LessEqual[t$95$2, 1e-274], N[(N[(N[(2.0 * x), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision], If[LessEqual[t$95$2, 5e+238], t$95$3, t$95$1]]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := 2 \cdot \frac{\frac{x}{z}}{y - t}\\
t_2 := y \cdot z - z \cdot t\\
t_3 := \frac{x}{z \cdot \left(\left(y - t\right) \cdot 0.5\right)}\\
\mathbf{if}\;t_2 \leq -2 \cdot 10^{+270}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_2 \leq -1 \cdot 10^{-123}:\\
\;\;\;\;t_3\\
\mathbf{elif}\;t_2 \leq 10^{-274}:\\
\;\;\;\;\frac{\frac{2 \cdot x}{y - t}}{z}\\
\mathbf{elif}\;t_2 \leq 5 \cdot 10^{+238}:\\
\;\;\;\;t_3\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 6.9 |
|---|---|
| Target | 2.5 |
| Herbie | 0.4 |
if (-.f64 (*.f64 y z) (*.f64 t z)) < -2.0000000000000001e270 or 4.99999999999999995e238 < (-.f64 (*.f64 y z) (*.f64 t z)) Initial program 18.8
Simplified0.3
if -2.0000000000000001e270 < (-.f64 (*.f64 y z) (*.f64 t z)) < -1.0000000000000001e-123 or 9.99999999999999966e-275 < (-.f64 (*.f64 y z) (*.f64 t z)) < 4.99999999999999995e238Initial program 0.2
Simplified9.2
Taylor expanded in x around 0 0.2
Simplified9.2
Applied egg-rr0.2
if -1.0000000000000001e-123 < (-.f64 (*.f64 y z) (*.f64 t z)) < 9.99999999999999966e-275Initial program 16.2
Simplified3.4
Taylor expanded in x around 0 16.2
Simplified3.6
Applied egg-rr2.9
Final simplification0.4
herbie shell --seed 2022211
(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))))