Skip to content

Commit a309401

Browse files
committed
fixing accuracy
1 parent f6be461 commit a309401

2 files changed

Lines changed: 43 additions & 47 deletions

File tree

mathics/builtin/assignment.py

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -863,43 +863,38 @@ class Information(PrefixOperator):
863863
864864
865865
>> a = 2;
866-
>> Information[a]
867-
= a = 2
868-
869-
866+
X> Information[a]
867+
| a = 2
870868
>> f[x_] := x ^ 2
871869
>> g[f] ^:= 2
872870
>> f::usage = "f[x] returns the square of x";
873871
X> Information[f]
874-
= f[x] returns the square of x
875-
876-
>> ? Table
877-
=
878-
. 'Table[expr, {i, n}]'
879-
. evaluates expr with i ranging from 1 to n, returning
880-
. a list of the results.
881-
. 'Table[expr, {i, start, stop, step}]'
882-
. evaluates expr with i ranging from start to stop,
883-
. incrementing by step.
884-
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
885-
. evaluates expr with i taking on the values e1, e2,
886-
. ..., ei.
887-
.
888-
889-
>> Information[Table]
890-
=
891-
. 'Table[expr, {i, n}]'
892-
. evaluates expr with i ranging from 1 to n, returning
893-
. a list of the results.
894-
. 'Table[expr, {i, start, stop, step}]'
895-
. evaluates expr with i ranging from start to stop,
896-
. incrementing by step.
897-
. 'Table[expr, {i, {e1, e2, ..., ei}}]'
898-
. evaluates expr with i taking on the values e1, e2,
899-
. ..., ei.
900-
.
901-
. Attributes[Table] = {HoldAll, Protected}
902-
.
872+
| f[x] returns the square of x
873+
874+
X> ? Table
875+
| 'Table[expr, {i, n}]'
876+
| evaluates expr with i ranging from 1 to n, returning
877+
| a list of the results.
878+
| 'Table[expr, {i, start, stop, step}]'
879+
| evaluates expr with i ranging from start to stop,
880+
| incrementing by step.
881+
| 'Table[expr, {i, {e1, e2, ..., ei}}]'
882+
| evaluates expr with i taking on the values e1, e2,
883+
| ..., ei.
884+
885+
X> Information[Table]
886+
| 'Table[expr, {i, n}]'
887+
| evaluates expr with i ranging from 1 to n, returning
888+
| a list of the results.
889+
| 'Table[expr, {i, start, stop, step}]'
890+
| evaluates expr with i ranging from start to stop,
891+
| incrementing by step.
892+
| 'Table[expr, {i, {e1, e2, ..., ei}}]'
893+
| evaluates expr with i taking on the values e1, e2,
894+
| ..., ei.
895+
|
896+
| Attributes[Table] = {HoldAll, Protected}
897+
|
903898
"""
904899

905900
operator = "??"
@@ -910,14 +905,14 @@ class Information(PrefixOperator):
910905

911906
def format_definition(self, symbol, evaluation, options, grid=True):
912907
'StandardForm,TraditionalForm,OutputForm: Information[symbol_, OptionsPattern[Information]]'
908+
ret = Symbol("Null")
913909
lines = []
914910
if isinstance(symbol, String):
915911
evaluation.print_out(symbol)
916-
evaluation.evaluate(Expression('Information', Symbol('System`String')))
917-
return
912+
return ret
918913
if not isinstance(symbol, Symbol):
919914
evaluation.message('Information', 'notfound', symbol)
920-
return Symbol('Null')
915+
return ret
921916
# Print the "usage" message if available.
922917
usagetext = _get_usage_string(symbol, evaluation)
923918
if usagetext is not None:
@@ -928,17 +923,16 @@ def format_definition(self, symbol, evaluation, options, grid=True):
928923

929924
if grid:
930925
if lines:
931-
return Expression(
926+
infoshow = Expression(
932927
'Grid', Expression(
933928
'List', *(Expression('List', line) for line in lines)),
934929
Expression(
935930
'Rule', Symbol('ColumnAlignments'), Symbol('Left')))
936-
else:
937-
return Symbol('Null')
931+
evaluation.print_out(infoshow)
938932
else:
939933
for line in lines:
940934
evaluation.print_out(Expression('InputForm', line))
941-
return Symbol('Null')
935+
return ret
942936

943937
# It would be deserable to call here the routine inside Definition, but for some reason it fails...
944938
# Instead, I just copy the code from Definition
@@ -1005,7 +999,9 @@ def rhs(expr):
1005999

10061000
def format_definition_input(self, symbol, evaluation, options):
10071001
'InputForm: Information[symbol_, OptionsPattern[Information]]'
1008-
return self.format_definition(symbol, evaluation, options, grid=False)
1002+
self.format_definition(symbol, evaluation, options, grid=False)
1003+
ret = Symbol("Null")
1004+
return ret
10091005

10101006

10111007
class Clear(Builtin):

mathics/builtin/constants.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,10 @@ def get_constant(self, precision, evaluation, preference=None):
118118
return MachineReal(value)
119119
elif preference == "sympy":
120120
if hasattr(self, "sympy_name"):
121-
value = sympy_constant(self.sympy_name, d)
121+
value = sympy_constant(self.sympy_name, d+2)
122122
elif preference == "mpmath":
123123
if hasattr(self, "sympy_name"):
124-
value = mp_constant(self.mpmath_name, d)
124+
value = mp_constant(self.mpmath_name, d+2)
125125
if value:
126126
return PrecisionReal(sympy.Float(str(value), d))
127127
# If the value is not available, return none
@@ -272,8 +272,8 @@ def to_numpy(self, expr=None, **kwargs):
272272
# return mpmath.degree
273273
return numpy.pi / 180
274274

275-
def apply_N(self, precision, evaluation):
276-
"N[Degree, precision_]"
275+
def apply_N(self, precision, evaluation, options={}):
276+
"N[Degree, precision_, OptionsPattern[%(name)s]]"
277277
try:
278278
d = get_precision(precision, evaluation)
279279
except PrecisionValueError:
@@ -311,8 +311,8 @@ class E(MPMathConstant, NumpyConstant, SympyConstant):
311311
numpy_name = "e"
312312
sympy_name = "E"
313313

314-
def apply_N(self, precision, evaluation):
315-
"N[E, precision_]"
314+
def apply_N(self, precision, evaluation, options={}):
315+
"N[E, precision_, OptionsPattern[%(name)s]]"
316316
return self.get_constant(precision, evaluation)
317317

318318

0 commit comments

Comments
 (0)