SlideShare a Scribd company logo
Literate programming and reproducible
research
Professor Eric S Fraga, UCL
6 June 2018
EGL2018, Essex
v1.33 4th June 2018
2
Outline
Introduction
The aim & challenge
Literate programming
Emacs
org mode
Programming
Writing
Conclusions
Summary
3 Introduction
Reproducible research
To ensure that our research is reproducible both by ourselves and
by others.
4 Introduction
Coding, processing, writing
In doing research,
1 we all write programs . . .
2 which generate results . . .
3 which need to be processed . . .
4 and which should be disseminated.
Currently, we use different tools for each step.
5 Introduction
Tools
Workflow:
coding IDE, MATLAB editor, vi, notepad, . . .
results .txt, .xls, .dat
processing spreadsheet, R
dissemination Word, PowerPoint, LATEX, beamer
project management ?
leading to constant transfer of data from one place to another.
6 Introduction
Definition
Literate programming is a programming paradigm intro-
duced by Donald Knuth in which a program is given as
an explanation of the program logic in a natural language,
such as English, interspersed with snippets of macros and
traditional source code, from which a compilable source
code can be generated.
https://en.wikipedia.org/wiki/Literate_programming
7 Introduction
Code and documentation
Source
8 Introduction
Example: the Strawberry algorithm
https://www.ucl.ac.uk/~ucecesf/strawberry.html
9 Introduction
Editor
originally written in 1976
content aware editing
fully extensible in Emacs LISP
self-documenting with comprehensive help system
large eco-system of packages
https://www.gnu.org/software/emacs/
10 Introduction
org mode
Text (it’s all text) based mode for
writing & dissemination
project management
literate programming
https://orgmode.org/
11 org mode
Example objective function
min
x
z =
n
i=1
x4
i + x3
i − 2x2
i
x ∈ [a, b] ∩ Rn
12 org mode
Plot of objective function
13 org mode
Tangling
Create an octave file with the objective function using tangling:
function [ z g ] = f ( x )
z = sum( x .^4 + x .^3 − 2∗x . ^ 2 ) ;
g = 0; % unconstrained
endfunction
14 org mode
Code segments
Specify the parameters for the optimisation problem:
n = 2;
x0 = rand (n , 1 ) ;
a = −2∗ones (n , 1 ) ;
b = 2∗ones (n , 1 ) ;
15 org mode
Bringing bits together
The code to include the problem setup directly and solve the
problem:
clear
format short
n = 2;
x0 = rand (n , 1 ) ;
a = −2∗ones (n , 1 ) ;
b = 2∗ones (n , 1 ) ;
[ x y ] = strawberry ( x0 , a , b , @f , 10 , 10);
[ x ; y ] ’
16 org mode
Plotting results
Using data in table of results on previous slide:
17 org mode
Processing results
Statistical analysis of results obtained above:
Statistic Value
Best -5.666
Average -5.582
Worst -5.255
Standard deviation 0.094
18 org mode
Outlines
Example (a recent paper):
Can show, hide, and move individual sub-trees.
19 org mode
Publishable output
org will export to LATEX (and hence to PDF) or ODT (MS Word
compatible).
20 org mode
Project management
Support for tasks, scheduling, appointments:
[3/4] prepare and give presentation on literate programming
collect images
write slides
book hotel
give presentation
21 org mode
Revision control
A research project is a long term activity comprised of many
individual tasks.
Revision control should (must) be an integral element of
project management.
Think track changes but on steroids and which works for data
as well.
Excellent tools exist: git, mercurial, subversion, . . .
22 org mode
Example of revision control
23 Conclusions
Emacs & org
Single tool for writing, coding, data manipulation, data provenance,
dissemination, and project management.
24 Conclusions
Testimonial I
By the age of 35 you should have realized that Emacs is
the One True Editor and should have embraced it. If that’s
not the case - your life so far has been completely wasted.
@bbatsov, 04:02 pm May 20, 2018
25 Conclusions
Testimonial II
The advantages of plain text are hard to overstate, as is the
advantage of having everything from plot notes to research
material in a single (large) file under version control. And
building up a novel from an outline is a natural process
with org-mode.
Bob Newell, emacs.help newsgroup, 2018-05-30.
26 Conclusions
Links
Emacs https://www.gnu.org/software/emacs/
Complete computing environment
http://doc.rix.si/cce/cce.html
org mode https://orgmode.org/
reproducible research
https://reproducibleresearch.net/links/
blog reproducible research for management
27 Conclusions
And finally
https://www.xkcd.com/378/

More Related Content

PDF
Data Analysis and Visualization: R Workflow
PPT
python workshop(one of the 15 chapters)
PPT
LECT9.ppt
PDF
PDF
Icpc16.ppt
PPTX
Algorithm,Pseudocode,Flowchart.pptx
PPTX
internship presentation report abt ms word ms office and word
PPTX
Csc1100 lecture01 ch01 pt2-paradigm (1)
Data Analysis and Visualization: R Workflow
python workshop(one of the 15 chapters)
LECT9.ppt
Icpc16.ppt
Algorithm,Pseudocode,Flowchart.pptx
internship presentation report abt ms word ms office and word
Csc1100 lecture01 ch01 pt2-paradigm (1)

Similar to Literate programming and reproducible research (20)

PPTX
Csc1100 lecture01 ch01 pt2-paradigm
PPTX
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jh
PPTX
Internship (7)szgsdgszdssagsagzsvszszvsvszfvsz
PDF
Computer Science (CSC 102) Lecture 1.pdf
PDF
Top Tips Every Notes Developer Needs To Know
PDF
Blueprints: Introduction to Python programming
PPT
CHAPTER 1
PPTX
GRAPHICAL STRUCTURES in our lives
PPT
SystemsProgrammingCourse FSDFFSFDSDSDSFSFS
PPT
Chapter 1.ppt
PPT
software project management.lpu.slide.ansh.gupta
DOCX
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
PDF
SE2_Lec 19_Design Principles and Design Patterns
PPT
Data sources with unified method and pulbish tes
PDF
Master thesis Francesco Serafin
PDF
Reproducible Research in R and R Studio
PPTX
Bug prediction + sdlc automation
PPTX
Programming _Language of Logic_ PPT.pptx
PDF
Fundamentals of programming with C++
Csc1100 lecture01 ch01 pt2-paradigm
Internship (7)gfytfyugiujhoiipobjhvyuhjkb jh
Internship (7)szgsdgszdssagsagzsvszszvsvszfvsz
Computer Science (CSC 102) Lecture 1.pdf
Top Tips Every Notes Developer Needs To Know
Blueprints: Introduction to Python programming
CHAPTER 1
GRAPHICAL STRUCTURES in our lives
SystemsProgrammingCourse FSDFFSFDSDSDSFSFS
Chapter 1.ppt
software project management.lpu.slide.ansh.gupta
Lab manual object oriented technology (it 303 rgpv) (usefulsearch.org) (usef...
SE2_Lec 19_Design Principles and Design Patterns
Data sources with unified method and pulbish tes
Master thesis Francesco Serafin
Reproducible Research in R and R Studio
Bug prediction + sdlc automation
Programming _Language of Logic_ PPT.pptx
Fundamentals of programming with C++
Ad

More from Eric Fraga (7)

PDF
Stochastic methods and models for multi-objective dynamic optimisation problems
PDF
Optimisation problems and methods in Chemical Engineering: a personal survey
PDF
Computationally efficient surrogate based multi-objective optimisation for PS...
PDF
An interactive exploration environment for complex process design
PDF
Visualisation and interaction for design
PDF
A Lindenmayer system for heat exchanger network design with stream splitting
PDF
Process systems engineering and the environment
Stochastic methods and models for multi-objective dynamic optimisation problems
Optimisation problems and methods in Chemical Engineering: a personal survey
Computationally efficient surrogate based multi-objective optimisation for PS...
An interactive exploration environment for complex process design
Visualisation and interaction for design
A Lindenmayer system for heat exchanger network design with stream splitting
Process systems engineering and the environment
Ad

Recently uploaded (20)

PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPT
Introduction Database Management System for Course Database
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Digital Strategies for Manufacturing Companies
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
System and Network Administraation Chapter 3
PDF
Understanding Forklifts - TECH EHS Solution
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Introduction Database Management System for Course Database
VVF-Customer-Presentation2025-Ver1.9.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
wealthsignaloriginal-com-DS-text-... (1).pdf
Softaken Excel to vCard Converter Software.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Which alternative to Crystal Reports is best for small or large businesses.pdf
PTS Company Brochure 2025 (1).pdf.......
Reimagine Home Health with the Power of Agentic AI​
Digital Strategies for Manufacturing Companies
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Designing Intelligence for the Shop Floor.pdf
Odoo Companies in India – Driving Business Transformation.pdf
Design an Analysis of Algorithms II-SECS-1021-03
System and Network Administraation Chapter 3
Understanding Forklifts - TECH EHS Solution

Literate programming and reproducible research

  • 1. Literate programming and reproducible research Professor Eric S Fraga, UCL 6 June 2018 EGL2018, Essex v1.33 4th June 2018
  • 2. 2 Outline Introduction The aim & challenge Literate programming Emacs org mode Programming Writing Conclusions Summary
  • 3. 3 Introduction Reproducible research To ensure that our research is reproducible both by ourselves and by others.
  • 4. 4 Introduction Coding, processing, writing In doing research, 1 we all write programs . . . 2 which generate results . . . 3 which need to be processed . . . 4 and which should be disseminated. Currently, we use different tools for each step.
  • 5. 5 Introduction Tools Workflow: coding IDE, MATLAB editor, vi, notepad, . . . results .txt, .xls, .dat processing spreadsheet, R dissemination Word, PowerPoint, LATEX, beamer project management ? leading to constant transfer of data from one place to another.
  • 6. 6 Introduction Definition Literate programming is a programming paradigm intro- duced by Donald Knuth in which a program is given as an explanation of the program logic in a natural language, such as English, interspersed with snippets of macros and traditional source code, from which a compilable source code can be generated. https://en.wikipedia.org/wiki/Literate_programming
  • 7. 7 Introduction Code and documentation Source
  • 8. 8 Introduction Example: the Strawberry algorithm https://www.ucl.ac.uk/~ucecesf/strawberry.html
  • 9. 9 Introduction Editor originally written in 1976 content aware editing fully extensible in Emacs LISP self-documenting with comprehensive help system large eco-system of packages https://www.gnu.org/software/emacs/
  • 10. 10 Introduction org mode Text (it’s all text) based mode for writing & dissemination project management literate programming https://orgmode.org/
  • 11. 11 org mode Example objective function min x z = n i=1 x4 i + x3 i − 2x2 i x ∈ [a, b] ∩ Rn
  • 12. 12 org mode Plot of objective function
  • 13. 13 org mode Tangling Create an octave file with the objective function using tangling: function [ z g ] = f ( x ) z = sum( x .^4 + x .^3 − 2∗x . ^ 2 ) ; g = 0; % unconstrained endfunction
  • 14. 14 org mode Code segments Specify the parameters for the optimisation problem: n = 2; x0 = rand (n , 1 ) ; a = −2∗ones (n , 1 ) ; b = 2∗ones (n , 1 ) ;
  • 15. 15 org mode Bringing bits together The code to include the problem setup directly and solve the problem: clear format short n = 2; x0 = rand (n , 1 ) ; a = −2∗ones (n , 1 ) ; b = 2∗ones (n , 1 ) ; [ x y ] = strawberry ( x0 , a , b , @f , 10 , 10); [ x ; y ] ’
  • 16. 16 org mode Plotting results Using data in table of results on previous slide:
  • 17. 17 org mode Processing results Statistical analysis of results obtained above: Statistic Value Best -5.666 Average -5.582 Worst -5.255 Standard deviation 0.094
  • 18. 18 org mode Outlines Example (a recent paper): Can show, hide, and move individual sub-trees.
  • 19. 19 org mode Publishable output org will export to LATEX (and hence to PDF) or ODT (MS Word compatible).
  • 20. 20 org mode Project management Support for tasks, scheduling, appointments: [3/4] prepare and give presentation on literate programming collect images write slides book hotel give presentation
  • 21. 21 org mode Revision control A research project is a long term activity comprised of many individual tasks. Revision control should (must) be an integral element of project management. Think track changes but on steroids and which works for data as well. Excellent tools exist: git, mercurial, subversion, . . .
  • 22. 22 org mode Example of revision control
  • 23. 23 Conclusions Emacs & org Single tool for writing, coding, data manipulation, data provenance, dissemination, and project management.
  • 24. 24 Conclusions Testimonial I By the age of 35 you should have realized that Emacs is the One True Editor and should have embraced it. If that’s not the case - your life so far has been completely wasted. @bbatsov, 04:02 pm May 20, 2018
  • 25. 25 Conclusions Testimonial II The advantages of plain text are hard to overstate, as is the advantage of having everything from plot notes to research material in a single (large) file under version control. And building up a novel from an outline is a natural process with org-mode. Bob Newell, emacs.help newsgroup, 2018-05-30.
  • 26. 26 Conclusions Links Emacs https://www.gnu.org/software/emacs/ Complete computing environment http://doc.rix.si/cce/cce.html org mode https://orgmode.org/ reproducible research https://reproducibleresearch.net/links/ blog reproducible research for management