Skip to content

Commit

Permalink
Add "Package updates" section and fill in
Browse files Browse the repository at this point in the history
  • Loading branch information
rocky committed Oct 1, 2024
1 parent b01df45 commit fa2c682
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@ Performance

* ``Blank*`` patterns without arguments are now singletons.

API Incompatibility
API incompatibility
-------------

* ``Matcher`` now requires an additional ``evaluation`` parameter


Package updates
+++++++++++++++

#. Python 3.12 is now supported
#. SymPy 1.13 is now supported


7.0.0
Expand Down
56 changes: 56 additions & 0 deletions mathics/builtin/numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,3 +785,59 @@ def eval(self, x, evaluation: Evaluation):
def eval_error(self, x, seqs, evaluation: Evaluation):
"Sign[x_, seqs__]"
evaluation.message("Sign", "argx", Integer(len(seqs.get_sequence()) + 1))


class UnitStep(Builtin):
"""
<url>
:WMA link:
https://reference.wolfram.com/language/ref/UnitStep.html</url>)
<dl>
<dt>'Sign[$x$]'
<dd>return -1, 0, or 1 depending on whether $x$ is negative, zero, or positive.
</dl>
>> Unitize[E]
= 1
>> Sign[-6]
= -1
>> Sign[0]
= 0
>> Sign[{-5, -10, 15, 20, 0}]
= {-1, -1, 1, 1, 0}
For a complex number, 'Sign' returns the phase of the number:
>> Sign[3 - 4*I]
= 3 / 5 - 4 I / 5
"""

summary_text = "turn number into 0 or 1"

attributes = A_LISTABLE | A_NUMERIC_FUNCTION | A_PROTECTED

messages = {
"argx": "Sign called with `1` arguments; 1 argument is expected.",
}

rules = {
"Sign[Power[a_, b_]]": "Power[Sign[a], b]",
}

def eval(self, x, evaluation: Evaluation):
"Sign[x_]"
result = eval_Sign(x)
if result is not None:
return result
# return None

sympy_x = x.to_sympy()
if sympy_x is None:
return None
# Unhandled cases. Use sympy
return super(Sign, self).eval(x, evaluation)

def eval_error(self, x, seqs, evaluation: Evaluation):
"Sign[x_, seqs__]"
evaluation.message("Sign", "argx", Integer(len(seqs.get_sequence()) + 1))

0 comments on commit fa2c682

Please sign in to comment.