cabbage972/GitChameleon-2.0 huggingface dataset:
Library: sympy==1.11 (Python 3.9, released 2022-08)

Problem: Create a function called custom_parse_mathematica that takes a Mathematica expression (as a string) and converts it into a Sympy expression using the parse_mathematica function. In addition, modify the resulting expression so that every occurrence of the function symbol F is replaced by a new function that, when evaluated with one or more arguments, returns the product of the maximum and the minimum of those arguments.

Starting code:
from sympy.parsing.mathematica import parse_mathematica
from sympy import Function, Max, Min
import sympy

def custom_parse_mathematica(expr : str) -> int:
    return 

Solution:
parse_mathematica(expr).replace(Function("F"), lambda *x: Max(*x)*Min(*x))

Test:
expr = "F[6,4,4]"
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    expect = 24
    assert custom_parse_mathematica(expr) == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.12 (Python 3.9, released 2023-05)

Problem: Create a function called custom_pinJoint that creates a pin joint connecting two bodies—a parent and a child. The joint should be defined such that: a PinJoint in the parent to be positioned at parent.frame.x with respect to the mass center, and in the child at -child.frame.x.  Return a PinJoint object that properly connects these bodies using the specified points.

Starting code:
from sympy.physics.mechanics import Body, PinJoint
import sympy.physics.mechanics

def custom_pinJoint(parent: sympy.physics.mechanics.Body, child: sympy.physics.mechanics.Body) -> sympy.physics.mechanics.PinJoint:
    return 

Solution:
PinJoint('pin', parent, child, parent_point=parent.frame.x,child_point=-child.frame.x)

Test:
parent, child = Body('parent'), Body('child')
pin = custom_pinJoint(parent, child)
expect1 = parent.frame.x
expect2 = -child.frame.x

assert pin.parent_point.pos_from(parent.masscenter) == expect1
assert pin.child_point.pos_from(child.masscenter) == expect2
Library: sympy==1.12 (Python 3.9, released 2023-05)

Problem: Create a function called custom_pinJoint that creates a pin joint connecting two bodies—a parent and a child. Configure the joint such that the connection point on the parent body is at parent.frame.x (relative to its mass center), and the connection point on the child body is at -child.frame.x. The function should return a PinJoint object that encapsulates this connection.

Starting code:
from sympy.physics.mechanics import Body, PinJoint
import sympy.physics.mechanics
import sympy as sp


def custom_pinJoint_connect(parent: sympy.physics.mechanics.Body, child: sympy.physics.mechanics.Body) -> sympy.physics.mechanics.PinJoint:
    return 

Solution:
PinJoint('pin', parent, child, parent_point=parent.frame.x,child_point=-child.frame.x)

Test:

parent, child = Body('parent'), Body('child')
pin = custom_pinJoint_connect(parent, child)
assertion_value = isinstance(pin.coordinates, sp.Matrix)
assert assertion_value
assertion_value = isinstance(pin.speeds, sp.Matrix)
assert assertion_value
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Create a function named custom_check_carmichael that takes an integer parameter n as input. The function should determine whether n is a Carmichael number. It should return the result, which is a Boolean value indicating if n is a Carmichael number.

Starting code:
from sympy import *

def custom_check_carmichael(n: int) -> bool:
    return 

Solution:
is_carmichael(n)

Test:

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

n = 561
with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    from sympy import is_carmichael
    expect = True
    output = custom_check_carmichael(n)
    assert output == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Create a function named custom_function that takes two parameters: an integer n and an integer k. The function should compute the divisor sigma function. The divisor sigma function returns the sum of the k powers of the divisors of n. 

Starting code:
from sympy import *

def custom_function(n: int, k : int) -> int:
    return 

Solution:
divisor_sigma(n, k)

Test:
n = 6
k = 1
output = custom_function(n, k)
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    expect = 12
    assert output == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Create a function named custom_function that takes two parameters: K and a. Here, K represents a finite field created using the GF class from Sympy, and a is an element of that finite field. The function should convert the field element a into its corresponding integer representation and then return this integer.

Starting code:
from sympy import GF
from sympy.polys.domains.finitefield import FiniteField


def custom_function(K: FiniteField, a: FiniteField) -> int:
    return 

Solution:
K.to_int(a)

Test:
K = GF(6)
a = K(8)
output = custom_function(K, a)

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    expect = 2
    assert output == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Create a custom_generateInertia function that accepts an input and returns a symbolic representation of a rigid body’s inertia tensor relative to a specified reference frame, constructed using the symbolic variables for its principal moments of inertia. Based on the provided code, give the complete function and import the necessary libraries.

Starting code:
from sympy import symbols
from sympy.physics.mechanics import ReferenceFrame
import sympy.physics.vector

def custom_generateInertia(N: sympy.physics.vector.frame.ReferenceFrame, Ixx: sympy.Symbol, Iyy: sympy.Symbol, Izz: sympy.Symbol) -> sympy.physics.vector.dyadic.Dyadic:
    from sympy.

Solution:
physics.mechanics import inertia
    return inertia(N, Ixx, Iyy, Izz)

Test:

N = ReferenceFrame('N')
Ixx, Iyy, Izz = symbols('Ixx Iyy Izz')
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    from sympy.physics.mechanics import inertia
    expect = Ixx * (N.x | N.x) + Iyy * (N.y | N.y) + Izz * (N.z | N.z)
    assert custom_generateInertia(N, Ixx, Iyy, Izz) == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Implement a function named custom_function that accepts a single parameter eq, which is expected to be a symbolic equation (an instance of Sympy's Eq class). The function should compute the difference and return the expression.

Starting code:
from sympy import *
import sympy

def custom_function(eq: sympy.Equality) -> sympy.Expr:
    return 

Solution:
eq.lhs - eq.rhs

Test:
x, y = symbols('x y')
eq = Eq(x, y)
output = custom_function(eq)

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    expect = x - y
    assert output == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Create a custom_generatePolyList function that accepts a polynomial object and returns a list of its coefficients based on its internal representation.

Starting code:
from sympy import symbols, Poly
import sympy

def custom_generatePolyList(poly: sympy.Poly) -> list[int]:
    return 

Solution:
poly.rep.to_list()

Test:

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

x = symbols('x')
p = Poly(x**2 + 2*x + 3)

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    expect = [1,2,3]
    assert custom_generatePolyList(p) == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Using Sympy’s mechanics module, create a mechanical system involving three rigid bodies—a wall, a cart, and a pendulum. The wall serves as the inertial (fixed) reference, while the cart is connected to the wall by a sliding joint along the wall’s x-axis. The pendulum is attached to the cart via a rotational joint about the cart’s z-axis, with its connection point offset by a symbolic distance along the pendulum’s y-axis. Write a custom function that sets up this system using the Newtonian formulation (with the wall as the inertial frame), adds the slider and pin joints, and returns the system’s equations of motion. What are the equations of motion generated by your function?

Starting code:
from sympy import symbols
from sympy.physics.mechanics import (
Particle, PinJoint, PrismaticJoint, RigidBody)
import sympy
import sympy.physics.mechanics

def custom_motion(wall: sympy.physics.mechanics.RigidBody, slider: sympy.physics.mechanics.PrismaticJoint, pin: sympy.physics.mechanics.PinJoint) -> sympy.Matrix:
    from sympy.physics.mechanics import 

Solution:
System
    system = System.from_newtonian(wall)
    system.add_joints(slider, pin)
    return system.form_eoms()


Test:
l = symbols("l")
wall = RigidBody("wall")
cart = RigidBody("cart")
pendulum = RigidBody("Pendulum")
slider = PrismaticJoint("s", wall, cart, joint_axis=wall.x)
pin = PinJoint("j", cart, pendulum, joint_axis=cart.z,
               child_point=l * pendulum.y)

from sympy import symbols, Function, Derivative, Matrix, sin, cos
t = symbols('t')
l, Pendulum_mass, cart_mass, Pendulum_izz = symbols('l Pendulum_mass cart_mass Pendulum_izz')

q_j = Function('q_j')
u_j = Function('u_j')
u_s = Function('u_s')
M = Matrix([
    [Pendulum_mass*l*u_j(t)**2*sin(q_j(t)) - Pendulum_mass*l*cos(q_j(t))*Derivative(u_j(t), t)
     - (Pendulum_mass + cart_mass)*Derivative(u_s(t), t)],
    [-Pendulum_mass*l*cos(q_j(t))*Derivative(u_s(t), t)
     - (Pendulum_izz + Pendulum_mass*l**2)*Derivative(u_j(t), t)]
])
assert custom_motion(wall,slider, pin) == M
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Using the SymPy's mechanics module, define a function named custom_body that takes two strings as inputs—one representing the name of a rigid body and the other representing the name of a particle—and returns a tuple containing a rigid body and a particle created with those names. 


Starting code:
from sympy.physics.mechanics import *
import sympy.physics.mechanics

def custom_body(rigid_body_text: str, particle_text: str) -> tuple[sympy.physics.mechanics.RigidBody, sympy.physics.mechanics.Particle]:
    return 

Solution:
RigidBody(rigid_body_text), Particle(particle_text)

Test:
rigid_body_text = "rigid_body"
particle_text = "particle"
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    exp1, exp2 = custom_body(rigid_body_text, particle_text)
    assert exp1.name == rigid_body_text
    assert exp2.name == particle_text
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.9 (Python 3.9, released 2021-06)

Problem: Implement a function named custom_symbol that takes an input parameter index, which represents an indexed expression or symbol. The function should extract all the free symbols present in the given indexed object and return it.

Starting code:
from sympy import Indexed, Symbol
import sympy
from typing import Set

def custom_symbol(index: Indexed) -> set[Symbol]:
    return 

Solution:
index.free_symbols

Test:

a = Indexed("A", 0)
output = custom_symbol(a)

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    A = Symbol('A')
    A0 = Indexed('A', 0)
    expect = {A, A0}
    assert output == expect
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.9 (Python 3.9, released 2021-06)

Problem: Write a custom_create_matrix function that takes two lists (first and second) and returns a matrix composed of these two lists as rows.

Starting code:
from sympy import Matrix
import sympy

def custom_create_matrix(first: sympy.Matrix, second: sympy.Matrix) -> list[int]:
    return 

Solution:
Matrix([first, second])

Test:

first = [1,2]
second =[3,4]
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expected_shape = (2, 2)
    expected_content: list[list[int]] = [[1, 2], [3, 4]]
    output = custom_create_matrix(first, second)

    assert output.shape == expected_shape

    assert output.tolist() == expected_content
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.9 (Python 3.9, released 2021-06)

Problem: Write a custom_function that accepts a Sympy Matrix and returns a flat, read-only copy of its data 

Starting code:
from sympy import Matrix
import sympy

def custom_function(matrix: sympy.Matrix) -> list[int]:
    return 

Solution:
matrix.flat()

Test:
m = Matrix([[1, 2], [3, 4]])

output = custom_function(m)
output[0] = 100
assertion_value = m[0, 0] == 1
assert assertion_value
assertion_value = output[0] == 100
assert assertion_value
Library: sympy==1.9 (Python 3.9, released 2021-06)

Problem: Write a custom_function that accepts a Sympy SparseMatrix and returns its dictionary-of-keys representation.

Starting code:
from sympy import Matrix
import sympy

def custom_function(matrix: sympy.Matrix) -> list[int]:
    return 

Solution:
matrix.todok()

Test:
m = Matrix([[1, 2], [3, 4]])

output = custom_function(m)
output[(0, 0)] = 100

assertion_value = m[0, 0] == 1
assert assertion_value
assertion_value = output[(0, 0)] == 100
assert assertion_value
Library: sympy==1.10 (Python 3.9, released 2022-03)

Problem: Write a custom_bottom_up function that applies a bottom-up traversal to expr with a lambda function on each node.

Starting code:
import sympy

def custom_bottom_up(expr: sympy.Expr) -> int:
    return 

Solution:
sympy.bottom_up(expr, lambda x: x.doit())

Test:
expr = sympy.Add(1, sympy.Mul(2, 3))
expect = 7
assert custom_bottom_up(expr) == expect
Library: sympy==1.10 (Python 3.9, released 2022-03)

Problem: Write a custom_use function that traverses the expression so that every subexpression is evaluated, and returns final evaluated result. 

Starting code:
import sympy


def custom_use(expr: sympy.Expr) -> int:
    return 

Solution:
sympy.use(expr, lambda x: x.doit())

Test:
expr = sympy.Add(1, sympy.Mul(2, 3))

expect = 7

assert custom_use(expr) == expect
Library: sympy==1.11 (Python 3.9, released 2023-07)

Problem: Write a custom_is_perfect_square function that check if the input is a perfect square.

Starting code:
import sympy

def custom_is_perfect_square(n: int) -> bool:
    return 

Solution:
sympy.ntheory.primetest.is_square(n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = True
    output = custom_is_perfect_square(4)

    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.11 (Python 3.9, released 2023-07)

Problem: Write a custom_is_prime function that check if the input is prime

Starting code:
import sympy

def custom_is_prime(n: int) -> bool:
    return 

Solution:
sympy.isprime(n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = True
    output = custom_is_prime(13)

    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.11 (Python 3.9, released 2023-07)

Problem: Write a custom_divides function that checks whether the integer p divides the integer n evenly (i.e., with no remainder).

Starting code:
import sympy

def custom_divides(n: int, p: int) -> bool:
    return 

Solution:
n % p == 0

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = True
    output = custom_divides(10,2)

    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.12 (Python 3.9, released 2023-05)

Problem: Write a custom_array_to_matrix function that convert input array into matrix by import correct sympy modules.

Starting code:
from sympy import Matrix, symbols, Array
import sympy

def custom_array_to_matrix(array: sympy.Array) -> sympy.Matrix:
    from sympy.tensor.array.expressions.

Solution:
from_array_to_matrix import convert_array_to_matrix
    return convert_array_to_matrix(array)


Test:

a1, a2, a3, a4 = symbols('a1 a2 a3 a4')
array_expr = Array([[a1, a2], [a3, a4]])

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    from sympy.tensor.array.expressions.from_array_to_matrix import convert_array_to_matrix

    expect = Matrix([[a1, a2], [a3, a4]])
    output = custom_array_to_matrix(array_expr)

    assert Matrix(output) == Matrix(expect)
    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_jacobi_symbols function that compute the Jacobi symbol (a/n).

Starting code:
import sympy

def custom_jacobi_symbols(a: int, n: int) -> int:
    return 

Solution:
sympy.jacobi_symbol(a, n)

Test:

import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = -1
    output = custom_jacobi_symbols(1001, 9907)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_npartitions function that compute the number of partitions of n.

Starting code:
import sympy

def custom_npartitions(n: int) -> int:
    return 

Solution:
sympy.functions.combinatorial.numbers.partition(n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = 7
    output = custom_npartitions(5)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_primefactors function that compute the number of distinct prime factors of n.

Starting code:
import sympy

def custom_primefactors(n: int) -> int: 
    return 

Solution:
sympy.primeomega(n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = 3
    output = custom_primefactors(18)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_prime_counting function that compute the prime counting function for n.

Starting code:
import sympy

def custom_prime_counting(n: int) -> int:
 return 

Solution:
sympy.primepi(n)


Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = 10
    output = custom_prime_counting(30)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_totient function that compute Euler's totient function for n (number of integers relatively prime to n).

Starting code:
import sympy

def custom_totient(n: int) -> int:
    return 

Solution:
sympy.totient(n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = 8
    output = custom_totient(30)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_mobius function that compute the Möbius function for n. 

Starting code:
import sympy

def custom_mobius(n: int) -> int:
    return 

Solution:
sympy.mobius(n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = -1
    output = custom_mobius(30)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"
Library: sympy==1.13 (Python 3.9, released 2023-07)

Problem: Write a custom_legendre function that compute the Legendre symbol (a/p).

Starting code:
import sympy

def custom_legendre(a: int, n: int) -> int:
    return 

Solution:
sympy.legendre_symbol(a, n)

Test:
import warnings
from sympy.utilities.exceptions import SymPyDeprecationWarning

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always", SymPyDeprecationWarning)
    
    expect = -1
    output = custom_legendre(200, 13)
    assert output == expect

    assert not any(isinstance(warn.message, SymPyDeprecationWarning) for warn in w), "Test Failed: Deprecation warning was triggered!"