Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #431 and #274 #441

Merged
merged 3 commits into from
Jul 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,10 @@ class Sum(_IterationFunction, SympyFunction):

#> a=Sum[x^k*Sum[y^l,{l,0,4}],{k,0,4}]]
: "a=Sum[x^k*Sum[y^l,{l,0,4}],{k,0,4}]" cannot be followed by "]" (line 1 of "<test>").

## Issue431
#> Sum[2^(-i), {i, 1, \[Infinity]}]
= 1
"""

# Do not throw warning message for symbolic iteration bounds
Expand Down
21 changes: 16 additions & 5 deletions mathics/builtin/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import sympy
from mpmath import mp

from mathics.builtin.base import Builtin
from mathics.builtin.base import Builtin, SympyConstant
from mathics.core.convert import from_sympy
from mathics.core.expression import Expression, Integer, Symbol, Real

Expand Down Expand Up @@ -149,7 +149,7 @@ class VectorAngle(Builtin):
}


class Degree(Builtin):
class Degree(SympyConstant):
"""
<dl>
<dt>'Degree'
Expand All @@ -158,11 +158,22 @@ class Degree(Builtin):

>> Cos[60 Degree]
= 1 / 2

Degree has the value of Pi / 180
>> Degree == Pi / 180
= True

#> Cos[Degree[x]]
= Cos[Degree[x]]

## Issue 274
#> \[Degree] == ° == Degree
= True
"""

rules = {
'Degree': '(Pi/180)'
}
def to_sympy(self, expr):
if expr == Symbol('System`Degree'):
return sympy.pi / 180


class Inverse(Builtin):
Expand Down
13 changes: 12 additions & 1 deletion mathics/core/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@
inequality_ops, misc_ops)


special_symbols = {
'\u03C0': 'Pi', # Pi
'\uF74D': 'E', # ExponentialE
'\uF74E': 'I', # ImaginaryI
'\uF74F': 'I', # ImaginaryJ
'\u221E': 'Infinity', # Infinity
'\u00B0': 'Degree', # Degree
}


class Parser(object):
def __init__(self):
# no implicit times on these tokens
Expand Down Expand Up @@ -287,7 +297,8 @@ def p_String(self, token):
return result

def p_Symbol(self, token):
result = Symbol(token.text, context=None)
symbol_name = special_symbols.get(token.text, token.text)
result = Symbol(symbol_name, context=None)
self.consume()
return result

Expand Down
8 changes: 8 additions & 0 deletions test/test_parser/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ def testSymbol(self):
self.check('`name', Symbol('`name'))
self.check('`context`name', Symbol('`context`name'))

def testSpecialSymbol(self):
self.check('\[Pi]', 'Pi')
self.check('\[Degree]', 'Degree')
self.check('\[ExponentialE]', 'E')
self.check('\[ImaginaryI]', 'I')
self.check('\[ImaginaryJ]', 'I')
self.check('\[Infinity]', 'Infinity')

def testNumber(self):
self.check_number('0')
self.check_number('-1')
Expand Down