|
From: Stavros M. <mac...@al...> - 2022-01-11 13:44:29
|
On Mon, Jan 10, 2022 at 9:59 PM Eduardo Ochs <edu...@gm...> wrote:
> ...
I am trying - first - to understand the difference between these ways
> of defining functions,
>
> f : x^2;
> g(x) := x^3;
> h(x) ::= x^4;
>
> both from a user's points of view and from a common lisper's point of
> view
>
The *:* statement assigns an *expression* (not a function) to a variable.
The *:=* statement defines a *routine* which can be called to perform a
certain calculation.
The *::= *statement defines a *macro.*
You'll note that I haven't used the word "function" for any of these,
because it lends itself to misunderstandings.
In particular, the function application syntax *f(x)* means two quite
different (though related) things in Maxima:
- If *f* has been defined as a routine (built-in or with *:=*), or if
*f* is a lambda-expression, then it applies that routine to the given
arguments when it is evaluated. For example, in *integrate(x,x)*, the
built-in routine *integrate *is called on the expression *x* to return
*x^2/2*.
- If *f* has *not* been defined as a routine, then it simply *denotes* a
function application. If *f* has a value as a variable, then the value
is substituted for *f*. Maxima may *simplify *the function application
in many cases. For example, in Maxima, the transformation of *sin(%pi/4)* to
*2^(-1/2)* is a *simplification, *not an *evaluation.* In Maxima,
mathematical functions like *sin, gamma, **etc.* are represented this
way.
Even if *f* is a defined routine, you can force a function application to
be interpreted as a denotation rather than a call of the routine by quoting
the function: *'integrate(x,x)* returns itself and does not call the
*integrate* routine. This is useful for manipulating the integration as a
mathematical object. There *are*, however, some simplifications that apply
to *'integrate*; for example, if the first argument is free of the second
argument: *'integrate(a,x) => a*x*. This did *not* call the
*integrate* routine.
The details of how this all works are covered by the noun/verb distinction
in Maxima.
When you are using Maxima to perform mathematical manipulations, it is
almost always best to manipulate *expressions*, not named functions.
Substituting values for variables is usually best done using *subst* and
not as a function application.
I do not recommend you try to understand all this by looking at the
implementation. I recommend instead that you first understand it on its own
terms. There is a lot more to say, but I'm afraid I don't have the time to
say it right now!
-s
> , and - second - I'm looking for some references on how people
> decided to implement things in this way... let me explain.
>
> First: what are your favorite ways to show how the innards of Maxima
> see the "f", the "g(x)", and the "h(x)" above? I executed this,
>
> f : x^2;
> g(x) := x^3;
> h(x) ::= x^4;
> f;
> g;
> g(x);
> g(y);
> dispfun(g);
> dispfun(h);
>
> :lisp #$[f]$
> :lisp #$[F]$
> :lisp #$[g]$
> :lisp #$[g(x)]$
> :lisp #$[g(y+z)]$
> :lisp (displa #$[g(y+z)]$)
> :lisp '((MLIST SIMP) ((MEXPT SIMP) ((MPLUS SIMP) $Y $Z) 3))
> :lisp (displa '((MLIST SIMP) ((MEXPT SIMP) ((MPLUS SIMP) $Y $Z) 3)))
>
> :lisp $functions
> :lisp (cdr $functions)
> :lisp (dispfun1 (cdr $functions) t nil)
> :lisp $macros
> :lisp (cdr $macros)
> :lisp (dispfun1 (cdr $macros) t nil)
>
> I haven't progressed much beyond this point yet... for example, I
> still don't know where f is stored, and I am trying to understand the
> "(defmspec $dispfun ...)" and the "(defun dispfun1 ...)" in
> src/mlisp.lisp, but my attempts to run parts of their code in "(let
> (...) ...)" inside the Lisp REPL, i.e., inside a "to_lisp();" /
> "(to-maxima)" block in the Maxima REPL, are not working - and I don't
> even know why first line below works but the second one doesn't:
>
> dispfun(g);
> :lisp #$[dispfun(g)]#
>
> So I'm a beginner asking questions that may look too advanced...
> sorry! By the way, my favorite style for explaining these inner
> details _in Emacs Lisp_ is with tutorials like this one,
>
> http://angg.twu.net/eev-intros/find-elisp-intro.html#6
>
> in which I expect people to execute lots of sexps in different orders,
> and understand their results.
>
>
>
> Now the second question. This one is more open-ended, and any pointer
> to references and/or to keywords to search for are more than welcome.
>
> I teach Calculus 2 and 3 in a small university in Brazil - or, more
> precisely, in a small countryside campus that is part of a big
> university whose main campus is 300 Km away - and I started an
> experiment a few semesters ago. Instead of teaching the students only
> the modern notational conventions, in which in
>
> g(x) := x^3;
>
> the name "x" is always totally irrelevant and can be replaced by any
> other name, I am trying to teach them both the "old" convention and
> the "new" one, and I trying to show how to translate between the two,
> even though I don't know all the rules of the translation...
>
> The "old" convention can be seen for example here,
>
> Silvanus P. Thompson - "Calculus Made Easy" (1914) - p.14:
> https://www.gutenberg.org/files/33283/33283-pdf.pdf#page=25
>
> and the "new" convention is the one that says that variables and
> functions must have different names, all arguments should be explicit,
> there is no such thing as a "dependent variable", and so on.
>
> I call the "old" convention "physicists' notation" and the "new" one
> the "mathematicians' notation", always between quotes, and I always
> explain to the students that my attempts to formalize the translation
> are totally improvised, and that I've asked my friends who work in
> EDPs or in Mathematical Physics where I can find formalizations of the
> translation and they simply don't know...
>
> So: Maxima has some support for dependent variables - see "? depends"
> - and I _guess_ that as Maxima is quite old some of its old papers may
> contain discussions on how people were trying to implement both the
> "mathematicians' notation" and the "physicists' notation" on Computer
> Algebra Systems, and how they reached the implementation that Maxima
> still uses today... I took a look here,
>
> http://ftp.math.utah.edu/pub/tex/bib/macsyma.html
>
> but that list is huge, it has very few links to online versions, and
> most of them are broken, and none of the titles mention dependent
> variables explicitly...
>
> Thanks in advance!!!
> Eduardo Ochs
> http://angg.twu.net/eev-maxima.html
>
>
> P.S.: for the sake of completeness, my material on the "physicists'
> notation" is here -
> http://angg.twu.net/LATEX/2021-2-C3-notacao-de-fisicos.pdf - but it is
> messy and in Portuguese...
>
> _______________________________________________
> Maxima-discuss mailing list
> Max...@li...
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
|