From 633f8a77090ed39773ff546560a8949824f0a356 Mon Sep 17 00:00:00 2001 From: Chenbo Li Date: Sun, 21 Sep 2025 10:48:12 -0700 Subject: [PATCH] Replace chapter 3 demos with official NKS versions --- demos/chapter3/chapter3-interactive.html | 559 ------- demos/chapter3/chapter3-lab.html | 483 ------ demos/chapter3/chapter3-reader.html | 348 ----- .../chapter3-universality-gallery.html | 435 ------ demos/chapter3/index.html | 392 ++--- demos/chapter3/mobile-automata-demo.html | 1343 ++++------------ demos/chapter3/register-machine-demo.html | 1169 ++++---------- .../sequential-substitution-demo.html | 1383 +++-------------- demos/chapter3/substitution-system-demo.html | 1064 +++---------- demos/chapter3/tag-system-demo.html | 1156 +++----------- demos/chapter3/tag-system-nks-demo.html | 554 ------- .../three-color-ca-demo-standalone.html | 429 ----- demos/chapter3/three-color-ca-demo.html | 894 +++++------ demos/chapter3/turing-machine-demo.html | 1256 ++++----------- 14 files changed, 2111 insertions(+), 9354 deletions(-) delete mode 100644 demos/chapter3/chapter3-interactive.html delete mode 100644 demos/chapter3/chapter3-lab.html delete mode 100644 demos/chapter3/chapter3-reader.html delete mode 100644 demos/chapter3/chapter3-universality-gallery.html delete mode 100644 demos/chapter3/tag-system-nks-demo.html delete mode 100644 demos/chapter3/three-color-ca-demo-standalone.html diff --git a/demos/chapter3/chapter3-interactive.html b/demos/chapter3/chapter3-interactive.html deleted file mode 100644 index 8646c74..0000000 --- a/demos/chapter3/chapter3-interactive.html +++ /dev/null @@ -1,559 +0,0 @@ - - - - - - - The World of Simple Programs: An Interactive Exploration - - - - - - - - - - - - - - -
-
-

The World of Simple Programs

-

This chapter from Stephen Wolfram's "A New Kind of Science" explores a - fundamental question: what do simple programs typically do? By examining various computational systems, - from cellular automata to Turing machines, it reveals a surprising and universal phenomenon: even - programs with extremely simple rules can produce behavior of immense complexity. This interactive - application allows you to explore these systems and discover the core principles for yourself.

-
- -
-

Exploring Cellular Automata

-

Cellular automata are the first and one of the most compelling - examples in the book. They consist of a line of cells, each with a color, that evolves in discrete steps - according to a simple rule based on the colors of its neighbors. Below, you can explore the behavior of - the 256 "elementary" cellular automata, which use two colors and consider the cell itself and its - immediate left and right neighbors.

- -
- -
- - Rule 30 - -
- -
- -
- -
- -
-
-

Classification of Behavior

-

Despite the vast number of rules, the behaviors they produce can be - grouped into four main classes: simple repetition, nesting (fractal patterns), randomness, and - complex localized structures. This chart shows the approximate distribution of these behaviors - among the 88 unique elementary rules.

-
- -
-
-
-

Key Examples

-
-
-

Rule 250 (Repetition)

- -
-
-

Rule 90 (Nesting)

- -
-
-

Rule 30 (Randomness)

- -
-
-

Rule 110 (Complexity)

- -
-
-
-
-
- -
-

Universality across Different Systems

-

A key discovery is that the phenomenon of complexity is not unique to - cellular automata. The same classes of behavior appear in a vast range of other simple programs, - demonstrating a principle of universality. This section provides a glimpse into some of these other - systems, showing how different underlying structures can lead to remarkably similar outcomes.

- -
-
- -
- -
-
-

Mobile Automata

-

Instead of updating all cells at once, a mobile automaton has a - single "active cell" that moves and updates its color based on its neighbors. While complex - behavior is rarer than in cellular automata, it still emerges, often requiring slightly more - complex rules.

-
- -
-

An example of a mobile automaton exhibiting - complex, seemingly random behavior.

-
- -
- -
- - -
-
-
- -
-

Core Discoveries and Principles

-

The exploration of these diverse systems leads to several profound - conclusions about the nature of computation and complexity. These principles form the foundation of "A - New Kind of Science".

-
- -
- -
-
-
- 🌌
-
-

Universality of Complexity

-

Complex behavior is not a rare or special phenomenon. It is a universal - feature of computation, appearing across a vast range of systems with different underlying - structures.

-
-
-
-
- ⚖️
-
-

Low Threshold for Complexity

-

Extremely simple rules are sufficient to produce the most complex - behavior. There is a surprisingly low threshold in rule complexity that, once crossed, - unlocks the full potential for complexity.

-
-
-
-
- 📈
-
-

Complexity Doesn't Imply Complex Rules

-

Making the underlying rules more complex does not necessarily lead to - more complex overall behavior. The essential ingredients for complexity are already present - in very simple systems.

-
-
-
-
-
- - - - - \ No newline at end of file diff --git a/demos/chapter3/chapter3-lab.html b/demos/chapter3/chapter3-lab.html deleted file mode 100644 index 6780fb5..0000000 --- a/demos/chapter3/chapter3-lab.html +++ /dev/null @@ -1,483 +0,0 @@ - - - - - - - A Deeper Dive into Simple Programs - - - - - - - - - - - - -
-
- - -
-
-

A Deeper Dive into Simple Programs

-

This interactive exhibit expands on the core thesis of Chapter - 3: that the universe of simple programs is filled with immense complexity, and this complexity - arises from universal principles that are independent of the specific mechanics of the programs - themselves. Here, you can directly experiment with the systems discussed and observe these - principles in action.

-
- -
-

Lab 1: Cellular Automata

-

Cellular Automata update all their cells in parallel at each step. - This lab allows you to explore the emergent behavior of different elementary rules and initial - conditions. Observe how tiny changes in the rule can lead to fundamentally different outcomes, - from perfect order to complete chaos.

- -
-
-
- - -
-
- - -
-
- -
-
-
- -
-
-
-
- -
-

Lab 2: Head-Based Systems

-

Unlike Cellular Automata, Mobile Automata and Turing Machines update - only a single "active cell" or "head" at each step. This sequential nature makes complex - behavior rarer, but still possible. This lab visualizes both the full evolution and the - "compressed" history, which only shows steps where the head reaches a new position, revealing - the underlying structure of the computation.

- -
-
- - -
-
-
-

Full Evolution (First 500 steps)

-
- -
-
-
-

Compressed Evolution (First 500 new positions)

-
- -
-
-
-
-
-
- -
-

Lab 3: Growth & Substitution

-

Systems like Substitution and Tag systems can change the number of - elements they contain at each step. Their complexity is often revealed in their growth patterns. - Explore how different rules lead to predictable exponential growth, nested fluctuations, or - chaotic changes in size.

- -
-

Comparing Growth Signatures

-
- - - -
-
- -
-

-
-
- -
-

The Principle of Universality

-

The overarching discovery is that the fundamental types of behavior - are universal. The details of the underlying rules change, but the emergent - phenomena—repetition, nesting, randomness, and localized structures—remain the same. Click on a - concept below to highlight the relevant interactive examples on this page.

- -
-
-

Repetition

-

Systems that settle into simple, stable, or periodic - patterns.

-
-
-

Nesting

-

Behavior that produces intricate but regular fractal - patterns.

-
-
-

Randomness

-

Chaotic and unpredictable behavior emerging from - deterministic rules.

-
-
-

Complexity

-

A mix of order and randomness, with localized - structures that interact.

-
-
-
-
-
-
- - - - \ No newline at end of file diff --git a/demos/chapter3/chapter3-reader.html b/demos/chapter3/chapter3-reader.html deleted file mode 100644 index 04e6b2c..0000000 --- a/demos/chapter3/chapter3-reader.html +++ /dev/null @@ -1,348 +0,0 @@ - - - - - - - The World of Simple Programs: An Interactive Reader - - - - - - - - - - - - -
-

The World of Simple Programs

-

An interactive exploration of Stephen Wolfram's "A New Kind of Science," - Chapter 3.

-
- -
-
-
-

The Search for General Features

- -
-
-

At the beginning of the last chapter we asked the basic question of what simple programs - typically do. And as a first step towards answering this question we looked at several specific - examples of a class of programs known as cellular automata. The basic types of behavior that we - found are illustrated in the pictures on the next page. In the first of these there is pure - repetition, and a very simple pattern is formed. In the second, there are many intricate details, - but at an overall level there is still a very regular nested structure that emerges.

-

In the third picture, however, one no longer sees such regularity, and instead there is - behavior that seems in many respects random. And finally in the fourth picture there is what appears - to be still more complex behavior—with elaborate localized structures being generated that interact - in complex ways.

-

At the outset there was no indication that simple programs could ever produce behavior - so diverse and often complex. But having now seen these examples, the question becomes how typical - they are. Is it only cellular automata with very specific underlying rules that produce such - behavior? Or is it in fact common in all sorts of simple programs?

-

My purpose in this chapter is to answer this question by looking at a wide range of - different kinds of programs. And in a sense my approach is to work like a naturalist—exploring and - studying the various forms that exist in the world of simple programs.

-

I start by considering more general cellular automata, and then I go on to consider a - whole sequence of other kinds of programs—with underlying structures further and further away from - the array of black and white cells in the cellular automata of the previous chapter.

-

And what I discover is that whatever kind of underlying rules one uses, the behavior - that emerges turns out to be remarkably similar to the basic examples that we have already seen in - cellular automata. Throughout the world of simple programs, it seems, there is great universality in - the types of overall behavior that can be produced. And in a sense it is ultimately this that makes - it possible for me to construct the coherent new kind of science that I describe in this book—and to - use it to elucidate a large number of phenomena, independent of the particular details of the - systems in which they occur.

-
-
- -
-
-

More Cellular Automata

- -
-
-

The core of the chapter is the discovery that simple rules can lead to immense - complexity. This interactive demo allows you to explore the behavior of any of the 256 "elementary" - cellular automaton rules. See for yourself how a tiny change in the rule can shift behavior from - simple repetition to apparent randomness.

-
- -
- - Rule - 30 -
-
- -
-
-

Repetition and nesting are widespread themes in many cellular automata. But as we saw in - the previous chapter, it is also possible for cellular automata to produce patterns that seem in - many respects random. And out of the 256 rules discussed here, it turns out that 10 yield such - apparent randomness. There are three basic forms, as illustrated on the facing page.

-

Beyond randomness, the last example in the previous chapter was rule 110: a cellular - automaton whose behavior becomes partitioned into a complex mixture of regular and irregular parts. - This particular cellular automaton is essentially unique among the 256 rules considered here: of the - four cases in which such behavior is seen, all are equivalent if one just interchanges the roles of - left and right or black and white.

-
-
- -
-
-

Universality in Other Systems

- -
-
-

The central discovery of this chapter is that the phenomenon of complexity is not unique - to cellular automata. It emerges in a vast range of other simple programs, from mobile automata to - Turing machines. Below you can see demonstrations of these systems, which despite having entirely - different structures, can exhibit similar complex behaviors.

-
-
-

Mobile Automata

-

Instead of updating all cells in parallel, a mobile - automaton has a single "active cell." The rule specifies its movement and color change. This - is a crucial test of whether parallel updates are necessary for complexity.

-
- -
-

A complex pattern generated by a mobile - automaton.

- -
-
-

Turing Machines

-

The first widely understood theoretical computer program. - It has a "head" that moves along a "tape" of cells. Even with only two states and two - colors, complex behavior emerges.

-
- -
-

A 4-state, 2-color Turing machine producing a - complex pattern.

- -
-
-

Substitution Systems

-

Unlike the fixed-array systems, these allow the number of - elements to change. An element is replaced by a block of new elements. Neighbor-dependent - rules can lead to chaotic, random-like patterns.

-
- -
-

A substitution system generating a seemingly - random pattern.

- -
-
-
-
- -
-
-

Some Conclusions

- -
-
-

The exploration of these diverse systems leads to several profound conclusions. The - phenomenon of complexity is quite universal and independent of the specific details of a system. The - threshold for complexity is surprisingly low—even very simple rules can produce behavior of great - complexity. And finally, adding more complexity to the rules does not necessarily yield more complex - behavior.

-

This universality is what makes it possible to construct a coherent new kind of science, - implying that general principles can govern the behavior of a wide range of systems, independent of - their precise details.

-
-
-
- - - - - \ No newline at end of file diff --git a/demos/chapter3/chapter3-universality-gallery.html b/demos/chapter3/chapter3-universality-gallery.html deleted file mode 100644 index 074f838..0000000 --- a/demos/chapter3/chapter3-universality-gallery.html +++ /dev/null @@ -1,435 +0,0 @@ - - - - - - - Behavior Atlas · Chapter 3 | A New Kind of Science - - - - - -
- - ← Back to Chapter 3 demos - - -
-

- Behavior Atlas · Universal Patterns in Simple Programs -

-

- Chapter 3 of A New Kind of Science reveals that simple rules across many models of computation fall into - the same four behavioral classes. This gallery lets you switch among those classes and immediately compare how - a cellular automaton, a head-based system, and a tag system express the very same theme. -

-
- -
- - - - -
- -

- -
-
-
-

Cellular Automaton

- parallel update -
- -

-
- -
-
-

Turing Machine

- single head -
- -

-
- -
-
-

Tag System

- growth dynamics -
- -
-

-
-
- -
-

How to read this gallery

-

- Each canvas shows 120–200 steps of evolution. Rows correspond to successive steps, read from top to bottom. The - cellular automaton colours mark active cells; the Turing machine visualisation tracks tape colours as the head - sweeps; the tag system paints the evolving string after each deletion-and-append cycle. Switching classes makes it - immediately obvious that—despite their very different mechanics—their long-term behaviour falls into the same - categories Wolfram catalogues throughout Chapter 3. -

-
-
- - - - - diff --git a/demos/chapter3/index.html b/demos/chapter3/index.html index f5d263c..fad0c2e 100644 --- a/demos/chapter3/index.html +++ b/demos/chapter3/index.html @@ -1,273 +1,129 @@ - - + - - - 第3章演示合集 | 一种新科学 - + + NKS Chapter 3 Demonstrations + - -
- ← 返回演示总览 - -
-

第3章:简单程序的世界 · 演示合集

-

汇总第三章涉及的系统演示,涵盖多色元胞自动机、移动自动机、替换与标签系统以及章节辅助工具。

-
- -
-

细胞自动机

-
-
-

三色元胞自动机探索器

-

交互式探索三色元胞自动机,观察不同规则下的复杂纹理、嵌套结构与随机行为。

- 立即打开 → -
-
-

三色元胞自动机(独立版)

-

性能优化的独立版本,适合在移动设备或离线环境中体验三色元胞自动机。

- 立即打开 - → -
-
-

移动自动机演示

-

展示移动自动机的局部更新机制,感受并行度变化对复杂性出现频率的影响。

- 立即打开 → -
-
-
- -
-

计算模型

-
-
-

图灵机模拟器

-

交互式图灵机模拟器,支持多状态程序与逐步执行,直观理解复杂行为的阈值。

- 立即打开 → -
-
-

寄存器机演示

-

使用最简指令集模拟 CPU 级寄存器机,体验指令数量达到阈值后出现的复杂行为。

- 立即打开 → -
-
-
- -
-

替换与标签系统

-
-
-

替换系统演示

-

观察近邻独立替换规则带来的嵌套分形,并探索允许创造与毁灭后的随机扩散。

- 立即打开 → -
-
-

顺序替换系统

-

模拟“查找-替换”式的顺序规则,体验字符串在局部修改下如何涌现复杂模式。

- 立即打开 - → -
-
-

标签系统探索器

-

交互探索标签系统的删除与附加规则,直观观察序列演化的规律与不可预测性。

- 立即打开 → -
-
-

NKS 风格标签系统

-

仿照《一种新科学》图示的标签系统演示,配备可视化演化历史与详细步骤记录。

- 立即打开 → -
-
-
- -
-

章节辅助工具

-
-
-

行为全景图

-

通过四类行为并排对比元胞自动机、图灵机与标签系统,直观展示第三章强调的“简单规则共享同样复杂性”这一核心结论。

- 立即打开 → -
-
-

第3章交互式读者

-

伴随章节文本的交互式略读器,整合动画、图像与关键概念的快速复习。

- 立即打开 → -
-
-

第3章实验室

-

整合章节中的多个实验,提供统一的实验室界面,便于集中探索。

- 立即打开 → -
-
-

第3章阅读器

-

章节内容的可视化阅读界面,集中展示要点与配图,适合课堂或演示使用。

- 立即打开 → -
-
-
- - -
+
+
+

Chapter 3 · The World of Simple Programs

+

+ The demonstrations below faithfully reproduce the interactive experiments that accompany chapter 3 of + A New Kind of Science. Each one focuses on a specific model studied in the book—exactly the same + systems, rules and initial conditions that appear in the original NKS online demos. +

+
+ +
- - \ No newline at end of file + diff --git a/demos/chapter3/mobile-automata-demo.html b/demos/chapter3/mobile-automata-demo.html index 03c9e01..433bac0 100644 --- a/demos/chapter3/mobile-automata-demo.html +++ b/demos/chapter3/mobile-automata-demo.html @@ -1,1055 +1,298 @@ - - + - - - 移动自动机探索器 - 交互式移动细胞实验 - + + Mobile Automata – NKS Chapter 3 + - - - - - -
-
-

移动自动机探索器

-

探索Wolfram的移动自动机系统,观察单个活跃细胞的移动和更新规律

-
- -
-
-
定义规则
-

- 设置移动自动机的状态转移规则: -

- -
-
-
读取0时
-
-
-
-
-
写1
-
写0
-
-
-
-
读取1时
-
-
-
-
-
写0
-
写1
-
-
-
- -
-
- 当前规则: - 简单 -
-
- -
预设规则
-
-
-
简单移动
-
基础左右移动
-
-
-
振荡运动
-
周期性摆动
-
-
-
扫描模式
-
逐渐扩展
-
-
-
复杂行为
-
不可预测
-
-
-
细胞分裂
-
多活跃细胞
-
-
-
标签系统
-
序列处理
-
-
- -
初始配置
-
-
-
单细胞
-
中心单个活跃
-
-
-
三细胞
-
三个随机细胞
-
-
-
随机模式
-
随机分布
-
-
-
边缘激活
-
两端活跃
-
-
- -
控制参数
- -
- -
- - 100 -
-
- -
- -
- - 150 -
-
- -
- -
- - 5 -
-
- -
-
- - -
-
- - -
-
- -
-
规则分析
-
- 简单移动:活跃细胞在空白区域向右移动并写入1,在已填充区域向左移动并写入0。这创造了基本的来回移动模式。 -
-
-
- -
- - -
-
- 当前步数 - 0 -
-
- 活跃细胞 - 1 -
-
- 头部位置 - 50 -
-
- 状态 - 就绪 -
-
-
-
-
- - +
+
+

Mobile Automata

+

+ Chapter 3 studies single active-cell mobile automata with two colours and nearest-neighbour motion. The selector below + enumerates the 16 rules from the original demo. Each rule specifies what happens when the head encounters a white cell + (0) or a black cell (1): write a new colour and move left or right. The traces plotted here match the behaviour shown on + the NKS website—revealing how simple sequential update rules already realise Wolfram’s four classes. +

+
+ +
+
+ + +
+
+ + + + +
+
+ + +
+
+ +
+ +
+
Generation: 0
+
Head index: 0
+
Visited cells: 0
+
+

+
+
+ + - - \ No newline at end of file + diff --git a/demos/chapter3/register-machine-demo.html b/demos/chapter3/register-machine-demo.html index 797e7db..231ac97 100644 --- a/demos/chapter3/register-machine-demo.html +++ b/demos/chapter3/register-machine-demo.html @@ -1,904 +1,279 @@ - - + - - - 寄存器机器演示 - 交互式计算模型实验 - + + Register Machines – NKS Chapter 3 + - - - - - -
-
-

寄存器机器演示

-

交互式探索计算的基本模型,理解简单指令如何产生复杂计算

-
- -
-
-
程序选择
-

- 选择不同的程序来探索寄存器机器的计算能力: -

- -
-
-
简单递增
-
将R0寄存器递增3次
-
-
-
加法运算
-
计算R0 + R1,结果存入R0
-
-
-
乘法运算
-
计算R1 × R2,结果存入R0
-
-
-
斐波那契数列
-
生成斐波那契数列
-
-
-
减法运算
-
计算R0 - R1,结果存入R0
-
-
-
最大公约数
-
计算R0和R1的最大公约数
-
-
- -
执行控制
- -
-
- - -
-
- - -
-
- -
- -
- - 5 -
-
- -
-
关于寄存器机器
-
- 寄存器机器是Wolfram在《一种新科学》中讨论的基本计算模型。它们由有限个寄存器(存储非负整数)和简单指令组成,却能实现图灵完备的计算。 -
-
-
- -
-
-
-
寄存器机器
- -
-
-
R0
-
0
-
-
-
R1
-
0
-
-
-
R2
-
0
-
-
- -
- -
- -
-
- 程序计数器 - 1 -
-
- 执行步数 - 0 -
-
- 状态 - 就绪 -
-
- 当前指令 - - -
-
-
-
-
-
-
- - + } + + updateStats() { + document.getElementById('step-count').textContent = this.steps.toString(); + document.getElementById('pc').textContent = this.pc.toString(); + } + } + + const demo = new RegisterMachineDemo(); + + document.getElementById('program-select').addEventListener('change', (event) => { + demo.setProgram(event.target.value); + document.getElementById('run-btn').textContent = 'Run'; + }); + + document.getElementById('run-btn').addEventListener('click', () => { + if (demo.running) { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + } else { + demo.run(); + document.getElementById('run-btn').textContent = 'Pause'; + } + }); + + document.getElementById('step-btn').addEventListener('click', () => { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + demo.step(); + }); + + document.getElementById('reset-btn').addEventListener('click', () => { + demo.reset(); + document.getElementById('run-btn').textContent = 'Run'; + }); + - - \ No newline at end of file + diff --git a/demos/chapter3/sequential-substitution-demo.html b/demos/chapter3/sequential-substitution-demo.html index df5dd1b..27608b5 100644 --- a/demos/chapter3/sequential-substitution-demo.html +++ b/demos/chapter3/sequential-substitution-demo.html @@ -1,1136 +1,263 @@ - - - Sequential Substitution Systems Demo - NKS Explorer - + + Sequential Substitution Systems – NKS Chapter 3 + -
-
-

Sequential Substitution Systems Demo

-

Explore Wolfram's sequential substitution systems from "A New Kind of Science" (Pages 88-89)
- One-at-a-time string rewriting with causal network generation and multiway analysis

-
- -
-
-

System Selection

-
- - -
- -
- - - -
-
- -
-

Execution Control

-
- - - 1000ms -
-
- - - 30 -
-
- - -
- - - - -
- -
-

Initial Configuration

-
- - -
-
- - -
-
-
- -
-

Sequential Substitution Evolution

- -
-

Rules (Applied in Priority Order)

-
-
- -
- - - - -
- -
-

About Sequential Substitution Systems

-

- Sequential substitution systems, explored by Stephen Wolfram in "A New Kind of Science" (pages 88-89), - differ from parallel systems by applying only one rule at a time. The system scans - the string from left to right, applies the first matching rule found, and then repeats. This creates - fundamentally different dynamics than parallel systems. -

-

- These systems generate causal networks where each substitution event becomes a node, - connected to events that causally influence each other. This forms the foundation for Wolfram's work on - multiway systems and his theory of fundamental physics, where the universe might operate - as a giant sequential substitution system. -

- -
-
-
0
-
Current Step
-
-
-
5
-
String Length
-
-
-
0
-
Rules Applied
-
-
-
None
-
Last Rule Used
-
-
-
0
-
Causal Events
-
-
-
-
- - + const last = this.history[this.history.length - 1]; + document.getElementById('step-count').textContent = (this.history.length - 1).toString(); + document.getElementById('length').textContent = last.text.length.toString(); + } + } + + const demo = new SequentialSubstitutionDemo(); + + document.getElementById('preset').addEventListener('change', (event) => { + demo.setPreset(event.target.value); + document.getElementById('run-btn').textContent = 'Run'; + }); + + document.getElementById('run-btn').addEventListener('click', () => { + if (demo.running) { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + } else { + demo.run(); + document.getElementById('run-btn').textContent = 'Pause'; + } + }); + + document.getElementById('step-btn').addEventListener('click', () => { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + demo.step(); + }); + + document.getElementById('reset-btn').addEventListener('click', () => { + demo.reset(); + document.getElementById('run-btn').textContent = 'Run'; + }); + - \ No newline at end of file + diff --git a/demos/chapter3/substitution-system-demo.html b/demos/chapter3/substitution-system-demo.html index 2bfd382..fb13dd7 100644 --- a/demos/chapter3/substitution-system-demo.html +++ b/demos/chapter3/substitution-system-demo.html @@ -1,837 +1,243 @@ - - - Substitution Systems Demo - NKS Explorer - + + Substitution Systems – NKS Chapter 3 + -
-
-

Substitution Systems Demo

-

Explore Wolfram's substitution systems from "A New Kind of Science"
- String rewriting systems that generate complex patterns through simple rules

-
- -
-
-

System Selection

-
- - -
- -
- - - -
-
- -
-

Evolution Control

-
- - - 800ms -
-
- - - 12 -
- - - - -
- -
-

Initial Configuration

-
- - -
-
- - -
-
-
- -
-

Substitution System Evolution

- -
-

Current Rules

-
-
- -
- - - - -
- -
-

About Substitution Systems

-

- Substitution systems, extensively studied by Stephen Wolfram in "A New Kind of Science," are - computational systems that operate by repeatedly applying string rewriting rules. - Starting from an initial string (axiom), each symbol is simultaneously replaced according to - predefined rules, generating increasingly complex patterns. -

-

- These systems are closely related to L-systems (Lindenmayer systems) and demonstrate - how simple rules can generate fractal patterns, biological growth models, and - complex mathematical sequences like the Fibonacci sequence. Wolfram showed that even - neighbor-independent substitution rules can produce sophisticated emergent behaviors. -

- -
-
-
0
-
Generation
-
-
-
1
-
String Length
-
-
-
1.0
-
Growth Rate
-
-
-
1
-
Unique Symbols
-
-
-
1
-
Total Symbols
-
-
-
-
- - + const latest = this.generations[this.generations.length - 1]; + document.getElementById('generation').textContent = (this.generations.length - 1).toString(); + document.getElementById('length').textContent = latest.length.toString(); + const alphabet = new Set(Array.from(latest)); + document.getElementById('alphabet').textContent = Array.from(alphabet).sort().join(', '); + } + } + + const demo = new SubstitutionDemo(); + + document.getElementById('system-select').addEventListener('change', (event) => { + demo.setSystem(event.target.value); + document.getElementById('run-btn').textContent = 'Run'; + }); + + document.getElementById('run-btn').addEventListener('click', () => { + if (demo.running) { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + } else { + demo.run(); + document.getElementById('run-btn').textContent = 'Pause'; + } + }); + + document.getElementById('step-btn').addEventListener('click', () => { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + demo.step(); + }); + + document.getElementById('reset-btn').addEventListener('click', () => { + demo.reset(); + document.getElementById('run-btn').textContent = 'Run'; + }); + - \ No newline at end of file + diff --git a/demos/chapter3/tag-system-demo.html b/demos/chapter3/tag-system-demo.html index 1f689e5..e9fde21 100644 --- a/demos/chapter3/tag-system-demo.html +++ b/demos/chapter3/tag-system-demo.html @@ -1,918 +1,248 @@ - + - - - 标记系统探索器 - 交互式序列替换实验 - + + Tag Systems – NKS Chapter 3 + - - - - - -
-
-

标记系统探索器

-

交互式探索序列替换系统,理解计算复杂性的基础模型

-
- -
-
-
预设系统
-

- 选择经典标记系统进行探索: -

- -
-
-
Wolfram 925
-
经典规则
-
-
-
循环系统
-
3符号循环
-
-
-
倍增系统
-
二进制倍增
-
-
-
类科拉茨
-
Collatz-like
-
-
- -
系统配置
- -
- -
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
替换规则
-
- -
- -
当前规则
-
- -
- -
控制操作
- -
-
- - -
-
- - -
-
- -
-
- -
-
系统分析
-
- Wolfram 925系统:经典标记系统,展现了简单规则产生复杂行为的典型例子。通过删除前2个符号并根据第一个符号应用替换规则。 -
-
-
- -
-
-
-
准备开始...
-
-
- -
-
- 当前步数 - 0 -
-
- 字符串长度 - 0 -
-
- 系统状态 - 就绪 -
-
- 行为类型 - 复杂 -
-
- -
-
演化历史
-
- -
-
-
-
-
- - +
+
+

Tag Systems

+

+ Tag systems remove a fixed number of symbols from the front of the string and append a replacement based on the symbol + that was just removed. The presets reproduce Wolfram’s 1-tag and 2-tag examples from chapter 3, including the famous + system 925. +

+
+ +
+
+ + +
+
+ + + + +
+
+ +
    +
    +
    + +
    +
    +
    +
    Steps: 0
    +
    Deletion number: 1
    +
    Current length: 0
    +
    +
    +
    + + - \ No newline at end of file + diff --git a/demos/chapter3/tag-system-nks-demo.html b/demos/chapter3/tag-system-nks-demo.html deleted file mode 100644 index 12da6d2..0000000 --- a/demos/chapter3/tag-system-nks-demo.html +++ /dev/null @@ -1,554 +0,0 @@ - - - - - - NKS-Style Tag System Demo - - - - - - -
    -
    -

    Tag System (NKS‑style) Demo

    -

    - A tag system evolves a word by: (1) looking at the first symbol, appending a string determined by it, then (2) deleting a fixed number m of symbols from the front. Repeat until the word is shorter than m (halts) or a loop occurs. -

    -
    - -
    -
    -

    Setup

    -
    - - -
    -
    - - -
    -
    - - -
    - -
    -
    - - - - -
    -
    -
    - - - -
    - -
    - - -
    - -
    -
    Status: Ready
    -
    Step:
    -
    Length:
    -
    - -
    - -
    -
    -
    Undefined symbols simply append nothing.
    -
    - -
    -

    Current State

    -
    Define a system and press Run.
    - -

    Evolution (rows over time)

    - - -

    History

    -
    - -
    -
    -
    - - diff --git a/demos/chapter3/three-color-ca-demo-standalone.html b/demos/chapter3/three-color-ca-demo-standalone.html deleted file mode 100644 index 3f77be7..0000000 --- a/demos/chapter3/three-color-ca-demo-standalone.html +++ /dev/null @@ -1,429 +0,0 @@ - - - - - - 3‑Color Cellular Automata — Standalone Demo - - - -
    -

    3‑Color Cellular Automata — Standalone Demo

    -

    1D, radius‑1, 3 states {0,1,2}. Rule encoded as a base‑3 integer over all 27 neighborhoods (L,C,R) → output.

    -
    -
    - - -
    - -
    -
    - - - - - - - diff --git a/demos/chapter3/three-color-ca-demo.html b/demos/chapter3/three-color-ca-demo.html index c0e8c48..aff4afe 100644 --- a/demos/chapter3/three-color-ca-demo.html +++ b/demos/chapter3/three-color-ca-demo.html @@ -1,547 +1,369 @@ - - - 3-Color Cellular Automata Demo - NKS Explorer - + + +
    +
    +

    Three-Color Cellular Automata

    +

    + This recreation implements the exact totalistic three-color rules from chapter 3 of A New Kind of Science. + Choose the same rules and initial conditions Wolfram used—rule 777, rule 924, and the other reference cases—and + watch the successive rows accumulate exactly as in the original online demo. +

    +
    + +
    +
    + + +
    + +
    + + +
    +
    + + + + +
    +
    + +
    + +
    +
    +
    Current rule: 777
    +
    Generation: 0
    +
    White: 0
    +
    Gray: 0
    +
    Black: 0
    +
    +
    +
    + + + } + } + + const canvas = document.getElementById('ca-canvas'); + const automaton = new ThreeColorAutomaton(canvas); + automaton.reset(); + + const ruleSelect = document.getElementById('rule-select'); + const customWrapper = document.getElementById('custom-wrapper'); + const customInput = document.getElementById('custom-rule'); + + ruleSelect.addEventListener('change', () => { + if (ruleSelect.value === 'custom') { + customWrapper.style.display = 'block'; + customInput.focus(); + return; + } + customWrapper.style.display = 'none'; + automaton.setRule(parseInt(ruleSelect.value, 10)); + }); + + customInput.addEventListener('change', () => { + const value = Number(customInput.value); + if (!Number.isNaN(value)) { + automaton.setRule(value); + } + }); + + document.getElementById('seed-select').addEventListener('change', (event) => { + automaton.setSeed(event.target.value); + }); + + document.getElementById('run-btn').addEventListener('click', () => { + if (automaton.running) { + automaton.stop(); + document.getElementById('run-btn').textContent = 'Run'; + } else { + automaton.run(); + document.getElementById('run-btn').textContent = 'Pause'; + } + }); + + document.getElementById('step-btn').addEventListener('click', () => { + automaton.stop(); + document.getElementById('run-btn').textContent = 'Run'; + automaton.step(); + }); + + document.getElementById('reset-btn').addEventListener('click', () => { + automaton.reset(); + document.getElementById('run-btn').textContent = 'Run'; + }); + + automaton.renderRuleCards(); + - \ No newline at end of file + diff --git a/demos/chapter3/turing-machine-demo.html b/demos/chapter3/turing-machine-demo.html index a3cb58a..0d69fdc 100644 --- a/demos/chapter3/turing-machine-demo.html +++ b/demos/chapter3/turing-machine-demo.html @@ -1,934 +1,340 @@ - - - Turing Machine Demo - NKS Explorer - + + Turing Machines – NKS Chapter 3 + -
    -
    -

    Turing Machine Demo

    -

    Explore Wolfram's Turing machines from "A New Kind of Science"
    - Universal computation with simple rules: head states, tape symbols, and transition rules

    -
    - -
    -
    -

    Turing Machine Selection

    -
    - - -
    - -
    - - - -
    -
    - -
    -

    Simulation Control

    -
    - - - 500ms -
    - - - - -
    - -
    -

    Initial Configuration

    -
    - - -
    -
    - - - 6 -
    -
    - - -
    -
    -
    - -
    -

    Turing Machine Visualization

    - -
    -
    - Current State: -
    - 1 -
    -
    - Head Position: - 6 -
    -
    - Current Symbol: - 0 -
    -
    - -
    -
    -
    - Tape Head -
    -
    -
    - Symbol 0 -
    -
    -
    - Symbol 1 -
    -
    -
    - Symbol 2 -
    -
    -
    - Symbol 3 -
    -
    - - - -
    -

    Transition Rules

    -
    -
    -
    - -
    -

    About Turing Machines

    -

    - Turing machines, extensively studied by Stephen Wolfram in "A New Kind of Science," are fundamental - models of computation consisting of a tape of cells, a head that - can read and write symbols, and a finite set of states. The machine follows - transition rules that determine what symbol to write, which direction to move, - and what new state to enter based on the current state and symbol. -

    -

    - Wolfram demonstrated that even very simple Turing machines can exhibit complex behavior and achieve - universal computation. His famous 2-state 3-symbol machine was - proven universal in 2007, making it the smallest known universal Turing machine. This supports his - Principle of Computational Equivalence - that complex computation is ubiquitous - in simple systems. -

    - -
    -
    -
    0
    -
    Steps
    -
    -
    -
    1
    -
    State
    -
    -
    -
    6
    -
    Head Position
    -
    -
    -
    12
    -
    Tape Size
    -
    -
    -
    0
    -
    Ones on Tape
    -
    -
    -
    0
    -
    Non-Zero Symbols
    -
    -
    -
    -
    - - + } + + setWindow(size) { + this.window = size; + this.history = []; + this.recordHistory(); + this.draw(); + } + } + + const canvas = document.getElementById('tm-canvas'); + const demo = new TuringMachineDemo(canvas); + + document.getElementById('machine-select').addEventListener('change', (event) => { + demo.setMachine(event.target.value); + document.getElementById('run-btn').textContent = 'Run'; + }); + + document.getElementById('window-size').addEventListener('change', (event) => { + demo.setWindow(parseInt(event.target.value, 10)); + }); + + document.getElementById('run-btn').addEventListener('click', () => { + if (demo.running) { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + } else { + demo.run(); + document.getElementById('run-btn').textContent = 'Pause'; + } + }); + + document.getElementById('step-btn').addEventListener('click', () => { + demo.stop(); + document.getElementById('run-btn').textContent = 'Run'; + demo.step(); + }); + + document.getElementById('reset-btn').addEventListener('click', () => { + demo.reset(); + document.getElementById('run-btn').textContent = 'Run'; + }); + - \ No newline at end of file +