51b2e962f4891e7563543db5560e2bdc9a20bd6d,mathics/builtin/numeric.py,N,apply_other,#N#Any#Any#Any#,122
Before Change
def apply_other(self, expr, prec, evaluation):
"N[expr_, prec_]"
valid_prec = get_precision(prec, evaluation)
if valid_prec is not None:
if expr.get_head_name() in ("System`List", "System`Rule"):
return Expression(
expr.head, *[self.apply_other(leaf, prec, evaluation)
for leaf in expr.leaves])
if isinstance(expr, Number):
return expr.round(valid_prec)
name = expr.get_lookup_name()
if name != "":
nexpr = Expression("N", expr, prec)
result = evaluation.definitions.get_value(
name, "System`NValues", nexpr, evaluation)
if result is not None:
if not result.same(nexpr):
result = Expression(
"N", result, prec).evaluate(evaluation)
return result
if expr.is_atom():
return expr.round(valid_prec)
else:
attributes = expr.head.get_attributes(evaluation.definitions)
if "System`NHoldAll" in attributes:
eval_range = []
elif "System`NHoldFirst" in attributes:
eval_range = list(range(1, len(expr.leaves)))
elif "System`NHoldRest" in attributes:
if len(expr.leaves) > 0:
eval_range = (0,)
else:
eval_range = ()
else:
eval_range = list(range(len(expr.leaves)))
head = Expression("N", expr.head, prec).evaluate(evaluation)
leaves = expr.leaves[:]
for index in eval_range:
leaves[index] = Expression(
"N", leaves[index], prec).evaluate(evaluation)
return Expression(head, *leaves)
class MachinePrecision(Predefined):
<dl>
<dt>"MachinePrecision"
After Change
def apply_other(self, expr, prec, evaluation):
"N[expr_, prec_]"
if prec.get_name() == "System`MachinePrecision":
d = None
else:
d = prec.get_float_value(n_evaluation=evaluation)
if d is None:
return evaluation.message("N", "precbd", prec)
if expr.get_head_name() in ("System`List", "System`Rule"):
return Expression(
expr.head, *[self.apply_other(leaf, prec, evaluation)
for leaf in expr.leaves])
In pattern: SUPERPATTERN
Frequency: 3
Non-data size: 14
Instances
Project Name: mathics/Mathics
Commit Name: 51b2e962f4891e7563543db5560e2bdc9a20bd6d
Time: 2016-08-05
Author: 16sn6uv@gmail.com
File Name: mathics/builtin/numeric.py
Class Name: N
Method Name: apply_other
Project Name: mathics/Mathics
Commit Name: 51b2e962f4891e7563543db5560e2bdc9a20bd6d
Time: 2016-08-05
Author: 16sn6uv@gmail.com
File Name: mathics/builtin/numeric.py
Class Name: N
Method Name: apply_other
Project Name: mathics/Mathics
Commit Name: 51b2e962f4891e7563543db5560e2bdc9a20bd6d
Time: 2016-08-05
Author: 16sn6uv@gmail.com
File Name: mathics/builtin/exptrig.py
Class Name: Pi
Method Name: apply_N
Project Name: mathics/Mathics
Commit Name: 51b2e962f4891e7563543db5560e2bdc9a20bd6d
Time: 2016-08-05
Author: 16sn6uv@gmail.com
File Name: mathics/builtin/exptrig.py
Class Name: E
Method Name: apply_N