Lovelace's Note G Program in C

Bluestein1 pts0 comments

Lovelace's Note G Program in C · GitHub

/" data-turbo-transient="true" />

Skip to content

-->

Search Gists

Search Gists

Sign in

Sign up

You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.

Dismiss alert

{{ message }}

Instantly share code, notes, and snippets.

sinclairtarget/bernoulli.c

Created<br>August 17, 2018 20:22

Show Gist options

Download ZIP

Star

131<br>(131)

You must be signed in to star a gist

Fork

(5)

You must be signed in to fork a gist

Embed

Select an option

Embed<br>Embed this gist in your website.

Share<br>Copy sharable link for this gist.

Clone via HTTPS<br>Clone using the web URL.

No results found

Learn more about clone URLs

Clone this repository at &lt;script src=&quot;https://gist.github.com/sinclairtarget/ad18ac65d277e453da5f479d6ccfc20e.js&quot;&gt;&lt;/script&gt;

" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-0d5fd7ca-6ec1-4af8-8c47-5e6509bf130e" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-sized-down" />

Save sinclairtarget/ad18ac65d277e453da5f479d6ccfc20e to your computer and use it in GitHub Desktop.

Embed

Select an option

Embed<br>Embed this gist in your website.

Share<br>Copy sharable link for this gist.

Clone via HTTPS<br>Clone using the web URL.

No results found

Learn more about clone URLs

Clone this repository at &lt;script src=&quot;https://gist.github.com/sinclairtarget/ad18ac65d277e453da5f479d6ccfc20e.js&quot;&gt;&lt;/script&gt;

" readonly="readonly" data-autoselect="true" data-target="primer-text-field.inputElement " aria-describedby="validation-d492c1a9-c65f-4e3c-a8fa-17d633d72563" class="form-control FormControl-monospace FormControl-input FormControl-small rounded-left-0 rounded-right-0 border-right-0" type="text" name="gist-share-url-original" />

Save sinclairtarget/ad18ac65d277e453da5f479d6ccfc20e to your computer and use it in GitHub Desktop.

Download ZIP

Lovelace's Note G Program in C

Raw

bernoulli.c

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.<br>Learn more about bidirectional Unicode characters

Show hidden characters

#include

/*

* Calculates what Ada Lovelace labeled "B7", which today we would call the 8th

* Bernoulli number.

*/

int main(int argc, char* argv[])

// ------------------------------------------------------------------------

// Data

// ------------------------------------------------------------------------

float v1 = 1; // 1

float v2 = 2; // 2

float v3 = 4; // n

// ------------------------------------------------------------------------

// Working Variables

// ------------------------------------------------------------------------

float v4 = 0;

float v5 = 0;

float v6 = 0; // Factors in the numerator

float v7 = 0; // Factors in the denominator

float v8 = 0;

float v10 = 0; // Terms remaining count, basically

float v11 = 0; // Accumulates v6 / v7

float v12 = 0; // Stores most recent calculated term

float v13 = 0; // Accumulates the whole result

// ------------------------------------------------------------------------

// Result Variables

// ------------------------------------------------------------------------

float v21 = 1.0f / 6.0f; // B1

float v22 = -1.0f / 30.0f; // B3

float v23 = 1.0f / 42.0f; // B5

float v24 = 0; // B7, not yet calculated

// ------------------------------------------------------------------------

// Calculation

// ------------------------------------------------------------------------

// ------- A0 -------

/* 01 */ v4 = v5 = v6 = v2 * v3; // 2n

/* 02 */ v4 = v4 - v1; // 2n - 1

/* 03 */ v5 = v5 + v1; // 2n + 1

// In Lovelace's diagram, the below appears as v5 / v4, which is incorrect.

/* 04 */ v11 = v4 / v5; // (2n - 1) / (2n + 1)

/* 05 */ v11 = v11 / v2; // (1 / 2) * ((2n - 1) / (2n + 1))

/* 06 */ v13 = v13 - v11; // -(1 / 2) * ((2n - 1) / (2n + 1))

/* 07 */ v10 = v3 - v1; // (n - 1), set counter?

// A0 = -(1 / 2) * ((2n - 1) / (2n + 1))

// ------- B1A1 -------

/* 08 */ v7 = v2 + v7; // 2 + 0, basically a MOV instruction

/* 09 */ v11 = v6 / v7; // 2n / 2

/* 10 */ v12 = v21 * v11; // B1 * (2n / 2)

// A1 = (2n / 2)

// B1A1 = B1 * (2n / 2)

// ------- A0 + B1A1 -------

/* 11 */ v13 = v12 + v13; // A0 + B1A1

/* 12 */ v10 = v10 - v1; // (n - 2)

// On the first loop this calculates B3A3 and adds it on to v13.

// On the second loop this calculates B5A5 and adds it on.

while (v10 > 0)

// ------- B3A3, B5A5 -------

while (v6 > 2 * v3 - (2 * (v3 - v10) - 2))

{ // First Loop:

/* 13 */ v6 = v6 - v1; // 2n - 1

/* 14 */ v7 = v1 + v7; // 2 + 1

/* 15...

float gist clone data embed formcontrol

Related Articles