scmutils for Ubuntu 24.04

Scheme Mechanics Installation for GNU/Linux | scmutils, 4

.

1. Folks, the scmutils library is fantastic and it’s available in Ubuntu 24.04. You can install it very easily with this command:

sudo apt-get install scmutils

2. Then, you just run it with this command:

mit-scheme --band mechanics.com

.

Now, let me tell you, there’s no syntax highlighting. Not great! And more importantly, there’s no direct way to save your code. So, what do you do? You use the Emacs editor. It’s the best!

Now, this assumes you know Emacs. If you don’t, it’s a tremendous editor.

3. Open Emacs’ initialization file. It’s located right here:

~/.emacs

4. Add this beautiful code to the file:

(defun mechanics ()
  (interactive)
  (run-scheme
   "mit-scheme --band mechanics.com"))
(setq sicm-file "~/Documents/tt.scm")

(fset 'set-working-file
      (lambda (&optional arg) 
        (interactive "p")
        (funcall (lambda ()
                   (insert
                    (concat "(define sicm-file \""
                            sicm-file
                            "\")\n"))))))

(fset 'load-scm
      (lambda (&optional arg) 
        (interactive "p")
        (funcall (lambda ()
                   (insert "(load sicm-file)")))))

(defun mechan ()
  (interactive)
  (split-window-below)
  (windmove-down)
  (mechanics)
  (set-working-file)
  (comint-send-input)
  (windmove-up)
  (find-file sicm-file)
  (end-of-buffer)
  (windmove-down)
  (cond ((file-exists-p sicm-file)
         (interactive)
         (load-scm)
         (comint-send-input)))
  (windmove-up))

(defun sicm-exec-line ()
  (interactive)
  (save-buffer)
  (windmove-down)
  (comint-send-input)
  (windmove-up))

(defun sicm-exec-file ()
  (interactive)
  (save-buffer)
  (windmove-down)
  (load-scm)
  (comint-send-input)
  (windmove-up))

(global-set-key (kbd "C-x C-e") 'sicm-exec-line)

(global-set-key (kbd "C-x C-a") 'sicm-exec-file)

5. Close Emacs and then re-open it, folks.

6. Type the command

M-x mechan

Now, listen, when I say M-x, I mean you press the Alt key and x together. Then, just type mechan. It’s easy, believe me!

7. You’ll see the Emacs editor split into two windows, one on top and one on the bottom.

The lower window is the Scheme environment. You can type a line of code and then press Enter to execute it. So simple!

The upper window is the editor. Type multiple lines of code and then hit

C-x C-e

to execute it.

That means pressing Ctrl and x together, then Ctrl and e together. Easy stuff!

8. When you save the current file, your Scheme code will be saved to this location:

~/Documents/tt.scm

If you need to back up your code, just back up this file. It’s that simple, folks!

— Me@2020-03-10 10:59:45 PM

.

.

2024.12.01 Sunday (c) All rights reserved by ACHK

1.9 Abstraction of Path Functions, 2

Structure and Interpretation of Classical Mechanics

.

Let \displaystyle{\bar \Gamma} be a function such that

\displaystyle{\begin{aligned}  f &= \bar \Gamma (\bar f) \\  \end{aligned}}

So, to get a value of \displaystyle{\begin{aligned} f \end{aligned}}, we input a local tuple:

\displaystyle{\begin{aligned}  f (t, q(t), v(t), \cdots, q^{(n)}(t))   &= f (t, q, v, \cdots, q^{(n)})(t) \\   &= f(\Gamma[q])(t) \\   &= f \circ \Gamma[q](t) \\   &= \bar f [q](t) \\   \bar \Gamma (\bar f) (t, q(t), v(t), \cdots, q^{(n)}(t))   &= \bar f [q](t) \\   \end{aligned}}

(define ((Gamma-bar f-bar) path-q-local-tuple)
  (let* ((tqva path-q-local-tuple)
         (t (time tqva))         
         (O-tqva (osculating-path tqva)))   
    ((f-bar O-tqva) t)))

.

The procedure osculating-path takes a number of local components and returns a path with these components; it is implemented as a power series.

In scmutils, you can use the pp function to get the definition of a function. For example, the code

(pp osculating-path)

results

(define ((osculating-path state0) t)
  (let ((t0 (time state0))
        (q0 (coordinate state0))
        (k (vector-length state0)))
    (let ((dt (- t t0)))
      (let loop ((n 2) (sum q0) (dt^n/n! dt))
        (if (fix:= n k)
            sum
            (loop (+ n 1)
                  (+ sum
                     (* (vector-ref state0 n)
                        dt^n/n!))
                  (/ (* dt^n/n! dt) n)))))))

\displaystyle{\begin{aligned}   q(t) &= q_0 + v_0 (t-t_0) + \frac{1}{2} a_0 (t-t_0)^2 + ... +\frac{1}{n!} q^{(n)}_0 (t-t_0)^n \\   &= q_0 + v_0 (dt) + \frac{1}{2} a_0 (dt)^2 + ... +\frac{1}{n!} q^{(n)}_0 (dt)^n \\  \end{aligned}}

.

Note that for the function in the program, \displaystyle{\bar \Gamma (\bar f)}, the input is actually not \displaystyle{(t, q, v, \cdots, q^{(n)})} but \displaystyle{(t, q(t), v(t), \cdots, q^{(n)}(t))}.

\displaystyle{\begin{aligned}  \bar \Gamma (\bar f) (t, q(t), v(t), \cdots) &= \bar f[O(t, q, v, \cdots)](t) \\   \end{aligned}}

.

(define (F->C F)
  (define (f-bar q-prime)
    (define q
      (compose F (Gamma q-prime)))
    (Gamma q))
  (Gamma-bar f-bar))

(show-expression 
 ((F->C p->r)
  (->local 't
           (up 'r 'theta)
           (up 'rdot 'thetadot))))

— Me@2023-12-19 08:16:40 PM

.

.

2024.06.15 Saturday (c) All rights reserved by ACHK

1.9 Abstraction of Path Functions

Structure and Interpretation of Classical Mechanics

.

Given a function \displaystyle{f} of a local tuple, a corresponding path-dependent function \displaystyle{\bar f[q]} is

\displaystyle{\bar f[q] = f \circ \Gamma[q]}.

So while the input of \displaystyle{f} is a tuple \displaystyle{(t, q, v, \cdots)}, the input of \displaystyle{\bar f} is an abstract path \displaystyle{q}.

\displaystyle{\begin{aligned}  \Gamma [q] &= (t, q, v, \cdots) \\   \bar f &= f \circ \Gamma \\  \end{aligned}}

.

Given \displaystyle{\bar f} we can reconstitute \displaystyle{f} by taking the argument of \displaystyle{f}, which is a finite initial segment of a local tuple, constructing a path that has this local description, and finding the value of \displaystyle{\bar f} for this path.

1. The goal is to use \displaystyle{\bar f} to reconstitute \displaystyle{f}.

2. The argument of \displaystyle{f} is

\displaystyle{\begin{aligned}  \Gamma [q] &= (t, q, v, \cdots, q^{(n)}) \\   &= (t, q^{(0)}, q^{(1)}, \cdots, q^{(n)}) \\   \end{aligned}}

3. Assume that we have the value of the initial position of the path, \displaystyle{q_0 = q(t=0)}. Then the path \displaystyle{q(t)} can be constructed by

\displaystyle{q(t) = q_0 + v_0 t + \frac{1}{2} a_0 t^2 + ... +\frac{1}{n!} q^{(n)}_0 t^n}

Note that while \displaystyle{q} represents a path, \displaystyle{q(t)} represents the coordinates of the particle location on the path at time \displaystyle{t}.

Knowing the value of \displaystyle{q(t)} for every moment \displaystyle{t} is equivalent to knowing the path \displaystyle{q} as a whole.

— Me@2023-12-19 08:16:40 PM

.

.

2024.01.29 Monday (c) All rights reserved by ACHK

Taylor expansion of f around x

Series can also be formed by processes such as exponentiation of an
operator or a square matrix. For example, if f is any function of one
argument, and if x and dx are numerical expressions, then this
expression denotes the Taylor expansion of f around x.

(((exp (* dx D)) f) x)
= (+ (f x) (* dx ((D f) x)) (* 1/2 (expt dx 2) (((expt D 2) f) x)) ...)

— refman

.

(((exp (* 'dx D)) (literal-function 'f)) 'x)
#| (*series* (0 . 0) (*number* (expression (f x)) (literal-function #[apply-hook 40]) (type-expression Real)) . #[promise 41 (unevaluated)]) |#

(show-expression
 (series:print (((exp (* 'dx D))
                 (literal-function 'f)) 'x)))
(f x)
(* dx ((D f) x))
(* 1/2 (expt dx 2) (((expt D 2) f) x))
(* 1/6 (expt dx 3) (((expt D 3) f) x))
(* 1/24 (expt dx 4) (((expt D 4) f) x))
(* 1/120 (expt dx 5) (((expt D 5) f) x))
(* 1/720 (expt dx 6) (((expt D 6) f) x))
(* 1/5040 (expt dx 7) (((expt D 7) f) x))
(* 1/40320 (expt dx 8) (((expt D 8) f) x))
(* 1/362880 (expt dx 9) (((expt D 9) f) x))
(* 1/3628800 (expt dx 10) (((expt D 10) f) x))
(* 1/39916800 (expt dx 11) (((expt D 11) f) x))
(* 1/479001600 (expt dx 12) (((expt D 12) f) x))
(* 1/6227020800 (expt dx 13) (((expt D 13) f) x))
(* 1/87178291200 (expt dx 14) (((expt D 14) f) x))
;Aborting!: maximum recursion depth exceeded

— Me@2023-12-20 11:30:50 AM

.

.

2023.12.20 Wednesday (c) All rights reserved by ACHK

scmutils, 3

Structure and Interpretation of Classical Mechanics

Scheme Mechanics Installation for GNU/Linux

.

This post assumes that you have already installed the scmutils library and been able to open it using the standard editor Emacs.

If not, go to the bottom of this post to click the category scmutils, so that you can see all the posts in this scmutils series.

d_2020_02_22__16_02_00_PM_

Then go to the post “scmutils, 2.3.2” to follow the installation and setup instructions.

.

After installing and setting up the scmutils library, you can start to use it.

d_2020_02_22__18_12_54_PM_

However, what if you want to close the Emacs editor? How to save your scheme program before closing Emacs?

By default, you cannot. So I have written a small program to help. Here is the installation instruction:

1. Go to the end of the .emacs file. Add the following code, if it does not already exist:


(defun mechanics()
  (interactive)
  (run-scheme
   "/usr/local/scmutils/mit-scheme/bin/scheme --library
/usr/local/scmutils/mit-scheme/lib"
  ))

2. Add the following code:


(fset 'set-working-dir
      (lambda (&optional arg) "Keyboard macro."
	(interactive "p")
	(kmacro-exec-ring-item
	 (quote ("(set-working-directory-pathname! 
                  \"~/Documents/\")\n" 0 "%d")) arg)))
 
(fset 'load-scm
      (lambda (&optional arg) "Keyboard macro."
	(interactive "p")
	(kmacro-exec-ring-item
	 (quote ("(load \"tt.scm\")" 0 "%d")) arg)))
 
(defun mechan ()
  (interactive)
  (split-window-below)
  (windmove-down)
  (mechanics)
  (set-working-dir)
  (comint-send-input)
  (windmove-up)			
  (find-file "~/Documents/tt.scm")
  (end-of-buffer)
  (windmove-down)
  (cond ((file-exists-p "~/Documents/tt.scm")
	 (interactive)
	 (load-scm)
	 (comint-send-input)))
  (windmove-up)
)
 
(defun cxce ()
  (interactive)
  (save-buffer)
  (windmove-down)
  (load-scm)
  (comint-send-input)
  (windmove-up)
)
 
(global-set-key (kbd "C-x C-e") 'cxce)

3. Close Emacs. Re-open it.

4. Type the command

M-x mechan

The command M-x means pressing the Alt key and x together. Then type the word mechan.

5. You will see the Emacs editor is split into two windows, one up and one down.

The lower window is the scheme environment. You can type a line of code and the press Enter to execute it.

The upper window is the editor. You can type multiple lines of code and the type

C-x C-e

to execute it. The command C-x C-e means pressing Ctrl and x together and then Ctrl and e.

d_2020_03_11__20_28_27_PM_

6. Your scheme code is saved to the following file

"~/Documents/tt.scm"

In case you need to backup your code, backup this file.

— Me@2020-03-10 10:59:45 PM

.

.

2020.03.10 Tuesday (c) All rights reserved by ACHK

scmutils, 2.3.2

Scheme Mechanics Installation for GNU/Linux

.

Steps:

1. The following steps are tested in Ubuntu 18.04. Prepare Ubuntu 18.04 if you can.

Note: Since the installation of the library scmutils requires the root access of your Linux system, please do NOT use it on your working computer. Instead, create an isolated virtual machine to use it.

.

2. Go to the bottom of this post to click the category scmutils, so that you can see all the posts in this scmutils series.

d_2020_02_22__16_02_00_PM_

3. Go to the post titled “scmutils, 2.3” to download

scmutils-20160827-x86-64-gnu-linux

4. Although the official installation guide advises you to install “MIT/GNU Scheme system” before installing scmutils, you do NOT need to install “MIT/GNU Scheme system” at all.

5. Unzip the file scmutils-20160827-x86-64-gnu-linux.

In the following, if you need to copy any commands or programming codes, remember that any number on the left of the vertical green line is NOT part of the code.

6. Run the command

tar xzf scmutils-20160827-x86-64-gnu-linux.tar.gz

to further extract the file.

-x — extract files from an archive;
-f — specify the archive’s name;
-v — show a list of processed files.

— Wikipedia on tar (computing)

Then two folders will be created: bin and scmutils.

7. Run the command

cd bin

to go into the folder.

You will see a file called mechanics.

.

8.1 Run the command

mechanics

You will get the error

mechanics: command not found

8.2 Instead, you should run the command

./mechanics

to specify that the file mechanics is actually in the current folder.

You will get the error

./mechanics: line 16: exec: xterm: not found

It is because your Linux system has not the program xterm yet.

8.3 Run the following command to install it.

sudo apt-get install xterm

8.4 Run the command again:

./mechanics

There will be an xterm window popup, but with an error message inside:

d_2020_02_22__17_08_35_PM_

That means you should move the two folders, bin and scmutils, to the pre-defined locations.

.

9.1 Run the command to move the folder scmutils to its pre-defined location:

mv scmutils /usr/local/

You will get the error

mv: cannot move 'scmutils' to '/usr/local/scmutils': 
Permission denied

9.2 Try again by

sudo mv scmutils /usr/local/

.

10.1 Go inside the folder bin.

10.2 Move its content to the pre-defined location by this command:

sudo mv mechanics /usr/local/bin/

.

11. Run the command

mechanics

Then you will see the Edwin window is opened. That means, in theory, you system has successfully installed the scmutils library. You can use it within the Edwin window if you like.

However, in practice, it is difficult, because it provides no syntax-highlighting. Also, you cannot use mouse in the Edwin window, so if you want to copy and paste a command or a series of commands, there will be no obvious way to achieve that.

So I suggest you to use the standard Emacs as the editor instead.

.

12.1 If you do not know Emacs, learn its basics.

12.2 Also, learn how to open Emacs’ initialization file, which has the filename

.emacs

After opening the file, you will see that it is just a text file.

12.3 Go to the end of the .emacs file. Add the following code:

(defun mechanics()
  (interactive)
  (run-scheme
     "/usr/local/scmutils/mit-scheme/bin/scheme --library
     /usr/local/scmutils/mit-scheme/lib"))

12.4 Save the file. Close Emacs. Then re-open Emacs.

12.5 Within Emacs, type the command

M-x mechanics

M-x means that while the Alt key is pressed down, press also x. Then type the word mechanics.

d_2020_02_22__18_12_12_PM_

12.6 Type the command

(+ 1 1)

to test the system.

d_2020_02_22__18_12_54_PM_

13. If you want to access your last command without re-typing it, type the command

M-p

d_2020_02_22__18_19_31_PM_

— Me@2020-02-22 06:25:47 PM

.

.

2020.02.22 Saturday (c) All rights reserved by ACHK

scmutils, 2.3

Within the MIT Scheme environment, it is not the original command line (bash) anymore. I can neither repeat the last command by just pressing the up key once, nor select the last command by mouse in order to copy it.

So I think I have to use an older version of scmutils.

However, this method is not easy to implement, because the author’s website does not provide an older version. Luckily, I have found an old version in my computer. You can download it here:

scmutils-20160827-x86-64-gnu-linux

Note: Since the installation of the library scmutils requires the root access of your Linux system, please do NOT use it on your working computer. Instead, create an isolated virtual machine to use it.

— Me@2020-02-09 10:27:32 PM

.

.

2020.02.09 Sunday (c) All rights reserved by ACHK

scmutils, 2.2

Either use an older version of scmutils in order to follow the previous instructions for setting up Emacs for scmutils, or give up using Emacs for scmutils for the time being.

Using command line is the best way to go, so far.

The “using command line” method does not really work.

d_2020_01_27__16_12_48_PM_

Within the MIT Scheme environment, it is not the original command line (bash) anymore. I can neither repeat the last command by just pressing the up key once, nor select the last command by mouse in order to copy it.

So I think I have to use an older version of scmutils.

— Me@2020-01-26 07:38:31 PM

.

.

2020.01.26 Sunday (c) All rights reserved by ACHK

scmutils, 2

The original method of setting up Emacs for scmutils does not work anymore if you uses the newest (August 2019) version of scmutils, because its installation directories are not the same as those in the previous version.

Either use an older version of scmutils in order to follow the previous instructions for setting up Emacs for scmutils, or give up using Emacs for scmutils for the time being.

Using command line is the best way to go, so far.

Do not use the Edwin editor, since you cannot easily run, edit, or copy existing lines of code, unless you are familiar with it. I do not like it anyway, because after all, it does not provide syntax highlighting.

— Me@2019-12-28 07:50:32 PM

.

.

2019.12.28 Saturday (c) All rights reserved by ACHK

Literal numbers

All primitive mathematical procedures are extended to be generic over
symbolic arguments. When given symbolic arguments, these procedures
construct a symbolic representation of the required answer. There are
primitive literal numbers. We can make a literal number that is
represented as an expression by the symbol “a” as follows:

(literal-number 'a)        ==>  (*number* (expression a))

The literal number is an object that has the type of a number, but its
representation as an expression is the symbol “a”.

(type (literal-number 'a))          ==>  *number*

(expression (literal-number 'a))    ==>  a

— SCMUTILS Reference Manual

.

.

2019.08.17 Saturday ACHK

scmutils

In order to run the SICM code, you need to install the scmutils library. Just go to the official page to download the library and follow the official instructions to install it in a Linux operating system.

When you try to run it, your system may give the following error message:

/usr/local/bin/mechanics: line 16: exec: xterm: not found

If so, you should install the program xterm first.

.

Also, in case you like to use Emacs as editor, you can:

Just include the following in your .emacs file:

(defun mechanics ()
  (interactive)
  (run-scheme
    "ROOT/mit-scheme/bin/scheme --library ROOT/mit-scheme/lib"
  ))

Replace ROOT with the directory in which you installed the scmutils software. (Remember to replace it in both places. If it is installed differently on your system, just make sure the string has the form “/path/to/mit-scheme --library /path/to/scmutils-library“.) Restart emacs (or use C-x C-e to evaluate the mechanics defun), and launch the environment with the command M-x mechanics.

— Using GNU Emacs With SCMUtils

— Aaron Maxwell

.

In my Ubuntu 18.04, the paths are:

(defun mechanics()
  (interactive)
  (run-scheme
   "/usr/local/scmutils/mit-scheme/bin/scheme --library 
/usr/local/scmutils/mit-scheme/lib"
  ))

— Me@2019-04-07 02:52:50 PM

.

.

2019.04.07 Sunday (c) All rights reserved by ACHK