@@ -20,8 +20,8 @@ <h1>Herbie Tutorial</h1>
2020 </ header >
2121
2222 < p >
23- < a href ="../../ "> Herbie</ a > rewrites floating point expressions to
24- make them more accurate. Floating point arithmetic is
23+ < a href ="../../ "> Herbie</ a > rewrites floating- point expressions to
24+ make them more accurate. Floating- point arithmetic is
2525 < a href ="error.html "> inaccurate</ a > ; even 0.1 + 0.2 ≠ 0.3 in
2626 floating-point. Herbie helps find and fix these mysterious
2727 inaccuracies.
@@ -44,10 +44,13 @@ <h2>Giving Herbie expressions</h2>
4444
4545 < p >
4646 After a brief wait, your web browser should open and show you
47- Herbie's main window. The most important part of the page is this
48- bit:
47+ Herbie's main window. Re-check the
48+ < a href ="installing.html "> installation steps</ a >
49+ if this doesn't occur.
4950 </ p >
5051
52+ < p > The most important part of the page is this bit:</ p >
53+
5154 < figure >
5255 < img width ="100% " src ="web-input.png " alt ="The program input field in the Herbie web UI. "/>
5356 </ figure >
@@ -56,7 +59,7 @@ <h2>Giving Herbie expressions</h2>
5659 Let's start by just looking at an example of Herbie running.
5760 Click "Show an example". This will pre-fill the expression
5861 < kbd > sqrt(x + 1) - sqrt(x)</ kbd >
59- with < code > x</ code > ranging from to < kbd > 0</ kbd > and < kbd > 1.79e308</ kbd > .
62+ with < code > x</ code > ranging from < kbd > 0</ kbd > to < kbd > 1.79e308</ kbd > .
6063 </ p >
6164
6265 < figure >
@@ -81,6 +84,10 @@ <h2>Giving Herbie expressions</h2>
8184 < img width ="100% " src ="report-large.png " alt ="Statistics and error measures for this Herbie run. " />
8285 </ figure >
8386
87+ < p > Note that Herbie's algorithm is randomized, so you likely won't
88+ see the exact same thing; you might see more or fewer alternatives,
89+ and they might be more or less accurate and fast.</ p >
90+
8491 < p >
8592 Here, you can see that Herbie's most accurate alternative has an
8693 accuracy of 99.7%, much better than the initial program's 53.2%,
@@ -93,6 +100,18 @@ <h2>Giving Herbie expressions</h2>
93100 tutorial let's move on to a more realistic example.
94101 </ p >
95102
103+ < p >
104+ Herbie measures accuracy by comparing a program's result against
105+ the exact answer calculated using high-precision arithmetic. The difference
106+ between these two is then measured in "bits of error" which
107+ counts how many of the most significant bits that the
108+ approximate and exact result agree on. This error is then
109+ averaged across many different sample inputs to determine
110+ the program's overall accuracy. Herbie's
111+ < a href ="error.html "> error documentation</ a >
112+ describes the process in more detail.
113+ </ p >
114+
96115 < h2 > Programming with Herbie</ h2 >
97116
98117 < p >
@@ -128,7 +147,7 @@ <h2>Finding the problematic expression</h2>
128147
129148 < p >
130149 For our example, let's start
131- in < a href ="https://github.com/josdejong/mathjs/tree/master /lib/function "> < code > lib/function/</ code > </ a > .
150+ in < a href ="https://github.com/josdejong/mathjs/tree/da306e26ed34272db44e35f07a3b015c0155d99a /lib/function "> < code > lib/function/</ code > </ a > .
132151 This directory contains many subdirectories; each file in each
133152 subdirectory defines a collection of mathematical functions. We're
134153 interested in the complex square root function, which is defined in
@@ -203,7 +222,7 @@ <h2>Converting problematic code to Herbie input</h2>
203222 < h2 > Herbie's results</ h2 >
204223
205224 < p > Herbie will churn for a few seconds and produce a results page.
206- In this case, Herbie found 4 alternatives, and we're interested in
225+ In this case, Herbie found 6 alternatives, and we're interested in
207226 the most accurate one, which should have an
208227 < a href ="error.html "> accuracy of 84.6%:</ a > </ p >
209228
@@ -219,11 +238,12 @@ <h2>Herbie's results</h2>
219238 < img width ="100% " src ="problematic-xim.png " />
220239 </ figure >
221240
222- < p > The drop in accuracy once < code > xim</ code > is bigger than
223- about < code > 1e150</ code > really stands out, but you can also see
224- that Herbie's alternative more accurate for smaller < code > xim</ code >
225- values, too. You can also change the graph to plot accuracy
226- versus < code > xre</ code > instead:</ p >
241+ < p > There's a really obvious drop in accuracy once < code > xim</ code >
242+ gets bigger than about < code > 1e150</ code >
243+ (due to < a href ="https://en.wikipedia.org/wiki/Floating-point_arithmetic#Dealing_with_exceptional_cases "> floating-point overflow</ a > ),
244+ but you can also see that Herbie's alternative is more accurate
245+ for smaller < code > xim</ code > values, too. You can also change the
246+ graph to plot accuracy versus < code > xre</ code > instead:</ p >
227247
228248 < figure >
229249 < img width ="100% " src ="problematic-xre.png " />
@@ -241,10 +261,9 @@ <h2>Herbie's results</h2>
241261 < img width ="100% " src ="problematic-pareto-table.png " />
242262 </ figure >
243263
244- < p > Herbie's algorithm is randomized, so you likely won't see the
245- exact same thing; you might see more or fewer alternatives, and they
246- might be more or less accurate and fast. That said, the most
247- accurate alternative should be pretty similar.</ p >
264+ < p > Remember that Herbie's algorithm is randomized, so you likely
265+ won't see the exact same thing. That said, the most accurate
266+ alternative should be pretty similar.</ p >
248267
249268 < p > That alternative itself is shown lower down on the page:</ p >
250269
@@ -255,10 +274,11 @@ <h2>Herbie's results</h2>
255274 < p > A couple features of this alternative stand out immediately.
256275 First of all, Herbie inserted an < code > if</ code > statement.
257276 This < code > if</ code > statement handles a phenomenon known as
258- cancellation, and is part of why Herbie's alternative is more
259- accurate. Herbie also replaced the square root operation with
260- the < code > hypot</ code > function, which computes distances more
261- accurately than a direct square root operation.</ p >
277+ < a href ="https://en.wikipedia.org/wiki/Catastrophic_cancellation "> cancellation</ a > ,
278+ and is part of why Herbie's alternative is more accurate. Herbie
279+ also replaced the square root operation with the < code > hypot</ code >
280+ function, which computes distances more accurately than a direct
281+ square root operation.</ p >
262282
263283 < p > If you want to see more about how Herbie derived this result, you
264284 could click on the word "Derivation" to see a detailed, step-by-step
@@ -311,11 +331,11 @@ <h2>Using Herbie's alternatives</h2>
311331 gets better, you can re-run it on this original expression to see if
312332 it comes up with improvements in accuracy.</ p >
313333
314- < p > By the way , for some languages, including JavaScript, you can use
315- the drop-down in the top-right corner of the alternative block to
316- translate Herbie's output to that language. However, you will
317- still probably need to refactor and modify the results to fit your
318- code structure, just like here.</ p >
334+ < p > Additionally , for some languages (e.g. JavaScript, Python,
335+ Wolfram, etc) you can use the drop-down in the top-right corner
336+ of the alternative block to translate Herbie's output to that
337+ language. However, you will still probably need to refactor and
338+ modify the results to fit your code structure, just like here.</ p >
319339
320340 < h2 > Next steps</ h2 >
321341
0 commit comments