btscan2.boot query (is there a possible error in the code)

13 views
Skip to first unread message

Hill Strong

unread,
Sep 26, 2021, 3:06:43 PM9/26/21
to FriCAS - computer algebra system

When looking at the function dqAppend found in the btscan2.boot file (given below)

dqAppend(x,y)==
    if null x
    then y
    else if null y
         then x
         else
              RPLACD (CDR x,CAR y)
              RPLACD (x,    CDR y)
              x
what is the purpose of the line

RPLACD(CDR x,CAR y)

This appears to be entirely superfluous to the function. Is this correct? I have tried  these two lines in the interface on https://rextester.com/l/common_lisp_online_compiler with the following code

(setq l1 (list 'a 'b 'c 'd 'e))
(print l1)
(setq l2 (list 'k 'l 'm 'n 'o))
(print l2)
(rplacd (cdr l2) (car l1))
(print l2)
(rplacd l2 (cdr l1))
(print l2)

and I get the results

(A B C D E)
(K L M N O)
(K L . A)
(K B C D E)

Is this the expected results or is something else actually expected?

greetings

Hill Strong

oldk1331

unread,
Oct 11, 2021, 2:23:29 AM10/11/21
to fricas...@googlegroups.com
Hi,

The arguments (x,y) to dqAppend are "double ended queue",
implemented as "head-tail linked list",
note that the car and cdr of x/y have shared cons cell,
for example:

(setq l1 '(a b c d e))
(setq x (cons l1 (last l1)))
(setq l2 '(k l m n o))
(setq y (cons l2 (last l2)))

(rplacd (cdr x) (car y)) ;; connects l2 to the end of l1
(rplacd x (cdr y)) ;; replace the end node of l1 by the end node of l2

;; now x is ((A B C D E K L M N O) O)

- Qian
> --
> You received this message because you are subscribed to the Google
> Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to fricas-devel...@googlegroups.com
> <mailto:fricas-devel...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/fricas-devel/ea73f865-45d0-4ad7-b600-859f9f7db9b7n%40googlegroups.com
> <https://groups.google.com/d/msgid/fricas-devel/ea73f865-45d0-4ad7-b600-859f9f7db9b7n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Hill Strong

unread,
Oct 11, 2021, 5:01:25 AM10/11/21
to FriCAS - computer algebra system
Thank you Qian for the explanation

I must point out though that the documentation for the boot code is seriously lacking then if such data entities are found with no explanation. I have come into this from a non-lisp background (as in it is over thirty years ago that I was doing any lisp programming). I was looking at reimplementing the boot code in another language, which would have been fairly straight forward for the most part, but I think I'll stick with my first plan of just dealing with the Aldor compiler. Unless, you or anyone you know has some sort of documentation on these little quirks of coding?

greetings and regards

Hill Strong

Ralf Hemmecke

unread,
Oct 11, 2021, 5:11:10 AM10/11/21
to fricas...@googlegroups.com
Hi,

> I was looking at reimplementing the boot code in another language,

If BOOT goes away that would be good. We aim rather into the direction
of rewriting it into SPAD than LISP. But it is not a priority.

> I think I'll stick with my first plan of just dealing with the Aldor
> compiler.

Oh. What do you want to do with Aldor? What's your interest in it?

> Unless, you or anyone you know has some sort of
> documentation on these little quirks of coding?

The only things I can offer are linked at the bottom of

http://fricas.github.io/development.html

i.e.

http://fricas.sourceforge.net/doc/boot.notes
http://www.euclideanspace.com/prog/scratchpad/internals/boot/index.htm

Whether that helps is another question.

Ralf

Hill Strong

unread,
Oct 30, 2021, 1:27:18 AM10/30/21
to FriCAS - computer algebra system
Thank you Ralf,

My interest in FriCAS is in the development of a mathematical model for certain physical investigations  that I am interested in. There are certain aspects of current theory that, shall we say, leave me cold. There are a couple of alternative theoretical models that give some, from my perspective, better reconciliation with what we observe in the universe. That is, less strange if I can put it that way. My interest arose in my undergraduate days in the late 70's and I have been on and off investigating the theoretical side of things since then. Owing to the kind of work I have been doing over the last 40 years, I have developed an interest in the various CAS systems available. I also have a deep interest in language design and compiler implementation.

I am trying to see if the underlying virtual machine for FriCAS can be changed to something that is quite different to LISP. This means that I have to understand the current implementations that are available.

The current BOOT code is, for the most part, able to be rewritten in a language called Icon (or its descendant Unicon). However, there are quite specific implementation issues that is used in the BOOT code which relies directly on the LISP model of computing and creates a problem with the Icon model of computation. For starters, Icon and Unicon do not have Booleans anywhere in the language. Booleans have been replaced with Success (provide a value) or Failure (stop the computation).

I'll give a couple of quick examples:

x := 10
y := 20
x := 30

The following will update the value of x if the value being supplied is larger than the current value of x

x >:= 15

The following will fail since the value is smaller than the current value and leave the value of x unchanged.

x >:= 4

If you are testing to see if a value is inside a range, you can do the following

if 5 < x < 100 then { do something } else { do something if it is not }

since if x is larger than 5 then the expression 5 < x will return the value of x which will then be directly used in the rest of the expression. This is basically the mathematicians viewpoint and not the normal programming viewpoint using Booleans.

So, thank you again for giving me the relevant pointers. I will chase those us. My current position is looking at the SPAD code and seeing what can be done to somewhat formalise the syntax for it. The Euclidean Space website has given me some pointers in that direction. But I don't think I have, as yet, followed up the specific URL you have provided.

There is much of the SPAD library files that can be directly translated in Icon. But there is other sections that need an infrastructure that I am currently looking at, which effectively means developing a parser and parse tree and associated database using Icon's (Unicon's) current list, set and table  and record structures. It is something that I am interested in and as I no longer have to work for other people, I can now devote my time into this area.

At any rate, may you and your family be blessed in these interesting times.

regards

Hill Strong

Ralf Hemmecke

unread,
Oct 30, 2021, 6:12:52 AM10/30/21
to fricas...@googlegroups.com
Hi,

> The current BOOT code is, for the most part, able to be rewritten in
> a language called Icon (or its descendant Unicon).

Well, replacing one unfamiliar language by another isn't something we
are currently looking for. Of course, since everything is open-source
and you have time to spare, you can go in any direction you like and see
how far you get. However, although I personally do not like programming
in LISP or BOOT, I see the value (at least of LISP) and replacing it by
a different language or even computing model would take quite a while
and would probably not help much in attracting more people to FriCAS.

> Icon and Unicon do not have Booleans anywhere in the language.
> Booleans have been replaced with Success (provide a value) or Failure
> (stop the computation).

> If you are testing to see if a value is inside a range, you can do
> the following
>
> if 5 < x < 100 then { do something } else { do something if it is
> not }

There is a sister-project to FriCAS (called Aldor) which aims at
replacing the SPAD compiler by a non-lispy implementation. Rather than
extending the SPAD language in many directions it rather reduced it so
that quite a number of things can be done through library code instead
of being language-defined.

See https://github.com/aldorlang/aldor and
http://www.aldor.org/docs/aldorug.pdf .

Here is a little piece of code that I have found in the BasicMath
library (unfortunately not commonly available) that *defines* the
"a < x < b" syntax.

BX ==> Cross(Boolean, X);
+++ `BMOrderSyntaxPackage' provides the functions that enable
+++ expressions like `1 < x < 10' (meaning `1 < x and x < 10')
++ to work correctly.
OrderSyntaxPackage(X: OrderedSetCategory): with {
<: (X, X) -> BX;
<=: (X, X) -> BX;

<: (BX, X) -> BX;
<=: (BX, X) -> BX;

<: (BX, X) -> Boolean;
<=: (BX, X) -> Boolean;

} == add {
(x: X) < (y: X): BX == (x < y, y);
(x: X) <= (y: X): BX == (x <= y, y);
(bx: BX) < (y: X): BX == {(b,x):=bx; (b and x < y, y)}
(bx: BX) <= (y: X): BX == {(b,x):=bx; (b and x <= y, y)}
(bx: BX) < (y: X): Boolean == {(b,x):=bx; b and x < y}
(bx: BX) <= (y: X): Boolean == {(b,x):=bx; b and x <= y}
}

With that in the library one can then use

import from OrderSyntaxPackage(Integer);
s: String := if 2 < x <= y <= 10 then "A" else "B"

in order to assign either "A" or "B" to s depending on whether
or not 2 < x <= y <= 10 holds.

I would be much more happy to combine FriCAS with Aldor (and perhaps
replace the Lisp and Boot part by what Aldor provides).

However, also that is not soo easy, since it would mean to replace the
FriCAS code that deals with an interactive session by a completely new
system based on Aldor. Certainly doable, but obviously very
time-consuming. And whether the result is something that is better than
the current system based on LISP is yet to be proved.

> There is much of the SPAD library files that can be directly
> translated in Icon.

That is certainly not a goal. SPAD and even more Aldor (see Aldor User
Guide) are lanugages that are developed with a mathematical/symbolic
mindset.

All the best
Ralf

Hill Strong

unread,
Oct 31, 2021, 8:55:47 AM10/31/21
to FriCAS - computer algebra system
Good evening Ralf,

Thank you for your feedback and comments. I will give what you say some consideration as to whether or not the work I am doing will be useful to FriCAS itself. I may be the only one interested in what I am doing. However, when finished I will make it available for others to look at and use if they want.

regards and blessings to you and your family

Hill Strong
Reply all
Reply to author
Forward
0 new messages