aboutsummaryrefslogtreecommitdiff
path: root/src/input/is.input.pamphlet
blob: 4f451c22af8a5e11b8129a0ed22225e7c6c7acba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
\documentclass{article}
\usepackage{axiom}
\begin{document}
\title{\$SPAD/src/input is.input}
\author{The Axiom Team}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{License}
<<license>>=
--Copyright The Numerical Algorithms Group Limited 1991.
@
<<*>>=
<<license>>

--  This is the 3n + 1 function:   f(n) = n/2    if n is even,
--                                        3n + 1 otherwise
--
-- It can obviously be coded as
--  f n ==
--    even? n => n quo 2
--    3 * n + 1

-- but we code using the pattern matching syntax:
-- f n ==
--    n is 2*m% => m%
--    3 * n + 1

-- The 'integer' is to return an integer instead of a polynomial
f n ==
   not empty?(u := Is(n, 2*m%)) => integer eval(m%, u)
   3 * n + 1

)set stream showall on

-- The function g generates the stream of the repeated applications of f
g(n:INT):STREAM(INT) == generate(f, n)

-- There is a conjecture that g(n) gets into the cycle (1 4 2)
-- for every n
s := g 27
extend(s, 150)
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}