From 96eb94ef139ecc51fb5dd439dfa672b6c81a99ff Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 25 Dec 2024 08:21:18 -0500 Subject: [PATCH] Weird changes needed... _ListPlot[] needs to evaluate its arguements in order to check them! There is this weird place in caching where we were caching the Expression form of a ListExpression. This is something that has been plaguing our code. Finding and fixing these simplifies coding speeds up execution. --- mathics/builtin/drawing/plot.py | 19 ++++++++++--------- mathics/core/expression.py | 8 ++++++-- mathics/eval/drawing/plot.py | 8 ++++---- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/mathics/builtin/drawing/plot.py b/mathics/builtin/drawing/plot.py index e9eef5951..50ae1f26f 100644 --- a/mathics/builtin/drawing/plot.py +++ b/mathics/builtin/drawing/plot.py @@ -301,6 +301,16 @@ def eval(self, points, evaluation: Evaluation, options: dict): class_name = self.__class__.__name__ + # Scale point values down by Log 10. Tick mark values will be adjusted to be 10^n in GraphicsBox. + if self.use_log_scale: + points = ListExpression( + *( + Expression(SymbolLog10, point).evaluate(evaluation) + for point in points + ) + ) + + points = points.evaluate(evaluation) if not isinstance(points, ListExpression): evaluation.message(class_name, "lpn", points) return @@ -315,15 +325,6 @@ def eval(self, points, evaluation: Evaluation, options: dict): evaluation.message(class_name, "lpn", points) return - # Scale point values down by Log 10. Tick mark values will be adjusted to be 10^n in GraphicsBox. - if self.use_log_scale: - points = ListExpression( - *( - Expression(SymbolLog10, point).evaluate(evaluation) - for point in points - ) - ) - # If "points" is a literal value with a Python representation, # it has a ".value" attribute with a non-None value. So here, # we don't have to eval_N().to_python(). diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 927791f70..b96085e9f 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -1410,8 +1410,12 @@ def rules(): if not isinstance(result, EvalMixin): return result, False if result.sameQ(new): - new._timestamp_cache(evaluation) - return new, False + # Even though result and new may be the same, + # new can be a Expression[SymbolConstant: System`List...] + # while "result' might be ListExpression!? + # So make sure to use "result", not "new". + result._timestamp_cache(evaluation) + return result, False else: return result, True diff --git a/mathics/eval/drawing/plot.py b/mathics/eval/drawing/plot.py index 7a0e51748..addcf2b47 100644 --- a/mathics/eval/drawing/plot.py +++ b/mathics/eval/drawing/plot.py @@ -201,14 +201,14 @@ def eval_ListPlot( [xx for xx, yy in plot_groups], [xx for xx, yy in plot_groups], x_range ) plot_groups = [plot_groups] - elif all(isinstance(line, list) for line in plot_groups): - if not all(isinstance(line, list) for line in plot_groups): + elif all(isinstance(line, (list, tuple)) for line in plot_groups): + if not all(isinstance(line, (list, tuple)) for line in plot_groups): return # He have a list of plot groups if all( - isinstance(point, list) and len(point) == 2 - for plot_group in plot_groups + isinstance(point, (list, tuple)) and len(point) == 2 + for _ in plot_groups for point in plot_groups ): pass