GusLovesMath commited on
Commit
aee272f
·
verified ·
1 Parent(s): 8e10b6a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -20
app.py CHANGED
@@ -11,7 +11,6 @@ import math
11
  import random
12
  from typing import Literal
13
 
14
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
15
  import math
16
  import random
17
  from typing import Literal
@@ -22,7 +21,6 @@ def get_approximate_integral(
22
  expr: str,
23
  a: float,
24
  b: float,
25
- method: Literal["auto", "simpson", "montecarlo"] = "auto",
26
  samples: int = 1000
27
  ) -> str:
28
  """Approximate the definite integral of a function over [a, b].
@@ -42,24 +40,6 @@ def get_approximate_integral(
42
  def f(x):
43
  return eval(code, {"__builtins__": {}}, {"x": x, "math": math})
44
 
45
- # Auto‑choose method by sampling curvature
46
- if method == "auto":
47
- mid = (a + b) / 2
48
- # estimate curvature via second finite difference
49
- f0, f1, f2 = f(a), f(mid), f(b)
50
- curvature = abs((f0 - 2*f1 + f2) / ((b - a)/2)**2)
51
- method = "montecarlo" if curvature > 1e3 else "simpson"
52
-
53
- if method == "simpson":
54
- n = samples if samples % 2 == 0 else samples + 1
55
- h = (b - a) / n
56
- total = f(a) + f(b)
57
- for i in range(1, n):
58
- weight = 4 if i % 2 else 2
59
- total += weight * f(a + i * h)
60
- result = total * h / 3
61
- return f'{{"value": {result}, "method": "simpson", "panels": {n}}}'
62
-
63
  # Monte Carlo fallback
64
  inside = 0.0
65
  for _ in range(samples):
 
11
  import random
12
  from typing import Literal
13
 
 
14
  import math
15
  import random
16
  from typing import Literal
 
21
  expr: str,
22
  a: float,
23
  b: float,
 
24
  samples: int = 1000
25
  ) -> str:
26
  """Approximate the definite integral of a function over [a, b].
 
40
  def f(x):
41
  return eval(code, {"__builtins__": {}}, {"x": x, "math": math})
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  # Monte Carlo fallback
44
  inside = 0.0
45
  for _ in range(samples):