Generating Magical Performances with Constraint Programming (Short Paper)

Author Guilherme de Azevedo Silveira

Thumbnail PDF


  • Filesize: 0.72 MB
  • 13 pages

Document Identifiers

Author Details

Guilherme de Azevedo Silveira
  • Alura, São Paulo, Brazil


We thank Daniela Mikyung Song for assistance providing the card designs and illustrations.

Cite AsGet BibTex

Guilherme de Azevedo Silveira. Generating Magical Performances with Constraint Programming (Short Paper). In 27th International Conference on Principles and Practice of Constraint Programming (CP 2021). Leibniz International Proceedings in Informatics (LIPIcs), Volume 210, pp. 10:1-10:13, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2021)


Professional magicians employ the use of interesting properties of a deck of cards to create magical effects. These properties were traditionally discovered through trial and error, the application of heuristics or analytical proofs. We discuss the limitations of relying on humans for such methods and present how professional magicians can use constraint programming as a computer-aided design tool to search for desired properties in a deck of cards. Furthermore, we implement a solution in Python making use of generative magic to design a new effect, demonstrating how this process broadens the level of freedom a magician can decree to their volunteers while retaining control of the outcomes of the magic. Finally, we demonstrate the model can be easily adapted to multiple languages.

Subject Classification

ACM Subject Classification
  • Applied computing → Computer-aided design
  • Theory of computation → Constraint and logic programming
  • Constraint
  • generative design
  • computer aided design
  • constraint programming
  • generative magic
  • magical performance


  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    PDF Downloads


  1. Simon Aronson. A Stack To Remember. Self-published, 1979. Google Scholar
  2. J. B. Bobo. WATCH THIS ONE! Lloyd E. Jones, 1947. Google Scholar
  3. Robert Cassidy. The Art of Mentalism. Collectors' Workshop, 1984. Google Scholar
  4. Michael Close. Workers Number 5. Self-published, 1996. Google Scholar
  5. Michael Close. Closely Guarded Secrets., 2 edition, 2004. Google Scholar
  6. Guilherme de Azevedo Silveira. Freedom of spelling demonstration, 2021. URL:
  7. Guilherme de Azevedo Silveira. Freedom of spelling source code, July 2021. URL:
  8. Guilherme de Azevedo Silveira. Generative magic, 2021. URL:
  9. Leonardo de Moura and Nikolaj Bjørner. Z3: An Efficient SMT Solver. In David Hutchison, Takeo Kanade, Josef Kittler, Jon M. Kleinberg, Friedemann Mattern, John C. Mitchell, Moni Naor, Oscar Nierstrasz, C. Pandu Rangan, Bernhard Steffen, Madhu Sudan, Demetri Terzopoulos, Doug Tygar, Moshe Y. Vardi, Gerhard Weikum, C. R. Ramakrishnan, and Jakob Rehof, editors, Tools and Algorithms for the Construction and Analysis of Systems, volume 4963, pages 337-340. Springer Berlin Heidelberg, Berlin, Heidelberg, 2008. URL:
  10. Persi Diaconis, R.L Graham, and William M Kantor. The mathematics of perfect shuffles. Advances in Applied Mathematics, 4(2):175-196, 1983. URL:
  11. Karl Fulves. Hocus Poker. Self-published, 1982. Google Scholar
  12. Glenn Gravatt. Encyclopedia of Self-working Card Tricks. Quality Magic Company, 1936. Google Scholar
  13. Charles R. Harris, K. Jarrod Millman, St'efan J. van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan Haldane, Jaime Fern'andez del R'ıo, Mark Wiebe, Pearu Peterson, Pierre G'erard-Marchant, Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and Travis E. Oliphant. Array programming with NumPy. Nature, 585(7825):357-362, 2020. URL:
  14. Pit Hartling. In Order To Amaze. Self-published, 2016. Google Scholar
  15. Jean Hugard and Frederick Braue. The royal road to card magic. Farber and Farber, London, 1979. OCLC: 25036735. Google Scholar
  16. Jean Hugard, John J. Crimmins, and Glenn G. Gravatt. Encyclopedia of card tricks. Dover Publications, New York, 1974. Google Scholar
  17. Edward Marlo. The Ten Hand Poker Stack. Self-published, 1974. Google Scholar
  18. Hugh Miller. Baker’s Bonanza. Supreme Magic Publication, 2 edition, 1978. Google Scholar
  19. Stephen Minch. The Collected Works of Alex Elmsley, volume 2. L & L Publishing, 1994. Google Scholar
  20. S. Brent Morris. The basic mathematics of the faro shuffle. Pi Mu Epsilon Journal, 6(2):85-92, 1975. URL:
  21. S.Brent Morris and Robert E. Hartwig. The generalized faro shuffle. Discrete Mathematics, 15(4):333-346, 1976. URL:
  22. Nike Arts. Enciclopedia de los juegos de cartas. RobinBook, Barcelona, 1999. OCLC: 807845266. Google Scholar
  23. Darwin Ortiz. Darwin Ortiz on casino gambling: the complete guide to playing and winning. Dodd, Mead & Co, New York, 1st ed edition, 1986. Google Scholar
  24. McCabe Pete and Michael Close. The PM Card System., 2019. Google Scholar
  25. David Regal. Close-up & personal. Hermetic Press, Seattle, Wash., 1999. OCLC: 45272617. Google Scholar
Questions / Remarks / Feedback

Feedback for Dagstuhl Publishing

Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail