Skip to content

Function Property Analysis (functions/functions.py)

functions/functions.py provides range, monotonic intervals, parity, period, and extrema analysis. All functions take the function f, variable s, and domain d as strings, with fs the function dictionary.

Note

In the functions below, is_increase and arg are reserved/placeholder parameters: passing them does not affect parsing of frange/monotonic_interval; odd_or_even/period are currently called with arg=None.

frange — range

Purpose: compute the range of a function over a given domain.

def frange(f, s, d, is_increase, fs):
    ...
Param Type Meaning
f str function expression, e.g. "x**2"
s str variable symbol, e.g. "x"
d str domain, a SymPy Interval string, e.g. "Interval(0, 3)"
is_increase bool placeholder (unused)
fs dict function dictionary

Returns: the range as a SymPy Set (from function_range).

monotonic_interval — monotonic intervals

Purpose: compute the increasing or decreasing intervals of a function.

def monotonic_interval(f, s, d, is_increase, fs):
    ...
Param Type Meaning
f str function expression
s str variable symbol
d str domain (Interval form)
is_increase bool True for increasing, False for decreasing
fs dict function dictionary

Returns: monotonic interval as a SymPy Set.

odd_or_even — parity

Purpose: determine the parity of a function.

def odd_or_even(f, s, d, arg, fs):
    ...
Param Type Meaning
f str function expression
s str variable symbol
d str domain
arg placeholder unused (pass None)
fs dict function dictionary

Returns: "既奇又偶函数" / "奇函数" / "偶函数" / "非奇非偶函数".

period — period

Purpose: compute the period of a function.

def period(f, s, d, arg, fs):
    ...
Param Type Meaning
f str function expression
s str variable symbol
d str domain
arg placeholder unused (pass None)
fs dict function dictionary

Returns: period expression; "该函数无周期" when aperiodic.

mvalues — extrema

Purpose: compute the maximum or minimum value of a function over its domain.

def mvalues(f, s, d, is_max, fs):
    ...
Param Type Meaning
f str function expression
s str variable symbol
d str domain (Interval form)
is_max bool True for maximum, False for minimum
fs dict function dictionary

Returns: extreme-value expression (SymPy maximum / minimum).

get_function_attr — unified entry

Purpose: dispatch the above analyses by the attr index; used by the UI palette.

def get_function_attr(f, s, d, attr, fs):
    ...
Param Type Meaning
f str function expression
s str variable symbol
d str domain
attr int attribute index 0–7 (see table below)
fs dict function dictionary

Returns: the result for the chosen attribute.

attr mapping

attr meaning calls
0 function expression & domain (sympify(f), sympify(d))
1 range frange
2 increasing interval monotonic_interval(is_increase=True)
3 decreasing interval monotonic_interval(is_increase=False)
4 parity odd_or_even
5 period period
6 maximum mvalues(is_max=True)
7 minimum mvalues(is_max=False)

Example

python frange("x**2", "x", "Interval(0, 3)", True, {}) # -> Interval(0, 9) odd_or_even("x**3", "x", "Interval(-oo, oo)", None, {}) # -> "奇函数" get_function_attr("x**2", "x", "Interval(0, 3)", 1, {}) # -> range Interval(0, 9)