## the function of reasoning prompt is to supplement the commonsense and extract the necessary information from the questions
reasoning_one_shot = [
    "Question:\nMary spends $3 a day on lunch in the cafeteria. She bought a $5 mouthly membership card that gives her a 20% discount. How much did she spend on lunch in December? \n\nAnswer:\nFirst, let's extract the necessary information and rewrite the question using labels.\n#1. Mary spends $3 a day on lunch in the cafeteria.\n#2. She bought a $5 membership card.\n#3. The membership card gives her a 20% discount.\n#4. How much did she spend on lunch in December?\nNext，we add the necessary knowledge from the question if needed.\n#5. December has 31 days.\nFinally, let us solve the problem step by step with reference to the question and reasoning process:\n\n#6. (by #1, #3) Step 1: Calculate the discounted daily cost. \nNormal daily cost: $3, Discount: 20%\nDiscounted daily cost = $3 × (1 − 0.20) = $3 × 0.80 = $2.40\n\n#7. (by#5 #6) Step 2: Calculate the total cost for December lunches. \nDecember has 31 days, Daily discounted cost: $2.40, Total discounted lunch cost = 31 × $2.40 = $74.40\n\n#8. (by #2) Step 3: Include the cost of the membership card. \nMembership card cost: $5\n\n#9. (by #7 #8) Step 4: Determine Mary’s total spending. \nTotal lunch cost (discounted): $74.40\nMembership card cost: $5\nTotal spent = $74.40 + $5 = $79.40\n\n#10. (by #4 #9) The original question is #4. How much did she spend on lunch in December? We do not miss information on the rewritten labels. So the answer to this question is in December Mary spent $79.40."
]

## forward verification for conditions
condition_forward_verification_one_shot = [
    "Here is a set of details:\n#1. Jenny pays $2 for her daily bus ticket.\n#2. She has a membership card that reduces the daily fare by 20%.\n#3. The membership card costs $5.\n#4. April has 30 days.\n\nBased on these details, here is a reasoning process:\nStep #5 (by #1 #4): Jenny’s total bus fare for April is 30 × $2 = $60.\nStep #6 (by #2 #5): After applying a 20% discount, her fare is $60 × (1 − 0.20) = $48.\nStep #7 (by #3 #6): Adding the membership card cost of $5, her final payment is $48 + $5 = $53.\n\nDouble-check the numeric references, and verify the correctness of any common knowledge used. End with \"yes\" or \"no\" for whether the condition check passes.\n\nAnswer:\n\nConditions check\nObjective: Confirm that the numbers and references in each step align with the stated details or valid prior conclusions, and ensure that common knowledge is properly applied.\nRule: Any condition reference without support or misused common knowledge from the given information will fail the check.\n30 (from Step #5) comes from #4 (verified)\n$2 (from Step #5) comes from #1 (verified)\n$60 (from Step #5) is derived from the above figures (verified)\n$20% (from Step #6) is from #2 (verified)\n$48 (from Step #6) follows from $60 with the discount (verified)\n$5 (from Step #7) matches #3 (verified)\n$53 (from Step #7) is derived from $48 + $5, both figures are verified (verified)\n\nResult: Since all steps in the reasoning process are grounded, the answer is \"yes\", the condition check passes."
]

## forward verification for logic reasoning
logic_forward_verification_one_shot = [
    "Here is a set of details:\n#1. Jenny pays $2 for her daily bus ticket.\n#2. She has a membership card that reduces the daily fare by 20%.\n#3. The membership card costs $5.\n#4. April has 30 days.\n\nBased on these details, here is a reasoning process:\nStep #5 (by #1 #4): Jenny’s total bus fare for April is 30 × $2 = $60.\nStep #6 (by #2 #5): After applying a 20% discount, her fare is $60 × (1 − 0.20) = $45.\nStep #7 (by #3 #6): Adding the membership card cost of $5, her final payment is $45 + $5 = $50.\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 fails\n Step #5: Jenny’s total bus fare for April is calculated by multiplying 30 days × $2 = $60. This calculation is accurate(verified).\n Step #6: A 20% discount of $60 gives $60 × 0.8 = $45. This calculation is incorrect(unverified).\n Step #7: The $5 membership card is added to the $45, giving a final total of $50. This calculation is accurate (verified).\n\nIn summary: \n1. There are no irrelevant steps. \n2. There is one calculation mistakes.\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: Calculate the discounted daily cost.\nStep 2: Calculate the total cost for December lunches.\nStep 3: Include the cost of the membership card.\nStep 4: Determine Mary’s total spending.\n\nThe original question is: How much did she spend on lunch in December?\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 Analysis #1: The reasoning steps focus on calculating the total lunch cost for Mary in December, considering her daily spending, the discount, and the membership card fee.\nAnalysis #2: A plausible guessed question could be: How much did Mary spend on lunch in December, including her discount and membership fees?\nAnalysis #3: Comparing the guessed question with the original question, it shows they are semantically consistent.\n\nResult: Based on the check, the answer is \"yes\", the reasoning check passes."
]


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 numeric references, and verify the correctness of any common knowledge used. End with \"yes\" or \"no\" for whether the condition check passes.\n\nAnswer:\n\nConditions check\nObjective: Confirm that the numbers and references in each step align with the stated details or valid prior conclusions, and ensure that common knowledge is properly applied.\nRule: Any condition reference without support or misused common knowledge from the given information 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:\nPurpose: Check whether the reasoning process is consistent\nRule: Any inconsistent step makes the check fails\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. 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"

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
