Symbolic minimum and maximum¶
Sage provides a symbolic maximum and minimum due to the fact that the
Python builtin max() and min() are not able to deal with variables
as users might expect. These functions wait to evaluate if there are variables.
Here you can see some differences:
sage: max(x, x^2)
x
sage: max_symbolic(x, x^2)
max(x, x^2)
sage: f(x) = max_symbolic(x, x^2); f(1/2)
1/2
>>> from sage.all import *
>>> max(x, x**Integer(2))
x
>>> max_symbolic(x, x**Integer(2))
max(x, x^2)
>>> __tmp__=var("x"); f = symbolic_expression(max_symbolic(x, x**Integer(2))).function(x); f(Integer(1)/Integer(2))
1/2
This works as expected for more than two entries:
sage: max(3, 5, x)
5
sage: min(3, 5, x)
3
sage: max_symbolic(3, 5, x)
max(x, 5)
sage: min_symbolic(3, 5, x)
min(x, 3)
>>> from sage.all import *
>>> max(Integer(3), Integer(5), x)
5
>>> min(Integer(3), Integer(5), x)
3
>>> max_symbolic(Integer(3), Integer(5), x)
max(x, 5)
>>> min_symbolic(Integer(3), Integer(5), x)
min(x, 3)
- class sage.functions.min_max.MaxSymbolic[source]¶
Bases:
MinMax_baseSymbolic \(\max\) function.
The Python builtin
max()function does not work as expected when symbolic expressions are given as arguments. This function delays evaluation until all symbolic arguments are substituted with values.EXAMPLES:
sage: max_symbolic(3, x) max(3, x) sage: max_symbolic(3, x).subs(x=5) 5 sage: max_symbolic(3, 5, x) max(x, 5) sage: max_symbolic([3, 5, x]) max(x, 5)
>>> from sage.all import * >>> max_symbolic(Integer(3), x) max(3, x) >>> max_symbolic(Integer(3), x).subs(x=Integer(5)) 5 >>> max_symbolic(Integer(3), Integer(5), x) max(x, 5) >>> max_symbolic([Integer(3), Integer(5), x]) max(x, 5)
- class sage.functions.min_max.MinMax_base[source]¶
Bases:
BuiltinFunction- eval_helper(this_f, builtin_f, initial_val, args)[source]¶
EXAMPLES:
sage: max_symbolic(3, 5, x) # indirect doctest max(x, 5) sage: max_symbolic([5.0r]) # indirect doctest 5.0 sage: min_symbolic(3, 5, x) min(x, 3) sage: min_symbolic([5.0r]) # indirect doctest 5.0
>>> from sage.all import * >>> max_symbolic(Integer(3), Integer(5), x) # indirect doctest max(x, 5) >>> max_symbolic([5.0]) # indirect doctest 5.0 >>> min_symbolic(Integer(3), Integer(5), x) min(x, 3) >>> min_symbolic([5.0]) # indirect doctest 5.0
- class sage.functions.min_max.MinSymbolic[source]¶
Bases:
MinMax_baseSymbolic \(\min\) function.
The Python builtin
min()function does not work as expected when symbolic expressions are given as arguments. This function delays evaluation until all symbolic arguments are substituted with values.EXAMPLES:
sage: min_symbolic(3, x) min(3, x) sage: min_symbolic(3, x).subs(x=5) 3 sage: min_symbolic(3, 5, x) min(x, 3) sage: min_symbolic([3, 5, x]) min(x, 3)
>>> from sage.all import * >>> min_symbolic(Integer(3), x) min(3, x) >>> min_symbolic(Integer(3), x).subs(x=Integer(5)) 3 >>> min_symbolic(Integer(3), Integer(5), x) min(x, 3) >>> min_symbolic([Integer(3), Integer(5), x]) min(x, 3)