From: Richard F. <fa...@gm...> - 2023-10-24 14:05:27
|
It's not clear what the point of map_list is here, but it may be useful to realize that essentially all algebraic expressions have a prefix form, which should explain how map works. for instance, "+" (a,b,c) is the same as a+b+c "["(a,b,c) is the same as [a,b,c] so mappng f on a+b+c is going to result in "+" (f(a),f(b),f(c)). It is possible to try to make illegal constructs within the map operation, in which case you would get errors. It is not an error in map() per se if you ask it to do something erroneous... Maxima sometimes lets questionable stuff pass through, since there is a prospect that you might later make sense of the expression. Sometimes it objects. Like sin(a,b) is an error, but max(1,3,q) is not an error, but max(3,q). If you expected max to return a numeric value you might be disappointed. It is always possible to construct an expression replacing the main operator (like "+") with something else, perhaps "[". RJF On Tue, Oct 24, 2023 at 9:42 AM Barton Willis via Maxima-discuss < max...@li...> wrote: > > If you have found a bug in map, please report it. Also, try doing* listarith > : false *and rerunning your examples. > > --Barton > ------------------------------ > *From:* Eduardo Ochs <edu...@gm...> > *Sent:* Tuesday, October 24, 2023 08:30 > *To:* Michel Talon <ta...@lp...> > *Cc:* max...@li... < > max...@li...> > *Subject:* Re: [Maxima-discuss] How do I translate "(map 'list f as)" to > Maxima? > > Non-NU Email > ------------------------------ > Hi Michel, > map sometimes recurses on trees, not on lists: > > f : lambda([x], x+10); > g : lambda([ab], 10*ab[1]+ab[2]); > f([3,4]); > map(f, [[1,2],[3,4],[5,6]]); /* [[11, 12], [13, 14], [15, 16]] */ > map(g, [[1,2],[3,4],[5,6]]); /* [12, 34, 56] */ > map(f, [[1,2],[3,4],5]); /* [[11, 12], [13, 14], 15] */ > map(g, [[1,2],[3,4],5]); /* error */ > > It tries to do the right thing and it usually does, but there are some > cases in which its dtrt-iness is not what I expected... so I thought > that it would be nice to also have some functions with a simpler > logic. > Cheers, > Eduardo > > > On Tue, 24 Oct 2023 at 05:48, Michel Talon <ta...@lp...> wrote: > > What is the problem with the simpler: > > (%i1) map(lambda([x],x+a),[2,3,4]); > (%o1) [a + 2, a + 3, a + 4] > (%i2) x:5; > (%o2) 5 > (%i3) map(lambda([x],x+a),[2,3,4]); > (%o3) [a + 2, a + 3, a + 4] > (%i4) a:3; > (%o4) 3 > (%i5) map(lambda([x],x+a),[2,3,4]); > (%o5) [5, 6, 7] > > Le 24/10/2023 à 01:24, Eduardo Ochs a écrit : > > Hi list, > > what is the right/recommended way to define something like Lisp's > "map" in Maxima? I tried this, > > to_lisp(); > (defun foo (x) (* x 10)) > (map 'list 'foo '(2 3 5 8)) ;;-> (20 30 50 80) > (to-maxima) > > map_list(f, as) := makelist(apply(f, [a]), a, as); > map_list(lambda([x], 10*x), [2, 3, 5, 8]); /* [20, 30, 50, 80] */ > map_list(lambda([x], x+b), [2, 3, 5, 8]); /* [b+2, b+3, b+5, b+8] */ > map_list(lambda([x], x+a), [2, 3, 5, 8]); /* [4, 6, 10, 16] */ > > but it doesn't work well in cases like the last one, in which f > mentions a global variable with the same name as the variable used in > the makelist... > > Thanks in advance! > Cheers =), > Eduardo Ochs > > > _______________________________________________ > Maxima-discuss mailing lis...@li...https://lists.sourceforge.net/lists/listinfo/maxima-discuss <https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!CF7OnbdkTSf-tofhEy1XexZwzM1O66mv06yRhhdJ18I5kjMHfTRRHxQK3cud2CC5VyZ2FgnSeznP93MRADM$> > > -- > Michel Talon > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > <https://urldefense.com/v3/__https://lists.sourceforge.net/lists/listinfo/maxima-discuss__;!!PvXuogZ4sRB2p-tU!CF7OnbdkTSf-tofhEy1XexZwzM1O66mv06yRhhdJ18I5kjMHfTRRHxQK3cud2CC5VyZ2FgnSeznP93MRADM$> > > _______________________________________________ > Maxima-discuss mailing list > Max...@li... > https://lists.sourceforge.net/lists/listinfo/maxima-discuss > |