Discussion:
A question about 1//2
(too old to reply)
Andreas Eder
2017-06-23 09:46:56 UTC
Permalink
Raw Message
Hi,
i found that in the file ellipt.lisp we define the variable 1//2
like:
(defvar 1//2 '((rat simp) 1 2))
and in mopers.lisp there is a macro definition like:
(defmacro 1//2 () ''((rat simp) 1 2))

Does anybody know the reason - apart from mere historical accident
- for
this situation. If there is one :-)

Shouldn't we unify thes uses?
The use of the macro definition looks clumsy to me, since it looks
like
a function call for what should simply be the use of a constant.
In this
respect the variable definitions looks better.
Another approach would be to define a symbol macro.
What is your opinion about that?
I'm sure 1//2 is not the only case (there is also a definition of
half).
There a surely more such occurances.

Andreas
--
ceterum censeo redmondinem esse delendam
Richard Fateman
2017-06-23 11:27:16 UTC
Permalink
Raw Message
On 6/23/17, 2:46 AM, Andreas Eder wrote:
> Hi,
> i found that in the file ellipt.lisp we define the variable 1//2 like:
> (defvar 1//2 '((rat simp) 1 2))
> and in mopers.lisp there is a macro definition like:
> (defmacro 1//2 () ''((rat simp) 1 2))
>
> Does anybody know the reason - apart from mere historical accident - for
> this situation. If there is one :-)
>
Historical accident, I think. the person who wrote ellipt was unaware
of the line in mopers.

> Shouldn't we unify thes uses?
sure
> The use of the macro definition looks clumsy to me, since it looks like
> a function call for what should simply be the use of a constant. In this
> respect the variable definitions looks better.
after compilation it doesn't make any difference.
There is a slight disadvantage to having 2 definitions -- it uses more
storage. even better might be
(defvar 1//2 (simplifya '((rat) 1 2) nil))
which would use even less storage -- it would use the canonical copy of
the sublist (rat simp) instead of another one.

> Another approach would be to define a symbol macro.
> What is your opinion about that?
what is a symbol macro?
> I'm sure 1//2 is not the only case (there is also a definition of half).
> There a surely more such occurances.

In some ways it would be better to use common lisp rationals.
(There were no rationals in Maclisp, 1966). But if we used
common lisp rationals, we could not use ((rat) 1 0) for infinity,
((rat) -1 0) for minf, ((rat)0 0) for undefined, ((rat) 0 -1) for
minus zero.
which I have been playing with. No, it is not part of Maxima
today.
RJF

>
> Andreas
Andreas Eder
2017-06-23 14:19:31 UTC
Permalink
Raw Message
On Fr 23 Jun 2017 at 13:27, Richard Fateman <***@berkeley.edu>
wrote:
> after compilation it doesn't make any difference.

certainly not to the machine. But I think it does make a
difference to
the one reading the code.

> what is a symbol macro?

A symbol macro provides a mechanism for globally affecting the
macro
expansion of the indicated symbol. See the definition of
DEFINE-SYMBOL-MACRO in the Hyperspec.
http://www.lispworks.com/documentation/HyperSpec/Body/m_defi_1.htm#define-symbol-macro

Andreas


--
ceterum censeo redmondinem esse delendam
Stavros Macrakis (Σταῦρος Μακράκης)
2017-06-23 19:58:48 UTC
Permalink
Raw Message
defconstant is probably the best way to handle this. This delegates to the
compiler any worries about structure sharing, variable dereferencing
overhead, etc. (which are really nano-optimizations anyway).


On Fri, Jun 23, 2017 at 5:46 AM, Andreas Eder <***@gmx.net> wrote:

> Hi,
> i found that in the file ellipt.lisp we define the variable 1//2 like:
> (defvar 1//2 '((rat simp) 1 2))
> and in mopers.lisp there is a macro definition like:
> (defmacro 1//2 () ''((rat simp) 1 2))
>
> Does anybody know the reason - apart from mere historical accident - for
> this situation. If there is one :-)
>
> Shouldn't we unify thes uses?
> The use of the macro definition looks clumsy to me, since it looks like
> a function call for what should simply be the use of a constant. In this
> respect the variable definitions looks better.
> Another approach would be to define a symbol macro.
> What is your opinion about that?
> I'm sure 1//2 is not the only case (there is also a definition of half).
> There a surely more such occurances.
>
> Andreas
> --
> ceterum censeo redmondinem esse delendam
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
> _______________________________________________
> Maxima-discuss mailing list
> Maxima-***@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
Raymond Toy
2017-06-23 20:49:20 UTC
Permalink
Raw Message
>>>>> "Andreas" == Andreas Eder <***@gmx.net> writes:

Andreas> Hi,
Andreas> i found that in the file ellipt.lisp we define the variable 1//2 like:
Andreas> (defvar 1//2 '((rat simp) 1 2))
Andreas> and in mopers.lisp there is a macro definition like:
Andreas> (defmacro 1//2 () ''((rat simp) 1 2))

Andreas> Does anybody know the reason - apart from mere historical
Andreas> accident - for this situation. If there is one :-)

That was probably me and I didn't know about the other.

Andreas> Shouldn't we unify thes uses?

Yes, we should.

Andreas> The use of the macro definition looks clumsy to me, since it looks like
Andreas> a function call for what should simply be the use of a constant. In
Andreas> this
Andreas> respect the variable definitions looks better.
Andreas> Another approach would be to define a symbol macro.
Andreas> What is your opinion about that?
Andreas> I'm sure 1//2 is not the only case (there is also a definition of
Andreas> half).
Andreas> There a surely more such occurances.

Using a macro or symbol macro seems wasteful since there would be a
copy everywhere instead of just the one in the defvar.

--
Ray
Barton Willis
2017-06-24 18:27:15 UTC
Permalink
Raw Message
> In some ways it would be better to use common lisp rationals.


Incidentally: there are several tests in the testsuite that pass CL rationals and complex numbers to simplifya; two that I know of are


is(part(?complex(1,2),0)="+")


?nformat(?/(1,2))


These might be good tests, but they are arguably bogus input--I know of no nonbogus test in the testsuite that passes a CL rational or complex number to simplifya.


More Maxima trivia: Expand has the feature:


(%i3) expand(exp(-x)/(1+x));
(%o3) 1/(x*%e^x+%e^x)

No (so-called) expansion (controlled by mminusp, I think)

(%i4) expand(exp(x)/(1+x));
(%o4) %e^x/(x+1)

I have evidence that eliminating this expansion rule allows integrate(x^4/(a*x^2+x+c)^(5/2),x) to evaluate correctly, but prevents specint(exp(-t)/(t+1)^2,t) from evaluating.

For evaluating integrate(x^4/(a*x^2+x+c)^(5/2),x), I'd guess that the expansion prevents Maxima from detecting a derivative divides opportunity.

I'd guess that if the rule x^(-y)/(a +b) --> 1/(a * x^y + b*x^y) only worked when x is %e, the testsuite would run OK and that the bug

integrate(x^4/(a*x^2+x+c)^(5/2),x) --> nounform

would be fixed.



--Barton
________________________________
From: Raymond Toy <***@gmail.com>
Sent: Friday, June 23, 2017 3:49:20 PM
To: maxima-***@lists.sourceforge.net
Subject: Re: [Maxima-discuss] A question about 1//2

>>>>> "Andreas" == Andreas Eder <***@gmx.net> writes:

Andreas> Hi,
Andreas> i found that in the file ellipt.lisp we define the variable 1//2 like:
Andreas> (defvar 1//2 '((rat simp) 1 2))
Andreas> and in mopers.lisp there is a macro definition like:
Andreas> (defmacro 1//2 () ''((rat simp) 1 2))

Andreas> Does anybody know the reason - apart from mere historical
Andreas> accident - for this situation. If there is one :-)

That was probably me and I didn't know about the other.

Andreas> Shouldn't we unify thes uses?

Yes, we should.

Andreas> The use of the macro definition looks clumsy to me, since it looks like
Andreas> a function call for what should simply be the use of a constant. In
Andreas> this
Andreas> respect the variable definitions looks better.
Andreas> Another approach would be to define a symbol macro.
Andreas> What is your opinion about that?
Andreas> I'm sure 1//2 is not the only case (there is also a definition of
Andreas> half).
Andreas> There a surely more such occurances.

Using a macro or symbol macro seems wasteful since there would be a
copy everywhere instead of just the one in the defvar.

--
Ray
Robert Dodier
2017-06-24 19:53:47 UTC
Permalink
Raw Message
On 2017-06-24, Barton Willis <***@unk.edu> wrote:

> I'd guess that if the rule x^(-y)/(a +b) --> 1/(a * x^y + b*x^y) only
> worked when x is %e, the testsuite would run OK and that the bug
>
> integrate(x^4/(a*x^2+x+c)^(5/2),x) --> nounform
>
> would be fixed.

I haven't looked at this problem, but I encourage you to plow ahead and
have at it.

best

Robert Dodier
Loading...