Skip to content
Closed
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
87 changes: 87 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''

---
<!-- Feel free to remove sections marked optional if they are not relevant. The other sections, please fill out. See also https://github.com/Mathics3/mathics-core/blob/master/REPORTING-BUGS.md -->

## Description

<!-- Please add a clear and concise description of the bug. Try to reduce the bug to the minimum expression that exhibits the bug.
For example, if an expression occurs with several terms, can these be removed and the bug still appear? If so, we would like the reduced, simpler expression.

If the expression can be written in SymPy, does SymPy also exhibit the problem?
-->

## How to Reproduce

<!--
Steps to reproduce the behavior.

For Django:
1. Go to ...
2. Enter ....
2. Click on ....
3. Scroll down to '....'
4. See error

For a command-line environment:

$mathics -c 'E ^ (Pi I)' # adjust expression E ^ (Pi I) for the specific bug

-->

## Output Given

<!--
Please include not just the error message but all output leading to the message, which includes echoing input and messages up to the error.
For a command-line environment, include the command invocation and all the output produced.

If this is too long, then try narrowing the problem to something short.
-->


## Expected behavior

<!-- Add a clear and concise description of what you expected to happen. -->

## Your Environment

<!--

Sometimes problems are specific to a particular environment or
software release. If you have access to several environments, it is helpful to check whether this fails on more than one environment. Please
indicate that when available.

If you are using a recently released Python package that Mathics3
uses, it is possible we haven't tested this, and the new package is not
compatible. Try on an older software release, and if that is still the problem, let us
know about the breakage in the version.

In either case, please include the output from:

mathics --version

This information is also posted when you enter either the `mathics` or `mathicsscript` commands.

If you are running from a browser Django, please note the browser type, e.g., Firefox, Chrome, Safari.

Inside Django, http://localhost/about provides information, which you can cut and paste here.
-->

## Workarounds

<!-- If there is a workaround for the problem, describe that here. -->

## Priority

<!-- If this is blocking some important activity, let us know what activity it blocks. -->

## Additional context

<!--
This is optional. Please add any other context about the problem here or special environment setup.
-->
21 changes: 21 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''

---
*Note: If the feature is about adding or filling out an existing deficiency in the Mathics3 language, please file this as an [issue](https://github.com/Mathics3/mathics-core/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=).*

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
1 change: 1 addition & 0 deletions SYMBOLS_MANIFEST.txt
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,7 @@ System`NumberQ
System`NumberString
System`Numerator
System`NumericFunction
System`NumericArray
System`NumericQ
System`O
System`Octahedron
Expand Down
67 changes: 27 additions & 40 deletions mathics/builtin/binary/bytearray.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# -*- coding: utf-8 -*-
"""
ByteArrays
Byte Arrays
"""

from typing import Optional

from mathics.core.atoms import ByteArray, Integer, String
from mathics.core.atoms import ByteArrayAtom, Integer, String
from mathics.core.builtin import Builtin
from mathics.core.convert.expression import to_mathics_list
from mathics.core.evaluation import Evaluation
from mathics.core.list import ListExpression
from mathics.core.expression import Expression
from mathics.core.systemsymbols import SymbolByteArray, SymbolFailed


class ByteArray_(Builtin):
class ByteArray(Builtin):
r"""
<url>:WMA link:
https://reference.wolfram.com/language/ref/ByteArray.html</url>
Expand All @@ -37,55 +35,44 @@ class ByteArray_(Builtin):
>> ByteArray["ARkD"]
= ByteArray[<3>]
>> B=ByteArray["asy"]
: The argument at position 1 in ByteArray[asy] should be a vector of unsigned byte values or a Base64-encoded string.
= ByteArray[asy]

A 'ByteArray" is a kind of Atom:

>> AtomQ[ByteArray[{4, 2}]]
= True
: The first argument in Bytearray[asy] should be a B64 encoded string or a vector of integers.
= $Failed
"""

messages = {
"batd": "Elements in `1` are not unsigned byte values.",
"lend": (
"The argument at position 1 in ByteArray[`1`] should "
"be a vector of unsigned byte values or a Base64-encoded string."
),
"aotd": "Elements in `1` are inconsistent with type Byte",
"lend": "The first argument in Bytearray[`1`] should "
+ "be a B64 encoded string or a vector of integers.",
}

name = "ByteArray"
summary_text = "array of bytes"

def eval_str(self, string, evaluation: Evaluation) -> Optional[ByteArray]:
def eval_str(self, string, evaluation):
"ByteArray[string_String]"
try:
atom = ByteArray(string.value)
except TypeError:
atom = ByteArrayAtom(string.value)
except Exception:
evaluation.message("ByteArray", "lend", string)
return None
return atom
return SymbolFailed
return Expression(SymbolByteArray, atom)

def eval_to_str(self, baa, evaluation: Evaluation):
"ToString[baa_ByteArray]"
def eval_to_str(self, baa, evaluation):
"ToString[ByteArray[baa_ByteArrayAtom]]"
return String(f"ByteArray[<{len(baa.value)}>]")

def eval_normal(self, baa, evaluation: Evaluation):
"System`Normal[baa_ByteArray]"
def eval_normal(self, baa, evaluation):
"System`Normal[ByteArray[baa_ByteArrayAtom]]"
return to_mathics_list(*baa.value, elements_conversion_fn=Integer)

def eval_list(self, values, evaluation) -> Optional[ByteArray]:
"ByteArray[values_]"
if not isinstance(values, ListExpression):
evaluation.message("ByteArray", "lend", values)
return None

def eval_list(self, values, evaluation):
"ByteArray[values_List]"
if not values.has_form("List", None):
return
try:
ba = ByteArray(bytearray([b.value for b in values.elements]))
ba = bytearray([b.get_int_value() for b in values.elements])
except Exception:
evaluation.message("ByteArray", "batd", values)
return None
return ba
evaluation.message("ByteArray", "aotd", values)
return
return Expression(SymbolByteArray, ByteArrayAtom(ba))


# TODO: BaseEncode, BaseDecode, ByteArrayQ, ByteArrayToString, StringToByteArray, ImportByteArray, ExportByteArray
4 changes: 2 additions & 2 deletions mathics/builtin/compilation.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mathics.core.element import ImmutableValueMixin
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.keycomparable import LITERAL_EXPRESSION_ELT_ORDER
from mathics.core.keycomparable import LITERAL_EXPRESSION_SORT_KEY
from mathics.core.symbols import Atom, Symbol, SymbolFalse, SymbolTrue
from mathics.core.systemsymbols import SymbolCompiledFunction

Expand Down Expand Up @@ -146,7 +146,7 @@ def element_order(self) -> tuple:
lexicographically.

"""
return (LITERAL_EXPRESSION_ELT_ORDER, hex(id(self)))
return (LITERAL_EXPRESSION_SORT_KEY, hex(id(self)))

@property
def pattern_precedence(self) -> tuple:
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/exp_structure/size_and_sig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import platform
import zlib

from mathics.core.atoms import ByteArray, Integer, String
from mathics.core.atoms import ByteArrayAtom, Integer, String
from mathics.core.attributes import A_PROTECTED, A_READ_PROTECTED
from mathics.core.builtin import Builtin
from mathics.core.evaluation import Evaluation
Expand Down Expand Up @@ -132,7 +132,7 @@ def compute(user_hash, py_hashtype, py_format):
if py_format == "DecimalString":
return String(str(res))
elif py_format == "ByteArray":
return Expression(SymbolByteArray, ByteArray(res))
return Expression(SymbolByteArray, ByteArrayAtom(res))
return Integer(res)

def eval(self, expr, hashtype: String, outformat: String, evaluation: Evaluation):
Expand Down
8 changes: 5 additions & 3 deletions mathics/builtin/files_io/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from urllib.error import HTTPError, URLError

from mathics.builtin.pymimesniffer import magic
from mathics.core.atoms import ByteArray
from mathics.core.atoms import ByteArrayAtom
from mathics.core.attributes import A_NO_ATTRIBUTES, A_PROTECTED, A_READ_PROTECTED
from mathics.core.builtin import Builtin, Integer, Predefined, String, get_option
from mathics.core.convert.expression import to_mathics_list
Expand Down Expand Up @@ -2005,7 +2005,7 @@ def eval_elements(self, expr, elems, evaluation: Evaluation, **options):
evaluation.predetermined_out = current_predetermined_out
return SymbolFailed
if is_binary:
res = Expression(SymbolByteArray, ByteArray(res))
res = Expression(SymbolByteArray, ByteArrayAtom(res))
else:
res = String(str(res))
elif function_channels == ListExpression(String("Streams")):
Expand All @@ -2030,7 +2030,9 @@ def eval_elements(self, expr, elems, evaluation: Evaluation, **options):
res = exporter_function.evaluate(evaluation)
if res is SymbolNull:
if is_binary:
res = Expression(SymbolByteArray, ByteArray(pystream.getvalue()))
res = Expression(
SymbolByteArray, ByteArrayAtom(pystream.getvalue())
)
else:
res = String(str(pystream.getvalue()))
else:
Expand Down
4 changes: 2 additions & 2 deletions mathics/builtin/image/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from mathics.core.builtin import AtomBuiltin, String
from mathics.core.evaluation import Evaluation
from mathics.core.expression import Expression
from mathics.core.keycomparable import IMAGE_EXPRESSION_ELT_ORDER
from mathics.core.keycomparable import IMAGE_EXPRESSION_SORT_KEY
from mathics.core.list import ListExpression
from mathics.core.systemsymbols import SymbolImage, SymbolRule
from mathics.eval.image import image_pixels, pixels_as_float, pixels_as_ubyte
Expand Down Expand Up @@ -122,7 +122,7 @@ def element_order(self) -> tuple:
# and adding two extra fields: the length in the 5th position,
# and a hash in the 6th place.
return (
IMAGE_EXPRESSION_ELT_ORDER,
IMAGE_EXPRESSION_SORT_KEY,
SymbolImage,
len(self.pixels),
tuple(),
Expand Down
2 changes: 1 addition & 1 deletion mathics/builtin/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class Format(Builtin):

Raw objects cannot be formatted:
>> Format[3] = "three";
: Tag Integer in 3 is Protected.
: Cannot assign to raw object 3.

Format types must be symbols:
>> Format[r, a + b] = "r";
Expand Down
7 changes: 4 additions & 3 deletions mathics/builtin/list/constructing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
from typing import Optional, Tuple

from mathics.builtin.box.layout import RowBox
from mathics.core.atoms import ByteArray, Integer, Integer1, is_integer_rational_or_real
from mathics.core.atoms import Integer, Integer1, is_integer_rational_or_real, NumericArray
from mathics.core.attributes import A_HOLD_FIRST, A_LISTABLE, A_LOCKED, A_PROTECTED
from mathics.core.builtin import BasePattern, Builtin, IterationFunction
from mathics.core.convert.expression import to_expression
from mathics.core.convert.python import from_python
from mathics.core.convert.sympy import from_sympy
from mathics.core.element import ElementsProperties
from mathics.core.evaluation import Evaluation
Expand Down Expand Up @@ -197,9 +198,9 @@ class Normal(Builtin):

def eval_general(self, expr: Expression, evaluation: Evaluation):
"Normal[expr_]"
if isinstance(expr, NumericArray):
return from_python(expr.to_python())
if isinstance(expr, Atom):
if isinstance(expr, ByteArray):
return ListExpression(*expr.items)
return expr
if expr.has_form("RootSum", 2):
return from_sympy(expr.to_sympy().doit(roots=True))
Expand Down
Loading