Changes
1 changed files (+30/-13)
-
-
@@ -2,6 +2,7 @@ from time import timefrom IPython.core.magic import register_line_magic from requests import post @register_line_magic def nl(line, testing=False): """
-
@@ -12,12 +13,15 @@ def nl(line, testing=False):Example usage: %nl Invert the 4x4 matrix with 0s on the diagonal and 1s off diagonal """ r = post("http://localhost:11434/api/generate", json={ "model": "gemma3:27b", "system": "Translate this request directly into SageMath code. Be very concise and don't output Markdown code blocks or anything extraneous, only output the raw SageMath code. Make sure it's valid SageMath syntax!", "prompt": line, "stream": False }) r = post( "http://localhost:11434/api/generate", json={ "model": "gemma3:27b", "system": "Translate this request directly into SageMath code. Be very concise and don't output Markdown code blocks or anything extraneous, only output the raw SageMath code. Make sure it's valid SageMath syntax!", "prompt": line, "stream": False, }, ) code = r.json()["response"] print(code) if testing or input("Run? (y/N) ") == "y":
-
@@ -26,21 +30,34 @@ def nl(line, testing=False):if testing: return res nl_tests = [ ("Determinant of the 4x4 matrix with 0s on the diagonal and 1s off diagonal", -3), ("Solve x^2 = 2", [x == -sqrt(2), x == sqrt(2)]), ("Is 42069 prime", False), (r"Take \begin{bmatrix}\frac{9}{10} & \frac{1}{10}\\\frac{3}{10} & \frac{7}{10}\end{bmatrix} to the power of 10 and get the answer as a decimal", matrix([[0.751511654400000, 0.248488345600000], [0.745465036800000, 0.254534963200000]])), (r"\frac{1^3e^{-1}}{3!}\frac{(1/2)^0e^{-1/2}{0!}\frac{1/2)^0e^{-1/2}}{0!}", e^(-2)/6), ( r"Take \begin{bmatrix}\frac{9}{10} & \frac{1}{10}\\\frac{3}{10} & \frac{7}{10}\end{bmatrix} to the power of 10 and get the answer as a decimal", matrix( [ [0.751511654400000, 0.248488345600000], [0.745465036800000, 0.254534963200000], ] ), ), ( r"\frac{1^3e^{-1}}{3!}\frac{(1/2)^0e^{-1/2}{0!}\frac{1/2)^0e^{-1/2}}{0!}", e ^ (-2) / 6, ), ("Find the minimum of x^x on 0 to 10", (0.6922006275553464, 0.3678794331853406)), ("sum_{n=0}^oo 1/n! x^n", e^x), ("int 0 to x 2e^(-2y) dy", 1 - e^(-2*x)), ("sum_{n=0}^oo 1/n! x^n", e ^ x), ("int 0 to x 2e^(-2y) dy", 1 - e ^ (-2 * x)), ("Number of partitions of 69", 3554345), ("solve dy/dx+y-1 = 0 where y(10) = 2", (e^10 + e^x)*e^(-x)), (r"e^{\log(\sqrt2)-3i\pi/4} rectangular form", -1-i), ("solve dy/dx+y-1 = 0 where y(10) = 2", (e ^ 10 + e ^ x) * e ^ (-x)), (r"e^{\log(\sqrt2)-3i\pi/4} rectangular form", -1 - i), ("Answer to the ultimate question of life the universe and everything", 42), ] def run_nl_tests(): start_time = time() passes = 0
-
@@ -49,6 +66,6 @@ def run_nl_tests():for _ in range(5): if ans == nl(line, True): passes += 1 total = len(nl_tests) * 5. total = len(nl_tests) * 5.0 print(passes / total) print((time() - start_time) / total)
-