Skip to content

Commit

Permalink
Trac #34738: tiny details in symbolic min and max
Browse files Browse the repository at this point in the history
URL: https://trac.sagemath.org/34738
Reported by: chapoton
Ticket author(s): Frédéric Chapoton
Reviewer(s): Matthias Koeppe
  • Loading branch information
Release Manager committed Nov 21, 2022
2 parents fb213df + d097f77 commit a4748c3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/sage/functions/min_max.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
r"""
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.
Sage provides a symbolic maximum and minimum due to the fact that the
Python builtin :func:`max` and :func:`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::
Expand All @@ -24,14 +24,13 @@
max(x, 5)
sage: min_symbolic(3, 5, x)
min(x, 3)
"""
###############################################################################
# Sage: Open Source Mathematical Software
# Copyright (C) 2010 Burcin Erocal <burcin@erocal.org>
# Distributed under the terms of the GNU General Public License (GPL),
# version 2 or any later version. The full text of the GPL is available at:
# http://www.gnu.org/licenses/
# https://www.gnu.org/licenses/
###############################################################################

from sage.symbolic.function import BuiltinFunction
Expand All @@ -40,6 +39,7 @@

from builtins import max as builtin_max, min as builtin_min


class MinMax_base(BuiltinFunction):
def eval_helper(self, this_f, builtin_f, initial_val, args):
"""
Expand All @@ -53,7 +53,6 @@ def eval_helper(self, this_f, builtin_f, initial_val, args):
min(x, 3)
sage: min_symbolic([5.0r]) # indirect doctest
5.0
"""
# __call__ ensures that if args is a singleton, the element is iterable
arg_is_iter = False
Expand Down Expand Up @@ -151,12 +150,13 @@ def __call__(self, *args, **kwds):
except ValueError:
pass


class MaxSymbolic(MinMax_base):
def __init__(self):
r"""
Symbolic `\max` function.
The Python builtin `\max` function doesn't work as expected when symbolic
The Python builtin :func:`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.
Expand Down Expand Up @@ -236,7 +236,6 @@ def _evalf_(self, *args, **kwds):
...
sage: r.n() # abs tol 1e-8
0.873911256504955
"""
return max_symbolic(args)

Expand All @@ -249,7 +248,7 @@ def __init__(self):
r"""
Symbolic `\min` function.
The Python builtin `\min` function doesn't work as expected when symbolic
The Python builtin :func:`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.
Expand Down Expand Up @@ -323,4 +322,5 @@ def _evalf_(self, *args, **kwds):
"""
return min_symbolic(args)


min_symbolic = MinSymbolic()

0 comments on commit a4748c3

Please sign in to comment.