From 33eddd2fb32e0ee673848200ca83c7dda8fc0208 Mon Sep 17 00:00:00 2001 From: Nuno Sempere Date: Thu, 24 Sep 2020 13:51:43 +0200 Subject: [PATCH] Explained problems with reverse shooting --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index de542c9..6f7b34d 100644 --- a/README.md +++ b/README.md @@ -42,3 +42,27 @@ print(x) ``` The two examples should give the same results, but don't. + +### Why reverse shooting doesn't work + +Consider this example: + +```r +## Stylized forward shooting + +x <- 0 +for(i in c(1:200)){ + x <- x + 7^i +} + +## Stylized reverse shooting + +y <- x +for(i in c(200:1)){ + y <- y - 7^i +} +print(y) +# [1] -3.762262199769919175323e+152 +``` + +Here, `y` should at the end be 0, but floating point errors ensure that it isn't. Given that our variables grow exponentially, we work with very large numbers and reverse shooting encounters similar errors.