Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
  1. Home
  2. /
  3. Learn
  4. /
  5. Thue

Learn Thue - 10 Code Examples & CST Typing Practice Test

Thue is an abstract computational model based on string rewriting systems. It allows defining rules to transform strings, serving as a theoretical model for computation and a framework for exploring universal computation.

View all 10 Thue code examples →
Hello World in ThueSimple IncrementSimple DecrementPrint Numbers 1 to 3Swap Two SymbolsSimple Copy RuleConditional Output ExamplePalindrome CheckReverse StringFactorial Concept

Learn THUE with Real Code Examples

Updated Nov 26, 2025

Explain

Uses string rewriting rules of the form ‘pattern -> replacement’.

Can simulate any Turing-complete computation.

Non-deterministic or deterministic execution depending on rule application.

Primarily theoretical, but has been used to explore formal language theory and computation.

Instructive for understanding the foundations of computation and algorithmic processes.

Core Features

Alphabet - finite set of symbols

Strings - sequences over the alphabet

Rules - pattern -> replacement transformations

Initial string - starting state of computation

Halting condition - no more applicable rules

Basic Concepts Overview

Alphabet - set of allowed symbols

String - sequence of symbols

Rule - defines how substrings can be replaced

Initial string - starting point for rewriting

Halting - when no rules match

Project Structure

rules.thue - file defining pattern -> replacement rules

input.txt - initial string(s) to transform

output.txt - resulting strings after computation

logs/ - optional, tracks transformation steps

docs/ - notes on rules and expected behaviors

Building Workflow

Define the alphabet

Write the rewriting rules

Set the initial string

Choose execution strategy (deterministic or non-deterministic)

Apply rules until halting or desired output

Difficulty Use Cases

Beginner: simple string replacement examples

Intermediate: small deterministic Thue programs

Advanced: non-deterministic systems exploring multiple paths

Expert: Turing-complete computation simulations

Architect: formal language and computational proofs

Comparisons

Thue vs Turing Machine: abstract but equivalent computational power

Thue vs Lambda Calculus: string-based vs function-based

Thue vs Post systems: generalization of rewriting systems

Thue vs Regular Expressions: more powerful, Turing-complete

Thue vs Practical languages: educational and theoretical only

Versioning Timeline

1914 - Axel Thue introduces Thue system

1920s-1930s - Expanded in combinatorial word studies

1960s - Recognized as Turing-complete string rewriting system

1970s - Used in formal language theory

1980s - Implemented in simple computational simulators

1990s - Non-deterministic Thue explored in automata research

2000s - Online interpreters and educational tools

2010s - Used in computational theory teaching

2020s - Visualization tools for Thue introduced

2025 - Still mainly academic and theoretical model

Glossary

Alphabet - symbols used in Thue

String - sequence over alphabet

Rule - transformation instruction

Initial string - starting point for computation

Halting condition - no further rules apply

Installation Setup

No installation required; Thue is theoretical.

Optional interpreters or simulators can be used.

Download a Thue interpreter from academic repositories.

Write rules in the Thue syntax.

Run strings through the interpreter to simulate computation.

Environment Setup

Install Thue interpreter (optional)

Use text editor to define rules

Prepare initial strings

Run simulation locally or online

Observe outputs and halting conditions

Config Files

rules.thue - defines rewriting rules

input.txt - initial strings

output.txt - resulting strings

log.txt - optional rule application log

docs/ - notes on rules and expected transformations

Cli Commands

thue-run rules.thue input.txt

thue-step - execute one rewriting step

thue-deterministic - force deterministic execution

thue-non-deterministic - explore multiple paths

thue-visualize - generate string transformation graph

Internationalization

Rule syntax uses ASCII symbols

Documentation available in multiple languages

Interpreters may support Unicode extensions

Educational translations exist

Flexible for different symbol sets in theory

Accessibility

Text-based interface accessible in terminals

Rule files readable by screen readers

Optional web-based visualizers for graphical accessibility

Keyboard navigation for CLI tools

Educational aids for teaching Thue

Ui Styling

Mostly CLI or text-based

Optional graphical simulators

Visualization of string derivation trees

Color-coded transformations in some tools

Educational diagrams for understanding rules

State Management

String represents current state

Rules applied sequentially or non-deterministically

Each step produces new string state

Halting occurs when no rules match

Optional branching for non-deterministic exploration

Data Management

Strings as primary data

Rules as transformation definitions

Logs of transformations for analysis

Input and output files for persistence

Visualization of state transitions

Architecture

Abstract computation model with strings and rewriting rules

No fixed hardware requirements

Rule set defines transformations

Computation proceeds by applying rules to strings

Halts when no rule can be applied

Rendering Model

Strings as states

Rules as transformations

Application of rules leads to new strings

Halting when no rules apply

Optional non-deterministic branching

Architectural Patterns

String-based abstract computation

Rule set defines system behavior

Initial string as input

Transformation sequence as computation path

Termination when no rules remain

Real World Architectures

Formal language exploration

Automata theory teaching

Turing-completeness demonstrations

String manipulation algorithm experiments

Non-deterministic computation studies

Design Principles

Minimalistic computation

String rewriting as computation

Rule-based transformations

Deterministic and non-deterministic exploration

Foundation for formal language research

Scalability Guide

Simulate small examples first

Avoid exponential growth of non-deterministic paths

Use visualization tools for large transformations

Break rules into modular sets

Document rules and expected outputs

Migration Guide

Copy rules.thue and input files to new system

Install compatible interpreter if needed

Run simulations with same initial strings

Verify output consistency

Adjust for any interpreter version differences

Performance Notes

Execution grows exponentially with non-deterministic rules

Minimalistic systems are slow for complex computation

Optimize rule order for deterministic Thue programs

Simulate small examples first

Use software interpreters for automation

Security Notes

No inherent security concerns; purely theoretical

Beware of unbounded resource usage in simulators

Ensure proper environment for interpreter execution

Avoid malicious scripts if using online simulators

Back up experiment files

Monitoring Analytics

Track string derivation sequences

Log rule application counts

Analyze branching paths in non-deterministic systems

Visualize transformation trees

Compare outputs to theoretical expectations

Code Quality

Rules should be consistent and non-contradictory

Avoid infinite loops unless intended

Document rule purpose

Keep input strings within defined alphabet

Test transformations incrementally

Practical Examples

String reversal via Thue rules

Generating arithmetic sequences

Simulating finite automata transformations

Encoding small algorithms as Thue programs

Demonstrating universal computation

Troubleshooting

Check for unreachable rules

Avoid overlapping rules causing infinite loops

Verify initial string contains only alphabet symbols

Debug non-deterministic paths systematically

Ensure rules are consistent with intended computation

Testing Guide

Validate rules on small strings

Check for expected outputs

Test deterministic and non-deterministic paths

Log all transformations for debugging

Compare results to theoretical expectations

Deployment Options

Academic or local simulation

Online Thue interpreters

Embedded in educational tutorials

Proof-of-concept computation demonstrations

Offline experiments using scripting language wrappers

Tools Ecosystem

Thue interpreters (various academic implementations)

Online simulators for experimenting

Text editors for rule definition

Version control for rule sets

Visualization tools for string transformations

Integrations

Can interface with Python or Ruby scripts for automation

Integration with educational platforms for computation teaching

Optional GUI visualizers

Simulation with logging and reporting

Export results for analysis in spreadsheets or databases

Productivity Tips

Start with simple rules

Visualize derivations for understanding

Use consistent notation

Document transformations

Experiment incrementally

Challenges

Handling non-determinism

Avoiding infinite rewriting loops

Designing consistent rules

Mapping algorithms to string rules

Debugging long transformation sequences

Learning Path

Understand basic string rewriting

Study Thue rules and notation

Explore deterministic vs non-deterministic applications

Simulate simple Thue programs

Read about Thue’s Turing-completeness

Skill Improvement Plan

Week 1: Simple string replacements

Week 2: Deterministic Thue programs

Week 3: Non-deterministic transformations

Week 4: Encode basic algorithms

Week 5: Explore Turing-complete constructions

Interview Questions

What is a Thue system?

How do rewriting rules work?

Explain deterministic vs non-deterministic Thue execution.

How is Thue Turing-complete?

What are practical applications of Thue?

Cheat Sheet

Alphabet = set of symbols

String = sequence of symbols

Rule = pattern -> replacement

Initial string = starting state

Halting = no applicable rules remain

Books

Combinatorial Word Problems by Axel Thue

Theory of Formal Languages

Introduction to Automata Theory

Rewriting Systems in Computation

Turing-Complete Minimal Systems

Tutorials

Introduction to Thue string rewriting

Writing your first Thue rules

Simulating simple deterministic programs

Exploring non-deterministic Thue derivations

Using Thue to demonstrate Turing-completeness

Official Docs

https://en.wikipedia.org/wiki/Thue_system

https://www.cs.umd.edu/~gasarch/TOPICS/thue.html

Community Links

Formal language research forums

University course materials on computation theory

StackExchange Computer Science tag

Academic publications and blogs

Online Thue interpreters and discussion boards

Community Support

Academic papers and publications

Formal language textbooks

Theoretical computer science courses

Online forums for computational theory

University lecture notes and tutorials

Monetization

Primarily academic, no direct monetization

Educational toolkits for computation theory

University courses and textbooks

Workshops and seminars

Research publications

Future Roadmap

Interactive online Thue simulators

Integration with computational theory courses

Graphical visualization of non-deterministic derivations

Extensions to Unicode and complex alphabets

Enhanced teaching tools for string rewriting systems

When Not To Use

For practical software development

Large-scale data processing

Performance-critical applications

Production system automation

Tasks requiring libraries, APIs, or GUI

Final Summary

Thue is a theoretical string rewriting system and computational model.

It uses rules to transform strings to explore universal computation.

Deterministic or non-deterministic execution allows modeling algorithms.

Primarily used in academia to study formal languages and computation.

Provides insight into minimalistic Turing-complete systems.

Faq

Is Thue a programming language? -> No, theoretical model.

Can Thue simulate any computation? -> Yes, it is Turing-complete.

Does Thue require a computer? -> Can be simulated manually or in software.

Is Thue practical for production? -> No, purely theoretical.

Where is Thue studied? -> Computational theory, formal languages, automata.

Code Sample Descriptions

1

Hello World in Thue

::=

::=Hello World!

::=::

A simple Thue program that outputs 'Hello World!'. The rules transform an initial start symbol into the target string.

Let’s Try →
2

Simple Increment

N::=0
N::=N1
N::=N2
N::=N3
N::=N4
N::=N5
N::=N6
N::=N7
N::=N8
N::=N9

Increment a number represented as a string of digits.

Let’s Try →
3

Simple Decrement

D1::=0
D2::=1
D3::=2
D4::=3
D5::=4
D6::=5
D7::=6
D8::=7
D9::=8
D0::=9

Decrement a number represented as a string of digits.

Let’s Try →
4

Print Numbers 1 to 3

S::=1A
A::=2B
B::=3
C::=::
S

Prints numbers 1, 2, 3 sequentially using Thue rules.

Let’s Try →
5

Swap Two Symbols

S::=AB
AB::=BA
BA::=AB

Swaps two symbols A and B in the string.

Let’s Try →
6

Simple Copy Rule

X::=Y
Y::=X

Copies symbol X to Y using Thue rules.

Let’s Try →
7

Conditional Output Example

S::=A?YES:NO
A::=::
S

Outputs 'YES' if symbol A exists, 'NO' otherwise.

Let’s Try →
8

Palindrome Check

S::=ABA
ABA::=PALINDROME
B::=::
S

Checks if a string is a palindrome using Thue transformations.

Let’s Try →
9

Reverse String

S::=ABC
ABC::=CBA
CBA::=ABC

Reverses the string 'ABC' to 'CBA'.

Let’s Try →
10

Factorial Concept

F::=1
F::=F*2
F::=F*3
F::=F*4
F::=RESULT
RESULT::=::
F

A simple conceptual Thue program to illustrate factorial transformation.

Let’s Try →

Frequently Asked Questions about Thue

What is Thue?

Thue is an abstract computational model based on string rewriting systems. It allows defining rules to transform strings, serving as a theoretical model for computation and a framework for exploring universal computation.

What are the primary use cases for Thue?

Study of formal languages and rewriting systems. Turing-completeness demonstrations. Exploration of non-deterministic algorithms. Teaching computational theory concepts. Theoretical experiments in automata and computation

What are the strengths of Thue?

Simple yet universal computational model. Demonstrates Turing-completeness in minimal form. Useful for educational purposes in computation theory. Explores non-determinism and computational paths. Highly abstract, applicable to various formal systems

What are the limitations of Thue?

Not practical for real-world programming. Execution can be highly inefficient. Non-deterministic versions are hard to analyze. Limited tooling and software support. Requires strong theoretical background to use effectively

How can I practice Thue typing speed?

CodeSpeedTest offers 10+ real Thue code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.

Learn Other Programming Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlinPartiqlHaskellElixirFsharpView all languages →
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.