Knowledge in Action: Logical Foundations for Specifying and Implementing Dynamical Systems