## the function of reasoning prompt is to supplement the commonsense and extract the necessary information from the questions
reasoning_one_shot = [
    "Please compute the date.\nQuestion:\nYesterday is 02/22/2012. What is the date one week from today in MM/DD/YYYY?\n\nAnswer:\nFirst, please extract the necessary information and rewrite the question using labels.\n#1. Yesterday is 02/22/2012.\n#2. Write the answer in MM/DD/YYYY.\n#3. What is the date one week from today?\n\nNext, we add the necessary knowledge from the question if needed.\n#4. 2012 is a leap year and February in 2012 has 29 days.\n\nFinally, please solve the problem step by step with reference to the question and reasoning process:\n\n#5. (by #1) Step 1: Calculate the date today.\nThe date of Yesterday is 02/22/2012.\nSo the date of today is 02/23/2012.\n\n#6. (by #4 #5) Step 2: Calculate the date one week from today.\nBecause 2012 is a leap year and February in 2012 has 29 days, the date one week from today is 03/01/2012.\n\n#7. (by #2 #3 #6) Step 3: Write the answer in MM/DD/YYYY.\nThe date one week from today is 03/01/2012. #### 03/01/2012\n\nQuestion:\nToday is 3/2 and Bob is watching NBA 2011. What is the date one week before today? Please answer in format MM/DD/YYYY.\n\nAnswer:\nFirst, please extract the necessary information and rewrite the question using labels.\n#1. Today is 3/2.\n#2. Bob is watching NBA 2011 today.\n#3. Write the answer in MM/DD/YYYY.\n#4. What is the date one week before today?\n\nNext, we add the necessary knowledge from the question if needed.\n#5. 2011 is not a leap year and February in 2011 has 28 days.\n\nFinally, please solve the problem step by step with reference to the question and reasoning process:\n\n#6. (by #1 #2) Step 1: Calculate the date today.\nToday is 3/2 and Bob is watching NBA 2011 today. So today is 03/02/2011.\n\n#7. (by #4 #5 #6) Step 2: Calculate the date one week before today.\nBecause 2011 is not a leap year and February in 2011 has 28 days, the date one week before today is 02/23/2011.\n\n#7. (by #3 #7) Step 3: Write the answer in MM/DD/YYYY.\nThe date one week before today is 02/23/2011. #### 02/23/2011\nPlease answer the following questions using the reasoning format of the above example rather than the content and follow the example by placing your final answer after ####."
]

## forward verification for conditions
condition_forward_verification_one_shot = [
    "Please compute the date.\nQuestion:\nToday is 02/27/2012. What is the date two days from today in MM/DD/YYYY?\n\nAnswer:\nFirst, please extract the necessary information and rewrite the question using labels.\n#1. Today is 02/27/2012.\n#2. Write the answer in MM/DD/YYYY.\n#3. What is the date two days from today?\n\nNext, we add the necessary knowledge from the question if needed.\n#4. 2012 is a leap year and February in 2012 has 28 days.\n\nFinally, please solve the problem step by step with reference to the question and reasoning process:\n\n#5. (by #1) Step 1: Today is 02/27/2012.\n#6. (by #3 #4 #5) Step 2: Two days from today is 02/29/2012, but since February has 28 days, it should roll over to March 1st.\nSo the date is 03/01/2012.\n#7. (by #2 #6) Step 3: The answer is 03/01/2012.\n\nDouble-check the temporal references, and verify the correctness of any date arithmetic and calendar rules. End with \"yes\" or \"no\" for whether the condition check passes.\n\nAnswer:\n\nConditions check\nObjective: Confirm that the time-based references in each step align with the stated dates and calendar logic, and ensure that leap years and month day counts are correctly applied.\nRule: Any miscalculation in date logic, incorrect use of leap year knowledge, or unsupported reference will fail the check.\n02/27/2012 (from Step #5) comes from #1 (verified)\n#4 says 2012 is a leap year, but claims February has only 28 days — this is incorrect (failed)\nIn a leap year, February has 29 days, so 02/27 + 2 days should result in 02/29/2012, not 03/01/2012 (failed)\nFinal date calculation in Step #6 is based on incorrect calendar knowledge (failed)\n\nResult: Since Step #4 uses incorrect leap year logic, the answer is \"no\", the condition check fails."
]

## forward verification for logic reasoning
logic_forward_verification_one_shot = [
    "Please compute the date.\nQuestion:\nToday is 02/27/2012. What is the date two days from today in MM/DD/YYYY?\n\nAnswer:\nFirst, please extract the necessary information and rewrite the question using labels.\n#1. Today is 02/27/2012.\n#2. Write the answer in MM/DD/YYYY.\n#3. What is the date two days from today?\n\nNext, we add the necessary knowledge from the question if needed.\n#4. 2012 is a leap year and February in 2012 has 29 days.\n\nFinally, please solve the problem step by step with reference to the question and reasoning process:\n\n#5. (by #1) Step 1: Today is 02/27/2012.\n#6. (by #4 #5) Step 2: Add two days: 02/27 + 2 days = 02/28/2012.\n#7. (by #2 #6) Step 3: The answer is 02/28/2012.\n\nNow let’s verify the reasoning processing and analyze its consistency. End with \"yes\" or \"no\" for whether the reasoning check passes.\n\nAnswer:\nReasoning check:\nObjective: Check whether the reasoning process is consistent\nRule: Any inconsistent step makes the check fail\n Step #5: Today is 02/27/2012 — correct (verified).\n Step #6: Incorrect addition — 02/27 + 2 days should be 02/29/2012 (since 2012 is a leap year). The reasoning incorrectly adds only 1 day (unverified).\n Step #7: Final answer follows from Step #6, so it also carries the same logic error (unverified).\n\nIn summary:\n1. Steps are logically connected.\n2. There is a **calculation mistake**: 27 + 2 ≠ 28.\nResult: Based on the check, the answer is \"no\", the reasoning check fails."
]

## backward verification for question hallucination
backward_verification_one_shot = [
    "Here is a set of details:\n\nStep 1: Identify that today is 03/05/2023.\nStep 2: Subtract 1 day to get the date of yesterday.\nStep 3: Write the result in MM/DD/YYYY format.\n\nThe original question is: What is the date two days from today in MM/DD/YYYY?\n\nNow, please disregard the original question and focus on the provided reasoning steps. Use these steps to infer and guess the original question. The guessed question should not be output.\n\nEnd with \"yes\" or \"no\" for whether the backward check passes.\n\nAnswer:\nBackward check:\nObjective: Check whether the guessed question is semantically similar to the original question.\nRule: Any semantic difference causes the validation to fail.\n\nOriginal question: What is the date two days from today in MM/DD/YYYY?\nAnalysis #1: The reasoning steps are focused on calculating the date of **yesterday** by subtracting 1 day from today.\nAnalysis #2: A plausible guessed question could be: What was the date yesterday?\nAnalysis #3: The original question asks for a **future date**, while the reasoning steps are about a **past date**.\n\nResult: Based on the check, the answer is \"no\", the reasoning check fails."
]


reasoning_beginning_guide = "\n\nAnswer:\nFirst, let's extract the necessary information and rewrite the question using labels.\n\n"

condition_beginning_guide = "\n\nDouble-check the temporal references, and verify the correctness of any date arithmetic and calendar rules. End with \"yes\" or \"no\" for whether the condition check passes.\n\nAnswer:\n\nConditions check\nObjective: Confirm that the time-based references in each step align with the stated dates and calendar logic, and ensure that leap years and month day counts are correctly applied.\nRule: Any miscalculation in date logic, incorrect use of leap year knowledge, or unsupported reference will fail the check.\n"

logic_beginning_guide = "\n\nNow let’s verify the reasoning processing and analyze its consistency. End with \"yes\" or \"no\" for whether the reasoning check passes.\n\nAnswer:\nReasoning check:\nObjective: Check whether the reasoning process is consistent\nRule: Any inconsistent step makes the check fail\n"

backward_beginning_guide = "\n\nNow, please disregard the original question and focus on the provided reasoning steps. Use these steps to infer and guess the original question. \n\nEnd with \"yes\" or \"no\" for whether the backward check passes.\n\nAnswer:\nBackward check:\nObjective: Check whether the guessed question is semantically similar to the original question.\nRule: Any semantic difference causes the validation to fail.\n\n"

prompts = {
    "commonsense_enhanced_generation": (reasoning_one_shot, reasoning_beginning_guide),
    "conditions_check": (condition_forward_verification_one_shot, condition_beginning_guide),
    "logic_check": (logic_forward_verification_one_shot, logic_beginning_guide),
    "backward_verification": (backward_verification_one_shot, backward_beginning_guide),
}


# choose the mode based on specific tasks (reasoning, forward verification or backward verification)
def prompt_fn(question, mode):
    prompt, guide = prompts[mode]
    return "\n".join(prompt) + question + guide