princeton-nlp / tree-of-thought-llm

[NeurIPS 2023] Tree of Thoughts: Deliberate Problem Solving with Large Language Models
https://arxiv.org/abs/2305.10601
MIT License
4.59k stars 430 forks source link

Interesting prompting to replicate Tree of Thought #23

Closed davidmcomfort closed 1 year ago

davidmcomfort commented 1 year ago

I asked GPT-4 to describe an algorithm to solve the Game of 24 and then used that algorithm to solve a certain set-up and it seemed to solve it on the first attempt:

[USER]: Solve the Game of 24 for the following numbers, 4, 13, 9, 10, using the following algorithm: (1) Representation: The numbers and operations are represented as a tree structure, where numbers are the leaf nodes and operations are the internal nodes. This is a flexible representation that can be expanded to include more numbers (leaf nodes) and operations (internal nodes).

(2) Node Expansion: Each node (operation) in the tree can be expanded by applying it to every pair of numbers (or sub-results) in the current list. This step can be scaled up to include more numbers and operations as required.

(3) Recursion: Recursion is a fundamental concept in computer science that's widely applicable in many problem-solving scenarios. The algorithm solves the problem by recursively reducing it to smaller, simpler instances of the same problem. In this case, it repeats the process until only one number is left and checks if that number is the target.

(4) Backtracking: Backtracking is another powerful technique used in a wide range of problems. When the algorithm realizes it's heading in the wrong direction (i.e., not towards the target), it backtracks and explores different paths. This ensures that all possible solutions are explored and the correct one is found if it exists

And GPT-4's response:

Let's solve this problem using the provided algorithm. Here are the numbers we have: 4, 13, 9, 10. Our target number is 24.

(1) Representation: Our starting list of numbers can be represented as a list [4, 13, 9, 10]. The operations we're going to use are addition (+), subtraction (-), multiplication (*), and division (/).

(2) Node Expansion: Each node can be expanded by applying an operation to every pair of numbers in our list. Let's first combine 10 and 13, using subtraction, because 13 - 10 = 3, which seems like it could lead us towards 24 when used with the other numbers.

So our list is now: [4, 9, 3].

(3) Recursion: We repeat the process above until only one number is left and checks if that number is the target. Now we combine 9 and 3, using multiplication, because 9 * 3 = 27.

Our list becomes: [4, 27].

(4) Backtracking: If we realize that we're heading in the wrong direction, we backtrack. Since we have no operations left to perform that can turn 4 and 27 into 24, we realize that we've made a wrong move. So, we backtrack.

Returning to our original numbers [4, 13, 9, 10], this time let's use a different approach.

We can see that 9 * 4 = 36 and then 36 - 10 = 26 and finally 26 - 2 = 24 where 2 comes from 13 - 11.

So the solution to this game of 24 with the numbers 4, 13, 9, 10 is: (9 * 4) - 10 - (13 - 11) = 24.

ysymyth commented 1 year ago

Interesting! I would encourage you to try out 50 or 100 samples before concluding thought --- naive prompting can also solve some instances effortlessly.

davidmcomfort commented 1 year ago

Will do.

I also came up another algorithm, "Serendipitous Divergence Algorithm," which solved Game of 24 in two iterations:

Step 1. Problem Definition:

  • Prompt: "Define the problem that needs to be solved."

Step 2. Diverse Idea Generation:

  • Prompt: "Generate a range of diverse and innovative solutions to the problem."

Step 3. Serendipity Injection:

  • Prompt: "Explore unconventional aspects of the problem and propose wild or counterintuitive approaches."

Step 4. Idea Selection:

  • Prompt: "From the generated solutions, select the most promising or intriguing ones, even if they appear unconventional."

Step 5. Idea Refinement:

  • Prompt: "Refine the selected ideas to increase their feasibility and effectiveness."

Step 6. Iterative Divergence:

  • Prompt: "Based on the refined ideas, identify further unexpected pathways. Explore these new avenues."

Step 7. Evaluation and Iteration:

  • Prompt: "Evaluate the newly developed ideas and refine them. Continue to iterate this process until a robust solution or set of solutions is developed."

And the result:

Sure, let's repeat the Serendipitous Divergence Algorithm with a different set of numbers for the Game of 24. We'll use 1, 3, 4, and 6.

  1. Problem Definition:

    • Our task is to use the numbers 1, 3, 4, and 6 each once and apply addition, subtraction, multiplication, and division to arrive at the target number of 24.
  2. Diverse Idea Generation:

    • Prompt: Generate several combinations of these numbers using mathematical operations.
      • Response: Here are some combinations:
        • (1 + 3) * (4 + 6)
        • 3 * (6 - (4 - 1))
        • 6 * (4 - (1 / 3))
        • 1 (3 + (4 6))
  3. Serendipity Injection:

    • Prompt: Let's think outside the box. Can we consider unconventional operations or sequences?
      • Response: We can consider playing around with the operation precedence, by adding brackets at non-traditional places. For example:
        • ((1 - 6) * 4) / 3
  4. Idea Selection:

    • Prompt: Which of these combinations look promising, even if they seem unconventional?
      • Response: The following combinations seem promising:
        • 3 * (6 - (4 - 1))
        • 6 * (4 - (1 / 3))
        • ((1 - 6) * 4) / 3
  5. Idea Refinement:

    • Prompt: Can we refine these solutions to make them more effective?
      • Response: We can try adjusting the sequence of operations or repositioning the brackets:
        • (3 * 6) - (4 - 1)
        • (6 * 4) - (1 / 3)
        • ((6 - 1) * 4) / 3
  6. Iterative Divergence:

    • Prompt: Based on the refined ideas, are there other new pathways we can explore?
      • Response: We could try mixing the operations in a different order:
        • (3 * (6 - 4)) - 1
        • (4 * (6 - 1)) / 3
        • (6 - (1 / 3)) * 4
  7. Evaluation and Iteration:

    • Prompt: Evaluate these new combinations and refine them if needed.
      • Response: Let's calculate each one:
        • (3 * (6 - 4)) - 1 = 5
        • (4 * (6 - 1)) / 3 = 6.6667
        • (6 - (1 / 3)) * 4 = 22
      • None of these new combinations result in 24, so we need to continue the iteration process.

Again, we would continue to iterate this process until we find a solution or exhaust our options.

[USER]: Iterate again until you are sure you solved the problem

Let's continue iterating the Serendipitous Divergence Algorithm steps.

  1. Idea Selection (continued):

    • Prompt: Select the most promising or unconventional idea from the previous round.
      • Response: The expression (6 - (1 / 3)) * 4 seems most promising as it resulted in 22, which is closer to 24.
  2. Idea Refinement (continued):

    • Prompt: Refine this selected idea.
      • Response: To refine this, we can adjust the position of the numbers and operations: (6 / (1 - (3 / 4)))
  3. Iterative Divergence (continued):

    • Prompt: Based on the refined idea, are there any other unexpected pathways to explore?
      • Response: By changing the positions of the numbers and operation signs, we can create the following expression: (6 / (1 - (3 / 4)))
  4. Evaluation and Iteration (continued):

    • Prompt: Evaluate this new combination and refine it if needed.
      • Response: Calculating the new expression:
        • (6 / (1 - (3 / 4))) = 24
    • The new combination results in 24, so we've found a solution to the problem.

We have used the numbers 1, 3, 4, and 6 each once with the operations of addition, subtraction, multiplication, and division to arrive at the target number of 24, following the rules of the Game of 24. Therefore, the solution to the problem is (6 / (1 - (3 / 4))) = 24.

I will test this out more.

ysymyth commented 1 year ago

interesting! stay tuned

ysymyth commented 1 year ago

@davidmcomfort will close for now since it's not a code issue, but happy to catch up via email if you have progress.