Introduction

In this notebook we ingest the text of the US Constitution , [Wk1], and use it as a part of different Large Language Model (LLM) requests, like, summaries and most important statements.
We also use LLM to derive analogies with the game "Plants vs Zombies" , [Wk2].
The visualization of those analogies is an interesting task, and we apply OpenAI's model DALL-E 3 to generate (mostly) relevant images. (Following [AA2, MTn1].)
At this point, the idea to apply LLMs to the US Constitution should have occurred in many (human) heads. For example, see the GitHub repository "ConstitutionGPT" , [VD7r1]. (Also see these search results.)
The US Constitution is popular, well known document, hence, it is expected LLMs to be able to "converse about it" without providing its full text in the prompts. Nevertheless, below we do ingest the full text of the US Constitution and include in our LLM interactions. That makes the presented LLM workflows (fairly) text independent.
Remark: Very similar LLM workflows are presented in the article "LLM aids for processing of the first Carlson-Putin interview" , [AA3, AAn2].
Remark: Most recent ChatGPT models fairly often put their generated output into Markdown format. Below the Markdown outputs are converted into Mathematica text cells -- in some cases programmatically, in others manually. We did not include the conversion codes for exposition brevity. This also means, that some discrepancies are observed between corresponding outputs and "nicely formatted" text under them.

Setup

Here we load certain packages and define a text statistics function:
Here we define a text statistics function:
In[]:=
Clear[TextStats];​​TextStats[t_String]:=AssociationThread[{"Chars","Words","Lines"},{StringLength[t],Length@TextWords[t],Length@StringSplit[t,"\n"]}];​​TextStats[t_?AssociationQ]:=TextStats[ToString[t]];
Here we derive a configuration object for accessing OpenAI's LLM service with one of its latest ChatGPT models:
In[]:=
conf=LLMConfiguration[<|"Model"->"gpt-4-turbo-preview","MaxTokens"->4096,"Temperature"->0.2|>]
Out[]=
LLMConfiguration
Model: ServiceAutomatic,Namegpt-4-turbo-preview

(Additional setup code is given in the last section.)

Get text

Here we make an LLM request for the authoritative source of the USA constitution text:
In[]:=
LLMSynthesize["Give the most athoritative of URL for US constitution in plain text."]
Out[]=
The plain text version of the US Constitution can be found on the official website of the National Archives:​https://www.archives.gov/founding-docs/constitution-transcript
Here we get the HTML text of the US constitution transcript from the "National Archives" site :
In[]:=
url0="https://www.archives.gov/founding-docs/constitution-transcript";​​url1="https://www.archives.gov/founding-docs/bill-of-rights-transcript";​​txtUSACon0=Import[url0,"Source"];​​txtUSACon0=StringReplace[txtUSACon0,WhitespaceCharacter..->"\n"];​​Print["Constitution transcript : ",TextStats[txtUSACon0]];​​txtUSACon1=Import[url1,"Source"];​​txtUSACon1=StringReplace[txtUSACon1,WhitespaceCharacter..->"\n"];​​Print["Bill of Rights transcript : ",TextStats[txtUSACon1]];
Constitution transcript : Chars65587,Words7444,Lines6634
Bill of Rights transcript : Chars41549,Words3784,Lines3372
Those variables with HTML texts, though. Instead of trying to figure out how to use WL for stripping HTML code, we can just find plain text files of the US constitution from other sources. Here we get the text of the US constitution from https://www.usconstitution.net :
In[]:=
url="https://www.usconstitution.net/const.txt";​​txtUSACon=Import[url,"Text"];​​txtUSACon=StringReplace[txtUSACon,WhitespaceCharacter..->""];​​txtUSACon=StringReplace[txtUSACon,StartOfString~~Shortest[__]~~(WhitespaceCharacter|"")~~("We the People of the United States"...)->""];​​TextStats[txtUSACon]
Out[]=
Chars44946,Words7637,Lines7652
Here we get the US constitution content in JSON format from [MBr1] and then convert into a WL data structure:
In[]:=
txtUSAConJSON
In[]:=
urlJSON="https://raw.githubusercontent.com/markbiek/constitution.json/master/constitution.json";​​txtUSAConJSON=Association@Import[urlJSON,"JSON"];​​TextStats[txtUSAConJSON]
Out[]=
Chars259345,Words7501,Lines18
Remark: The repository [MBr1] refers to https://www.usconstitution.net/const.txt as a source to derive the JSON file from.
In[]:=
txtUSAConJSON//Keys
Out[]=
{preamble,articles,signatories,amendments}

Summaries

Whole document

Here is summary of the whole document:
In[]:=
LLMSynthesize[{"Summarize the document in less than 300 words:",txtUSACon},LLMEvaluator->conf]
The document is the Constitution of the United States, which outlines the framework for the federal government, including its three branches: legislative, executive, and judicial. It begins with the Preamble, stating the purpose of the document to ensure justice, peace, defense, welfare, and liberty for the nation and its future generations.
Article 1 establishes the legislative branch, Congress, divided into the Senate and House of Representatives, detailing their composition, powers, and operational rules. It grants Congress the power to legislate on various matters, including taxes, defense, commerce, and the creation of laws necessary for executing its powers.
Article 2 sets forth the executive branch, headed by the President, outlining the process for election, qualifications, powers, and duties, including serving as the Commander in Chief, making treaties with Senate approval, and appointing officials.
Article 3 establishes the judicial branch, led by the Supreme Court, and allows for lower courts. It defines the judiciary's powers, including jurisdiction over various cases and the trial process, especially for crimes and treason.
Articles 4 through 7 address the states' rights and relations, the process for amending the Constitution, the federal government's supremacy over state laws, and the ratification process of the Constitution.
The document also includes 27 amendments, the first ten known as the Bill of Rights, which protect individual freedoms such as speech, religion, and the press; the right to bear arms; protection against unreasonable searches and seizures; and rights to fair trials. Subsequent amendments address issues including the abolition of slavery (13th), citizenship and equal protection under the law (14th), voting rights regardless of race (15th), income tax (16th), direct election of senators (17th), prohibition and its repeal (18th and 21st), women's suffrage (19th), presidential term limits (22nd), voting age (26th), and congressional pay changes (27th).

Bill of Rights

Here we summarize Bill of Rights:
In[]:=
LLMSynthesize[{"Summarize in less than 300 words the Bill of Rights given in the following text:",txtUSACon},LLMEvaluator->conf]
The Bill of Rights, the first ten amendments to the United States Constitution, guarantees fundamental civil rights and liberties.
1
.
First Amendment : Protects freedom of religion, speech, press, assembly, and the right to petition the government.
2
.
Second Amendment : Ensures the right of individuals to keep and bear arms.
3
.
Third Amendment : Prohibits the quartering of soldiers in private homes without the owner's consent in peacetime.
4
.
Fourth Amendment : Guards against unreasonable searches and seizures, requiring any warrant to be judicially sanctioned and supported by probable cause.
5
.
Fifth Amendment : Provides the right to due process and prohibits self-incrimination and double jeopardy. It also contains the takings clause, which ensures that private property is not taken for public use without just compensation.
6
.
Sixth Amendment : Guarantees the rights of criminal defendants, including the right to a public trial without unnecessary delay, the right to a lawyer, the right to an impartial jury, and the right to know who your accusers are and the nature of the charges and evidence against you.
7
.
Seventh Amendment : Provides for the right to trial by jury in certain civil cases, according to common law.
8
.
Eighth Amendment : Prohibits excessive fines and excessive bail, as well as cruel and unusual punishment.
9
.
Ninth Amendment : Asserts that the enumeration of specific rights in the Constitution does not exclude other rights possessed by the people.
10. Tenth Amendment : States that the powers not delegated to the United States by the Constitution, nor prohibited by it to the States, are reserved to the States respectively, or to the people.
These amendments were ratified on December 15, 1791, and form a critical foundation of American freedoms.

Structures and relationships

Powers and restrictions per governmental branch

From reading the summaries above we can come up with LLM requests to obtain a structured (e.g. tabular) outline of document's content. Here is one a such request, in which the powers and restrictions of the governmental branches are tabulated:
In[]:=
llmRes=LLMSynthesize[{"Cross-tabulate the powers and restrictions three branches: legislative, executive, and judicial. The table rows should correspond to the branches.",txtUSACon,LLMPrompt["NothingElse"]["CSV"]},LLMEvaluator->conf];
In[]:=
tbl=FromLLMResult[llmRes,"CSV"];​​ResourceFunction["GridTableForm"][tbl[[2;;-1,2;;-1]],TableHeadings->{tbl[[2;;-1,1]],First[tbl]}]
Out[]=
#
Branch
Powers
Legislative
Make laws, Tax and spend, Declare war, Regulate interstate and foreign commerce, Establish lower federal courts and the number of judges
No ex post facto laws, No titles of nobility, No suspension of habeas corpus (except in cases of rebellion or invasion), No tax or duty on articles exported from any state, No preference to ports of one state over those of another
Executive
Enforce laws, Act as commander-in-chief of armed forces, Conduct foreign policy, Negotiate treaties (with Senate's advice and consent), Appoint federal officers and judges (with Senate's advice and consent), Grant pardons and reprieves for federal offenses
Must be a natural-born citizen, Must be at least 35 years old, Can be impeached and removed from office for treason, bribery, or other high crimes and misdemeanors, Cannot accept titles of nobility, gifts, or emoluments from foreign states without Congress's consent, Treaty ratification and appointments require Senate's advice and consent
Judicial
Interpret laws, Review lower court decisions, Decide cases involving states' rights, Determine constitutionality of laws
Judges serve during good behavior, Cannot hold any other office or accept gifts, Cannot make laws or enforce laws, Decisions subject to amendment or legislative clarification

Amendments vs Articles

In this subsection we use LLM requests to tabulate the relationships between the concepts in the Constitution and the Bill of Rights.
In[]:=
k=1;​​articles=StringJoin["Article ",ToString[k++],":\n",#]&/@txtUSAConJSON["articles"];​​articles=StringJoin[articles,"\n"];​​​​l=1;​​amendments=StringJoin["Amendment ",ToString[l++],":\n",#]&/@txtUSAConJSON["amendments"];​​amendments=StringJoin[amendments,"\n"];

Most important statements

Here we define a function for extracting most important elements for text:
Here are the most important statements:
Given the extensive nature of the document you've provided, which is essentially the United States Constitution along with its amendments, identifying the "top 3 most important statements" can be subjective and dependent on the criteria used for importance. However, considering the foundational principles and rights it establishes, the following can be considered among the most significant statements:
1
.
Preamble to the Constitution : "We the People of the United States, in Order to form a more perfect Union, establish Justice, insure domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United States of America." This statement encapsulates the purpose and guiding principles behind the establishment of the Constitution and the government it creates.
2
.
First Amendment : "Congress shall make no law respecting an establishment of religion, or prohibiting the free exercise thereof; or abridging the freedom of speech, or of the press; or the right of the people peaceably to assemble, and to petition the Government for a redress of grievances." This amendment is crucial as it protects fundamental freedoms such as religion, speech, press, assembly, and petition, which are essential to a democratic society.
3
.
Fourteenth Amendment, Section 1 : "All persons born or naturalized in the United States, and subject to the jurisdiction thereof, are citizens of the United States and of the State wherein they reside. No State shall make or enforce any law which shall abridge the privileges or immunities of citizens of the United States; nor shall any State deprive any person of life, liberty, or property, without due process of law; nor deny to any person within its jurisdiction the equal protection of the laws." This amendment addresses citizenship rights and equal protection under the law and is foundational to civil rights in the United States.
These statements are pivotal as they lay the groundwork for the governance, rights, and freedoms of the United States, impacting not only the legal framework but also the societal and cultural ethos of the nation.

Most important amendments

Most important amendments:
Determining the "top 3 most important amendments" from the United States Constitution can be subjective and depends on the criteria used for evaluation (e.g., impact on civil liberties, structural changes to government, etc.). However, based on their broad implications for civil rights and liberties, the following three amendments are often highlighted for their significance:
1
.
First Amendment : Protects several fundamental rights, including freedom of speech, religion, press, assembly, and the right to petition the government for a redress of grievances. This amendment is foundational to the American democratic system and the protection of individual liberties.
2
.
Fourteenth Amendment : Addresses citizenship rights and equal protection under the law and was pivotal in extending civil rights protections. Its clauses, particularly the Equal Protection Clause and the Due Process Clause, have been the basis for many landmark Supreme Court decisions that have expanded civil rights and liberties.
3
.
Nineteenth Amendment : Prohibits the states and the federal government from denying the right to vote to citizens of the United States on the basis of sex. This amendment marked a significant milestone in the women's suffrage movement in the United States, ensuring women the right to vote and advancing gender equality.
These amendments are among the most cited and have had profound impacts on American society, law, and governance.

Analogies with "Plants vs Zombies"

In this section we use LLMs to explain the elements of US constitution to people who are familiar with the game "Plants vs Zombies" , [Wk2].
Alright, let's break this down into something more relatable to a "Plants vs. Zombies" player. Imagine the United States Constitution and its Bill of Rights as the ultimate game guide for running a country, where the goal is to ensure a balanced, fair, and free society, much like strategizing to protect your garden from zombies.
Preamble (Introduction): This is like the game's intro screen, setting the stage. It tells us why the Constitution was created: to make a better "team" (union), ensure peace at home, provide defense, improve everyone's well-being, and guarantee freedom for now and the future.
Article 1: Legislative Branch (Congress) - Think of Congress as two different types of plants in your garden, the Senate and the House of Representatives, each with unique powers and responsibilities. They make the rules (laws) of the game, deciding how resources are distributed, how to defend against threats, and how to keep the garden (country) running smoothly.
Article 2: Executive Branch (President and Administration) - This is like choosing your main plant or hero, the President, who executes the laws made by Congress, leads the military, and deals with other gardens (countries). The President has a team (administration) to help manage specific areas, like defense or agriculture.
Article 3: Judicial Branch (Supreme Court and other Federal Courts) - Imagine this as the game's referees or rule-checkers. They interpret the laws, settle disputes, and ensure that everything aligns with the game guide (Constitution). They make sure everyone plays fair.
Bill of Rights (First 10 Amendments): These are like the essential power-ups or protections for the players (citizens) to ensure they can play the game freely and fairly.
1
.
Freedom Power-Up: You can speak, write, gather, and believe freely.
2
.
Defense Boost: You have the right to hold onto and use tools (in this case, weapons) for protection.
3
.
Privacy Shield: Soldiers can't just crash at your place without permission.
4
.
Anti-Spyware: Your personal space and belongings can't be searched or taken without a good reason.
5
.
Fair Play Protocol: You have rights in legal situations, like not having to incriminate yourself and being treated fairly by the law.
6
.
Rapid Response: In legal battles, you're guaranteed a quick and public trial, with a chance to defend yourself.
7
.
Trial by Jury: For serious disputes in court, you can have a jury decide.
8
.
No Cheat Codes: Punishments can't be overly harsh or unfair.
9
.
Hidden Levels: Just because a right isn't listed here doesn't mean you don't have it.
10. Local Control: Powers not given to the federal government belong to the states or the people.
The rest of the amendments (11-27) are like updates or expansions to the game, adding new features, fixing bugs, or adjusting the gameplay to make sure it stays fair and fun for everyone playing.
So, just like in "Plants vs. Zombies," where you need to know your plants, zombies, and strategies to win, the Constitution and the Bill of Rights lay out the rules, roles, and protections to ensure the game of governance is played effectively and fairly for all citizens.

Supporting illustrations

Let us try to generate the illustration images that correspond to the USA Constitution vs Plants vs Zombies analogies. First attempt with a "simple" prompt:
Remark: In this section we used the function CallDALLE defined and demonstrated by Marko Thiel in the Wolfram Community notebook: "Direct API access to new features of GPT-4 (including vision, DALL-E, and TTS)", [MTn1].
Here we make a more comprehensive prompt and request another image generation from DALL-E 3:
Here is another image created with the prompt above that can be seen as more dramatic and metaphorical:

Setup code

References

Articles

[AA1] Anton Antonov, "Workflows with LLM functions", (2023), RakuForPrediction at WordPress .
[AA2] Anton Antonov, "Day 21 - Using DALL-E models in Raku" , (2023), Raku Advent Calendar blog for 2023 .
[AA3] Anton Antonov, "LLM aids for processing of the first Carlson-Putin interview" , (2024), RakuForPrediction at WordPress .
[Wk1] Wikipedia entry, "Constitution of the United States" .
[Wk2] Wikipedia entry, "Plants vs Zombies" .

Notebooks

[AAn1] Anton Antonov, "Workflows with LLM functions (in WL)", (2023), Wolfram Community .
[AAn2] Anton Antonov, "LLM aids for processing of the first Carlson-Putin interview" , (2024), Wolfram Community .
[MTn1] Marco Thiel, "Direct API access to new features of GPT-4 (including vision, DALL-E, and TTS)", (2023), Wolfram Community .

Packages

[AAp1] Anton Antonov, WWW::OpenAI Raku package, (2023), GitHub/antononcube .
[AAp2] Anton Antonov, WWW::PaLM Raku package, (2023), GitHub/antononcube .
[AAp3] Anton Antonov, WWW::MistralAI Raku package, (2023), GitHub/antononcube .
[AAp4] Anton Antonov, WWW::MermaidInk Raku package, (2023), GitHub/antononcube .
[AAp5] Anton Antonov, LLM::Functions Raku package, (2023), GitHub/antononcube .
[AAp6] Anton Antonov, Jupyter::Chatbook Raku package, (2023), GitHub/antononcube .
[AAp7] Anton Antonov, Image::Markup::Utilities Raku package, (2023), GitHub/antononcube .

Repositories

[MBr1] Mark Biek, constitution.json , (2016-2018), GitHub/markbiek .
[VD7r1] vdutts7, Constitution GPT , (2023), GitHub/vdutts7 .

Videos

[AAv1] Anton Antonov, "Jupyter Chatbook LLM cells demo (Raku)" (2023), YouTube/@AAA4Prediction .
[AAv2] Anton Antonov, "Jupyter Chatbook multi cell LLM chats teaser (Raku)" , (2023), YouTube/@AAA4Prediction .
[AAv3] Anton Antonov "Integrating Large Language Models with Raku" , (2023), YouTube/@therakuconference6823 .

CITE THIS NOTEBOOK

US Constitution elements explained by Plants vs Zombies terms​
by Anton Antonov​
Wolfram Community, STAFF PICKS, February 26, 2024
​https://community.wolfram.com/groups/-/m/t/3129945