| Alternative 1 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 708 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+66}:\\
\;\;\;\;\frac{y \cdot t}{\frac{1}{x - z}}\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
\]

(FPCore (x y z t) :precision binary64 (* (- (* x y) (* z y)) t))
(FPCore (x y z t) :precision binary64 (if (<= y -2.8e+66) (/ (* y t) (/ 1.0 (- x z))) (* t (* y (- x z)))))
double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.8e+66) {
tmp = (y * t) / (1.0 / (x - z));
} else {
tmp = t * (y * (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 * y) - (z * y)) * t
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) :: tmp
if (y <= (-2.8d+66)) then
tmp = (y * t) / (1.0d0 / (x - z))
else
tmp = t * (y * (x - z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
return ((x * y) - (z * y)) * t;
}
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2.8e+66) {
tmp = (y * t) / (1.0 / (x - z));
} else {
tmp = t * (y * (x - z));
}
return tmp;
}
def code(x, y, z, t): return ((x * y) - (z * y)) * t
def code(x, y, z, t): tmp = 0 if y <= -2.8e+66: tmp = (y * t) / (1.0 / (x - z)) else: tmp = t * (y * (x - z)) return tmp
function code(x, y, z, t) return Float64(Float64(Float64(x * y) - Float64(z * y)) * t) end
function code(x, y, z, t) tmp = 0.0 if (y <= -2.8e+66) tmp = Float64(Float64(y * t) / Float64(1.0 / Float64(x - z))); else tmp = Float64(t * Float64(y * Float64(x - z))); end return tmp end
function tmp = code(x, y, z, t) tmp = ((x * y) - (z * y)) * t; end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -2.8e+66) tmp = (y * t) / (1.0 / (x - z)); else tmp = t * (y * (x - z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := N[(N[(N[(x * y), $MachinePrecision] - N[(z * y), $MachinePrecision]), $MachinePrecision] * t), $MachinePrecision]
code[x_, y_, z_, t_] := If[LessEqual[y, -2.8e+66], N[(N[(y * t), $MachinePrecision] / N[(1.0 / N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(t * N[(y * N[(x - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\left(x \cdot y - z \cdot y\right) \cdot t
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+66}:\\
\;\;\;\;\frac{y \cdot t}{\frac{1}{x - z}}\\
\mathbf{else}:\\
\;\;\;\;t \cdot \left(y \cdot \left(x - z\right)\right)\\
\end{array}
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 90.6% |
|---|---|
| Target | 96.1% |
| Herbie | 97.0% |
if y < -2.8000000000000001e66Initial program 80.9%
Simplified92.9%
[Start]80.9% | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]88.4% | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
associate-*l* [=>]92.9% | \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)}
\] |
Applied egg-rr63.2%
[Start]92.9% | \[ y \cdot \left(\left(x - z\right) \cdot t\right)
\] |
|---|---|
add-cbrt-cube [=>]63.2% | \[ \color{blue}{\sqrt[3]{\left(\left(y \cdot \left(\left(x - z\right) \cdot t\right)\right) \cdot \left(y \cdot \left(\left(x - z\right) \cdot t\right)\right)\right) \cdot \left(y \cdot \left(\left(x - z\right) \cdot t\right)\right)}}
\] |
pow3 [=>]63.2% | \[ \sqrt[3]{\color{blue}{{\left(y \cdot \left(\left(x - z\right) \cdot t\right)\right)}^{3}}}
\] |
Applied egg-rr99.7%
[Start]63.2% | \[ \sqrt[3]{{\left(y \cdot \left(\left(x - z\right) \cdot t\right)\right)}^{3}}
\] |
|---|---|
rem-cbrt-cube [=>]92.9% | \[ \color{blue}{y \cdot \left(\left(x - z\right) \cdot t\right)}
\] |
associate-*r* [=>]88.4% | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right) \cdot t}
\] |
*-commutative [=>]88.4% | \[ \color{blue}{\left(\left(x - z\right) \cdot y\right)} \cdot t
\] |
associate-*l* [=>]99.7% | \[ \color{blue}{\left(x - z\right) \cdot \left(y \cdot t\right)}
\] |
Applied egg-rr99.7%
[Start]99.7% | \[ \left(x - z\right) \cdot \left(y \cdot t\right)
\] |
|---|---|
*-commutative [=>]99.7% | \[ \color{blue}{\left(y \cdot t\right) \cdot \left(x - z\right)}
\] |
flip-- [=>]83.3% | \[ \left(y \cdot t\right) \cdot \color{blue}{\frac{x \cdot x - z \cdot z}{x + z}}
\] |
+-commutative [<=]83.3% | \[ \left(y \cdot t\right) \cdot \frac{x \cdot x - z \cdot z}{\color{blue}{z + x}}
\] |
clear-num [=>]83.2% | \[ \left(y \cdot t\right) \cdot \color{blue}{\frac{1}{\frac{z + x}{x \cdot x - z \cdot z}}}
\] |
div-inv [<=]83.3% | \[ \color{blue}{\frac{y \cdot t}{\frac{z + x}{x \cdot x - z \cdot z}}}
\] |
clear-num [=>]83.3% | \[ \frac{y \cdot t}{\color{blue}{\frac{1}{\frac{x \cdot x - z \cdot z}{z + x}}}}
\] |
+-commutative [=>]83.3% | \[ \frac{y \cdot t}{\frac{1}{\frac{x \cdot x - z \cdot z}{\color{blue}{x + z}}}}
\] |
flip-- [<=]99.7% | \[ \frac{y \cdot t}{\frac{1}{\color{blue}{x - z}}}
\] |
if -2.8000000000000001e66 < y Initial program 92.7%
Simplified94.6%
[Start]92.7% | \[ \left(x \cdot y - z \cdot y\right) \cdot t
\] |
|---|---|
distribute-rgt-out-- [=>]94.6% | \[ \color{blue}{\left(y \cdot \left(x - z\right)\right)} \cdot t
\] |
Final simplification95.4%
| Alternative 1 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 708 |
| Alternative 2 | |
|---|---|
| Accuracy | 73.4% |
| Cost | 649 |
| Alternative 3 | |
|---|---|
| Accuracy | 73.5% |
| Cost | 649 |
| Alternative 4 | |
|---|---|
| Accuracy | 91.7% |
| Cost | 580 |
| Alternative 5 | |
|---|---|
| Accuracy | 96.8% |
| Cost | 580 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.0% |
| Cost | 580 |
| Alternative 7 | |
|---|---|
| Accuracy | 55.0% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 55.2% |
| Cost | 320 |
herbie shell --seed 2023263
(FPCore (x y z t)
:name "Linear.Projection:inverseInfinitePerspective from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< t -9.231879582886777e-80) (* (* y t) (- x z)) (if (< t 2.543067051564877e+83) (* y (* t (- x z))) (* (* y (- x z)) t)))
(* (- (* x y) (* z y)) t))