# The Einstein Puzzle

• From: "Costello, Roger L." <costello@mitre.org>
• To: "xml-dev@lists.xml.org" <xml-dev@lists.xml.org>
• Date: Mon, 15 Jan 2018 13:59:59 +0000

 Hi Folks,   Scenario: You create an XML Schema that specifies the structure of XML instances. You create a Schematron schema that specifies constraints.   Sometimes constraints are complex. In such cases it may not be immediately obvious what instances satisfy the constraints. The Einstein puzzle is a neat example of this.   Below I show the Einstein puzzle. Then I show how to automatically generate—from the constraints—the set of instances.   The Einstein Puzzle There are five houses of different colors next to each other on the same road. In each house lives a man of a different nationality. Every man has his favorite drink, his favorite brand of cigarettes, and keeps pets of a particular kind. The Englishman lives in the red house. The Swede keeps dogs. The Dane drinks tea. The green house is just to the left of the white one. The owner of the green house drinks coffee. The Pall Mall smoker keeps birds. The owner of the yellow house smokes Dunhills. The man in the center house drinks milk. The Norwegian lives in the first house. The Blend smoker has a neighbor who keeps cats. The man who smokes Blue Masters drinks beer. The man who keeps horses lives next to the Dunhill smoker. The German smokes Prince. The Norwegian lives next to the blue house. The Blend smoker has a neighbor who drinks water. Create an XML Schema. Create a Schematron schema. What are the valid instances? In other words, what is the color of house1? What is the nationality of the person living in house1? What is his favorite drink? What brand of cigarette does he smoke? What is his pet? Ditto for the other houses. Perhaps you created an XML Schema that specifies XML instances be structured like this:             ...         ...         ...         ...         ...         ... Your Schematron schema specifies the 15 constraints listed above. Good. Now, what is a valid instance? ………. I’m waiting ………. still waiting ………. give up? The constraints in the Einstein puzzle are pretty complex. It’s not immediately obvious the instances that satisfy the constraints. And there’s no tool support to help you find the instances. That’s a problem. Here’s the state of technology as I see it: We have languages and tools (e.g., XML Schema/Saxon, Schematron/XSLT Processor) for expressing structure and constraints. But we do not have languages and tools which auto-generate the instances that satisfy the structure and constraints: The Einstein puzzle is an example of a constraint satisfaction problem – given a bunch of constraints, what are the instances that satisfy the constraints. There are tools called SAT (satisfiability) tools which can evaluate a bunch of constraints and tell you the instances that satisfy the constraints. In the last 20 years there has been a revolution in SAT technology. Today, SAT tools, such as SAT4j (SAT for Java), can solve enormous constraint expressions. 20 years ago it would have taken a supercomputer days to solve expressions that can today be solved in a few seconds, using an ordinary laptop. Here's what Donald Knuth says: Enormous technical breakthroughs in recent years have led to amazingly good ways to approach the satisfiability problem. We now have algorithms that are much more efficient than anyone had dared believe possible before the year 2000. These so-called “SAT solvers” are able to handle industrial-strength problems, involving millions of variables. [Donald Knuth, Satisfiability and the Art of Computer Programming] Professor Daniel Jackson and his team at MIT have created a language and tool (the tool wraps SAT4J) called Alloy. Alloy can show you all the instances satisfying a set of constraints. Want to see the solution to the Einstein Puzzle? Want to extend your XML skills to express more complex constraints and have a tool automatically generate the instances satisfying the constraints? See here: http://xfront.com/Alloy/Einstein-Puzzle.docx /Roger

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]

### PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
 RSS 2.0 Atom 0.3 Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.