Programming with dual numbers and its applications in mechanisms design