Skip to content

Commit f59e967

Browse files
committed
Fix variable name collision in any_listp which surfaces in algebraic_equivalence when an atom is both a function name and a variable name.
1 parent 9a91870 commit f59e967

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

stack/maxima/assessment.mac

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ select_apply([ex1]) := block([f1, ex, s1],
184184
/* ********************************** */
185185

186186
/* True if and only if ex is in the list l. */
187-
element_listp(ex, l) := any_listp(lambda([ex2], is(ex2=ex)), l)$
187+
element_listp(ex, _l) := any_listp(lambda([ex2], is(ex2=ex)), _l)$
188188

189189
/* all_listp(p,l) true if all elements of l satisfy p. */
190-
all_listp(p, l) := if listp(l) then apply("and", maplist(p, l)) else error("all_listp expects its argument to be a list.")$
190+
all_listp(_p, _l) := if listp(_l) then apply("and", maplist(_p, _l)) else error("all_listp expects its argument to be a list.")$
191191

192192
/* any_listp(p,l) true if all elements of l satisfy p. */
193-
any_listp(p, l) := if listp(l) then apply("or", maplist(p, l)) else error("any_listp expects its argument to be a list.")$
193+
any_listp(_p, _l) := if listp(_l) then apply("or", maplist(_p, _l)) else error("any_listp expects its argument to be a list.")$
194194

195195
/* Returns true iff a and b are lists (not necessarily same length) with one or more common elements, false o/w. */
196196
listsoverlap(a, b) := not(emptyp(intersection(setify(a), setify(b))))$
@@ -199,10 +199,10 @@ listsoverlap(a, b) := not(emptyp(intersection(setify(a), setify(b))))$
199199
listscontain(a, b, v) := elementp(v, intersection(setify(a), setify(b)))$
200200

201201
/* Removes the first occurance of ex from the list l. */
202-
removeonce(ex, l) := block(
203-
if listp(l)#true or emptyp(l) then return([]),
204-
if first(l)=ex then return(rest(l)),
205-
append([first(l)], removeonce(ex,rest(l)))
202+
removeonce(ex, _l) := block(
203+
if listp(_l)#true or emptyp(_l) then return([]),
204+
if first(_l)=ex then return(rest(_l)),
205+
append([first(_l)], removeonce(ex,rest(_l)))
206206
)$
207207

208208
/* All the elements of l1, which do not occur in l2. Removes all occurances from l1, not one at a time. */
@@ -974,6 +974,7 @@ texput(binomial, binomialtex);
974974
24/11/13. Avoid fullratsimp. This expands out exprsssions such as (x+a)^6000, which results in an overflow.
975975
04/01/19. Avoid trigexpand too soon, i.e. before trying to factor.
976976
24/02/20. Using a lambda expression is causing an infinite loop. Use a named function: algebraic_equivalence_zero.
977+
25/04/10. Change any_listp args to prevent an infinite loop.
977978
*/
978979

979980
algebraic_equivalence_zero(ex) := algebraic_equivalence(ex, 0)$
@@ -1034,6 +1035,7 @@ algebraic_equivalence(SA, SB) :=
10341035
ex:[ex],
10351036
if ex=[] then error("algebraic_equivalence: factoring the difference of two expressions threw an error."),
10361037
ex:ex[1],
1038+
if ex=0 then return(true),
10371039
/* Try to return a negative result without expanding anything! */
10381040
if safe_op(ex)="-" then
10391041
ex:first(args(ex)),

tests/fixtures/answertestfixtures.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ class stack_answertest_test_data {
524524
['AlgEquiv', '', 'g(x):=x^2', 'f(x):=x^2', 0, 'ATFunction_wrongname. ATFunction_true.', ''],
525525
['AlgEquiv', '', 'f(y):=y^2', 'f(x):=x^2', 1, 'ATFunction_arguments_different. ATFunction_true.', ''],
526526
['AlgEquiv', '', 'f(a,b):=a^2+b^2', 'f(x,y):=x^2+y^2', 1, 'ATFunction_arguments_different. ATFunction_true.', ''],
527+
// F appears as both a variable and as a function name.
528+
['AlgEquiv', '', '-30*F', '6*F(l-5*x)', 0, '', ''],
527529

528530
['AlgEquiv', '', '1', 'x>1', 0, 'ATAlgEquiv_SA_not_inequality.', 'Inequalities'],
529531
['AlgEquiv', '', 'x=1', 'x>1 and x<5', 0, 'ATAlgEquiv_TA_not_equation.', ''],

0 commit comments

Comments
 (0)