Add as_scalars, similar to as_scalar, useful to produce simpler expressions in AD than before in some cases.
Comment and minor fix.
Translate all AD rules into new multifunction/map_expr_dag framework. Looks like potential for some significant savings.
Add more tests of new AD implementation.

Managed to simplify some more the tangled mess of as_tensor and
indexed that occurs in some scenarios. It remains to be seen
how much of an impact this will have on the overall output
and performance.
Add some more tests. Change sin rule to give slightly cleaner output representation.
Move apply_derivatives algorithm to ufl/algorithms/apply_derivatives.py.
Bugfix in new AD implementation. Tests pass.
Revert to previous formulation of derivatives of power, dolfin
integration tests complain.
Add a new traversal option cutoff_post_traversal, skipping subtrees of particular types. Automatically skip subtrees in map_expr_dag there the multifunction handlers take no additional argument. Modify apply_derivatives such that unneccesary subtree traversals are avoided.
Update some comments.
Implement new version of propagate_restrictions, called
apply_restrictions, using a two-level map_expr_dag and multifunction
pattern to avoid recursion and speed it up.
Delete old propagate_restrictions implementation.
Change reuse_if_possible implementation to reuse_if_untouched which only compares ids, should speed up a few auxilliary algorithms inheriting from ReuseTransformer.
Implement new check_form_arity algorithm.
Tweak a little.
Handle stack size manually in traversal algorithms, shaving off a little bit more time.