\start
Date: Mon, 01 Apr 2013 19:15:22 +0400
From: Andrey Bulychev
To: list
Subject: Higher order derivatives.

Hello.

I have learnt about axiom recently and now I'm trying to apply it to 
some of my current problems (numerical computations in physics).

I need to evaluate higher order derivatives of Lewis integral ( 
http://link.aps.org/doi/10.1103/PhysRev.102.537 , Appendix A, eq. 9) for 
further fortran export.

Using a straightforward approach (see -----v1 below), I run out of 
memory already on the second derivative.

Following an example from the 'Derivatives' section of the axiom book 
(sec.1.11), I can evaluate the derivative I need in a general form. (see 
----v2).
But when I substitute actual expressions for operators LiBt, LiDt and 
LiAg, I run out of memory again.

Another way (see ---v3) could be to replace derivatives of operators in 
the general form by some dummy variables, then actually define them and 
export to fortran.
This way looks promising but I do not know how to automate it, so it 
becomes impractical for derivatives of 2nd order and higher.

So, my question is: what is the best way to evaluate, for example, 5th 
derivative of 'Li' function from examples below and
export this result to fortran?

P.S: sorry for my english.

--------------- v1

)clear all

LiBt :=_
   mu * ((qx-px)^2 + (qy-py)^2 + (qz-pz)^2 + (a+b)^2 )_
   + b * ( mu^2 + qx^2 + qy^2 + qz^2 + a^2 )_
   + a * ( mu^2 + px^2 + py^2 + pz^2 + b^2 );

LiAg :=_
   ( (qx-px)^2 + (qy-py)^2 + (qz-pz)^2 + (a+b)^2 )_
   * ( qx^2 + qy^2 + qz^2 + (mu+a)^2 )_
   * ( px^2 + py^2 + pz^2 + (mu+b)^2 );

LiD := sqrt( LiBt^2 - LiAg );

Li := %pi^2 / LiD * log( (LiBt + LiD) / (LiBt - LiD) );

--Runs out of memory during computation.
dLidMudAdB := D(Li,[mu,a,b]);

----------- v2

)clear all

LiDt := operator 'LiDt
LiBt := operator 'LiBt
LiAg := operator 'LiAg

Li := (%pi^2 / LiDt(LiBt(mu,a,b),LiAg(mu,a,b)))_
     * log(_
      ( LiBt(mu,a,b) + LiDt( LiBt(mu,a,b), LiAg(mu,a,b)))_
      / ( LiBt(mu,a,b) - LiDt( LiBt(mu,a,b), LiAg(mu,a,b))) );

dLidMudAdBGeneral := D(Li,[mu,a,b]);

--Runs out of memory.
dLidMudAdBsubstBt := eval(dLidMudAdBGeneral,_
   'LiBt, (x) +-> x.1 * ( (qx-px)^2 + (qy-py)^2 + (qz-pz)^2 + (x.2+x.3)^2 )_
   + x.3 * ( x.1^2 + qx^2 + qy^2 + qz^2 + x.2^2 )_
   + x.2 * ( x.1^2 + px^2 + py^2 + pz^2 + x.3^2 ));
-- dLidMudAdBsubstAg := eval(dLidMudAdBsubstBt,_
--   'LiAg, (x) +-> ( (qx-px)^2 + (qy-py)^2 + (qz-pz)^2 + (x.2+x.3)^2 )_
--   * ( qx^2 + qy^2 + qz^2 + (x.1+x.2)^2 )_
--   * ( px^2 + py^2 + pz^2 + (x.1+x.3)^2 ));
-- dLidMudAdBsubstDt := eval(dLidMudAdBsubstAg, 'LiDt, (x) +-> 
sqrt(x.1^2 - x.2) );


----------v3

)clear all

LiDt := operator 'LiDt
LiBt := operator 'LiBt
LiAg := operator 'LiAg

Li := (%pi^2 / LiDt(LiBt(mu,a,b),LiAg(mu,a,b)))_
     * log(_
      ( LiBt(mu,a,b) + LiDt( LiBt(mu,a,b), LiAg(mu,a,b)))_
      / ( LiBt(mu,a,b) - LiDt( LiBt(mu,a,b), LiAg(mu,a,b))) )

dLidMuGeneral := D(Li,mu)

d1DRules := rule
     D(LiDt(beta,alphagamma),[beta]) == dDdB
     D(LiDt(beta,alphagamma),[alphagamma]) == dDdAg
d0DRules := rule
     LiDt(beta,alphagamma) == LiD
d1BRules := rule
     D(LiBt(mu,a,b),[mu]) == dBdMu
d0BRules := rule
     LiBt(mu,a,b) == LiB
d1AgRules := rule
     D(LiAg(mu,a,b),[mu]) == dAgdMu
d0AgRules := rule
     LiAg(mu,a,b) == LiA

dLidMuSubst := 
d0AgRules(d0BRules(d0DRules(d1AgRules(d1BRules(d1DRules(dLidMuGeneral))))))
-- Then export dLidMuSubst to fortran.
-- Then define
--   LiD := sqrt( b^2 - ag)
--   dDdB := D(LiD,b)
--   dDdA := D(LiD,ag)
-- and similar definitions for dBdMu, dAgdMu, LiB, LiA.
-- Then somehow export them.

\start
Date: Sat, 13 Apr 2013 12:41:39 -0400
From: Tim Daly
To: <genkuro2@mail.ru>
Subject: Speed of compilation

Axiom does take a while to build. Let me explain why.

In general, Axiom is concentrating on Literate Programming.  The goal is
to keep Axiom alive by writing down all of the information necessary to
use, maintain, and modify it.

I was a member of the original development team at IBM. We normally
developed code, even algebra code, without any documentation and without
a test suite. As a result, when I got my own code back years later I did
not understand WHY I wrote the code. I understood WHAT it did and I knew
it was necessary because removing it broke the system.  I needed all of
my original background knowledge and experience to build Axiom as open
source.

That raised the question "How can I make Axiom live beyond the
current developers?" I believe the answer is Literate Programming.

I have the "Hawaii" test for a Literate Program.  You should be able to
give a developer a paper copy of your program, send them to Hawaii for a
2 week, all expense paid vacation, and when they return they should be
able to maintain and modify the program as well as the current
developers. To do that you need to write down WHY something exists as
well as how it works, how to use it, and how to test it. This is
especially important for the algebra since very few people are domain
experts.

To see where we'd like to be look at the book "Lisp in Small Pieces".
Christian has set the gold standard for Axiom documentation.

Axiom is now structured as a 20 volume book set.  The goal is to have
the full Axiom system source code completely embedded in the books.=20
Every time the system is modified and rebuilt, all of the books
are also rebuilt. Eventually it will be normal to require updating the
human-readable text along with every code change, just as you would with
any textbook. New algebra will require some background theory as well as
explanations for code, help text, and a test suite.

Axiom is well on the way to being fully literate. It will take many
years before anyone gets a Hawaii vacation, of course, but that is the
goal.=20

Building the documentation and running the test suites every time a
change is made means that compilation takes longer.  It currently takes
about 1 hour to build the system without tests and 2.5 hours with full
testing. Full system builds are done at every commit.

Build times only affect developers, not users. Axiom is focusing on
making it easier for end users. The )help command has many new pages.
The test suite has more documented examples. Many of the functions shown
by the )display operations command have examples of use shown in the
output. Individual domain test suites and help pages are embedded with
the source code of the domain so they are part of the documentation a
user sees in the books. A standard browser based front-end is partially
built. It will function as a web front and replace both HyperDoc and
Graphics with standard HTML5.

Writing naked code was acceptable in 1975. Machines were slow. Axiom
took about 3 weeks for a full build. Build time mattered a lot.
That is no longer true. Now Human understanding is much more important.

It is now time to raise the standards. We need to expect quality code
that is well documented (including some theory), easy to modify and
maintain, with a comprehensive test suite. Human-to-Human communication
is more important than Human-to-Machine (code).

\start
Date: Sun, 14 Apr 2013 20:24:03 -0400 (EDT)
From: Tim Daly
To: list
Subject: Sourceforge Axiom update

Sourceforge has changed the Axiom project to conform to their new
file structure.

If you have used git to clone Axiom you need to modify your config
file to point to the new master. 

In .git/config look for the sourceforge URL line. It now needs to read:

[remote "origin"]
  url = git://git.code.sf.net/p/axiom/code
  fetch = +refs/heads/*:refs/remotes/origin/*

cloning the code is now done with:

git clone git://git.code.sf.net/p/axiom/code axiom

\start
Date: Sat, 20 Apr 2013 13:59:31 -0400
From: Eugene Surowitz
To: Tim Daly
Subject: /src/interp contains identical files 'libdb.text' and 'temp.text'

The directory /src/interp contains two files,
'libdb.text' and 'temp.text' that diff says are identical.

Is there an 'rm' missing somewhere?

\start
Date: Mon, 22 Apr 2013 09:21:12 -0400
From: Eugene Surowitz
To: list
Subject: Re: [fricas-devel] Re: trademarks

Personally, I would very much prefer a single wiki.

I believe that users would have great difficulty in distinguishing
the various forks in a systematic way; they may not have
been the one to set up which ever variation was installed with
their working group.

Gene

On 4/21/2013 11:00 PM, Bill Page wrote:
> Tim,

> I have no comment concerning your trademark claims but it was
> certainly not my intention to cause any confusion. I have updated
> the web page to which you referred to indicate that it uses FriCAS.

> The axiom-wiki web site is currently hosted by the FriCAS project
> and Waldek has commented in an email to the FriCAS list that he does
> not intend that the web site be exclusive to FriCAS but he does not
> have the resources to support more than the FriCAS part of the the
> site. Since this is a wiki the contents of the site is under the
> control of the wiki user community.  If there is continued
> disagreement about the appearance and contents of the site regarding
> the use of the work "axiom", then the likely result is that the
> original Axiom project will no longer be represented there at
> all. But before anyone takes such steps I think it would be better
> to discuss it a little further.

> Regards,
> Bill Page.
>
> On 21 April 2013 18:54, Tim Daly <Tim Daly
> <mailto:Tim Daly>> wrote:
>
>     Bill,
>
>     You posted a note to the FriCAS mailing list about Frobenius algebras,
>     pointing to a web page on the "Axiom Wiki".
>
>     Today I received an Axiom bug report...
>         "the enumerate()$V function does not work"
>
>     So, I looked at the page pointed out in the bug report:
>     http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2
>
>     It has the line:
>         gens: List M := enumerate()$V
>
>     and CLEARLY STATES THAT THIS IS AXIOM OUTPUT.
>
>     Axiom does not implement enumerate from that domain.
>
>     So I fired up a copy of FriCAS and found that it exists there.
>
>     Bill, I could forgive this "mistake" by anyone else but not you.
>     I have begged and pleaded with you to not spread confusion between
>     Axiom and the forks. I have begged and pleaded with Waldek and Gaby.
>
>     Please stop. Please. I'm begging you.
>
>     Do the professional thing, the right thing.
>     Use "Axiom" when you use Axiom.
>     Use "FriCAS" when you use FriCAS.
>     Stop using FriCAS and calling it Axiom.
>
>     Axiom is a trademark of the Axiom project, not of FriCAS or OpenAxiom.
>
>      >From the faq:
>
>     ===================================================================
>     FAQ 46: Axiom Trademark information
>     ===================================================================
>     The name "Axiom" and the Axiom-included iconic images are common
>     law trademarks of this project. The term of service applies to the
>     code distributed and compiled versions of code distributed from the
>     Axiom websites at
>     axiom-developer.org <http://axiom-developer.org>
>     savannah.nongnu.org/projects/axiom <http://savannah.nongnu.org/projects/axiom>
>     sourceforge.net/projects/axiom <http://sourceforge.net/projects/axiom>
>     github.com/daly/axiom <http://github.com/daly/axiom>
>
>
>     You are deliberately causing confusion and the result is that I
>     get bug reports that don't apply.
>
>     Please either change the page to use Axiom facilities or
>     change the page to use the name FriCAS.

\start
Date: Mon, 22 Apr 2013 11:53:45 -0400
From: Bill Page
To: list
Subject: Re: [fricas-devel] Re: trademarks

The frontpage of the website

http://axiom-wiki.newsynthesis.org

and more specifically the following linked page

http://axiom-wiki.newsynthesis.org/AboutAxiom

Refers to all three "Axiom-related" projects (plus Reduce, Maxima,
Sage although I think Waldek has already disabled support for these
"non-Axiom" systems).  It would be good to review especially these
pages to help give users the right impression.

One thing in particular on the FrontPage that stands out is:

"The Axiom Foundation is our means to promote the development and
maintenance of the open source version of Axiom through the
dispersement of donations and royalties from Axiom Gear to support
Axiom-related projects and through theAward Of Bounties."

In fact there has been no such active "foundation" for more than 5
years!  A few days ago I checked and was surprised to see that there
is a balance of about $300 US in the donation paypal account from
almost 10 years ago,  I emailed Tim Daly and suggested that he might
be best situated to use these funds. He agreed and if no one raises
any objection here I will find some way to transfer the money to him
and remove all mention of the "Axiom Foundation" from the AxiomWiki.

Bill Page.

On 22 April 2013 09:21, Eugene Surowitz wrote:
> Personally, I would very much prefer a single wiki.
>
> I believe that users would have great difficulty in distinguishing
> the various forks in a systematic way; they may not have
> been the one to set up which ever variation was installed with
> their working group.
>
> Gene
>
>
> On 4/21/2013 11:00 PM, Bill Page wrote:
>>
>> Tim,
>>
>> I have no comment concerning your trademark claims but it was certainly
>> not my
>> intention to cause any confusion. I have updated the web page to which you
>> referred
>> to indicate that it uses FriCAS.
>>
>> The axiom-wiki web site is currently hosted by the FriCAS project and
>> Waldek has
>> commented in an email to the FriCAS list that he does not intend that the
>> web site be
>> exclusive to FriCAS but he does not have the resources to support more
>> than the
>> FriCAS part of the the site. Since this is a wiki the contents of the site
>> is under
>> the control of the wiki user community.  If there is continued
>> disagreement about the
>> appearance and contents of the site regarding the use of the work "axiom",
>> then the
>> likely result is that the original Axiom project will no longer be
>> represented there
>> at all. But before anyone takes such steps I think it would be better to
>> discuss it a
>> little further.
>>
>> Regards,
>> Bill Page.
>>
>> On 21 April 2013 18:54, Tim Daly <Tim Daly
>> <mailto:Tim Daly>> wrote:
>>
>>     Bill,
>>
>>     You posted a note to the FriCAS mailing list about Frobenius algebras,
>>     pointing to a web page on the "Axiom Wiki".
>>
>>     Today I received an Axiom bug report...
>>         "the enumerate()$V function does not work"
>>
>>     So, I looked at the page pointed out in the bug report:
>>     http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2
>>
>>     It has the line:
>>         gens: List M := enumerate()$V
>>
>>     and CLEARLY STATES THAT THIS IS AXIOM OUTPUT.
>>
>>     Axiom does not implement enumerate from that domain.
>>
>>     So I fired up a copy of FriCAS and found that it exists there.
>>
>>     Bill, I could forgive this "mistake" by anyone else but not you.
>>     I have begged and pleaded with you to not spread confusion between
>>     Axiom and the forks. I have begged and pleaded with Waldek and Gaby.
>>
>>     Please stop. Please. I'm begging you.
>>
>>     Do the professional thing, the right thing.
>>     Use "Axiom" when you use Axiom.
>>     Use "FriCAS" when you use FriCAS.
>>     Stop using FriCAS and calling it Axiom.
>>
>>     Axiom is a trademark of the Axiom project, not of FriCAS or OpenAxiom.
>>
>>      >From the faq:
>>
>>     ===================================================================
>>     FAQ 46: Axiom Trademark information
>>     ===================================================================
>>     The name "Axiom" and the Axiom-included iconic images are common
>>     law trademarks of this project. The term of service applies to the
>>     code distributed and compiled versions of code distributed from the
>>     Axiom websites at
>>     axiom-developer.org <http://axiom-developer.org>
>>     savannah.nongnu.org/projects/axiom
>> <http://savannah.nongnu.org/projects/axiom>
>>     sourceforge.net/projects/axiom <http://sourceforge.net/projects/axiom>
>>     github.com/daly/axiom <http://github.com/daly/axiom>
>>
>>
>>
>>     You are deliberately causing confusion and the result is that I
>>     get bug reports that don't apply.
>>
>>     Please either change the page to use Axiom facilities or
>>     change the page to use the name FriCAS.
>>
>>     Please.
>>

\start
Date: Mon, 22 Apr 2013 11:57:08 -0400
From: Tim Daly
To: Eugene Surowitz
Subject: Re: [fricas-devel] Re: trademarks

The issue has nothing to do with the wiki. I don't care if the wiki
uses Axiom. Axiom is open source software and can be used by anyone.

The issue is using the Axiom name to label things that are not Axiom.

In this instance, the web page

     http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2

has 72 instances of the name "Axiom" on the page. However, it was not
developed using Axiom. It was developed using FriCAS. 

Nobody would accept the web page if every line was labeled 
"Mathematica". FriCAS and Mathematica are not the same thing.
You cannot run this code in Mathematica.

And you cannot run this code in Axiom.

I received a bug report because of this confusion.  I am asking people
who are mathematicians, who know how to be precise, to BE precise and
use the names properly.

SBCL is a fork of CMUCL. You never see SBCL claiming to BE CMUCL.
Jenkins is a fork of Hudson. You never see Jenkins claiming to BE Hudson.
Ubuntu is a fork of RedHat. You never see Ubuntu claiming to BE RedHat.
...

It would seem too obvious for words. Need I say more?

Tim Daly

(p.s. I cannot post to the fricas-devel mailing list so you might want
to mirror this to your fricas-devel reply)

\start
Date: Mon, 22 Apr 2013 12:43:46 -0400
From: Eugene Surowitz
To: Tim Daly
Subject: Re: [fricas-devel] Re: trademarks

Already understood and I had already mirrored my comments
to the FriCAS-devel list; just forgot to include OpenAxiom.

The issue is deeper though: An inspection of only the src/interp
source files reveals numerous references to 'axiom' or 'Axiom'.
FriCAS appears to use boot code -- I assume, without having got
around to inspecting it in more detail, that it too may contain
many such references; I haven't looked at OpenAxiom.

Cheer, Gene

On 4/22/2013 11:57 AM, u1204 wrote:
> Eugene,
>
> The issue has nothing to do with the wiki. I don't care if the wiki
> uses Axiom. Axiom is open source software and can be used by anyone.
>
> The issue is using the Axiom name to label things that are not Axiom.
>
> In this instance, the web page
>
>       http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2
>
> has 72 instances of the name "Axiom" on the page. However, it was not
> developed using Axiom. It was developed using FriCAS.
>
> Nobody would accept the web page if every line was labeled
> "Mathematica". FriCAS and Mathematica are not the same thing.
> You cannot run this code in Mathematica.
>
> And you cannot run this code in Axiom.
>
> I received a bug report because of this confusion.  I am asking people
> who are mathematicians, who know how to be precise, to BE precise and
> use the names properly.
>
> SBCL is a fork of CMUCL. You never see SBCL claiming to BE CMUCL.
> Jenkins is a fork of Hudson. You never see Jenkins claiming to BE Hudson.
> Ubuntu is a fork of RedHat. You never see Ubuntu claiming to BE RedHat.
> ...
>
> It would seem too obvious for words. Need I say more?
>
> Tim Daly
>
> (p.s. I cannot post to the fricas-devel mailing list so you might want
> to mirror this to your fricas-devel reply)

\start
Date: Mon, 22 Apr 2013 13:42:04 -0400
From: Tim Daly
To: Eugene Surowitz
Subject: Re: [fricas-devel] Re: trademarks

> Already understood and I had already mirrored my comments
> to the FriCAS-devel list; just forgot to include OpenAxiom.
> 
> The issue is deeper though: An inspection of only the src/interp
> source files reveals numerous references to 'axiom' or 'Axiom'.
> FriCAS appears to use boot code -- I assume, without having got
> around to inspecting it in more detail, that it too may contain
> many such references; I haven't looked at OpenAxiom.

There is a tool called 'sed' that could fix this in a single command.
Any person who uses unix could do this in minutes.

The only thing it won't fix is the "axiom*.{png,jpg}" files.
I created those using gimp so they would have to be redone.

The "30 year horizon" image is work done by an artist for Axiom.
It shows a bayou in Lousianna. I have special permission to use it.

Using names properly is such a simple thing. 
Nobody does a search on "Bing" and labels it "Google".
So why create a page with FriCAS and label each line Axiom?

I don't understand why this is a continuing problem.

\start
Date: Mon, 22 Apr 2013 13:52:35 -0400
From: Bill Page
To: Tim Daly
Subject: Re: [fricas-devel] Re: trademarks

On 22 April 2013 13:42, Tim Daly wrote:
>> Already understood and I had already mirrored my comments
>> to the FriCAS-devel list; just forgot to include OpenAxiom.
>>
>> The issue is deeper though: An inspection of only the src/interp
>> source files reveals numerous references to 'axiom' or 'Axiom'.
>> FriCAS appears to use boot code -- I assume, without having got
>> around to inspecting it in more detail, that it too may contain
>> many such references; I haven't looked at OpenAxiom.
>
> There is a tool called 'sed' that could fix this in a single command.
> Any person who uses unix could do this in minutes.
>
> The only thing it won't fix is the "axiom*.{png,jpg}" files.
> I created those using gimp so they would have to be redone.
>
> The "30 year horizon" image is work done by an artist for Axiom.
> It shows a bayou in Lousianna. I have special permission to use it.
>
> Using names properly is such a simple thing.
> Nobody does a search on "Bing" and labels it "Google".
> So why create a page with FriCAS and label each line Axiom?
>
> I don't understand why this is a continuing problem.
>

\start
Date: Mon, 22 Apr 2013 14:08:33 -0400
From: Bill Page
To: Tim Daly
Subject: Re: [fricas-devel] Re: trademarks

I am sorry, but changing variable names inside source code because of
a project fork seems incorrect to me.  I think it would be both wrong
and even more confusing if FriCAS and OpenAxiom tried to give the
impression that they had no relation to each other and no relation at
all to the original Axiom project when they still share between 75% to
90% of the same code, the user languages are nearly (but not exactly)
identical and for the most part they produce the same results.

\start
Date: Mon, 22 Apr 2013 15:42:31 -0400
From: Tim Daly
To: Bill Page
Subject: Re: [fricas-devel] Re: trademarks

>I am sorry, but changing variable names inside source code because of
>a project fork seems incorrect to me.  I think it would be both wrong
>and even more confusing if FriCAS and OpenAxiom tried to give the
>impression that they had no relation to each other and no relation at
>all to the original Axiom project when they still share between 75% to
>90% of the same code, the user languages are nearly (but not exactly)
>identical and for the most part they produce the same results.

Most common lisps share a large percentage of the CMUCL code because
most of the source code is common lisp and other lisps just copy it.

Indeed, SBCL shares 90% of the CMUCL code, including low level code
since it is a fork.

Considering they all implement the same standard, all the common 
lisps have identical results. 

SBCL never posts code or results and uses the name "CMUCL".
GCL never posts code or results under the CMUCL name.
CLISP never posts code or results under the CMUCL name.

As for the 75% to 90% of the code being shared, you'll notice that Boot
no longer exists in Axiom. I have hand-authored most of the replacement
code and expect it all to be rewritten by the end of the year.  So I've
written tens of thousands of lines of code that is not shared. A large
portion of the code in the interpreter (Volume 5) and the compiler 
(Volume 9) is code I rewrote from the Boot version. Even the algebra
syntax is not shared anymore. Waldek changed the meaning of primitives
like ^, symbol-creation, etc.

Code from one system will not even parse in the other.
Code you wrote on that page won't run in Axiom.

It is "wrong and confusing" to use the name Axiom when it is not Axiom.
Please stop.

\start
Date: Mon, 22 Apr 2013 19:58:13 -0400
From: Eugene Surowitz
To: Tim Daly
Subject: Re: [fricas-devel] Re: trademarks

I have known about 'sed' for a long time;
but have had enough experience with global
change mechanisms to avoid them like the plague.

Cheers, Gene

On 4/22/2013 1:42 PM, u1204 wrote:
>> Already understood and I had already mirrored my comments
>> to the FriCAS-devel list; just forgot to include OpenAxiom.
>>
>> The issue is deeper though: An inspection of only the src/interp
>> source files reveals numerous references to 'axiom' or 'Axiom'.
>> FriCAS appears to use boot code -- I assume, without having got
>> around to inspecting it in more detail, that it too may contain
>> many such references; I haven't looked at OpenAxiom.
>
> There is a tool called 'sed' that could fix this in a single command.
> Any person who uses unix could do this in minutes.
>
> The only thing it won't fix is the "axiom*.{png,jpg}" files.
> I created those using gimp so they would have to be redone.
>
> The "30 year horizon" image is work done by an artist for Axiom.
> It shows a bayou in Lousianna. I have special permission to use it.
>
> Using names properly is such a simple thing.
> Nobody does a search on "Bing" and labels it "Google".
> So why create a page with FriCAS and label each line Axiom?
>
> I don't understand why this is a continuing problem.

\start
Date: Tue, 23 Apr 2013 18:00:36 +0200 (CEST)
From: Waldek Hebisch
To: list
Subject: Re: [fricas-devel] Re: trademarks

Eugene Surowitz wrote:
> 
> The issue is deeper though: An inspection of only the src/interp
> source files reveals numerous references to 'axiom' or 'Axiom'.
> FriCAS appears to use boot code -- I assume, without having got
> around to inspecting it in more detail, that it too may contain
> many such references; I haven't looked at OpenAxiom.
> 

The issue is deeper than you think.  If you examined hits in
more detail you will note that most references falls into
two categories:

- historical or obsolete material
- names which part of user/external interface

Obsolete material eventually will be deleted.  User interfaces
may change but this is slow process to minimize negative
impact on the users.  I am not in the business of rewriting
history so I will still call NAG product Axiom and not FriCAS.
As long as Aldor is in use 'axiomxl' and similar names in the
Aldor interface will stay.

\start
Date: Tue, 23 Apr 2013 18:07:54 +0200 (CEST)
From: Waldek Hebisch
To: list
Subject: Re: [fricas-devel] Re: trademarks

Eugene Surowitz wrote:
> 
> Personally, I would very much prefer a single wiki.
> 
> I believe that users would have great difficulty in distinguishing
> the various forks in a systematic way; they may not have
> been the one to set up which ever variation was installed with
> their working group.

I am not sure how the two sentences above fit together.  Do
you mean that there should be a single wiki for all forks
and no attempt to distinguish them?

\start
Date: Tue, 23 Apr 2013 18:17:16 +0200
From: Ralf Hemmecke
To: list
Subject: Re: [fricas-devel] Re: trademarks

I think Tim would already be happy, if we modify the

<div id="axiomlabel" align="right">axiom</div>

that appears on every outputbox of

http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2
(and every such box on such generated output) into "fricas".

I don't care if fricas-devel get's more bug reports in this way.

That would be a simple change in some script and probably Bill knows
exactly where this has to be done.

That would stop such needless discussion.

We are in the unfortunate situation of having 3 systems that are
terribly similar but not equal. Would be nice if we converged, but I
don't see this to happen in the near future. So it's only fair if people
are made aware of the differences of the systems.

If we continue to support Axiom and OpenAxiom on
http://axiom-wiki.newsynthesis.org then there should (maybe) a link to
http://axiom-wiki.newsynthesis.org/PanAxiom on every single wiki page.

Personally, I don't care much about non-FriCAS, i.e. not supporting
Axiom and OpenAxiom on the AxiomWiki anymore would be OK for me, but
then I'd prefer to rename it to FriCASWiki and change the URL accordingly.

\start
Date: Tue, 23 Apr 2013 12:55:52 -0400
From: Eugene Surowitz
To: Gabriel Dos Reis
Subject: Re: [fricas-devel] Re: trademarks

One Wiki with a clear indication which variant
is being exercised and auto-direction to the
appropriate list for comments and bug reports.

Cheers, Gene

On 4/23/2013 12:07 PM, Waldek Hebisch wrote:
> Eugene Surowitz wrote:
>>
>> Personally, I would very much prefer a single wiki.
>>
>> I believe that users would have great difficulty in distinguishing
>> the various forks in a systematic way; they may not have
>> been the one to set up which ever variation was installed with
>> their working group.
>
> I am not sure how the two sentences above fit together.  Do
> you mean that there should be a single wiki for all forks
> and no attempt to distinguish them?

\start
Date: Tue, 23 Apr 2013 20:01:18 +0200 (CEST)
From: Waldek Hebisch
To: list
Subject: Re: [fricas-devel] Re: trademarks

> I think Tim would already be happy, if we modify the
> 
> <div id="axiomlabel" align="right">axiom</div>
> 
> that appears on every outputbox of
> 
> http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2
> (and every such box on such generated output) into "fricas".
> 
> I don't care if fricas-devel get's more bug reports in this way.
> 
> That would be a simple change in some script and probably Bill knows
> exactly where this has to be done.

I have done such modification.  With little extra effort we should be
able to put correct label (depending on which flavor is run).
The change takes effect only one somebody trigger page refresh
(in particular when page is modified).

\start
Date: Tue, 23 Apr 2013 21:22:40 +0200 (CEST)
From: Waldek Hebisch
To: list
Subject: Re: [fricas-devel] Re: trademarks

Bill Page wrote:
> 
> The frontpage of the website
> 
> http://axiom-wiki.newsynthesis.org
> 
> and more specifically the following linked page
> 
> http://axiom-wiki.newsynthesis.org/AboutAxiom
> 
> Refers to all three "Axiom-related" projects (plus Reduce, Maxima,
> Sage although I think Waldek has already disabled support for these
> "non-Axiom" systems).  It would be good to review especially these
> pages to help give users the right impression.

ATM Reduce should work OK.  I think we could restore Maxima with
reasonable effort.  However, I am affraid that Sage would require
much more resources to keep is up to date and IMHO keeping obsolete
version makes no sense.

> One thing in particular on the FrontPage that stands out is:
> 
> "The Axiom Foundation ...

I am for transerring money to Tim and deleting reference.
However there are several other pages which are hopelessly
obsolete.  I am not sure if we should just delete them
or create "obsolete" part of wiki where such pages would
be kept frozen as a document of the past.

Coming back to front page: in Thank You part there is popup
saying that Sage hosts the VM, which is no longer true...
I doubt that CAISS is giving any support to wiki or any
of Axiom flavours.  I would rather keep thanks somewhere,
but IMHO it would be better to move them to separate page
(or maybe to "frozen" old front page).

Also, I think it would be reasonable to change name to
FriCAS Wiki and change logo (currently all pages show
Axiom logo).

\start
Date: Tue, 23 Apr 2013 16:37:16 -0400
From: Bill Page
To: list
Subject: Re: [fricas-devel] Re: trademarks

On 23 April 2013 15:22, Waldek Hebisch wrote:
> Bill Page wrote:
>>
>> The frontpage of the website
>>
>> http://axiom-wiki.newsynthesis.org
>>
>> and more specifically the following linked page
>>
>> http://axiom-wiki.newsynthesis.org/AboutAxiom
>>
>> Refers to all three "Axiom-related" projects (plus Reduce, Maxima,
>> Sage although I think Waldek has already disabled support for these
>> "non-Axiom" systems).  It would be good to review especially these
>> pages to help give users the right impression.
>
> ATM Reduce should work OK.  I think we could restore Maxima with
> reasonable effort.  However, I am affraid that Sage would require
> much more resources to keep is up to date and IMHO keeping obsolete
> version makes no sense.
>

Great.  I still think it is nice to have both Reduce and Maxima.  Sage
has it's own web support so really we shouldn't worry much about that.

>> One thing in particular on the FrontPage that stands out is:
>>
>> "The Axiom Foundation ...
>
> I am for transerring money to Tim and deleting reference.

OK.

> However there are several other pages which are hopelessly
> obsolete.  I am not sure if we should just delete them
> or create "obsolete" part of wiki where such pages would
> be kept frozen as a document of the past.

I do not care much about keeping old documents from the past.  It is
much more important to get on with updating the contents.

> Coming back to front page: in Thank You part there is popup
> saying that Sage hosts the VM, which is no longer true...

Delete.

> I doubt that CAISS is giving any support to wiki or any
> of Axiom flavours.

Right.

>  I would rather keep thanks somewhere,
> but IMHO it would be better to move them to separate page
> (or maybe to "frozen" old front page).
>

Separate page.

> Also, I think it would be reasonable to change name to
> FriCAS Wiki and change logo (currently all pages show
> Axiom logo).
>

Yes, pick a nice new logo.

\start
Date: Tue, 23 Apr 2013 15:42:59 -0300
From: Gabriel Gino Vincent
To: list
Subject: Axiom For Mac

Hello,

In Axiom's website there's a tutorial on how to install Axiom on a
Mac. I've tried a lot, but still can't. I tried to download it from
Github and follow the suggested steps, but I'm never able to go beyond
the make command. I have Xcode properly installed.

Isn't there a compatible version of Axiom for Mac? If not, could I
have some instructions on how to compile it so it can run on a Mac?

\start
Date: Tue, 23 Apr 2013 19:14:29 -0400
From: Tim Daly
To: Ralf Hemmecke
Subject: Re: [fricas-devel] Re: trademarks

Ralf,

>We are in the unfortunate situation of having 3 systems that are
>terribly similar but not equal. Would be nice if we converged, but I
>don't see this to happen in the near future. So it's only fair if people
>are made aware of the differences of the systems.

You'll notice that I have made an effort to pick up some of the changes
from FriCAS. For instance, the Type output form now includes parens for
InputForm parsing. I've also picked up some of the algebra changes as
I become aware of them. For instance, enumerate now exists, the MAMA
package exists, U8Matrix, U16Matrix, and U32Matrix as well as the
U{8,16,32}Vector domains exist.

However, changes that diverge from the Jenks book, such as the change
to the semantics of ^, are not likely to happen.

FriCAS has not picked up the work on PackageForAlgebraicFunctionField,
for instance. Nor has it picked up AxiomServer and its corresponding
browser front-end machinery so the new browser-based hyperdoc/graphics
won't work there. There are dozens of new test case files in src/input.
Code examples are shown on ")d op foo" for operation foo which I think
is a good idea for users. There is a help file for all algebra.
Volume 8.1 has dozens of graphics examples, all of which should work
in FriCAS. A lot of this effort is aimed at the end user.

Noweb is disappearing. The pamphlet files are now pure latex so 
there is no need for a "weave" step. Pamphlet files are a native
format so you can )tangle from the command line.

I don't believe that the systems will ever converge. 
We have different and incompatible project goals.

I would prefer that we at least tried to keep the algebra aligned.
We all have a common interest in that. I try to achieve that when
I find algebra incompatibilities. I do wish the algebra had better
documentation though. It can be hard to guess what the slattern()
function does if you're not a domain expert. Why bother keeping
the pamphlet file format if there are no words?

\start
Date: Tue, 23 Apr 2013 19:15:51 -0400
From: Tim Daly
To: Waldek Hebisch
Subject: Re: [fricas-devel] Re: trademarks

>> I think Tim would already be happy, if we modify the
>> 
>> <div id="axiomlabel" align="right">axiom</div>
>> 
>> that appears on every outputbox of
>> 
>> http://axiom-wiki.newsynthesis.org/SandBoxObserverAsIdempotent2
>> (and every such box on such generated output) into "fricas".
>> 
>> I don't care if fricas-devel get's more bug reports in this way.
>> 
>> That would be a simple change in some script and probably Bill knows
>> exactly where this has to be done.
>
>I have done such modification.  With little extra effort we should be
>able to put correct label (depending on which flavor is run).
>The change takes effect only one somebody trigger page refresh
>(in particular when page is modified).

Thank you.

\start
Date: Tue, 23 Apr 2013 19:21:48 -0400
From: Tim Daly
To: Waldek Hebisch
Subject: Re: [fricas-devel] Re: trademarks

Feel free to delete the CAISS thank-you information.
They get thanked on the Axiom home page.

I have no opinion about changing anything on the Wiki provided
that any use of "Axiom" actually refers to the Axiom project.

I see you've already taken steps to make it clear what system
is used. Thank you for that.

\start
Date: Thu, 25 Apr 2013 10:08:00 -0500
From: Gabriel Dos Reis
To: list
Subject: Re: [fricas-devel] Re: trademarks

Eugene Surowitz writes:

[...]

| The issue is deeper though: An inspection of only the src/interp
| source files reveals numerous references to 'axiom' or 'Axiom'.
| FriCAS appears to use boot code -- I assume, without having got
| around to inspecting it in more detail, that it too may contain
| many such references; I haven't looked at OpenAxiom.

I think OpenAxiom changed AXIOM to OpenAxiom.  
Or course, it makes no sense to ask people not to use axiom as variable names.

\start
Date: Thu, 25 Apr 2013 10:25:06 -0500
From: Gabriel Dos Reis
To: list
Subject: Re: [fricas-devel] Re: trademarks

Waldek Hebisch writes:

[...]

| Also, I think it would be reasonable to change name to
| FriCAS Wiki and change logo (currently all pages show
| Axiom logo).

this goes back to a question I asked some time ago.  Glad to see it has
found a more definitive answer.

\start
Date: Thu, 25 Apr 2013 16:07:53 -0400
From: Eugene Surowitz
To: Gabriel Dos Reis
Subject: Re: [fricas-devel] Re: icons

I like the idea of icons/logos acknowledging the common history;
Things that might be used create sufficiently non-infringing are
style, color, shape, wording.

I'm not quite sure what I mean by 'style'.

As a 'wording' example, to distinguish to things on my product disk,
I label their top directories as:

AXIOM=AXIOM  AXIOM=FRICAS  AXIOM=OpenAxiom

( "=" just is the result of Windows naming limits )

Just ideas; Cheers , Gene

On 4/25/2013 10:16 AM, Bill Page wrote:
> Of those examples on page so far
>
> http://axiom-wiki.newsynthesis.org/FriCASIcon
>
> I think I also prefer number 2 or maybe better it's inverse number 3.
>
> To me it seems less important to be "creative" and more important to remind us of the
> history by some similarity to the Axiom logo.
>
>
> On 25 April 2013 09:36, Ralf Hemmecke <ralf@hemmecke.org <mailto:ralf@hemmecke.org>>
> wrote:
>
>      >> having a nice logo for fricas would be great.
>
>      > My idea was very similar to second proposal by Bill Page.
>
>     Hmm, yes, that number 2 from
>     http://axiom-wiki.newsynthesis.org/FriCASIcon was also my first thought,
>     but in some sense it's a bit boring, because the i with the double dots
>     has been invented (by Johannes Grabmeier ?) for Axiom and using it for
>     FriCAS would no show big creativity on our side (even though the i would
>     remind on the origin of FriCAS).
>
>     I think I would be more in favour of a nice picture, not just a
>     name-logo. Maybe we need 2 logos.
>
>     Well, it's not terribly urgent, let's think about it for some more time.
>

\start
Date: Thu, 25 Apr 2013 16:45:37 -0400
From: Bill Page
To: list
Subject: Re: [fricas-devel] Re: icons
Cc: Gabriel Dos Reis

I think Gene has a good point also indirectly observed by Gaby: Most of the
proposals so far may not represent the actual intention of the web site -
even if FriCAS is the project which is hosting the site.

In the past when trying to refer to any of the original Axiom project,
FriCAS or OpenAxiom in a neutral way we have sometimes used the word

  PanAxiom

Perhaps some variant of this that might work. I just added #6 at

  http://axiom-wiki.newsynthesis.org/FriCASIcon

which incorporates all three names.

Bill.

On 25 April 2013 16:07, Eugene Surowitz wrote:

> I like the idea of icons/logos acknowledging the common history;
> Things that might be used create sufficiently non-infringing are
> style, color, shape, wording.
>
> I'm not quite sure what I mean by 'style'.
>
> As a 'wording' example, to distinguish to things on my product disk,
> I label their top directories as:
>
> AXIOM=AXIOM  AXIOM=FRICAS  AXIOM=OpenAxiom
>
> ( "=" just is the result of Windows naming limits )
>
> Just ideas; Cheers , Gene
>

\start
Date: Thu, 25 Apr 2013 17:10:04 -0400
From: Eugene Surowitz
To: Gabriel Dos Reis
Subject: Re: [fricas-devel] Re: icons and exprint

Publishers have what is known as "Imprints";
these are, historically, other companies that
were absorbed but the customers don't care
about the merger and acquisitions.

Axiom, FriCAS, and OpenAxiom could possibly adopt a
common "exprint" while having their own unique icon/trademark.

Cheers, Gene

On 4/25/2013 4:45 PM, Bill Page wrote:

> I think Gene has a good point also indirectly observed by Gaby: Most
> of the proposals so far may not represent the actual intention of
> the web site - even if FriCAS is the project which is hosting the
> site.

> In the past when trying to refer to any of the original Axiom
> project, FriCAS or OpenAxiom in a neutral way we have sometimes used
> the word

>    PanAxiom
>
> Perhaps some variant of this that might work. I just added #6 at
>
> http://axiom-wiki.newsynthesis.org/FriCASIcon
>
> which incorporates all three names.
>
> Bill.
>
> On 25 April 2013 16:07, Eugene Surowitz <Eugene Surowitz
> <mailto:Eugene Surowitz>> wrote:
>
>     I like the idea of icons/logos acknowledging the common history;
>     Things that might be used create sufficiently non-infringing are
>     style, color, shape, wording.
>
>     I'm not quite sure what I mean by 'style'.
>
>     As a 'wording' example, to distinguish to things on my product disk,
>     I label their top directories as:
>
>     AXIOM=AXIOM  AXIOM=FRICAS  AXIOM=OpenAxiom
>
>     ( "=" just is the result of Windows naming limits )
>
>     Just ideas; Cheers , Gene

\start
Date: Thu, 25 Apr 2013 18:05:30 -0500
From: Tim Daly
To: list
Subject: AXIOM pamphlet file format is now pure latex
Cc: Kai Kaminski

I just ran across this paper:

 Clifford Yapp, Waldek Hebisch, Kai Kaminski
 CL-WEB v0.5 - Literate Programming Tools Implemented in Common Lisp
 March 25, 2013

It is a Common Lisp implementation of a tangle program which 
recognizes NOWEB syntax to delimit chunks in a literate program.

AXIOM and NOWEB

NOWEB was originally chosen for the Axiom project as a language
neutral mechanism for embedding code chunks in a file. The standard
file format for Axiom files is a "pamphlet".

The pamphlet file format was an almost-latex file. It required using a
TANGLE program to extract the source code. It required using a WEAVE
program to create a valid latex file. This is normal for doing
Knuth-style WEB programming.

All Axiom source files were converted to "pamphlet" format, using
NOWEB syntax.

Eventually it became clear that it was possible to simplify the whole
process. The NOWEB syntax delimits a chunk of code using a marker:

<<this is the name of the chunk>>=
    THIS IS THE SOURCE CODE FOR THIS CHUNK
@

where the code lives between the <<...>>= and the @. The TANGLE and
WEAVE program recognize and act on these delimiters. There is a way
to "include" a chunk of code by using the syntax

<<this is the name of the chunk>>

which is just the chunk name without the trailing = sign.

NOWEB has much more functionality than Axiom needs and the WEAVE
function can do many more things than Axiom needs. Indeed,
NOWEB is much more complex than necessary.




AXIOM and LATEX

A major simplification changes the chunking syntax to be pure latex.
This means that there is no WEAVE step required.  Only the TANGLE 
function is needed to extract the code. Thus pamphlet files are now
latex files.

Axiom now has a new chunk syntax which is pure latex. The required
latex macros live in axiom.sty (see src/scripts/axiom.sty). Just 

\usepackage{axiom}

The above chunk now looks like:

\begin{chunk}{this is the name of the chunk}
    THIS IS THE SOURCE CODE FOR THIS CHUNK
\end{chunk}

The "\begin{chunk}" creates an environment, similar to the latex
"\begin{verbatim}" environment, which is ended by "\end{chunk}"

The way to "include" a chunk of code is

\getchunk{this is the name of the chunk}

which looks up the chunk in a hash table and inserts it inline.

The advantage of this approach is that pamphlet files are now
pure latex files. There is no need for a WEAVE function.



AXIOM )tangle COMMAND

In Axiom you can have a foo.input.pamphlet file (see the test
cases in src/input/*.input.pamphlet) and from the command line
issue:

)tangle foo
)read foo

which makes working with input files trivially easy. 




MAKING PDF FILES (without WEAVE)

Creating a foo.pdf for foo.input.pamphlet involves:

latex foo.input.pamphlet
dvipdfm foo.input.dvi

The code to implement the TANGLE function is in Common Lisp
(see books/tangle.lisp). This code will also handle the legacy
NOWEB format for files that have not yet been converted.

Run from a lisp command line it accepts 2 or 3 arguments:

The first argument is always the file from which to extract code

The second argument is the name of the chunk to extract
   If the name starts with < then we assume noweb format as in:
       (tangle "clweb.pamphlet" "<<name>>")  <== noweb syntax
   Otherwise we assume latex format as in:
       (tangle "clweb.pamphlet "name")       <== latex syntax (default)

The standard noweb chunk name is ``*'' but any name can be used.

The third arument is the name of an output file:
   (tangle "clweb.pamphlet" "clweb.chunk" "clweb.spadfile")

The implementation code is included below.

Tim Daly





=============================================================
TANGLE.LISP
=============================================================

;  0 AUTHOR and LICENSE
;  1 ABSTRACT
;  2 THE LATEX SUPPORT CODE
;  3 GLOBALS
;  4 THE TANGLE COMMAND
;  5 THE TANGLE FUNCTION
;  6 GCL-READ-FILE (aka read-sequence)
;  7 GCL-HASHCHUNKS
;  8 GCL-EXPAND
;  9 ISCHUNK-LATEX
; 10 ISCHUNK-NOWEB
; 11 ALLCHUNKS

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 0 AUTHOR and LICENSE

;;; Timothy Daly (Tim Daly) 
;;; License: Public Domain

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 1 ABSTRACT

;;; This program will extract the source code from a literate file

;;; A literate lisp file contains a mixture of latex and lisp sources code.
;;; The file is intended to be in one of two formats, either in latex
;;; format or, for legacy reasons, in noweb format.

;;; Latex format files defines a newenvironment so that code chunks
;;; can be delimited by \begin{chunk}{name} .... \end{chunk} blocks
;;; This is supported by the following latex code.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 2 THE LATEX SUPPORT CODE

;;; The verbatim package quotes everything within its grasp and is used to
;;; hide and quote the source code during latex formatting. The verbatim
;;; environment is built in but the package form lets us use it in our
;;; chunk environment and it lets us change the font.
;;;
;;; \usepackage{verbatim}
;;; 
;;; Make the verbatim font smaller
;;; Note that we have to temporarily change the '@' to be just a character
;;; because the \verbatim@font name uses it as a character
;;;
;;; \chardef\atcode=\catcode`\@
;;; \catcode`\@=11
;;; \renewcommand{\verbatim@font}{\ttfamily\small}
;;; \catcode`\@=\atcode

;;; This declares a new environment named ``chunk'' which has one
;;; argument that is the name of the chunk. All code needs to live
;;; between the \begin{chunk}{name} and the \end{chunk}
;;; The ``name'' is used to define the chunk.
;;; Reuse of the same chunk name later concatenates the chunks

;;; For those of you who can't read latex this says:
;;; Make a new environment named chunk with one argument
;;; The first block is the code for the \begin{chunk}{name}
;;; The second block is the code for the \end{chunk}
;;; The % is the latex comment character

;;; We have two alternate markers, a lightweight one using dashes
;;; and a heavyweight one using the \begin and \end syntax
;;; You can choose either one by changing the comment char in column 1
 
;;; \newenvironment{chunk}[1]{%   we need the chunkname as an argument
;;; {\ }\newline\noindent%                    make sure we are in column 1
;;; %{\small $\backslash{}$begin\{chunk\}\{{\bf #1}\}}% alternate begin mark
;;; \hbox{\hskip 2.0cm}{\bf --- #1 ---}%      mark the beginning
;;; \verbatim}%                               say exactly what we see
;;; {\endverbatim%                            process \end{chunk}
;;; \par{}%                                   we add a newline
;;; \noindent{}%                              start in column 1
;;; \hbox{\hskip 2.0cm}{\bf ----------}%      mark the end
;;; %$\backslash{}$end\{chunk\}%              alternate end mark (commented)
;;; \par%                                     and a newline
;;; \normalsize\noindent}%                    and return to the document

;;; This declares the place where we want to expand a chunk
;;; Technically we don't need this because a getchunk must always
;;; be properly nested within a chunk and will be verbatim.

;;; \providecommand{\getchunk}[1]{%
;;; \noindent%
;;; {\small $\backslash{}$begin\{chunk\}\{{\bf #1}\}}}% mark the reference

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 3 GLOBALS

;;; The *chunkhash* variable will hold the hash table of chunks.
;;;
;;; Every time we find a \begin{chunk}{name} ... \end{chunk} we look
;;; in this hash table. If the ``name'' is not found we add it.
;;; If the name is found, we concatentate it to the existing chunk.

(defvar *chunkhash* nil "this hash table contains the chunks found")

;;; This shows critical information for debugging purposes
(defvar *chunknoise* nil "turn this on to debug internals")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 4 THE TANGLE COMMAND

;;;
;;; The tangle command does all of the work of extracting code.
;;; For legacy reasons we support 2 syntax forms, latex and noweb
;;;
;;; In latex form the code blocks are delimited by
;;;     \begin{chunk}{name}
;;;     ... (code for name)...
;;;     \end{chunk}
;;;
;;; and referenced by \getchunk{name} which gets replaced by the code

;;; In noweb form the code blocks are delimited by
;;;     <<name>>=
;;;     ... (code for name)...
;;;     @
;;;
;;; and referenced by <<name>> which gets replaced by the code

:;; There are several ways to invoke the tangle function. 
;;;
;;; The first argument is always the file from which to extract code
;;;
;;; The second argument is the name of the chunk to extract
;;;    If the name starts with < then we assume noweb format as in:
;;;        (tangle "clweb.pamphlet" "<<name>>")  <== noweb syntax
;;;    Otherwise we assume latex format as in:
;;;        (tangle "clweb.pamphlet "name")       <== latex syntax (default)
;;;
;;; The standard noweb chunk name is ``*'' but any name can be used.
;;;
;;; The third arument is the name of an output file:
;;;  (tangle "clweb.pamphlet" "clweb.chunk" "clweb.spadfile")



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 5 THE TANGLE FUNCTION

;;; This routine looks at the first character of the chunk name.
;;; If it is a $<$ character then we assume noweb syntax otherwise
;;; we assume latex syntax.
;;;
;;; We initialize the chunk hashtable
;;; then read the file and store each chunk
;;; then we recursively expand the ``topchunk'' to the output stream

(defun tangle (filename topchunk &optional file)
 "Extract the source code from a pamphlet file"
 (let ((noweb? (char= (schar topchunk 0) #\<)))
  (setq *chunkhash* (make-hash-table :test #'equal))
  (when *chunknoise* (format t "PASS 1~%"))
  (gcl-hashchunks (gcl-read-file filename) noweb?)
  (when *chunknoise* (format t "PASS 2~%"))
  (if (and file (stringp file))
   (with-open-file (out file :direction :output)
     (gcl-expand topchunk noweb? out))
   (gcl-expand topchunk noweb? t))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 6 GCL-READ-FILE (aka read-sequence)

;;; This would be read-sequence in ansi common lisp. Here we read
;;; a line, push it onto a stack and then reverse the stack. The
;;; net effect is a list of strings, one per line of the file.

(defun gcl-read-file (streamname)
 "Implement read-sequence in GCL"
 (let (result)
  (with-open-file (stream (open streamname))
   (do (line eof)
      ((eq line 'done) (nreverse result))
    (multiple-value-setq (line eof) (read-line stream nil 'done)) 
    (unless (eq line 'done) (push line result))))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 7 GCL-HASHCHUNKS

;;; gcl-hashchunks gathers the chunks and puts them in the hash table
;;;
;;; if we find the chunk syntax and it is a
;;;   define ==> parse the chunkname and start gathering lines onto a stack
;;;   end    ==> push the completed list of lines into a stack of chunks
;;;              already in the hash table
;;;   otherwise ==> if we are gathering, push the line onto the stack

;;; a hash table entry is a list of lists such as
;;; (("6" "5") ("4" "3") ("2" "1"))
;;; each of the sublists is a set of lines in reverse (stack) order
;;; each sublist is a single chunk of lines. 
;;; there is a new sublist for each reuse of the same chunkname

;;; If the noweb argument is non-nil we assume that we are parsing
;;; using the noweb syntax. A nil argument implies latex syntax.

(defun gcl-hashchunks (lines noweb)
 "Gather all of the chunks and put them into a hash table"
 (let (type name chunkname oldchunks chunk gather)
  (dolist (line lines)
   (if noweb
    (multiple-value-setq (type name) (ischunk-noweb line))
    (multiple-value-setq (type name) (ischunk-latex line)))
   (cond
    ((eq type 'define)
      (when *chunknoise* (format t "DEFINE name=~a~%" name))
      (setq chunkname name)
      (setq gather t))
    ((eq type 'end)
      (when *chunknoise* 
       (format t "END name= ~a chunk=~s~%" chunkname (reverse chunk)))
      (setq oldchunks (gethash chunkname *chunkhash*))
      (setf (gethash chunkname *chunkhash*) (push chunk oldchunks))
      (setq gather nil)
      (setq chunk nil))
    (gather ;; collect lines into the chunk while gather is true
      (push line chunk))))))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 8 GCL-EXPAND

;;; gcl-expand will recursively expand chunks in the hash table
;;; 
;;; latex chunk names are just the chunkname itself e.g. chunkname
;;; noweb chunk names include the delimiters, e.g: <<chunkname>>

;;; a hash table entry is a list of lists such as
;;; (("6" "5") ("4" "3") ("2" "1"))
;;; so to process the chunk we reverse the main list and
;;; for each sublist we reverse the sublist and process the lines

;;; if a chunk name reference is encountered in a line we call expand
;;; recursively to expand the inner chunkname.

(defun gcl-expand (chunk noweb? file)
 "Recursively expand a chunk into the output stream"
 (let ((chunklist (gethash chunk *chunkhash*)) type name)
  (dolist (chunk (reverse chunklist))
   (dolist (line (reverse chunk))
    (if noweb?
     (multiple-value-setq (type name) (ischunk-noweb line))
     (multiple-value-setq (type name) (ischunk-latex line)))
    (if (eq type 'refer) 
      (progn
       (when *chunknoise* (format t "REFER name=~a~%" name))
       (gcl-expand name noweb? file))
      (format file "~a~%" line))))))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 9 ISCHUNK-LATEX

;;; There is a built-in assumption (in the ischunk-* functions)
;;; that the chunks occur on separate lines and that the indentation
;;; of the chunk reference has no meaning.
;;;
;;; ischunk-latex  recognizes chunk names in latex convention
;;;
;;; There are 3 cases to recognize:
;;;  \begin{chunk}{thechunkname}  ==> 'define thechunkname
;;;  \end{chunk}                  ==> 'end nil
;;;  \getchunk{thechunkname}      ==> 'refer thechunkname

(defun ischunk-latex (line)
 "Find chunks delimited by latex syntax"
 (let ((mark (search "chunk" line))      ; is this a line we care about?
       (point 0)
       name 
       (beginstring "\\begin{chunk}{")   ; this is the define marker string
       beginlength
       (endstring "\end{chunk}")         ; this is the end marker string
       (referstring "\getchunk{")        ; this is the refer string
       referlength)
  (setq beginlength (length beginstring))
  (setq referlength (length referstring))
  (when mark
   (cond
    ((setq mark (search beginstring line)) ; recognize define
      (setq point (position #\} line :start (+ mark beginlength)))
      (cond
       ((null point) (values nil nil))
       ((= point 0)  (values nil nil))
       (t
         (setq name (subseq line (+ mark beginlength) point)) 
         ;(print (list 'ischunk-latex 'define name))
         (values 'define name))))
    ((setq mark (search endstring line))     ; recognize end
       ;(print (list 'ischunk-latex 'end))
       (values 'end nil))
    ((setq mark (search referstring line))         ; recognize reference
      (setq point (position #\} line :start (+ mark referlength)))
      (cond
       ((null point) (values nil nil))
       ((= point 0)  (values nil nil))
       (t
         (setq name (subseq line (+ mark referlength) point)) 
         ;(print (list 'ischunk-latex 'refer name))
         (values 'refer name))))
    (t (values nil nil))))))
  


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 10 ISCHUNK-NOWEB

;;; ischunk-noweb recognizes chunk names using the noweb convention
;;;
;;; There are 3 cases to recognize:
;;;  <<thechunkname>>=  ==> 'define thechunkname
;;;  @                  ==> 'end nil
;;;  <<thechunkname>>   ==> 'refer thechunkname

(defun ischunk-noweb (line)
 "Find chunks delimited by noweb syntax"
 (let ((len (length line)) (mark (position #\> line)) (point 0))
  (cond
   ((and mark                    ; recognize define
         (> len (+ mark 2))
         (char= #\< (schar line 0))
         (char= #\< (schar line 1))
         (char= #\> (schar line (+ mark 1)))
         (char= #\= (schar line (+ mark 2))))
     ;(print (list 'define (subseq line 0 (+ mark 2))))
     (values 'define (subseq line 0 (+ mark 2))))
   ((and mark                    ; recognize reference
         (> len (+ mark 1))
         (char= #\> (schar line (+ mark 1))))
     (setq point (position #\< line))
     (if
      (and point
           (< point (- mark 2))
           (char= #\< (schar line (+ point 1))))
        (values 'refer (subseq line point (+ mark 2)))
        (values 'noise nil)))
    ((and (> len 0)                ; end chunk
          (char= #\@ (schar line 0)))
      (values 'end nil))
    (t (values nil nil)))))
  

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 11 allchunks
;;; 
;;; allchunks will make a single pass over a book extracting any chunk
;;; that fits the PATTERN from the FROMFILE to the TODIR. The chunk
;;; format is either noweb (if true) or latex (if false).
;;;
;;; allchunks takes 4 arguments,
;;; the PATTERN (a string like ".help>>"
;;; the FROMFILE (a string like "/axiom/books/bookvol5.pamphlet")
;;; the TODIR (a string like "/axiom/mnt/ubuntu/doc/spadhelp")
;;; and a boolean NOWEB? (true is noweb format chunks, false is latex style)
;;;
;;; a chunk name is expected to be of the form:
;;; <<FROMFILE.PATTERN>>=
;;; which means that a chunk matching the pattern (e.g. ".input>>") 
;;; will be extracted to the file TODIR/FROMFILE.PATTERN
;;; 
;;; This is used for <<foo.help>> and <<foo.input>> file extraction.
;;; allchunks is used to extract help files and input files in a single
;;; pass over the books. Since there are hundreds of input files and
;;; help files this is a significant speedup.

(defun allchunks (pattern fromfile todir noweb?)
  (setq *chunkhash* (make-hash-table :test #'equal))
  (when *chunknoise* (format t "PASS 1~%"))
  (gcl-hashchunks (gcl-read-file fromfile) noweb?)
  (when *chunknoise* (format t "PASS 2~%"))
  (maphash #'(lambda (key value)
              (if (search pattern key)
               (let ((filename key) helpfile)
                (when noweb? (setq filename (subseq key 2 (- (length key) 2))))
                (setq helpfile (concatenate 'string todir "/" filename))
                (with-open-file (out helpfile :direction :output)
                 (format t "extracting ~a~%" helpfile)
                 (gcl-expand key noweb? out)))))
       *chunkhash*))







