chughtaihamad commited on
Commit
a525215
·
verified ·
1 Parent(s): 549470d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -11
app.py CHANGED
@@ -10,18 +10,34 @@ from tools.final_answer import FinalAnswerTool
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
- def get_roots(a:int, b:int, c:int)-> (int, int):
14
- #Keep this format for the description / args / args description but feel free to modify the tool
15
- """A tool that performs the quadratic formula to get the roots of a polynomial
16
  Args:
17
- a: the first argument
18
- b: the second argument
19
- c: the third argument
20
- """
21
- first_root = ((-1 * b) + math.sqrt(math.pow(b, 2) - (4 * a * c))) / (2 * a)
22
- second_root = ((-1 * b) - math.sqrt(math.pow(b, 2) - (4 * a * c))) / (2 * a)
23
-
24
- return (first_root, second_root)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
 
10
  from Gradio_UI import GradioUI
11
 
12
  @tool
13
+ def get_roots(a: float, b: float, c: float) -> Tuple[float, float]:
14
+ """Compute the real roots of a quadratic equation ax^2 + bx + c = 0.
15
+
16
  Args:
17
+ a: Quadratic coefficient (must be non-zero).
18
+ b: Linear coefficient.
19
+ c: Constant term.
20
+
21
+ Returns:
22
+ A tuple (x1, x2) containing the two real roots.
23
+
24
+ Raises:
25
+ ValueError: If a == 0 or the discriminant is negative (no real roots).
26
+ """
27
+ if a == 0:
28
+ raise ValueError("Coefficient 'a' must be non-zero for a quadratic equation.")
29
+
30
+ discriminant = b * b - 4 * a * c
31
+ if discriminant < 0:
32
+ raise ValueError(
33
+ f"Discriminant is negative ({discriminant}); equation has no real roots."
34
+ )
35
+
36
+ sqrt_disc = math.sqrt(discriminant)
37
+ denom = 2 * a
38
+ x1 = (-b + sqrt_disc) / denom
39
+ x2 = (-b - sqrt_disc) / denom
40
+ return (x1, x2)
41
 
42
  @tool
43
  def get_current_time_in_timezone(timezone: str) -> str: