Exemplo n.º 1
0
    def _start(self):
        """
        Start up the Mathics interpreter and sets the initial prompt and options.

        This is called the first time the Mathics interface is actually used.

        EXAMPLES::

            sage: mathics._start()            # optional - mathics
            sage: type(mathics._session)      # optional - mathics
            <class 'mathics.session.MathicsSession'>
        """
        if not self._session:
            from mathics.session import MathicsSession
            self._session = MathicsSession()
            from sage.interfaces.sympy import sympy_init
            sympy_init()
            from sympy import Symbol
            from sympy.core.relational import Relational
            Symbol._sage_ = _mathics_sympysage_symbol
Exemplo n.º 2
0
import time
from mathics.core.parser import parse, MathicsSingleLineFeeder
from mathics.core.definitions import Definitions
from mathics.core.evaluation import Evaluation
from mathics.session import MathicsSession

session = MathicsSession(add_builtin=True, catch_interrupt=False)


def check_evaluation(str_expr: str, str_expected: str, message=""):
    """Helper function to test that a WL expression against
    its results"""
    result = session.evaluate("ToString[" + str_expr + "]").value
    print("result=", result)
    expected = session.evaluate("ToString[" + str_expected + "]").value
    print("expected=", expected)
    print(time.asctime())
    print(message)
    if message:
        assert result == expected, message
    else:
        assert result == expected
Exemplo n.º 3
0
# print("  * Loading libraries")

# from helper import session, check_evaluation
# It would be nice to load this code from .helper, but
# for some reason I can make the relative load works...

# import time
# from mathics.core.parser import parse, MathicsSingleLineFeeder
# from mathics.core.definitions import Definitions
# from mathics.core.evaluation import Evaluation
# from mathics.core.expression import Expression, String
from mathics.session import MathicsSession

print("  * creating the session")

session = MathicsSession()


def test_asymptote_cmd():
    from subprocess import DEVNULL, STDOUT, check_call
    from pymathics.asy import asy_path
    res = check_call([asy_path, '--version'], stdout=DEVNULL, stderr=DEVNULL)
    assert res == 0


print("Try calling asy")
test_asymptote_cmd()
print(" now the other tests...")


def check_evaluation(str_expr: str, str_expected: str, message=""):
Exemplo n.º 4
0
        "AxesStyle": "{}",
        "LabelStyle": "{}",
        "AspectRatio": "Automatic",
        "PlotRange": "Automatic",
        "PlotRangePadding": "Automatic",
        "ImageSize": "Automatic",
        "Background": "Automatic",
        "$OptionSyntax": "Ignore",
    }

    def apply(self, expr, evaluation, options):
        "%(name)s[expr_, OptionsPattern[%(name)s]]"
        ticks_style = options.get('System`TicksStyle').to_python()
        axes_style = options.get('System`AxesStyle').to_python()
        if not axes_style:
            plt.axis("off")
        plt.show()
        return expr


if __name__ == "__main__":
    from mathics.session import MathicsSession

    session = MathicsSession(add_builtin=True, catch_interrupt=False)
    session.evaluate("""
        LoadModule["pymathics.matplotlib"];
        MPlot[ToMatplotlib[AspectRatio -> 1 / GoldenRatio]];
        MPlot[ToMatplotlib[Line[{{0.25,0.5},{0.25,0.25},{0.5,0.25},{0.5,0.5}}]]]
        MPlot[ToMatplotlib[Rectangle[{0, 0.5}]], AxesStyle->False]
        """)