include("models/cs405/JUGSinJS-E/jugspres.e"); ## to protect against loss of information whilst constructing the presentation ${{ var workIsDone = false; window.onbeforeunload = confirmBrowseAway; function confirmBrowseAway() { if (!workIsDone) { return "Are you sure? If you leave this page now, your work will NOT be saved."; } }; }}$; s0 is Slide("

Working Backwards with the JUGS Model

This model is an extension to the original JUGS model as implemented in JS-EDEN.

We now look at this model from a problem solving perspective - with particular emphasis on the benefits of Working Backwards from a solution.

To do this we will be adding to the slides and the features of this model.

For those unfamiliar with the JUGS model the original slides have been reproduced following this introduction.

To jump to the new content for this model please use the following:

currentSlide is 17;"); s14 is Slide("

Working Backwards with the JUGS Model

This is the start of our new slides.

If you have been playing around with the model already it may be helpful to reset the model at this point.

include(\"models/jugs/run.e\"); "); s17 is Slide("

The Problem

The following problem setup and analysis comes from Pólya (1990).

Given that you have a jug of capacity 9 and another of capacity 4 how can you bring only 6 units back with you?

To set up this problem you only need to change the target and the capacities of the jugs in this model as follows:

target = 6; capA = 4; capB = 9;"); s18 is Slide("

Analysis of the Problem

Up until now you have been given a problem to solve...

'Reach the target value in the jug'

...and only five tools with which to complete the goal...

'Fill A, Fill B, Empty A, Empty B and Pour'

With these current tools you can only 'Work Forwards' towards the goal of the problem.

Working forwards encourages a trial and error approach, which rarely results in success or the discovery of patterns.

"); s19 is Slide("

Working Backwards

When we find ourselves working with trial and error (rather than learning from specialised examples) we are often wasting our time.

We would rather be working on finding the single solution to the problem instead of trying all of the possibilities.

Therefore the best choice of attack is to turn the problem on its head and work from the solution back to the start.

This is what is meant by 'Working Backwards'.

"); s20 is Slide("

Working Backwards in EM

Typically when we realise we have to start from the end of the problem we have to clear our mind of the previous trials and start afresh.

However using a model which we can save and freely manipulate means that we can extend the model to match our new mental state without losing everything we might have accomplished.

In this example we just need one more feature so that we can formulate the problem from either a forwards or backwards direction:

The ability to set the capacities of the jugs ourselves

"); s21 is Slide("

Introducing the Features

We could just set the contents of Jug A and B directly to serve this purpose. However it is more flexible to build this functionality into the model itself.

We can provide the new functionality in a number of ways. In this example we have opted to leverage the extra input media in JS-EDEN and use two slider bars.

sliderA is Slider("sliderA",0,capA,1,0,0,30,280); sliderB is Slider("sliderB",0,capB,1,0,0,30,325); picture is [but1,but2,but3,but4,but5,jugA_left,jugA_right,jugA_base,jugB_left,jugB_right,jugB_base,jugA_water,jugB_water,statuslabel,sliderA,sliderB]; contentA is sliderA_value; contentB is sliderB_value;

It should be noted that use of the buttons in the original model will dominate the dependency of the sliders and the above commands will have to be executed again.

"); s22 is Slide("

Try it Yourself!

We can now manipulate the jugs' contents at will. Now that we have introduced this new functionality try working backwards from the end position to the beginning of the puzzle.

Don't be disheartened if you become stuck whilst working backwards. In doing so you have found a sub-goal closer to the starting position.

Experiment with the buttons to try and reach this new sub-goal. You may find the solution through a bright idea or through experience.

The solution is described on the next slide.

"); s23 is Slide("

Working Backwards Step by Step

Whilst we are going through the solution follow along with the sliders and try to get to the next step before reading it. Times you may wish to do this are marked with a *.

By considering the problem from each sub-goal we force ourselves to think in different ways. This is the key to problem solving. Skipping to the answer does not give you the knowledge of the problem solving process.

"); s24 is Slide("

Working Backwards Step by Step

Let's Begin

Goal: To get 6 units of fluid into the larger jug*.


By adjusting the B jug slider to 6 we can see that our new sub goal is to pour away 3 units of fluid from the large jug into the smaller.

Due to previous experimentation with the pouring, filling and emptying of jugs we know that the only way to pour exactly 3 units from the tall jug into the smaller jug is to have the same capacity free in the smaller jug.

Because we have a smaller jug size of four we can also work out that what we really need is an full tall jug and a smaller jug with only 1 unit of fluid within it*.

Thus when we pour from the larger jug into the smaller jug we arrive at our goal.

"); s25 is Slide("

Working Backwards Step by Step

Goal: To get the larger jug full and the smaller jug to have 1 unit of fluid*.


First of all we can note that a full jug is just the same as having a empty jug. Jugs can be filled and emptied at will therefore an empty jug is technically the same as a full jug.

So we can empty the taller jug*. This takes the taller jug right out of the goal entirely and so we can focus just on one problem.


Goal: To get 1 unit of fluid into the smaller jug*.


If we have any units of fluid in the smaller jug, and the smaller jug is not at maximum capacity then we know where the fluid came from.

Since the actions we have are fill or empty either jug (leading to maximum or minimum capacity) or pouring from the taller into the smaller we know that the only way to get a non-zero, non-maximal number of units of fluid in the smaller jug is by pouring.

Now that we realise this we can say that our new sub goal is to get 1 unit of fluid into the larger jug* (so that we can pour it across).

"); s26 is Slide("

Working Backwards Step by Step

Goal: To get 1 unit of fluid into the taller jug*.


We can reason with what we know about the puzzles mechanics to again help us.

Since non-zero, non-maximal units of fluid in the larger jug can only be reached by pouring away into the smaller jug we can reach another sub goal.

We need to find a way of pouring from a full tall jug into a smaller jug such that we are only left with 1 unit of fluid.

This may seem as difficult to achieve as our initial goal - to get 6 units of fluid into the larger jug. However the goals are not exactly the same.

The original goal was based around manipulating the two jugs together. In this goal we only need to find a way of removing the fluid and not switching it around.

We can assume, since we can only pour from a jug with more content that to get 1 unit we cannot transfer this one fluid back and forth between the jugs, only steadily remove fluid until we reach 1.

In this sense the new sub goal is very much different from our original problem and we can see this as a sign of progress towards a solution.

"); s27 is Slide("

Working Backwards Step by Step

Goal: To find a way of pouring from a full tall jug into a smaller one such that 1 unit of fluid is left behind*


This is where early experimentation can help us. You may have already come across a combination of pours that led to 1 unit being left behind. By not allowing pouring back from the smaller jug into the larger one just trying the possible combinations brings us to the answer fairly quickly.

But you can work out how to get 1 unit of fluid very fast by just considering the capacities of the jugs and not experimenting at all.

The capacity of jug B is 9 and the capacity of jug A is 4.

We need to get 1 unit in jug B so let's assume that that unit of fluid is immoveable or doesn't exist. Therefore the capacity of jug B suddenly becomes 8 and our goal is to empty jug B of this new capacity. This auxiliary problem is exactly the same as the current problem, but it is easier to understand.

"); s28 is Slide("

Working Backwards Step by Step

Goal: Assume that the capacity of the taller jug is actually 8*. How do you empty it using pouring and emptying jug A?


Immediately we can see that the new capacity of jug B is twice that of jug A. Another way of saying this is that you can fill up B, pour it into A and empty A to decrease the contents of B by 4.

Therefore pouring over to A and emptying A twice leads us to our goal of emptying this new jug.

Whilst we have done this in our minds we could have just have easily adapted the model we have to explore this new capacity challenge.

End of Solution


Solving this problem was the final step for our complete solution. We can tell this is the case because we have no more moves to make, there is no sub goal to solve anymore.

It's time to put our answer together and check that we were right.

"); s29 is Slide("

Putting the Pieces Together

Since we believe we have discovered the solution it's time to list the steps, take away our external puzzle mechanics (in this case the sliders) and apply the steps we found using the problems own features.

To put our steps together we only have to reverse the order in which we found them. We can also check off our sub goals as we go along (I mark thse with !).

Let us reset the problem back to its initial state without our extra mechanics.

picture is [but1,but2,but3,but4,but5,jugA_left,jugA_right,jugA_base,jugB_left,jugB_right,jugB_base,jugA_water,jugB_water,statuslabel]; contentA = 0; contentB = 0;

Notice that we are just removing the sliders from our use and not destroying them entirely. If we find that our solution is wrong we need to be able to use the sliders again to try a new solution.

"); s30 is Slide("

Checking Our Backwards Solution

Our steps are as follows:

  1. Fill jug B

  2. Pour from B into A and empty A.

  3. Pour from B into A and empty A again. We now have one unit of fluid in jug B!

  4. Pour from B into A. We now have one unit of fluid in jug A!

  5. Fill up jug B. We now have one unit of fluid in jug A and a full jug B!

  6. Pour from B into A. We now have four units of fluid in jug A and six units in jug B!

We have now reached our initial goal.

"); s31 is Slide("

Analysis of Working Backwards

By working backwards from the target we discovered a small number of easy steps that lead us from the initial position of the jugs to our goal. This is a very powerful technique and can be applied to many problems.

Whilst the jugs model is solvable in this form using trial and error without wasting too much time, there are plenty of problems that would take hours if not longer to check each and every path to a target. Sometimes the number of routes is too daunting to attempt working fowards.

Additionally by working backwards we can see if there are multiple ways to reach a target, each equally as valid. We can also have a better feeling of progress working backwards. Each sub goal should feel closer to the initial position, or at least more understandable or simpler to write down.

Finally it can help in proving that a problem has no solution. If you work from the target backwards and find yourself at a contradiction, that there are no routes to take or that expressions are false then the problem itself may be unsolvable. Working backwards means that these situations may be found much more quickly.

"); s32 is Slide("

Working Backwards in EM

Typically working backwards can become a difficult task. Usually the problem solver will have structured their mental model in such a way that it is difficult to break it apart and turn that logic around. This is why when traditionally attempting problems, like this for example, we often do not even think about the possibility of working from the endpoint to the start.

However by using empirical modelling this task becomes easier to implement for a number of reasons.

Firstly we can save the state of our mental model or stage of reasoning by simply saving the model we have created thus far.

Secondly with an empirical model it is typically easier to introduce extra features that give us the tools to attempt a backwards solution. This is due to the flexibility of EM and the ability it affords to the user to restructure their model quickly.

Finally we can easily take away our added features to check our backwards solutions hold up using just the tools the problem gives us.

In this way EM becomes a very helpful way of re-interpreting questions and changing our approach to problem solving.

"); slideList is [s0, s1, s2, s3, s4, s5, s6, s7, s8, s16, s15, s9, s10, s11, s12, s13, s14, s17, s18, s19, s20, s21, s22, s23, s24, s25, s26, s27, s28, s29, s30, s31, s32];