Skip to content
Merged

Qtime #936

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9417a90
fixing Information
mmatera Jan 4, 2017
c6fa542
only convert to set if needed
l1ebl Sep 23, 2016
8add595
write protection for Expression.leaves
l1ebl Sep 28, 2016
b87149f
fixes tuple incompatibilities
l1ebl Sep 28, 2016
c8dcb19
introduce restructure()
l1ebl Oct 12, 2016
5c23eb9
introduction of Structure (a work in progress)
l1ebl Oct 12, 2016
75c94bb
Structure is now faster; _list_parts now uses Structure
l1ebl Oct 12, 2016
5385407
improvements to general runtime
l1ebl Oct 12, 2016
b257965
changed all internal accesses to leaves to Expression._leaves
l1ebl Oct 12, 2016
51711fc
use self._head for private access to Expression head
l1ebl Oct 12, 2016
70bd86c
simpler and faster set handling in Expression._prepare_symbols()
l1ebl Oct 12, 2016
7c97d0f
massive improvement for large lists (again)
l1ebl Oct 12, 2016
16e4405
added _no_symbol()
l1ebl Oct 13, 2016
2402a26
set_leaves renamed to set_leaf
l1ebl Oct 13, 2016
5980cf7
unification with _sequences
l1ebl Oct 13, 2016
bbff7f4
better names, documentation, cleanup
l1ebl Oct 13, 2016
914e068
Sort now uses restructure
l1ebl Oct 17, 2016
bc31a2a
added atom_list, string_list
l1ebl Oct 17, 2016
4564d78
made atom_list into an atom_list_constructor; this is much better for…
l1ebl Oct 18, 2016
dc86be7
pep8 and removing duplicated class Information for n-esim time...
mmatera Sep 28, 2020
32e4415
added format cache
l1ebl Sep 23, 2016
0acae72
Add Subsets[]
larionvn Mar 31, 2017
7047e76
fix formatcache
mmatera Sep 30, 2020
7a9f83a
fix last_evaluated
mmatera Sep 30, 2020
dcaf693
fixing format_cache for sublist changes
mmatera Sep 30, 2020
cc9dd82
Merge branch 'master' into qtime
mmatera Sep 30, 2020
e47ed56
fix for leaf in leaf.leaves
mmatera Oct 1, 2020
a788829
Merge branch 'qtime' of https://github.com/mathics/Mathics into qtime
mmatera Oct 1, 2020
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
5 changes: 3 additions & 2 deletions mathics/builtin/algebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,13 +1236,14 @@ def _nth(poly, dims, exponents):
if not dims:
return from_sympy(poly.coeff_monomial(exponents))

result = Expression('List')
leaves = []
first_dim = dims[0]
for i in range(first_dim+1):
exponents.append(i)
subs = _nth(poly, dims[1:], exponents)
result.leaves.append(subs)
leaves.append(subs)
exponents.pop()
result = Expression('List', *leaves)
return result

return _nth(sympy_poly, dimensions, [])
Expand Down
17 changes: 9 additions & 8 deletions mathics/builtin/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def append_last():
leaves.append(last_item)
else:
if last_item.has_form('Times', None):
last_item.leaves.insert(0, from_sympy(last_count))
leaves.append(last_item)
leaves.append(Expression(
'Times', from_sympy(last_count), *last_item.leaves))
else:
leaves.append(Expression(
'Times', from_sympy(last_count), last_item))
Expand All @@ -280,7 +280,7 @@ def append_last():
for leaf in item.leaves:
if isinstance(leaf, Number):
count = leaf.to_sympy()
rest = item.leaves[:]
rest = item.get_mutable_leaves()
rest.remove(leaf)
if len(rest) == 1:
rest = rest[0]
Expand Down Expand Up @@ -589,8 +589,8 @@ def apply(self, items, evaluation):
elif (leaves and item.has_form('Power', 2) and
leaves[-1].has_form('Power', 2) and
item.leaves[0].same(leaves[-1].leaves[0])):
leaves[-1].leaves[1] = Expression(
'Plus', item.leaves[1], leaves[-1].leaves[1])
leaves[-1] = Expression('Power', leaves[-1].leaves[0], Expression(
'Plus', item.leaves[1], leaves[-1].leaves[1]))
elif (leaves and item.has_form('Power', 2) and
item.leaves[0].same(leaves[-1])):
leaves[-1] = Expression(
Expand Down Expand Up @@ -625,12 +625,13 @@ def apply(self, items, evaluation):
elif number.is_zero:
return number
elif number.same(Integer(-1)) and leaves and leaves[0].has_form('Plus', None):
leaves[0].leaves = [Expression('Times', Integer(-1), leaf)
for leaf in leaves[0].leaves]
leaves[0] = Expression(
leaves[0].get_head(),
*[Expression('Times', Integer(-1), leaf) for leaf in leaves[0].leaves])
number = None

for leaf in leaves:
leaf.last_evaluated = None
leaf.clear_cache()

if number is not None:
leaves.insert(0, number)
Expand Down
9 changes: 5 additions & 4 deletions mathics/builtin/assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def get_symbol_list(list, error_callback):
class _SetOperator(object):
def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
name = lhs.get_head_name()
lhs._format_cache = None

if name in system_symbols('OwnValues', 'DownValues', 'SubValues',
'UpValues', 'NValues', 'Options',
Expand Down Expand Up @@ -290,6 +291,7 @@ def assign_elementary(self, lhs, rhs, evaluation, tags=None, upset=False):
return True

def assign(self, lhs, rhs, evaluation):
lhs._format_cache = None
if lhs.get_head_name() == 'System`List':
if (not (rhs.get_head_name() == 'System`List') or
len(lhs.leaves) != len(rhs.leaves)): # nopep8
Expand Down Expand Up @@ -916,7 +918,6 @@ def format_definition(self, symbol, evaluation, options, grid=True):
# Instead, I just copy the code from Definition

def show_definitions(self, symbol, evaluation, lines):

def print_rule(rule, up=False, lhs=lambda l: l, rhs=lambda r: r):
evaluation.check_stopped()
if isinstance(rule, Rule):
Expand Down Expand Up @@ -1243,17 +1244,17 @@ def get_symbol_values(symbol, func_name, position, evaluation):
definition = evaluation.definitions.get_definition(name)
else:
definition = evaluation.definitions.get_user_definition(name)
result = Expression('List')
leaves = []
for rule in definition.get_values_list(position):
if isinstance(rule, Rule):
pattern = rule.pattern
if pattern.has_form('HoldPattern', 1):
pattern = pattern.expr
else:
pattern = Expression('HoldPattern', pattern.expr)
result.leaves.append(Expression(
leaves.append(Expression(
'RuleDelayed', pattern, rule.replace))
return result
return Expression('List', *leaves)


class DownValues(Builtin):
Expand Down
6 changes: 3 additions & 3 deletions mathics/builtin/combinatorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ def apply(self, values, evaluation):
'Multinomial[values___]'

values = values.get_sequence()
result = Expression('Times')
leaves = []
total = []
for value in values:
total.append(value)
result.leaves.append(Expression(
leaves.append(Expression(
'Binomial', Expression('Plus', *total), value))
return result
return Expression('Times', *leaves)


class _NoBoolVector(Exception):
Expand Down
9 changes: 6 additions & 3 deletions mathics/builtin/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import tempfile


from itertools import chain


from mathics.core.expression import (Expression, Real, Complex, String, Symbol,
from_python, Integer, BoxError,
MachineReal, Number, valid_context_name)
Expand Down Expand Up @@ -1501,17 +1504,17 @@ def apply(self, name, n, b, typ, evaluation):
elif t.startswith('Character'):
if isinstance(x, Integer):
x = [String(char) for char in str(x.get_int_value())]
pyb = pyb[:i] + x + pyb[i + 1:]
pyb = list(chain(pyb[:i], x, pyb[i + 1:]))
x = pyb[i]
if isinstance(x, String) and len(x.get_string_value()) > 1:
x = [String(char) for char in x.get_string_value()]
pyb = pyb[:i] + x + pyb[i + 1:]
pyb = list(chain(pyb[:i], x, pyb[i + 1:]))
x = pyb[i]
x = x.get_string_value()
elif t == 'Byte' and isinstance(x, String):
if len(x.get_string_value()) > 1:
x = [String(char) for char in x.get_string_value()]
pyb = pyb[:i] + x + pyb[i + 1:]
pyb = list(chain(pyb[:i], x, pyb[i + 1:]))
x = pyb[i]
x = ord(x.get_string_value())
else:
Expand Down
5 changes: 2 additions & 3 deletions mathics/builtin/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Functional programming
"""


from itertools import chain

from mathics.builtin.base import Builtin, PostfixOperator
from mathics.core.expression import Expression
Expand Down Expand Up @@ -68,8 +68,7 @@ class Function(PostfixOperator):
def apply_slots(self, body, args, evaluation):
'Function[body_][args___]'

args = args.get_sequence()
args.insert(0, Expression('Function', body))
args = list(chain([Expression('Function', body)], args.get_sequence()))
return body.replace_slots(args, evaluation)

def apply_named(self, vars, body, args, evaluation):
Expand Down
Loading