|
From: Stavros M. <mac...@gm...> - 2023-11-16 18:14:20
|
Thanks for the nice idea.
A few comments:
- Variables used within a function should be made local using *block*,
e.g., *block([A,B,C,D]).*
- Functions used with *apply*, *map, *etc., should be quoted, e.g., as
*'fundef*, because it's possible that someone has created a global
variable called *fundef*.
- *Most importantly, *it is not a good idea to use *ssearch* on the text
of a function to check if function A is called by function B. For
example, *ssearch("en","if
x=2 then 3") *returns *10*. It would be much better to define a function
*listoffuns *which looks at the tree structure of the function. Even
then, there will be some difficult cases. For example, what if your code
defines *mycall(f,l):=f(l)*. Then it looks like the function *f* is
being called by *mycall*. And what about another function which *calls*
*mycall*, e.g., *mycall('draw_graph,ll)*? How do you know that the first
argument is called as a function?
- Functions shouldn't normally load packages they need -- that will load
them every time they're called.
- It would be better for the graphing function to take a list of
function names, rather than operate on all defined functions.
On Wed, Nov 15, 2023 at 5:15 PM El Observatorio De Matemática <
obs...@gm...> wrote:
> Hi
>
> Here is a function that returns a graph associated with the current
> functions in a session (functions recognized by *functions*, not lisp
> functions).
> The function generates a graph that later can be used with the command
> draw_graph or print_graph.
> I do not know much about graph theory or computer science, but i wonder if
> some graph property is desirable for a package.
> More work can be done to improve the function (the graph includes the
> function itself), and some packages do not return, in the wxMaxima session,
> the plot in the same page (it is opened in an emerging window). Also, for
> some large packages is necessary to drop interactively the plot to take a
> closer look or zoom; packages must be "scanned" separately.
> Some results:
>
> (%i1) load("absimp.mac");
> (%o1)
> "C:\maxima-5.46.0\share\maxima\5.46.0\share\simplification\absimp.mac"
> (%i2) package_graph():=block(
> A:map(op,functions),
> len:length(A),
> B:map(lambda([x],rhs(apply(fundef,[x]))),A),
> C:makelist([i,A[i]],i,len),
> D:unique(map(sort,delete(false,map(lambda([x],if x[1]#x[2] and
> ssearch(string(A[x[1]]),string(B[x[2]]))#false then
> x),create_list([i,j],i,1,len,j,1,len))))),
> load(graphs),
> create_graph(C,D)
> )$
> (%i3) package_graph();
> (%o3) GRAPH\(8 vertices, 5 edges\)
>
>
> (%i1) file_search(nusum)$
> (%i2) load(%)$
> (%i3) package_graph():=block(
> A:map(op,functions),
> len:length(A),
> B:map(lambda([x],rhs(apply(fundef,[x]))),A),
> C:makelist([i,A[i]],i,len),
> D:unique(map(sort,delete(false,map(lambda([x],if x[1]#x[2] and
> ssearch(string(A[x[1]]),string(B[x[2]]))#false then
> x),create_list([i,j],i,1,len,j,1,len))))),
> load(graphs),
> create_graph(C,D)
> )$
> (%i4) package_graph();
> (%o4) GRAPH\(18 vertices, 19 edges\)
>
>
> (%i1) showtime:true$
> Evaluation took 0.0000 seconds (0.0000 elapsed) using 32 bytes.
> (%i2) file_search(sarag)$
> Evaluation took 0.2969 seconds (0.2969 elapsed) using 1.801 MB.
> (%i3) load(%)$
> Evaluation took 1.2187 seconds (1.2343 elapsed) using 28.744 MB.
> (%i4) package_graph():=block(
> A:map(op,functions),
> len:length(A),
> B:map(lambda([x],rhs(apply(fundef,[x]))),A),
> C:makelist([i,A[i]],i,len),
> D:unique(map(sort,delete(false,map(lambda([x],if x[1]#x[2] and
> ssearch(string(A[x[1]]),string(B[x[2]]))#false then
> x),create_list([i,j],i,1,len,j,1,len))))),
> load(graphs),
> create_graph(C,D)
> )$
> Evaluation took 0.0000 seconds (0.0000 elapsed) using 208 bytes.
> (%i5) package_graph();
> Evaluation took 104.1250 seconds (104.2445 elapsed) using 9173.345 MB.
>
> (%o5) GRAPH\(435 vertices, 824 edges\)
>
> To see the plot use draw_graph and the option show_label=true
> (draw_graph(%,show_label=true))
>
>
> best regards.
> --
> https://github.com/Observatorio-de-Matematica
> _______________________________________________
> Maxima-discuss mailing list
> Max...@li...
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
|