ArticleslgStudy

computer science

Natural language programming

Natural language programming is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Natural language programming rather than just read about it. In short: Natural language programming is an ontology-assisted way of programming in terms of natural language sentences, e.g. English.

Natural language programming — main illustration
Natural language programming — illustration

Key takeaways

  • Natural language programming belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Natural language programming to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Natural language programming from memory before moving on to harder problems.

Reference excerpt

Natural language programming is an ontology-assisted way of programming in terms of natural language sentences, e.g. English. A structured document with content, sections and subsections for explanations of sentences forms a natural language computer program. Some methods for program synthesis are based on natural-language programming. One application is to use natural language programming to represent the knowledge of an autonomous robot; the robots tasks can then be scripted by its users so that the robot can execute them autonomously while keeping to prescribed rules of behaviour as determined by the robot's user. Such robots are called transparent robots as their reasoning is transparent to users. Examples of natural language programming languages include: Inform 7, a natural programming language for making interactive fiction; Shakespeare, an esoteric natural programming language in the style of the plays of William Shakespeare; Plain English programming language, a programming language aiming to be as close to "plain English" as possible while being close to the hardware, and Wolfram Alpha, a computational knowledge engine, using natural-language input.

Interpretation The smallest statement in a natural language program is a sentence. Each sentence is stated in terms of concepts from the underlying ontology, attributes in that ontology, and named objects in capital letters. In a natural language program, every sentence unambiguously compiles into a procedure call in the underlying high-level programming language such as MATLAB, Octave, SciLab, Python, etc. Symbolic languages such as Wolfram Language are capable of interpreted processing of queries by sentences. This can allow interactive requests such as that implemented in Wolfram Alpha. However, this is not natural language programming. An example text from an English language natural language program is as follows:

If U_ is 'smc01-control', then do the following. Define surface weights Alpha as "[0.5, 0.5]". Initialise matrix Phi as a 'unit matrix'. Define J as the 'inertia matrix' of Spc01. Compute matrix J2 as the inverse of J. Compute position velocity error Ve and angular velocity error Oe from dynamical state X, guidance reference Xnow. Define the joint sliding surface G2 from the position velocity error Ve and angular velocity error Oe using the surface weights Alpha. Compute the smoothed sign function SG2 from the joint sliding surface G2 with sign threshold 0.01. Compute special dynamical force F from dynamical state X and surface weights Alpha. Compute control torque T and control force U from matrix J2, surface weights Alpha, special dynamical force F, smoothed sign function SG2. Finish conditional actions.

that defines a feedback control scheme using a sliding mode control method.

Software paradigm Natural-language programming is a top-down method of writing software. Its stages are as follows:

Definition of an ontology – taxonomy – of concepts needed to describe tasks in the topic addressed. Each concept and all their attributes are defined in natural-language words. This ontology will define the data structures the natural language program can use in sentences. Definition of one or more top-level sentences in terms of concepts from the ontology. These sentences are later used to invoke the most important activities in the topic. Defining of each of the top-level sentences in terms of a sequence of sentences. Defining each of the lower-level sentences in terms of other sentences or by a simple sentence of the form Execute code "...". where ... stands for a code in terms of the associated high-level programming language. Repeating the previous step until you have no sentences left undefined. During this process each of sentences can be classified to belong to a section of the document to be produced in HTML or Latex format to form the final natural-language program. Testing the meaning of each sentence by executing its code using testing objects. Providing a library of procedure calls (in the underlying high-level language) which are needed in the code definitions of some low-level-sentence meanings. Providing a title, author data and compiling the sentences into an HTML or LaTeX file. Publishing the natural-language program as a webpage on the Internet or as a PDF file compiled from the LaTeX document.

Publication value of natural-language programs and documents A natural-language program is a precise formal description of some procedure that its author created. It is human readable and it can also be read by a suitable software agent. For example, a web page in a natural language format can be read by a software personal assistant agent to a person and she or he can ask the agent to execute some sentences, i.e. carry out some task or answer a question. There is a reader agent available for English interpretation of HTML-based natural language programming documents that a person can run on their personal computer.

Contribution of natural-language programs to machine knowledge An ontology class is a natural-language program that is not a concept in the sense as humans use concepts. Concepts in a naturalmlanguage program are examples (samples) of generic human concepts. Each sentence in a natural-language program is either (1) stating a relationship in a world model or (2) carries out an action in the environment or (3) carries out a computational procedure or (4) invokes an answering mechanism in response to a question. A set of natural language programming sentences, with associated ontology defined, can also be used as a pseudo code that does not provide the details in any underlying high level programming language. In such an application the sentences used become high level abstractions (conceptualisations) of computing procedures that are computer language and machine independent.

AI in natural language programming Researchers have started to experiment with natural language programming environments that use plain language prompts and then use large language models to turn natural language into formal code. For example Spatial Pixel created a natural language programming environment to turn natural language into P5.js code through OpenAI's API. In 2021 OpenAI developed a natural language programming environment for their programming large language model called Codex.

Vibe coding

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Natural language programming

Start with the simplest possible case. Write down what Natural language programming claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Natural language programming before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Natural language programming ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Natural language programming

In research
Natural language programming appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Natural language programming in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Natural language programming is common in secondary-school and first-year university syllabi. It links to neighbouring topics Algorithm description languages, Computer programming, Natural language processing, so understanding it makes those chapters shorter.
In everyday life
Look for Natural language programming outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Natural language programming” →

How to study Natural language programming in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Natural language programming means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Natural language programming out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Natural language programming in simple terms?

Natural language programming is an ontology-assisted way of programming in terms of natural language sentences, e.g. English.

Why does Natural language programming matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Natural language programming?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Natural language programming.

Tags

  • Algorithm description languages
  • Computer programming
  • Natural language processing
  • Structured English

Keep exploring