total rewrite using symbolic derivatives