In this tutorial, I will walk you through the process of downloading and analyzing the "Structure of Euclid' s Elements" data from the Wolfram Data Repository . We will cover how to access the dataset, count the number of theorems and definitions per book, and export the data to CSV files for further use .

Data downloading

The dataset is stored in the Wolfram Data Repository. The most efficient way to access it is by connecting directly through Wolfram Language. Here’s how to load the data:
In[]:=
(*LoadingtheresourcedatafromWolframDataRepository*)​​data=ResourceData[ResourceObject["Structure of Euclid's Elements"]];
You can confirm that the dataset contains multiple books by checking the available entries:
In[]:=
(*Checkhowmanybooksareavailable*)​​data["Book"]
Out[]=
Missing[KeyAbsent,Book]

Exploring the Dataset

Once you’ve confirmed the structure, you can index each book’s theorems and definitions. This will allow us to quantify how many of each are included in the dataset.
​
The following code initializes variables to store the counts of definitions and theorems for each book, looping through each book to populate these variables:
(*Initializevariablestostorethenumberofdefinitionsandtheoremsforeachbook*)definitionsCountPerBook=<||>;​​theoremsCountPerBook=<||>;​​​​(*Totalnumberofbooks*)​​totalBooks=13;​​​​(*Setreasonablemaxboundsfordefinitionsandtheorems*)​​maxDefinitions=200;​​maxTheorems=200;​​​​(*Loopthrougheachbookandcountdefinitionsandtheorems*)​​Do[(*Countdefinitionsforthisbook*)definitionCount=0;​​Do[If[Head[data[<|"Book"->book,"Definition"->i|>]]=!=Missing,definitionCount++],{i,maxDefinitions}];​​definitionsCountPerBook[book]=definitionCount;​​(*Counttheoremsforthisbook*)theoremCount=0;​​Do[If[Head[data[<|"Book"->book,"Theorem"->i|>]]=!=Missing,theoremCount++],{i,maxTheorems}];​​theoremsCountPerBook[book]=theoremCount;,{book,1,totalBooks}]
You can then display the counts of definitions and theorems for each book:
(*Displaythecountsfordefinitionsandtheoremsforeachbook*)​​definitionsCountPerBook​​theoremsCountPerBook
Out[]=
123,22,311,47,518,65,722,80,90,100,1128,120,130
Out[]=
148,214,337,416,525,633,739,827,936,10115,1139,1218,1318

Exporting Data to CSV

To make further analysis easier, we can export the theorems, proofs, and definitions to CSV files.
​
The code below collects theorems and definitions from each book and exports them into separate CSV files:
In[]:=
(*Initializeliststostoretheorems,proofs,anddefinitions*)theoremProofData={};​​definitionData={};​​​​(*AddheadersfortheCSVfiles*)​​AppendTo[theoremProofData,{"question","proof"}];​​AppendTo[definitionData,{"Definition"}];​​​​(*Loopthrougheachbook*)​​Do[(*Collecttheoremsandtheirproofs*)Do[theorem=data[<|"Book"->book,"Theorem"->i|>];​​If[Head[theorem]=!=Missing,AppendTo[theoremProofData,{theorem["Text"],theorem["Proof"]}]],{i,theoremsCountPerBook[book]}];​​(*Collectdefinitions*)Do[definition=data[<|"Book"->book,"Definition"->i|>];​​If[Head[definition]=!=Missing,AppendTo[definitionData,{definition["Text"]}]],{i,definitionsCountPerBook[book]}];,{book,1,totalBooks}]​​​​(*ConvertdatatoCSVformatandexport*)​​​​(*Exporttheorem_proof.csv*)​​Export["theorem_proof.csv",theoremProofData]​​​​(*Exportdefinition.csv*)​​Export["definition.csv",definitionData]
Out[]=
theorem_proof.csv
Out[]=
definition.csv
Once the files are exported, you can open the directory containing the CSV files using:
In[]:=
SystemOpen[DirectoryName[AbsoluteFileName["definition.csv"]]]

Conclusion

This tutorial demonstrates how to download and structure data from the “Structure of Euclid’s Elements” dataset using Wolfram Language. You can now analyze this dataset or use the exported CSV files in other applications for deeper insights.
​
Feel free to modify the script according to your own project requirements!
​
This version explains each step clearly, adds context, and provides smooth transitions between the sections.

CITE THIS NOTEBOOK

How to access and analyze Euclid's geometry theorems from the Wolfram data repository​
by ZHENZHAO TU​
Wolfram Community, STAFF PICKS, September 26, 2024
​https://community.wolfram.com/groups/-/m/t/3284006