|
| 1 | +from typing import Dict, List, Tuple |
| 2 | +import re |
| 3 | +from math import isclose |
| 4 | + |
| 5 | +FEWSHOT_PROMPT = ( |
| 6 | + """Problem: |
| 7 | +Suppose that $10.0 \mathrm{~mol} \mathrm{C}_2 \mathrm{H}_6(\mathrm{~g})$ is confined to $4.860 \mathrm{dm}^3$ at $27^{\circ} \mathrm{C}$. Predict the pressure exerted by the ethane from the perfect gas. |
| 8 | +
|
| 9 | +Solution: |
| 10 | +To predict ethane's pressure using the ideal gas law (PV = nRT), I'll convert temperature from 27°C to Kelvin (300.15 K, rounded to 300 K for significant figures), then substitute the given values: 10.0 mol of ethane, volume of 4.860 L, gas constant R = 0.0821 L·atm/(mol·K), and T = 300 K. Rearranging the ideal gas equation to P = nRT/V and calculating: P = (10.0 mol × 0.0821 L·atm/(mol·K) × 300 K) ÷ 4.860 L = 246.3 L·atm ÷ 4.860 L ≈ 50.7 atm. Since temperature has two significant figures, the final pressure is \(\boxed{50.7}\) atm. |
| 11 | +Final Answer: The final answer is \(\boxed{50.7}\). I hope it is correct. |
| 12 | +
|
| 13 | +Problem: |
| 14 | +Assume that all gases are perfect and that data refer to 298.15 K unless otherwise stated. Calculate the change in chemical potential of a perfect gas when its pressure is increased isothermally from $1.8 \mathrm{~atm}$ to $29.5 \mathrm{~atm}$ at $40^{\circ} \mathrm{C}$. |
| 15 | +
|
| 16 | +Solution: |
| 17 | +To determine the change in chemical potential (Δμ) of a perfect gas during pressure change, I begin with the fundamental relation μ = μ° + RT ln(P/P°), which yields Δμ = RT ln(Pf/Pi) for changes between two states. Converting the given temperature of 40°C to 313.15K and using R = 8.314 J/(mol·K), I calculate Δμ = (8.314 J/(mol·K))(313.15K)ln(29.5/1.8). The pressure ratio 29.5/1.8 ≈ 16.39 gives ln(16.39) ≈ 2.797, so Δμ = 8.314 × 313.15 × 2.797 ≈ 7274.5 J/mol, which rounds to 7.3 kJ/mol. |
| 18 | +Final Answer: The final answer is \(\boxed{7.3}\). I hope it is correct. |
| 19 | +
|
| 20 | +Problem: |
| 21 | +Show that the small angular deviation of $\epsilon$ of a plumb line from the true vertical (i.e., toward the center of Earth) at a point on Earth's surface at a latitude $\lambda$ is $\epsilon = \frac{R\omega^2sin\lambda cos\lambda}{g_0 - R\omega^2 cos^2\lambda}$ where R is the radius of Earth. What is the value (in seconds of arc) of the maximum deviation? Note that the entire denominator in the answer is actually the effective $g$, and $g_0$ denotes the pure gravitational component. |
| 22 | +
|
| 23 | +Solution: |
| 24 | +To determine the small angular deviation (ε) of a plumb line from true vertical due to Earth's rotation, we analyze the balance of forces at latitude λ: gravitational force (Fg = mg0) toward Earth's center and centrifugal force (Fc = mRω²cosλ) perpendicular to the rotation axis. The centrifugal force resolves into a vertical component (Fc,v = mRω²cos²λ) that reduces effective gravity to g = g0 - Rω²cos²λ, and a horizontal component (Fc,h = mRω²sinλcosλ) pulling toward the equator. The angular deviation equals the ratio of horizontal force to effective gravity: ε = Rω²sinλcosλ/(g0 - Rω²cos²λ). To find maximum deviation, we differentiate with respect to λ and find it occurs at λ = 45°. Using Earth values (R = 6.371×10⁶ m, ω = 7.292×10⁻⁵ rad/s, g0 ≈ 9.81 m/s²), we calculate the numerator at 45° as 1.697×10⁻² m/s² and denominator as 9.793 m/s², yielding εmax = 1.733×10⁻³ rad or approximately 357 arcseconds (6 arcminutes). |
| 25 | +Final Answer: The final answer is \(\boxed{6}\). I hope it is correct.""" |
| 26 | +) |
| 27 | + |
| 28 | +def scibench_doc_to_text(doc: Dict, lmms_eval_specific_kwargs: Dict) -> str: |
| 29 | + pre_prompt = lmms_eval_specific_kwargs["pre_prompt"] |
| 30 | + post_prompt = lmms_eval_specific_kwargs["post_prompt"] |
| 31 | + question = doc["problem_text"] |
| 32 | + if doc["unit"].strip(): |
| 33 | + question = question + " The unit of the answer is " + doc["unit"] + "." |
| 34 | + return f"{pre_prompt}{question}{post_prompt}" |
| 35 | + |
| 36 | +def extract_boxed_answers(text): |
| 37 | + # Find all boxed contents |
| 38 | + matches = re.findall(r'boxed{([^}]*)}', text) |
| 39 | + for m in matches: |
| 40 | + # Strip spaces |
| 41 | + candidate = m.strip() |
| 42 | + # Keep only the numeric ones (int or decimal, with optional sign) |
| 43 | + if re.fullmatch(r'[-+]?\d*\.?\d+', candidate): |
| 44 | + return candidate |
| 45 | + return None |
| 46 | + |
| 47 | +def remove_not(x): |
| 48 | + match_number = re.compile('[\$]?\ *10\^[{]?\ *-?[0-9]+\ *[}]?\ *[\$]?') |
| 49 | + result=re.findall(match_number, x) |
| 50 | + if len(result) !=0: |
| 51 | + return re.split(match_number, x)[-1] |
| 52 | + return None |
| 53 | + |
| 54 | +def cal_not(inputs): |
| 55 | + try: |
| 56 | + x,ab=list(inputs) |
| 57 | + match_number = re.compile('10\^[{]?\ *-?[0-9]+\ *[}]?') |
| 58 | + ab=re.findall(match_number, ab)[0] |
| 59 | + ab=ab[ab.find('^')+1:] |
| 60 | + if '{' in ab: |
| 61 | + ab=ab[ab.find('{')+1:] |
| 62 | + if '}' in ab: |
| 63 | + ab=ab[:ab.find('}')] |
| 64 | + x=x.strip() |
| 65 | + out=float(x)*10**float(ab) |
| 66 | + # print(float(x)*10**float(ab)) |
| 67 | + return str(out) |
| 68 | + except: |
| 69 | + print('error') |
| 70 | + return inputs |
| 71 | + |
| 72 | +def parse_not(inputs): |
| 73 | + try: |
| 74 | + if not inputs: |
| 75 | + return '','' |
| 76 | + if '\\times' in inputs: |
| 77 | + x,ab=inputs.split('\\times') |
| 78 | + elif '\times' in inputs: |
| 79 | + x,ab=inputs.split('\times') |
| 80 | + elif '*' in inputs: |
| 81 | + x,ab=inputs.split('*') |
| 82 | + else: |
| 83 | + return inputs |
| 84 | + return x,ab |
| 85 | + except: |
| 86 | + return '','' |
| 87 | + |
| 88 | +def equiv_with_unit(model_output, answer, unit): |
| 89 | + model_output=model_output.replace(',', '') |
| 90 | + print("Model_output: ", model_output) |
| 91 | + try: |
| 92 | + ans=float(answer.strip()) |
| 93 | + first=isclose(float(model_output.strip()), ans, rel_tol=0.05) |
| 94 | + except: |
| 95 | + first=False |
| 96 | + try: |
| 97 | + model=model_output.strip().split()[0] |
| 98 | + second=isclose(float(model.strip()), ans, rel_tol=0.05) |
| 99 | + except: |
| 100 | + second=False |
| 101 | + if first or second: |
| 102 | + return True |
| 103 | + return False |
| 104 | + |
| 105 | +def clean_number_string(s): |
| 106 | + return s.replace(",", "").replace("−", "-").strip() |
| 107 | + |
| 108 | +def scibench_process_results(doc: Dict, result: List[str]) -> Dict[str, float]: |
| 109 | + pred = result[0] |
| 110 | + pred = extract_boxed_answers(pred) |
| 111 | + if pred: |
| 112 | + res_equiv = isclose(float(clean_number_string(pred)), float(clean_number_string(doc["answer_number"])), rel_tol=0.05) |
| 113 | + score = 1 if res_equiv else 0 |
| 114 | + else: |
| 115 | + score = 0 |
| 116 | + return {"accuracy": score} |
| 117 | + |
| 118 | +def scibench_multishot_doc_to_text(doc: Dict, lmms_eval_specific_kwargs: Dict) -> str: |
| 119 | + pre_prompt = lmms_eval_specific_kwargs["pre_prompt"] |
| 120 | + post_prompt = lmms_eval_specific_kwargs["post_prompt"] |
| 121 | + question = doc["problem_text"] |
| 122 | + if doc["unit"].strip(): |
| 123 | + question = question + " The unit of the answer is " + doc["unit"] + "." |
| 124 | + return FEWSHOT_PROMPT + "\n" + question + "\nAnswer: Let's think step by step." |
| 125 | + |
0 commit comments