Skip to content
Closed
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
b0e63ed
fixes to make cellstotex to work
mmatera Jan 9, 2021
9b9072e
adding options to ToString
mmatera Jan 10, 2021
657a738
Merge remote-tracking branch 'upstream/master' into newcellstotexfixes2
mmatera Jan 16, 2021
5441b9f
clean up
mmatera Jan 16, 2021
f10e3e0
restoring tests
mmatera Jan 16, 2021
b1ff26f
merge options
mmatera Jan 16, 2021
4a2f03e
Merge branch 'fixnamedOptionsPattern' into newcellstotexfixes2
mmatera Jan 16, 2021
5ed9220
fix optionpatterns with names
mmatera Jan 16, 2021
2a632b1
Merge branch 'fixnamedOptionsPattern' into newcellstotexfixes2
mmatera Jan 16, 2021
b1d1b88
merge
mmatera Jan 16, 2021
997ed17
fix OptionValue related
mmatera Jan 16, 2021
1d80bdc
Merge branch 'fixnamedOptionsPattern' into newcellstotexfixes2
mmatera Jan 16, 2021
a02a129
adding and fixing tests
mmatera Jan 17, 2021
d464c2f
Merge branch 'fixnamedOptionsPattern' of https://github.com/mathics/M…
mmatera Jan 19, 2021
b701894
fixing OptionQ
mmatera Jan 22, 2021
34c7646
(Stub) adding support for attributes in Function
mmatera Jan 22, 2021
bb8b78a
improve support of symbol Function with a third argument
mmatera Jan 22, 2021
15b993a
fix attribute support in abstract functions
mmatera Jan 22, 2021
39c9208
Improving support for OptionValue. Adding tests
mmatera Jan 16, 2021
1aae381
(Stub) adding support for attributes in Function
mmatera Jan 22, 2021
ed75290
DRY option tests
mmatera Jan 23, 2021
00ee8a3
merge to master
mmatera Jan 23, 2021
233f6c6
fix options
mmatera Jan 23, 2021
b549ebb
merge
mmatera Jan 23, 2021
efe392b
improve Hash support
mmatera Jan 23, 2021
ec97564
improve Hash support
mmatera Jan 23, 2021
9d163ff
fixing OptionValue
mmatera Jan 25, 2021
0b21fd3
Try 3.9
rocky Jan 23, 2021
6899ef4
Disable a test on OSX until we figure out what's wrong
rocky Jan 23, 2021
9bda8c4
basic.yml -> ubuntu.yml
rocky Jan 23, 2021
4530cbf
Will reinstate via GUI
rocky Jan 23, 2021
790a257
Create ubuntu.yml
rocky Jan 23, 2021
0e5436a
Combinatorica: Use RandomPermuation2 ...
rocky Jan 24, 2021
e5bc62a
Test up to but not including 2.1 Partitions
rocky Jan 24, 2021
016cd96
Added a dictionary for qualified named characters
GarkGarcia Jan 13, 2021
e347ab3
Refactored and renamed stuff
GarkGarcia Jan 13, 2021
553ebdf
Fixed a bug that aliased named character whose WL representation is t…
GarkGarcia Jan 15, 2021
e6a1fd7
Moved stuff to mathics.core.character and removed duplicate code
GarkGarcia Jan 15, 2021
0f66790
Fixed WL_TO_PLAIN_DICT
GarkGarcia Jan 16, 2021
ef474d2
Extracted the dictionaries to a separate file and cleaned the code
GarkGarcia Jan 16, 2021
af72edb
Added yaml as a dependency
GarkGarcia Jan 16, 2021
f3ef486
Fixed wrong import
GarkGarcia Jan 16, 2021
a16ed22
Fixed deprecation warning
GarkGarcia Jan 16, 2021
a33782f
Fixed some errors
GarkGarcia Jan 16, 2021
9865420
Fixed the last failing test
GarkGarcia Jan 16, 2021
753a2c1
Fixed another test
GarkGarcia Jan 16, 2021
fadc604
Fixed yet another test
GarkGarcia Jan 16, 2021
9adfdf1
Added missing entries `named-characters`
GarkGarcia Jan 16, 2021
034d816
Fixed syntax error
GarkGarcia Jan 16, 2021
d512025
Removed unnecessary file
GarkGarcia Jan 16, 2021
bd51315
Changed the format of the yml table
GarkGarcia Jan 17, 2021
8324fda
Use external mathics-scanner
rocky Jan 18, 2021
99d68d6
workflows test using github
rocky Jan 18, 2021
fa8c4d5
More import conversions
rocky Jan 18, 2021
b55e86b
Travis needs to get code from github for now..
rocky Jan 18, 2021
03c2246
Fixed https://github.com/mathics/Mathics/pull/1117#issuecomment-76256…
GarkGarcia Jan 19, 2021
a19fdcc
Added a PyYAML install in Makefile and .travis.yml
GarkGarcia Jan 19, 2021
0860093
Fixed typo
GarkGarcia Jan 19, 2021
727078e
Removed references to PyYAML in CI
GarkGarcia Jan 19, 2021
472e0ed
Revise for reworked mathics-scanner
rocky Jan 23, 2021
519e8ea
DRY load modules. fix Hash and FileHash symbols
mmatera Jan 26, 2021
117d6e3
Merge branch 'master' of https://github.com/mathics/Mathics into newc…
mmatera Jan 26, 2021
7719b83
merge
mmatera Feb 14, 2021
d31c40e
merge
mmatera Feb 14, 2021
87e8d36
Use MathicsSingleLineFeeder + lint changes
rocky Feb 21, 2021
6f25908
Merge remote-tracking branch 'upstream/master' into newcellstotexfixes2
mmatera Feb 21, 2021
0a26f3f
clean up
mmatera Feb 21, 2021
9b69dd5
merge remote
mmatera Feb 21, 2021
af54884
Merge remote-tracking branch 'upstream/master' into newcellstotexfixes2
mmatera Mar 3, 2021
1b5178b
Merge remote-tracking branch 'upstream/master' into newcellstotexfixes2
mmatera Mar 3, 2021
a9f6631
using asy for export
mmatera Mar 4, 2021
5a9782f
merge
mmatera Mar 7, 2021
e646493
Merge remote-tracking branch 'upstream/master' into newcellstotexfixes2
mmatera Mar 25, 2021
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
1 change: 0 additions & 1 deletion mathics/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
PatternObject,
)

from mathics.settings import ENABLE_FILES_MODULE

exclude_files = set(("files", "codetables", "base", "importexport", "colors"))
module_names = [
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1858,9 +1858,9 @@ class Sum(_IterationFunction, SympyFunction):
>> Sum[x ^ 2, {x, 1, y}] - y * (y + 1) * (2 * y + 1) / 6
= 0

## >> (-1 + a^n) Sum[a^(k n), {k, 0, m-1}] // Simplify
## = -1 + (a ^ n) ^ m # this is what I am getting
## = Piecewise[{{m (-1 + a ^ n), a ^ n == 1}, {-1 + (a ^ n) ^ m, True}}]

>> (-1 + a^n) Sum[a^(k n), {k, 0, m-1}] // Simplify
= Piecewise[{{m (-1 + a ^ n), a ^ n == 1}, {-1 + (a ^ n) ^ m, True}}]

Infinite sums:
>> Sum[1 / 2 ^ i, {i, 1, Infinity}]
Expand Down
31 changes: 30 additions & 1 deletion mathics/builtin/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,38 @@ def apply_named(self, vars, body, args, evaluation):
var.get_name() for var in vars), args[:len(vars)])))
return body.replace_vars(vars)

# Not sure if DRY is possible here...
def apply_named_attr(self, vars, body, attr, args, evaluation):
'Function[vars_, body_, attr_][args___]'

## FIXME: In order to get the proper behaviour, we need
## to take into account the attributes in the evaluation
##

print("Warning: incomplete implementation")
if attr.has_form('List', None):
attr = [str(a) for a in attr.leaves]
else:
attr = [str(attr)]


if vars.has_form('List', None):
vars = vars.leaves
else:
vars = [vars]


args = args.get_sequence()
if len(vars) > len(args):
evaluation.message('Function', 'fpct', )
else:
vars = dict(list(zip((
var.get_name() for var in vars), args[:len(vars)])))
return body.replace_vars(vars)


# Not sure if DRY is possible here...
def apply_named_attr(self, vars, body, attr, args, evaluation):
'Function[vars_, body_, attr_][args___]'
if vars.has_form('List', None):
vars = vars.leaves
else:
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ class Eigenvalues(Builtin):

Symbolic eigenvalues:
>> Eigenvalues[{{Cos[theta],Sin[theta],0},{-Sin[theta],Cos[theta],0},{0,0,1}}] // Sort
= {1, Cos[theta] + Sqrt[(-1 + Cos[theta]) (1 + Cos[theta])], Cos[theta] - Sqrt[(-1 + Cos[theta]) (1 + Cos[theta])]}
= {1, Cos[theta] + Sqrt[-1 + Cos[theta] ^ 2], Cos[theta] - Sqrt[-1 + Cos[theta] ^ 2]}

>> Eigenvalues[{{7, 1}, {-4, 3}}]
= {5, 5}
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def select(inner):
return inner.leaves[py_slice]

return select

def _parts_span_selector(pspec):
if len(pspec.leaves) > 3:
raise MessageException("Part", "span", pspec)
Expand Down
3 changes: 2 additions & 1 deletion mathics/builtin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ class OptionValue(Builtin):
'optnf': "Option name `1` not found.",
}


rules = {
'OptionValue[optnames_List]': 'OptionValue/@optnames',
'OptionValue[f_, optnames_List]': 'OptionValue[f,#1]&/@optnames',
Expand Down Expand Up @@ -299,6 +298,8 @@ def test(self, expr):
expr = [expr]
else:
expr = expr.get_leaves()


return all(e.has_form('Rule', None) or e.has_form('RuleDelayed', 2)
for e in expr)

Expand Down
1 change: 1 addition & 0 deletions mathics/builtin/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@ class Pattern_(PatternObject):
'pattern_?(!MatchQ[#, _Blank|_BlankSequence|_BlankNullSequence]&)]': (
'Infix[{symbol, pattern}, ":", 150, Left]'),
}
precedence = 1000

def init(self, expr):
super(Pattern_, self).init(expr)
Expand Down
1 change: 0 additions & 1 deletion mathics/builtin/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,6 @@ class ToString(Builtin):
>> "U" <> ToString[2]
= U2
"""

options = {'CharacterEncoding' : '"Unicode"',
'FormatType' : 'OutputForm',
'NumberMarks': '$NumberMarks',
Expand Down
2 changes: 0 additions & 2 deletions mathics/core/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,6 @@ def get_package_names(self) -> typing.List[str]:
packages = [c.get_string_value() for c in packages.leaves]
return packages

# return sorted({name.split("`")[0] for name in self.get_names()})

def shorten_name(self, name_with_ctx) -> str:
if "`" not in name_with_ctx:
return name_with_ctx
Expand Down
1 change: 0 additions & 1 deletion mathics/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ def format_result(self, str_expression=None, timeout = None, form=None):
if str_expression:
self.last_result = self.evaluate(str_expression, timeout)
return self.last_result.do_format(self.evaluation, form)

110 changes: 110 additions & 0 deletions test/test_cellstotex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
import os
from mathics.core.parser import parse, MathicsSingleLineFeeder
from mathics.core.definitions import Definitions
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Symbol
import pytest
import urllib.request

external_url = (
"https://raw.githubusercontent.com/jkuczm/MathematicaCellsToTeX/master/NoInstall.m"
)

pytestmark = pytest.mark.skipif(os.getenv("SKIP_CELLSTOTEX", None) is not None,
reason="SKIP_CELLSTOTEX environment variable set")

try:
http_code = urllib.request.urlopen(external_url).getcode()
except:
url_reachable = False
else:
url_reachable = http_code in (200,) # add other 2xx or 3xx's?

definitions = Definitions(add_builtin=True)
evaluation = Evaluation(definitions=definitions, catch_interrupt=False)
set_versionnumber = 'Unprotect[$VersionNumber];$VersionNumber=11;Protect[$VersionNumber];'
import_url = 'Import@"%s"' % external_url


def _evaluate(str_expression):
expr = parse(definitions, MathicsSingleLineFeeder(str_expression))
return expr.evaluate(evaluation)

def test_load():
str_expected1 = "{}"
message1 = ""
_evaluate(set_versionnumber)
result1 = _evaluate(import_url)
expected1 = _evaluate(str_expected1)


if message1:
assert result1 == expected1, message1
else:
assert result1 == expected1

result2 = _evaluate('Names["CellsToTeX`*"]')
expected2 = _evaluate('{"CellToTeX", "CellsToTeXException", "CellsToTeXPreamble"}')
print(result2)
assert result2 == expected2



@pytest.mark.skipif(not url_reachable, reason="skipping since we can't reach %s" % external_url)
#@pytest.mark.skip(
# reason="FIXME: full CellToTeX import test is not working yet: implement levelspec > 1"
#)
def test_load_and_run():
print("load and run")
str_expected0 = "None"
_evaluate(set_versionnumber)
result0 = _evaluate(import_url)
expected0 = _evaluate(str_expected0)

if result0 == Symbol("System`$Failed"):
return 0



str_expr1 = 'CellsToTeXPreamble[]'
str_expected1 = '"\\mmaSet{morefv={gobble=2,},}\\n"'
result1 = _evaluate(str_expr1)
expected1 = _evaluate(str_expected1)
assert result1 == expected1


str_expr1 = 'boxes=MakeBoxes[Pi];\
cell = Cell[BoxData[boxes], "Input"];res=Catch[CellToTeX[cell, Style->"Input"]]'
str_expected1 = '"\\begin{mmaCell}{Input}\n \\pi\n\\end{mmaCell}"'
message1 = ""
result1 = _evaluate(str_expr1)
expected1 = _evaluate(str_expected1)
if message1:
assert result1 == expected1, message1
else:
assert result1 == expected1

str_expr2 = 'boxes=MakeBoxes[(-b \\[PlusMinus] Sqrt[b^2-4*a*c])/(2 a)];\
cell = Cell[BoxData[boxes],"Input"];res=Catch[CellToTeX[cell], Style->"Input"]'
str_expected2 = '"\\begin{mmaCell}{Input}\n \\mmaFrac{-b\\(\\pmb{\\pm}\\)\\mmaSqrt{\\mmaSup{b}{2}-4 a c}}{2 a}\n\\end{mmaCell}"'
print(str_expr2)
message2 = ""
result2 = _evaluate(str_expr2)
expected2 = _evaluate(str_expected2)
if message2:
assert result2 == expected2, message2
else:
assert result2 == expected2

str_expr3 = 'boxes=MakeBoxes[Sqrt[Integrate[f[x],{x,a,b}]]];\
cell = Cell[BoxData[boxes],"Input"];res=Catch[CellToTeX[cell]]'
print(str_expr3)

str_expected3 = '"\\begin{mmaCell}[morefunctionlocal={x}]{Input}\n \\mmaSqrt{\\mmaSubSupM{\\int}{a}{b}f[x]dx}\n\\end{mmaCell}"'
message3 = ""
result3 = _evaluate(str_expr3)
expected3 = _evaluate(str_expected3)
if message3:
assert result3 == expected3, message3
else:
assert result3 == expected3
2 changes: 1 addition & 1 deletion test/test_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
def test_evaluation(str_expr: str, str_expected: str, message=""):
result = session.evaluate(str_expr)
expected = session.evaluate(str_expected)

print("message=", message)
if message:
assert result == expected, message
else:
Expand Down