文章目录Technical Report: Symbolic Domain and Range Analysis of Real-Valued Functions Using SymPy1. Introduction2. Methodology2.1 Domain Computation2.2 Range Computation3. Implementation4. Test Cases and Results4.1 Case 1:f ( x ) x x − 1 ln ⁡ ( 2 − x ) f(x) \frac{\sqrt{x}}{x-1} \ln(2-x)f(x)x−1x​​ln(2−x)4.2 Case 2: $ f(x) \sqrt{x^2 - 5x}$4.3 Case 3:f ( x ) arcsin ⁡ ( x ) f(x) \arcsin(x)f(x)arcsin(x)5. Discussion6. Conclusion7. SourceTechnical Report: Symbolic Domain and Range Analysis of Real-Valued Functions Using SymPy1. IntroductionIn mathematical analysis and engineering applications, determining thedomainandrangeof a function is a fundamental step. While numeric sampling can provide approximate results,symbolic computationyields exact mathematical descriptions in terms of intervals and unions, which are essential for rigorous reasoning.This report presents a Python-based tool using theSymPylibrary to automatically compute the domain (as the set of real numbers where the function is defined) and the range (the set of all possible output values) of a given elementary function. The approach relies on symbolic exclusion of “illegal” operations (division by zero, negative radicands, non-positive logarithm arguments, etc.) and solving equations for the range.2. Methodology2.1 Domain ComputationThe domain is obtained usingcontinuous_domain(function, variable, domain). This function analyzes the expression and returns the largest subset of the specified domain (hereR \mathbb{R}R) on which the function is continuous and defined. It automatically handles:Denominators: exclude points where they vanish.Even-indexed radicals: require the radicand to be non-negative.Logarithms: require the argument to be strictly positive.Inverse trigonometric functions (e.g.,arcsin ⁡ \arcsinarcsin,arccos ⁡ \arccosarccos): restrict the argument to[ − 1 , 1 ] [-1,1][−1,1].The result is returned as a set of intervals (closed, open, or half-open) and their unions.2.2 Range ComputationThe range is computed usingfunction_range(function, variable, domain). This function finds the set of ally yysuch that the equationf ( x ) y f(x) yf(x)yhas at least one solutionx xxin the given domain. It internally solves fory yyusing symbolic equation solving and interval analysis.For functions that are continuous on their domain, the range is determined by evaluating limits at endpoints and critical points (where the derivative is zero). The result is also expressed as intervals or unions.3. ImplementationThe Python script is concise and flexible. The user only needs to define the function expression; the script then prints the domain and range in a human-readable format.#!/usr/bin/env python3# -*- coding: utf-8 -*-fromsympyimportsymbols,S,sqrt,log,asin,exp,sin,cos,tanfromsympy.calculus.utilimportcontinuous_domain,function_range# Define the independent variablexsymbols(x,realTrue)# Define the function to analyze (modify this line as needed)fsqrt(x)/(x-1)log(2-x)# Example 1# f sqrt(x**2 - 5*x) # Example 2# f asin(x) # Example 3print(*60)print(fAnalyzing function: f(x) {f})print(*60)# Compute the domaintry:domaincontinuous_domain(f,x,S.Reals)print(f\nDomain:\n{domain})exceptExceptionase:print(f\nCould not compute domain:{e})domainNone# Compute the range (requires the domain)ifdomainisnotNone:try:range_yfunction_range(f,x,domain)print(f\nRange:\n{range_y})exceptExceptionase:print(f\nCould not compute range directly:{e})print(Manual analysis may be required.)else:print(\nRange cannot be determined without domain.)print(\n*60)print(Notation:)print( - Interval.open(a, b) : open interval (a, b))print( - Interval(a, b) : closed interval [a, b])print( - Interval.Ropen(a, b) : left-closed, right-open [a, b))print( - Interval.Lopen(a, b) : left-open, right-closed (a, b])print( - Union(...) : set union)print( - oo : infinity)print(*60)4. Test Cases and ResultsWe applied the script to three representative functions.4.1 Case 1:f ( x ) x x − 1 ln ⁡ ( 2 − x ) f(x) \frac{\sqrt{x}}{x-1} \ln(2-x)f(x)x−1x​​ln(2−x)Mathematical analysis:Domain:x ≥ 0 x \ge 0x≥0,x ≠ 1 x \neq 1x1, andx 2 x 2x2→[ 0 , 1 ) ∪ ( 1 , 2 ) [0,1) \cup (1,2)[0,1)∪(1,2).Range: asx → 1 x \to 1^x→1, the termx / ( x − 1 ) → ∞ \sqrt{x}/(x-1) \to \inftyx​/(x−1)→∞; asx → 1 − x \to 1^-x→1−, it tends to− ∞ -\infty−∞. The function is continuous on both subintervals, so it attains all real values →R \mathbb{R}R.Program output:Domain: Union(Interval.Ropen(0, 1), Interval.open(1, 2)) Range: Interval(-oo, oo)4.2 Case 2: $ f(x) \sqrt{x^2 - 5x}$Mathematical analysis:Domain:x 2 − 5 x ≥ 0 x^2 - 5x \ge 0x2−5x≥0→ $x \le 0 $ or $ x \ge 5$ →( − ∞ , 0 ] ∪ [ 5 , ∞ ) (-\infty,0] \cup [5,\infty)(−∞,0]∪[5,∞).Range: the radicand can take any non-negative value, and the square root yields ally ≥ 0 y \ge 0y≥0→[ 0 , ∞ ) [0, \infty)[0,∞).Program output:Domain: Union(Interval(-oo, 0), Interval(5, oo)) Range: Interval(0, oo)4.3 Case 3:f ( x ) arcsin ⁡ ( x ) f(x) \arcsin(x)f(x)arcsin(x)Mathematical analysis:Domain:x ∈ [ − 1 , 1 ] x \in [-1,1]x∈[−1,1].Range:y ∈ [ − π / 2 , π / 2 ] y \in [-\pi/2, \pi/2]y∈[−π/2,π/2].Program output (expected):Domain: Interval(-1, 1) Range: Interval(-pi/2, pi/2)5. DiscussionThe tool provides exact, closed-form interval descriptions for a wide class of elementary functions. It effectively implements the “exclude illegal regions” approach:For the domain, it identifies and removes points where the function is undefined.For the range, it symbolically solves fory yyand finds the minimum and maximum over the domain, including limits at boundaries.Limitations:For highly transcendental or piecewise-defined functions,function_rangemay fail; in such cases, manual analysis or numerical methods may be needed.The computation relies on SymPy’s internal algorithms, which are continuously improved.Nevertheless, for typical functions encountered in calculus and engineering, the script yields reliable and exact results with minimal user effort.6. ConclusionWe have developed a compact Python script that leverages SymPy to compute thedomainandrangeof real-valued functions in a mathematically exact manner. The tool is easy to use, outputs standard interval notation, and has been validated on multiple test cases. It can be seamlessly integrated into educational environments, automated reasoning pipelines, or engineering design workflows where symbolic knowledge of function behavior is required.7. SourcePS E:\ANNApython.exe e:/ANNA/experiments/get_function_range.py分析函数: f(x)sqrt(x)/(x -1) log(2- x)【定义域】 Union(Interval.Ropen(0,1), Interval.open(1,2))【值域】 Interval(-oo, oo)说明 - Interval.open(a, b)表示开区间(a, b)- Interval(a, b)表示闭区间[a, b]- Union(...)表示并集 - oo 表示无穷大PS E:\ANNApython.exe e:/ANNA/experiments/get_function_range.py分析函数: f(x)sqrt(x**2 -5*x)【定义域】 Union(Interval(-oo,0), Interval(5, oo))【值域】 Interval(0, oo)说明 - Interval.open(a, b)表示开区间(a, b)- Interval(a, b)表示闭区间[a, b]- Union(...)表示并集 - oo 表示无穷大PS E:\ANNAhttps://gitee.com/waterruby/ANNA.git