On ∃ ∀ ∃! solving: A case study on automated synthesis of magic card tricks

In formal synthesis, the goal is to find a composition of components from a finite library such that the composition satisfies a given logical specification. In this paper, we consider the problem of synthesizing magic card tricks from component actions, where some of the actions depend on non-deterministic choices made by the audience. This problem can be naturally represented as a quantified logical formula of the form: Exists a composition, Forall nondeterministic choices, Uniquely-Exists intermediate and final outputs satisfying a logical specification, that is, an (∃∀∃!) satisfiability problem. We present a novel approach to solve this problem that exploits the unique-existence of intermediate and final outputs for any given composition and choice values. We illustrate how several popular magic card tricks can be recovered using this approach. These tricks evolved through human ingenuity over decades, but we demonstrate that formal synthesis can generate a number of novel variants of these tricks within minutes. In contrast, a direct encoding to quantified SMT problem fails to find a solution in hours.

[1]  Martin Gardner,et al.  Mathematics, Magic and Mystery , 1956 .

[2]  Christophe Collewet,et al.  Optimised De Bruijn patterns for one-shot shape acquisition , 2005, Image Vis. Comput..

[3]  Sanjit A. Seshia,et al.  Combinatorial sketching for finite programs , 2006, ASPLOS XII.

[4]  Nikolaj Bjørner,et al.  Z3: An Efficient SMT Solver , 2008, TACAS.

[5]  S. Humble Magic Math Cards , 2008, The Mathematics Enthusiast.

[6]  Tom Davis Mathematical Card Tricks , 2008 .

[7]  Sumit Gulwani,et al.  Oracle-guided component-based program synthesis , 2010, 2010 ACM/IEEE 32nd International Conference on Software Engineering.

[8]  Martin Gardner,et al.  Magical Mathematics: The Mathematical Ideas That Animate Great Magic Tricks , 2011 .

[9]  Sumit Gulwani,et al.  Synthesis of loop-free programs , 2011, PLDI '11.

[10]  Rajeev Alur,et al.  Syntax-guided synthesis , 2013, 2013 Formal Methods in Computer-Aided Design.

[11]  João Fernando Ferreira,et al.  The magic of algorithm design and analysis: teaching algorithmic skills using magic card tricks , 2014, ITiCSE '14.

[12]  Sanjit A. Seshia,et al.  A theory of formal synthesis via inductive learning , 2015, Acta Informatica.