A Gentle Introduction to
PythonTEX Andrew Mertz, William Slough Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Gentle Introduction to PythonTEX
Andrew Mertz
William Slough
Mathematics and Computer Science Department
Eastern Illinois University
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Python Overview
◮
General purpose, high-level programming language
◮
Multi-paradigm: object-oriented, imperative, functional
◮
Comprehensive standard library
◮
Origins from late 1989
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Recent Question on TEX Stack Exchange
“I would like to write a L
A
TEX script that produces all the prime
numbers between the numbers
n
and
m
, where
n
<
m
. How can I do
this? I feel it should not be that hard, but I cannot seem to program
it.”
— Kevin
†
†
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
From The TEXBook, Page 218 (1984)
The first 30 prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,
37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107,
109, and 113. You may not find this fact very startling; but you may
be surprised to learn that the previous sentence was typeset by saying
The first thirty prime numbers are \primes{30}.
TEX did all the calculation by expanding the
primes
macro, so the
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Knuth’s Code,
-worthy
\newif\ifprime \newif\ifunknown % boolean variables
\newcount\n \newcount\p \newcount\d \newcount\a % integer variables
\def\primes#1{2,~3% assume that #1 is at least 3
\n=#1 \advance\n by-2 % n more to go
\p=5 % odd primes starting with p
\loop\ifnum\n>0 \printifprime\advance\p by2 \repeat}
\def\printp{, % we will invoke \printp if p is prime
\ifnum\n=1 and~\fi % and precedes the last value
\number\p \advance\n by -1 }
\def\printifprime{\testprimality \ifprime\printp\fi}
\def\testprimality{{\d=3 \global\primetrue
\loop\trialdivision \ifunknown\advance\d by2 \repeat}}
\def\trialdivision{\a=\p \divide\a by\d
\ifnum\a>\d \unknowntrue\else\unknownfalse\fi
\multiply\a by\d
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
David Carlisle’s Response
\makeatletter
\def\primes#1#2{{%
\def\comma{\def\comma{, }}%
\count@\@ne\@tempcntb#2\relax\@curtab#1\relax
\@primes}}
\def\@primes{\loop\advance\count@\@ne
\expandafter\ifx\csname p-\the\count@\endcsname\relax
\ifnum\@tempcntb<\count@\else
\ifnum\count@<\@curtab\else\comma\the\count@\fi\fi\else\repeat
\@tempcnta\count@\loop\advance\@tempcnta\count@
\expandafter\let\csname p-\the\@tempcnta\endcsname\@ne
\ifnum\@tempcnta<\@tempcntb\repeat
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Karl Koeller’s Response
A solution using the
\pgfmathisprime
macro provided by Alain
Matthes’
tkz-euclide
package:
\usepackage{tkz-euclide}
\newif\ifcomma
\newcommand{\primes}[2]{%
\commafalse%
\foreach\numb in {#1,...,#2}{%
\pgfmathisprime{\numb}%
\ifnum\pgfmathresult=1
\ifcomma, \numb\else\numb\global\commatrue\fi%
\fi%
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Can PythonTEX Make This Simpler?
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Evaluating Expressions With
\py
The macro
\py{expression}
evaluates a Python expression and
typesets its
value
.
Did you know that $2^{65} = \py{2**65}$?
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Evaluating Expressions With
\pyc
The macro
\pyc{expression}
evaluates a Python expression and
typesets anything that it
prints
.
Did you know that $2^{65} = \pyc{print(2**65)}$?
Did you know that 2
65
= 36893488147419103232?
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A More Complex Example Using
\pyc
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Charleston, Illinois USA
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables With
pycode
\begin{pycode}
print(r"\begin{tabular}{c|c}")
print(r"$m$ & $2^m$ \\ \hline")
print(r"%d & %d \\" % (1, 2**1))
print(r"%d & %d \\" % (2, 2**2))
print(r"%d & %d \\" % (3, 2**3))
print(r"%d & %d \\" % (4, 2**4))
print(r"\end{tabular}")
\end{pycode}
\begin{tabular}{c|c}
$m$ & $2^m$ \\ \hline
1 & 2 \\
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables With
pycode
\begin{pycode}
print(r"\begin{tabular}{c|c}")
print(r"$m$ & $2^m$ \\ \hline")
print(r"%d & %d \\" % (1, 2**1))
print(r"%d & %d \\" % (2, 2**2))
print(r"%d & %d \\" % (3, 2**3))
print(r"%d & %d \\" % (4, 2**4))
print(r"\end{tabular}")
\end{pycode}
m
2
m
1
2
2
4
3
8
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables With a Loop
\begin{pycode}
lo, hi = 1, 6
print(r"\begin{tabular}{c|c}")
print(r"$m$ & $2^m$ \\ \hline")
for m in range(lo, hi + 1):
print(r"%d & %d \\" % (m, 2**m))
print(r"\end{tabular}")
\end{pycode}
m
2
m
1
2
2
4
3
8
4
16
5
32
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Defining a Function
\begin{pycode}
def fib(n):
# nth Fibonacci value
a, b = 0, 1
for i in range(n):
a, b = b, a + b
return a
\end{pycode}
Did you know that $F_{10} = \py{fib(10)}$?
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Sessions
py
,
pyc
, and
pycode
all have an optional
session
argument.
This argument determines the name of the Python session in which
the code is executed.
Sessions with different names may be executed in parallel providing a
speedup.
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Introducing
pythontexcustomcode
\begin{pythontexcustomcode}{py}
def makeTable(lo, hi):
print(r"\begin{tabular}{c|c}")
print(r"$m$ & $2^m$ \\ \hline")
for m in range(lo, hi + 1):
print(r"%d & %d \\" % (m, 2**m))
print(r"\end{tabular}")
\end{pythontexcustomcode}
The
pythontexcustomcode
environment evaluates the code block
at the start of each “session” – which makes it a great place to
define well-tested functions.
\begin{pythontexcustomcode}{py}
python code block
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables in Multiple Sessions
\pyc[table1]{makeTable(1, 4)}
m
2
m
1
2
2
4
3
8
4
16
\pyc[table2]{makeTable(4, 10)}
m
2
m
4
16
5
32
6
64
7
128
8
256
9
512
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables From a Function
\begin{pythontexcustomcode}{py}
def makeTableFromFunction(lo, hi, funct, label):
print(r"\begin{tabular}{c|c}")
print(r"$m$ & %s \\ \hline" % label)
for m in range(lo, hi + 1):
print(r"%d & %d \\" % (m, funct(m)))
print(r"\end{tabular}")
\end{pythontexcustomcode}
\pyc{makeTableFromFunction(7, 11, fib, "$F_{m}$")}
m
F
m
7
13
8
21
9
34
10
55
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables From a Library Function
Python excels in the quantity and quality of its modules.
Modules make additional functions available. To use them, the
corresponding module needs to be imported.
\begin{pythontexcustomcode}{py}
import math
\end{pythontexcustomcode}
\pyc{makeTableFromFunction(30, 33, math.factorial, "$m!$")}
m
m
!
30
265252859812191058636308480000000
31
8222838654177922817725562880000000
32
263130836933693530167218012160000000
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Generating Tables From a Library Function
With the import statement the module name is needed each time a
member of the module is used.
To avoid this, a
from import
statement can be used.
This can shadow other functions and should be used with care.
\begin{pythontexcustomcode}{py}
from math import factorial
\end{pythontexcustomcode}
\pyc{makeTableFromFunction(30, 33, factorial, "$m!$")}
m
m
!
30
265252859812191058636308480000000
31
8222838654177922817725562880000000
32
263130836933693530167218012160000000
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Remember Kevin?
\begin{pythontexcustomcode}{py}
from sympy import prime
def generatePrimes(n):
# Assume n >= 3
for i in range(1, n):
print("%d, "
% prime(i))
print("and %d%%" % prime(n))
\end{pythontexcustomcode}
The first 30 primes are \pyc{generatePrimes(30)}.
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Processing PythonTEX Files
1. pdfL
A
TEX
2. pythonTEX
3. pdfL
A
TEX
my.tex
my.pytxcode
pythontex-files-my
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Symbolic Mathematics With Sympy
>>>
from
sympy
import
*
>>>
var("x, y")
# Define symbolic variables
(x, y)
>>>
z
=
(x
+
y)
**3
# Define an expression
>>>
z
# Display z
(x + y)**3
>>>
expand(z)
# Display the expansion of z
x**3 + 3*x**2*y + 3*x*y**2 + y**3
>>>
latex(expand(z))
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Expanding Binomials
\begin{pycode}
from sympy import *
var("x, y")
binomials = []
for m in range(3, 6):
binomials.append((x + y)**m)
print(r"\begin{align*}")
for expr in binomials:
print(r"%s &= %s\\" % (latex(expr), latex(expand(expr))))
print(r"\end{align*}")
\end{pycode}
(
x
+
y
)
3
=
x
3
+ 3
x
2
y
+ 3
xy
2
+
y
3
(
x
+
y
)
4
=
x
4
+ 4
x
3
y
+ 6
x
2
y
2
+ 4
xy
3
+
y
4
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Little Bit of Calculus
\begin{pycode}
functions = [sin(x), cos(x), tan(x)]
print(r"\begin{align*}")
for f in functions:
d = Derivative(f, x)
print(latex(d) + "&=" + latex(d.doit()) + r"\\")
print(r"\end{align*}")
\end{pycode}
d
dx
sin (
x
) = cos (
x
)
d
dx
cos (
x
) =
−
sin (
x
)
d
dx
tan (
x
) = tan
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Little Bit More
\begin{pycode}
functions = [sin(x), cos(x), tan(x)]
print(r"\begin{align*}")
for f in functions:
i = Integral(f, x)
print(latex(i) + "&=" + latex(i.doit()) + r"\\")
print(r"\end{align*}")
\end{pycode}
Z
sin (
x
)
dx
=
−
cos (
x
)
Z
cos (
x
)
dx
= sin (
x
)
Z
tan (
x
)
dx
=
−
1
2
log sin
2
(
x
)
−
1
A Gentle Introduction to PythonTEX Andrew Mertz, William Slough Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Stirling’s Triangle
Stirling’s Triangle for Subsets
n
n
0
n
1
n
2
n
3
n
4
n
5
n
6
n
7
n
8
0
1
1
0
1
2
0
1
1
3
0
1
3
1
4
0
1
7
6
1
5
0
1
15
25
10
1
6
0
1
31
90
65
15
1
7
0
1
63
301
350
140
21
1
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Stirling’s Triangle (code excerpt)
from sympy.functions.combinatorial.numbers import *
for n in range(numberOfRightHandColumns):
print("%d" % n)
for k in range(n + 1):
A Gentle Introduction to PythonTEX Andrew Mertz, William Slough Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Plotting With Matplotlib
0
1
2
3
4
5
time (s)
−
0
.
8
−
0
.
6
−
0
.
4
−
0
.
2
0
.
0
0
.
2
0
.
4
0
.
6
0
.
8
1
.
0
v
o
lt
a
g
e
(m
V
)
y
= cos(2
πt
)
e
−
t
Damped exponential decay
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Plot Details, Part 1
\begin{pycode}
from pylab import *
# Define f(t), the desired function to plot
def f(t):
return cos(2 * pi * t) * exp(-t)
# Generate the points (t_i, y_i) to plot
t = linspace(0, 5, 500)
y = f(t)
# Begin with an empty plot, 5 x 3 inches
clf()
figure(figsize=(5, 3))
# Use TeX fonts
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Plot Details, Part 2
# Generate the plot with annotations
plot(t, y)
title("Damped exponential decay")
text(3, 0.15, r"$y = \cos(2 \pi t) e^{-t}$")
xlabel("time (s)")
ylabel("voltage (mV)")
# Save the plot as a PDF file
savefig("myplot.pdf", bbox_inches="tight")
# Include the plot in the current LaTeX document
print(r"\begin{center}")
print(r"\includegraphics[width=0.85\textwidth]{myplot.pdf}")
print(r"\end{center}")
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Simple Access of a Web Service
Many powerful and freely available web services can be accessed
though the libraries of Python.
Python has excellent JSON, XML and networking libraries.
The first web service we will use is Google’s Geocoding API.
Geocoding is the process of converting an address into geographic
coordinates such as latitude and longitude.
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Using Google’s Geocoding Service
from urllib2 import urlopen
from urllib import urlencode
import json
def findLatlong(address):
# Build the data needed to call the Goggle API
query = {"address": address, "sensor": "false"}
data = urlencode(query)
url = "http://maps.googleapis.com/maps/api/geocode/json?"
url += data
# Fetch and parse
result = json.load(urlopen(url))
latlong = result["results"][0]["geometry"]["location"]
return (latlong["lat"], latlong["lng"])
The latitude and longitude of Tokyo is \py{findLatlong("Tokyo")}
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Executing a Subprocess
Python can run other programs and use their output.
Here we use
webkit2png
to render a web page as an image that is
included in the document.
import subprocess
def showWebpage(url, filename):
subprocess.call(["webkit2png", "-o", filename,
"-F", "javascript",
"-w", "5",
url])
print(r"\begin{center}")
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
How the Maps Were Made (pseudocode)
def showGoogleMap(address, zoomlevel):
# Find the latitude and longitude of the address
# Build a web page with the JavaScript needed to load
# a Google Map at the given location and zoom level
# Save the web page to a temporary file
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Issues
◮
PythonTEX adds significant processing time
Appropriate use of sessions can reduce this time, but
there is still a large overhead.
◮
Debugging Python code within TEX is difficult
Test complex Python code outside of TEX first
◮
TEX macros that have arguments generated by Python fail on
first processing step
Add such TEX macros from within Python
◮
Use parentheses for print statements:
print(x)
.
◮
Be clear of the differences between
\py
and
\pyc
.
◮
When using Beamer use the frame option
fragile=singleslide
if able.
◮
Be skeptical of SymPy results.
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
References
Python:
python.org
SciPy:
scipy.org
PythonTEX(Geoffrey Poore):
www.ctan.org/pkg/pythontex
Anaconda(Python distribution):
store.continuum.io/cshop/anaconda
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
How to Shorten a Long URL
from urllib2 import Request
def shortenURL(longURL):
# Build the data needed to call the Goggle API
url = "https://www.googleapis.com/urlshortener/v1/url"
query = {"longUrl": longURL, "key": googleAPIKey}
data = json.dumps(query)
request = Request(url, data,
{"Content-Type": "application/json"})
# Fetch and parse
result = json.load(urlopen(request))
shortURL = result["id"]
print(r"\url{%s}%%" % shortURL)
Here is a short url \pyc{shortenURL(
"http://mirror.jmu.edu/pub/CTAN/macros/latex/contrib/pythontex/pythontex.pdf"
)}
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Mail Merge
Address:
to field
Hello
name field
, I just wanted to say hello.
to,name
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples
Mail Merge
\begin{pythontexcustomcode}{py}
import csv
def mailMerge(filename, texcommand):
csvFile = open(filename, "r")
csvReader = csv.DictReader(csvFile)
for row in csvReader:
setCommand = r"\def\mail%s{%s}"
for keyValuePair in row.items():
print(setCommand % keyValuePair)
print(r"%s\vfill" % texcommand)
\end{pythontexcustomcode}
\newcommand{\mailBody}{
Address: \mailto\\
A Gentle Introduction to
PythonTEX
Andrew Mertz, William Slough
Overview A Question of Primes Introduction to PythonTEX Mathematics with Sympy Plots with matplotlib Web Services Conclusions Extra Examples