| Alternative 1 | |
|---|---|
| Error | 2.4 |
| Cost | 1096 |
(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) (* t z))) (t_2 (/ (* 2.0 (/ x z)) (- y t))))
(if (<= t_1 -2e+299)
(* (/ x (- y t)) (/ 2.0 z))
(if (<= t_1 -2e-264)
(* (/ x (* (- y t) z)) 2.0)
(if (<= t_1 1e-78)
t_2
(if (<= t_1 4e+46) (* x (/ (/ 2.0 (- y t)) z)) 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) - (t * z);
double t_2 = (2.0 * (x / z)) / (y - t);
double tmp;
if (t_1 <= -2e+299) {
tmp = (x / (y - t)) * (2.0 / z);
} else if (t_1 <= -2e-264) {
tmp = (x / ((y - t) * z)) * 2.0;
} else if (t_1 <= 1e-78) {
tmp = t_2;
} else if (t_1 <= 4e+46) {
tmp = x * ((2.0 / (y - t)) / z);
} 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) - (t * z)
t_2 = (2.0d0 * (x / z)) / (y - t)
if (t_1 <= (-2d+299)) then
tmp = (x / (y - t)) * (2.0d0 / z)
else if (t_1 <= (-2d-264)) then
tmp = (x / ((y - t) * z)) * 2.0d0
else if (t_1 <= 1d-78) then
tmp = t_2
else if (t_1 <= 4d+46) then
tmp = x * ((2.0d0 / (y - t)) / z)
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) - (t * z);
double t_2 = (2.0 * (x / z)) / (y - t);
double tmp;
if (t_1 <= -2e+299) {
tmp = (x / (y - t)) * (2.0 / z);
} else if (t_1 <= -2e-264) {
tmp = (x / ((y - t) * z)) * 2.0;
} else if (t_1 <= 1e-78) {
tmp = t_2;
} else if (t_1 <= 4e+46) {
tmp = x * ((2.0 / (y - t)) / z);
} 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) - (t * z) t_2 = (2.0 * (x / z)) / (y - t) tmp = 0 if t_1 <= -2e+299: tmp = (x / (y - t)) * (2.0 / z) elif t_1 <= -2e-264: tmp = (x / ((y - t) * z)) * 2.0 elif t_1 <= 1e-78: tmp = t_2 elif t_1 <= 4e+46: tmp = x * ((2.0 / (y - t)) / z) 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(t * z)) t_2 = Float64(Float64(2.0 * Float64(x / z)) / Float64(y - t)) tmp = 0.0 if (t_1 <= -2e+299) tmp = Float64(Float64(x / Float64(y - t)) * Float64(2.0 / z)); elseif (t_1 <= -2e-264) tmp = Float64(Float64(x / Float64(Float64(y - t) * z)) * 2.0); elseif (t_1 <= 1e-78) tmp = t_2; elseif (t_1 <= 4e+46) tmp = Float64(x * Float64(Float64(2.0 / Float64(y - t)) / z)); 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) - (t * z); t_2 = (2.0 * (x / z)) / (y - t); tmp = 0.0; if (t_1 <= -2e+299) tmp = (x / (y - t)) * (2.0 / z); elseif (t_1 <= -2e-264) tmp = (x / ((y - t) * z)) * 2.0; elseif (t_1 <= 1e-78) tmp = t_2; elseif (t_1 <= 4e+46) tmp = x * ((2.0 / (y - t)) / z); 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[(t * z), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * N[(x / z), $MachinePrecision]), $MachinePrecision] / N[(y - t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -2e+299], N[(N[(x / N[(y - t), $MachinePrecision]), $MachinePrecision] * N[(2.0 / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, -2e-264], N[(N[(x / N[(N[(y - t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision] * 2.0), $MachinePrecision], If[LessEqual[t$95$1, 1e-78], t$95$2, If[LessEqual[t$95$1, 4e+46], N[(x * N[(N[(2.0 / N[(y - t), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], t$95$2]]]]]]
\frac{x \cdot 2}{y \cdot z - t \cdot z}
\begin{array}{l}
t_1 := y \cdot z - t \cdot z\\
t_2 := \frac{2 \cdot \frac{x}{z}}{y - t}\\
\mathbf{if}\;t_1 \leq -2 \cdot 10^{+299}:\\
\;\;\;\;\frac{x}{y - t} \cdot \frac{2}{z}\\
\mathbf{elif}\;t_1 \leq -2 \cdot 10^{-264}:\\
\;\;\;\;\frac{x}{\left(y - t\right) \cdot z} \cdot 2\\
\mathbf{elif}\;t_1 \leq 10^{-78}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;t_1 \leq 4 \cdot 10^{+46}:\\
\;\;\;\;x \cdot \frac{\frac{2}{y - t}}{z}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
Results
| Original | 6.9 |
|---|---|
| Target | 2.3 |
| Herbie | 1.8 |
if (-.f64 (*.f64 y z) (*.f64 t z)) < -2.0000000000000001e299Initial program 18.5
Simplified18.5
[Start]18.5 | \[ \frac{x \cdot 2}{y \cdot z - t \cdot z}
\] |
|---|---|
rational.json-simplify-2 [=>]18.5 | \[ \frac{x \cdot 2}{\color{blue}{z \cdot y} - t \cdot z}
\] |
rational.json-simplify-52 [=>]18.5 | \[ \frac{x \cdot 2}{\color{blue}{z \cdot \left(y - t\right)}}
\] |
Applied egg-rr0.1
if -2.0000000000000001e299 < (-.f64 (*.f64 y z) (*.f64 t z)) < -2e-264Initial program 0.2
Simplified8.2
[Start]0.2 | \[ \frac{x \cdot 2}{y \cdot z - t \cdot z}
\] |
|---|---|
rational.json-simplify-2 [=>]0.2 | \[ \frac{x \cdot 2}{\color{blue}{z \cdot y} - t \cdot z}
\] |
rational.json-simplify-52 [=>]0.2 | \[ \frac{x \cdot 2}{\color{blue}{z \cdot \left(y - t\right)}}
\] |
rational.json-simplify-46 [=>]8.2 | \[ \color{blue}{\frac{\frac{x \cdot 2}{z}}{y - t}}
\] |
rational.json-simplify-49 [=>]8.2 | \[ \frac{\color{blue}{2 \cdot \frac{x}{z}}}{y - t}
\] |
Applied egg-rr7.9
Simplified8.2
[Start]7.9 | \[ \frac{\frac{2}{y - t}}{\frac{z}{x}} + 0
\] |
|---|---|
rational.json-simplify-4 [=>]7.9 | \[ \color{blue}{\frac{\frac{2}{y - t}}{\frac{z}{x}}}
\] |
rational.json-simplify-47 [=>]8.2 | \[ \color{blue}{\frac{2}{\left(y - t\right) \cdot \frac{z}{x}}}
\] |
Applied egg-rr0.2
if -2e-264 < (-.f64 (*.f64 y z) (*.f64 t z)) < 9.99999999999999999e-79 or 4e46 < (-.f64 (*.f64 y z) (*.f64 t z)) Initial program 10.9
Simplified3.9
[Start]10.9 | \[ \frac{x \cdot 2}{y \cdot z - t \cdot z}
\] |
|---|---|
rational.json-simplify-2 [=>]10.9 | \[ \frac{x \cdot 2}{\color{blue}{z \cdot y} - t \cdot z}
\] |
rational.json-simplify-52 [=>]8.5 | \[ \frac{x \cdot 2}{\color{blue}{z \cdot \left(y - t\right)}}
\] |
rational.json-simplify-46 [=>]3.9 | \[ \color{blue}{\frac{\frac{x \cdot 2}{z}}{y - t}}
\] |
rational.json-simplify-49 [=>]3.9 | \[ \frac{\color{blue}{2 \cdot \frac{x}{z}}}{y - t}
\] |
if 9.99999999999999999e-79 < (-.f64 (*.f64 y z) (*.f64 t z)) < 4e46Initial program 0.4
Simplified0.4
[Start]0.4 | \[ \frac{x \cdot 2}{y \cdot z - t \cdot z}
\] |
|---|---|
rational.json-simplify-2 [=>]0.4 | \[ \frac{\color{blue}{2 \cdot x}}{y \cdot z - t \cdot z}
\] |
rational.json-simplify-49 [=>]0.3 | \[ \color{blue}{x \cdot \frac{2}{y \cdot z - t \cdot z}}
\] |
rational.json-simplify-2 [=>]0.3 | \[ x \cdot \frac{2}{\color{blue}{z \cdot y} - t \cdot z}
\] |
rational.json-simplify-52 [=>]0.3 | \[ x \cdot \frac{2}{\color{blue}{z \cdot \left(y - t\right)}}
\] |
rational.json-simplify-46 [=>]0.3 | \[ x \cdot \color{blue}{\frac{\frac{2}{z}}{y - t}}
\] |
rational.json-simplify-44 [=>]0.4 | \[ x \cdot \color{blue}{\frac{\frac{2}{y - t}}{z}}
\] |
Final simplification1.8
| Alternative 1 | |
|---|---|
| Error | 2.4 |
| Cost | 1096 |
| Alternative 2 | |
|---|---|
| Error | 2.7 |
| Cost | 840 |
| Alternative 3 | |
|---|---|
| Error | 2.7 |
| Cost | 840 |
| Alternative 4 | |
|---|---|
| Error | 17.6 |
| Cost | 712 |
| Alternative 5 | |
|---|---|
| Error | 17.7 |
| Cost | 712 |
| Alternative 6 | |
|---|---|
| Error | 17.4 |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Error | 17.4 |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Error | 17.2 |
| Cost | 712 |
| Alternative 9 | |
|---|---|
| Error | 6.0 |
| Cost | 708 |
| Alternative 10 | |
|---|---|
| Error | 31.5 |
| Cost | 448 |
| Alternative 11 | |
|---|---|
| Error | 31.4 |
| Cost | 448 |
herbie shell --seed 2023074
(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))))