{"action":"created","issue":{"url":"https://api.github.com/repos/casadi/casadi/issues/1395","labels_url":"https://api.github.com/repos/casadi/casadi/issues/1395/labels{/name}","comments_url":"https://api.github.com/repos/casadi/casadi/issues/1395/comments","events_url":"https://api.github.com/repos/casadi/casadi/issues/1395/events","html_url":"https://github.com/casadi/casadi/issues/1395","id":69203645,"number":1395,"title":"Implement \"fold\" node in MX","user":{"login":"jaeandersson","id":2487645,"avatar_url":"https://avatars.githubusercontent.com/u/2487645?v=3","gravatar_id":"","url":"https://api.github.com/users/jaeandersson","html_url":"https://github.com/jaeandersson","followers_url":"https://api.github.com/users/jaeandersson/followers","following_url":"https://api.github.com/users/jaeandersson/following{/other_user}","gists_url":"https://api.github.com/users/jaeandersson/gists{/gist_id}","starred_url":"https://api.github.com/users/jaeandersson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaeandersson/subscriptions","organizations_url":"https://api.github.com/users/jaeandersson/orgs","repos_url":"https://api.github.com/users/jaeandersson/repos","events_url":"https://api.github.com/users/jaeandersson/events{/privacy}","received_events_url":"https://api.github.com/users/jaeandersson/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/casadi/casadi/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"open","locked":false,"assignee":{"login":"jaeandersson","id":2487645,"avatar_url":"https://avatars.githubusercontent.com/u/2487645?v=3","gravatar_id":"","url":"https://api.github.com/users/jaeandersson","html_url":"https://github.com/jaeandersson","followers_url":"https://api.github.com/users/jaeandersson/followers","following_url":"https://api.github.com/users/jaeandersson/following{/other_user}","gists_url":"https://api.github.com/users/jaeandersson/gists{/gist_id}","starred_url":"https://api.github.com/users/jaeandersson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaeandersson/subscriptions","organizations_url":"https://api.github.com/users/jaeandersson/orgs","repos_url":"https://api.github.com/users/jaeandersson/repos","events_url":"https://api.github.com/users/jaeandersson/events{/privacy}","received_events_url":"https://api.github.com/users/jaeandersson/received_events","type":"User","site_admin":false},"milestone":null,"comments":8,"created_at":"2015-04-17T19:37:42Z","updated_at":"2015-04-19T15:20:04Z","closed_at":null,"body":"Cf. #1064."},"comment":{"url":"https://api.github.com/repos/casadi/casadi/issues/comments/94287497","html_url":"https://github.com/casadi/casadi/issues/1395#issuecomment-94287497","issue_url":"https://api.github.com/repos/casadi/casadi/issues/1395","id":94287497,"user":{"login":"jaeandersson","id":2487645,"avatar_url":"https://avatars.githubusercontent.com/u/2487645?v=3","gravatar_id":"","url":"https://api.github.com/users/jaeandersson","html_url":"https://github.com/jaeandersson","followers_url":"https://api.github.com/users/jaeandersson/followers","following_url":"https://api.github.com/users/jaeandersson/following{/other_user}","gists_url":"https://api.github.com/users/jaeandersson/gists{/gist_id}","starred_url":"https://api.github.com/users/jaeandersson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaeandersson/subscriptions","organizations_url":"https://api.github.com/users/jaeandersson/orgs","repos_url":"https://api.github.com/users/jaeandersson/repos","events_url":"https://api.github.com/users/jaeandersson/events{/privacy}","received_events_url":"https://api.github.com/users/jaeandersson/received_events","type":"User","site_admin":false},"created_at":"2015-04-19T15:20:03Z","updated_at":"2015-04-19T15:20:03Z","body":"The reverse mode AD can be calculated using two mapAccum.\r\n1. Taping mapAccum (with g(x,u) := x)\r\n```\r\ninputs: x[0], u[0],..., u[N-1]\r\nfor k=0, ..., N-1\r\n  x[k+1] = f(x[k], u[k])\r\noutputs: x[1], ..., x[N]\r\n```\r\n2. Reverse sweep mapAccum:\r\n```\r\ninputs: z[0], v[0],..., v[N-1]\r\nfor k=0, ..., N-1\r\n  w[k] = adj_g(z[k], v[k])\r\n  z[k+1] = adj_f(z[k], v[k])\r\noutputs: w[0], ..., w[N-1], z[N]\r\n```\r\nWhere:\r\n  * `v[k] := {u[N-1-k], x[N-k]}`\r\n  * `w[k] := adj_u[N-1-k]`\r\n  * `z[k] := adj_x[N-k]`\r\n"}}