File size: 1,278 Bytes
5543e04
95151f6
5543e04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95151f6
 
 
 
 
 
db31576
 
95151f6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sympy
import gradio as gr

def derivative_polynomial(coefficients):
    """
    Calculate the derivative of a polynomial function.
    
    Args:
        coefficients (list): List of coefficients from highest to lowest degree
        
    Returns:
        list: Coefficients of the derivative polynomial
    """
    if len(coefficients) <= 1:
        return [0]
    
    result = []
    for i, coef in enumerate(coefficients[:-1]):
        power = len(coefficients) - i - 1
        result.append(coef * power)
    
    return result

derivative_interface = gr.Interface(
    fn=lambda coefficients: derivative_polynomial([float(c) for c in coefficients.split(',')]),
    inputs=gr.Textbox(label="Polynomial Coefficients (comma-separated, highest degree first)"),
    outputs="json",
    title="Polynomial Derivative",
    description="Find the derivative of a polynomial function.\n\n**Description:**\nThis tool computes the derivative of a polynomial given its coefficients (highest degree first).\n\n**Examples:**\n- Input: 3,2,1 (represents 3x^2 + 2x + 1) → Output: [6,2] (represents 6x + 2)\n- Input: 5,0,-4 (represents 5x^2 - 4) → Output: [10,0] (represents 10x)\n- Input: 7 (represents constant 7) → Output: [0]",
    examples=[["3,2,1"],["5,0,-4"],["7"]],
)