lean-explore 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lean_explore/__init__.py +1 -0
- lean_explore/api/__init__.py +1 -0
- lean_explore/api/client.py +124 -0
- lean_explore/cli/__init__.py +1 -0
- lean_explore/cli/agent.py +781 -0
- lean_explore/cli/config_utils.py +408 -0
- lean_explore/cli/data_commands.py +506 -0
- lean_explore/cli/main.py +659 -0
- lean_explore/defaults.py +117 -0
- lean_explore/local/__init__.py +1 -0
- lean_explore/local/search.py +921 -0
- lean_explore/local/service.py +394 -0
- lean_explore/mcp/__init__.py +1 -0
- lean_explore/mcp/app.py +107 -0
- lean_explore/mcp/server.py +247 -0
- lean_explore/mcp/tools.py +242 -0
- lean_explore/shared/__init__.py +1 -0
- lean_explore/shared/models/__init__.py +1 -0
- lean_explore/shared/models/api.py +117 -0
- lean_explore/shared/models/db.py +411 -0
- lean_explore-0.1.1.dist-info/METADATA +277 -0
- lean_explore-0.1.1.dist-info/RECORD +26 -0
- lean_explore-0.1.1.dist-info/WHEEL +5 -0
- lean_explore-0.1.1.dist-info/entry_points.txt +2 -0
- lean_explore-0.1.1.dist-info/licenses/LICENSE +201 -0
- lean_explore-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
# src/lean_explore/shared/models/db.py
|
|
2
|
+
|
|
3
|
+
"""SQLAlchemy ORM models for the lean_explore database.
|
|
4
|
+
|
|
5
|
+
Defines 'declarations', 'dependencies', 'statement_groups', and
|
|
6
|
+
'statement_group_dependencies' tables representing Lean entities,
|
|
7
|
+
their dependency graphs at different granularities, and source code groupings.
|
|
8
|
+
Uses SQLAlchemy 2.0 syntax.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import datetime
|
|
12
|
+
from typing import List, Optional
|
|
13
|
+
|
|
14
|
+
from sqlalchemy import (
|
|
15
|
+
Boolean,
|
|
16
|
+
DateTime,
|
|
17
|
+
Float,
|
|
18
|
+
ForeignKey,
|
|
19
|
+
Index,
|
|
20
|
+
Integer,
|
|
21
|
+
MetaData,
|
|
22
|
+
String,
|
|
23
|
+
Text,
|
|
24
|
+
UniqueConstraint, # Kept for potential standalone model testing
|
|
25
|
+
)
|
|
26
|
+
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column, relationship
|
|
27
|
+
|
|
28
|
+
# Naming conventions for constraints and indexes for database consistency.
|
|
29
|
+
convention = {
|
|
30
|
+
"ix": "ix_%(column_0_label)s",
|
|
31
|
+
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
|
32
|
+
"ck": "ck_%(table_name)s_%(constraint_name)s",
|
|
33
|
+
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
|
34
|
+
"pk": "pk_%(table_name)s",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
metadata_obj = MetaData(naming_convention=convention)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class Base(DeclarativeBase):
|
|
41
|
+
"""Base class for SQLAlchemy declarative models.
|
|
42
|
+
|
|
43
|
+
Includes metadata with naming conventions for database constraints and indexes,
|
|
44
|
+
ensuring consistency across the database schema.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
metadata = metadata_obj
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class StatementGroup(Base):
|
|
51
|
+
"""Represents a unique block of source code text.
|
|
52
|
+
|
|
53
|
+
This table groups multiple `Declaration` entries that originate from the
|
|
54
|
+
exact same source code text and location. This allows search results to
|
|
55
|
+
show a single entry for a code block, while retaining all individual
|
|
56
|
+
declarations for graph analysis and detailed views. It also tracks
|
|
57
|
+
dependencies to and from other statement groups.
|
|
58
|
+
|
|
59
|
+
Attributes:
|
|
60
|
+
id: Primary key identifier for the statement group.
|
|
61
|
+
text_hash: SHA-256 hash of `statement_text` for unique identification.
|
|
62
|
+
statement_text: Canonical source code text for this group (full block).
|
|
63
|
+
display_statement_text: Optional, potentially truncated version of the
|
|
64
|
+
source code, optimized for display (e.g., omitting proofs).
|
|
65
|
+
docstring: Docstring associated with this code block, typically from the
|
|
66
|
+
primary declaration.
|
|
67
|
+
informal_description: Optional informal English description, potentially
|
|
68
|
+
LLM-generated.
|
|
69
|
+
source_file: Relative path to the .lean file containing this block.
|
|
70
|
+
range_start_line: Starting line number of the block in the source file.
|
|
71
|
+
range_start_col: Starting column number of the block.
|
|
72
|
+
range_end_line: Ending line number of the block.
|
|
73
|
+
range_end_col: Ending column number of the block.
|
|
74
|
+
pagerank_score: PageRank score calculated for this statement group.
|
|
75
|
+
scaled_pagerank_score: Log-transformed, min-max scaled PageRank score.
|
|
76
|
+
primary_decl_id: Foreign key to the 'declarations' table, identifying
|
|
77
|
+
the primary or most representative declaration of this group.
|
|
78
|
+
created_at: Timestamp of when the record was created.
|
|
79
|
+
updated_at: Timestamp of the last update to the record.
|
|
80
|
+
primary_declaration: SQLAlchemy relationship to the primary Declaration.
|
|
81
|
+
declarations: SQLAlchemy relationship to all Declarations in this group.
|
|
82
|
+
dependencies_as_source: Links to `StatementGroupDependency` where this
|
|
83
|
+
group is the source (i.e., this group depends on others).
|
|
84
|
+
dependencies_as_target: Links to `StatementGroupDependency` where this
|
|
85
|
+
group is the target (i.e., other groups depend on this one).
|
|
86
|
+
"""
|
|
87
|
+
|
|
88
|
+
__tablename__ = "statement_groups"
|
|
89
|
+
|
|
90
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
91
|
+
text_hash: Mapped[str] = mapped_column(
|
|
92
|
+
String(64), nullable=False, index=True, unique=True
|
|
93
|
+
)
|
|
94
|
+
statement_text: Mapped[str] = mapped_column(Text, nullable=False)
|
|
95
|
+
display_statement_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
96
|
+
docstring: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
97
|
+
informal_description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
98
|
+
|
|
99
|
+
source_file: Mapped[str] = mapped_column(Text, nullable=False)
|
|
100
|
+
range_start_line: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
101
|
+
range_start_col: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
102
|
+
range_end_line: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
103
|
+
range_end_col: Mapped[int] = mapped_column(Integer, nullable=False)
|
|
104
|
+
|
|
105
|
+
pagerank_score: Mapped[Optional[float]] = mapped_column(
|
|
106
|
+
Float, nullable=True, index=True
|
|
107
|
+
)
|
|
108
|
+
scaled_pagerank_score: Mapped[Optional[float]] = mapped_column(
|
|
109
|
+
Float, nullable=True, index=True
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
primary_decl_id: Mapped[int] = mapped_column(
|
|
113
|
+
Integer, ForeignKey("declarations.id"), nullable=False, index=True
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
|
117
|
+
DateTime, default=datetime.datetime.utcnow, nullable=False
|
|
118
|
+
)
|
|
119
|
+
updated_at: Mapped[datetime.datetime] = mapped_column(
|
|
120
|
+
DateTime,
|
|
121
|
+
default=datetime.datetime.utcnow,
|
|
122
|
+
onupdate=datetime.datetime.utcnow,
|
|
123
|
+
nullable=False,
|
|
124
|
+
)
|
|
125
|
+
|
|
126
|
+
# Relationships
|
|
127
|
+
primary_declaration: Mapped["Declaration"] = relationship(
|
|
128
|
+
"Declaration", foreign_keys=[primary_decl_id]
|
|
129
|
+
)
|
|
130
|
+
declarations: Mapped[List["Declaration"]] = relationship(
|
|
131
|
+
"Declaration",
|
|
132
|
+
foreign_keys="[Declaration.statement_group_id]",
|
|
133
|
+
back_populates="statement_group",
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
dependencies_as_source: Mapped[List["StatementGroupDependency"]] = relationship(
|
|
137
|
+
foreign_keys="StatementGroupDependency.source_statement_group_id",
|
|
138
|
+
back_populates="source_group",
|
|
139
|
+
cascade="all, delete-orphan",
|
|
140
|
+
lazy="select",
|
|
141
|
+
)
|
|
142
|
+
dependencies_as_target: Mapped[List["StatementGroupDependency"]] = relationship(
|
|
143
|
+
foreign_keys="StatementGroupDependency.target_statement_group_id",
|
|
144
|
+
back_populates="target_group",
|
|
145
|
+
cascade="all, delete-orphan",
|
|
146
|
+
lazy="select",
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
__table_args__ = (
|
|
150
|
+
Index(
|
|
151
|
+
"ix_statement_groups_location",
|
|
152
|
+
"source_file",
|
|
153
|
+
"range_start_line",
|
|
154
|
+
"range_start_col",
|
|
155
|
+
),
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
def __repr__(self) -> str:
|
|
159
|
+
"""Provides a developer-friendly string representation."""
|
|
160
|
+
has_desc = "+" if self.informal_description else "-"
|
|
161
|
+
return (
|
|
162
|
+
f"<StatementGroup(id={self.id}, hash='{self.text_hash[:8]}...', "
|
|
163
|
+
f"primary_decl_id='{self.primary_decl_id}', informal_desc='{has_desc}', "
|
|
164
|
+
f"loc='{self.source_file}:{self.range_start_line}:{self.range_start_col}')>"
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class Declaration(Base):
|
|
169
|
+
"""Represents a Lean declaration, a node in the dependency graph.
|
|
170
|
+
|
|
171
|
+
Stores information about Lean declarations (definitions, theorems, axioms, etc.),
|
|
172
|
+
including source location, Lean code, descriptions, and (potentially)
|
|
173
|
+
embeddings. Declarations from the same source block can be grouped via
|
|
174
|
+
`statement_group_id`.
|
|
175
|
+
|
|
176
|
+
Attributes:
|
|
177
|
+
id: Primary key identifier.
|
|
178
|
+
lean_name: Fully qualified Lean name (e.g., 'Nat.add'), unique and indexed.
|
|
179
|
+
decl_type: Type of declaration (e.g., 'theorem', 'definition').
|
|
180
|
+
source_file: Relative path to the .lean source file.
|
|
181
|
+
module_name: Lean module name (e.g., 'Mathlib.Data.Nat.Basic'), indexed.
|
|
182
|
+
is_internal: True if considered compiler-internal or auxiliary.
|
|
183
|
+
docstring: Documentation string, if available.
|
|
184
|
+
is_protected: True if marked 'protected' in Lean.
|
|
185
|
+
is_deprecated: True if marked 'deprecated'.
|
|
186
|
+
is_projection: True if it's a projection (e.g., from a class/structure).
|
|
187
|
+
range_start_line: Starting line number of the source block.
|
|
188
|
+
range_start_col: Starting column number of the source block.
|
|
189
|
+
range_end_line: Ending line number of the source block.
|
|
190
|
+
range_end_col: Ending column number of the source block.
|
|
191
|
+
statement_text: Full Lean code text of the originating source block.
|
|
192
|
+
declaration_signature: Extracted Lean signature text of the declaration.
|
|
193
|
+
statement_group_id: Optional foreign key to `statement_groups.id`.
|
|
194
|
+
type_signature_text: Lean type signature (may be redundant with
|
|
195
|
+
`declaration_signature`).
|
|
196
|
+
informal_description: Informal English explanation.
|
|
197
|
+
lean_embedding: Text representation (e.g., JSON) of the embedding for
|
|
198
|
+
Lean code.
|
|
199
|
+
informal_description_embedding: Text representation (e.g., JSON) of the
|
|
200
|
+
embedding for the informal description.
|
|
201
|
+
pagerank_score: PageRank score within the dependency graph, indexed.
|
|
202
|
+
created_at: Timestamp of record creation.
|
|
203
|
+
updated_at: Timestamp of last record update.
|
|
204
|
+
statement_group: SQLAlchemy relationship to the StatementGroup.
|
|
205
|
+
"""
|
|
206
|
+
|
|
207
|
+
__tablename__ = "declarations"
|
|
208
|
+
|
|
209
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
210
|
+
lean_name: Mapped[str] = mapped_column(
|
|
211
|
+
Text, unique=True, index=True, nullable=False
|
|
212
|
+
)
|
|
213
|
+
decl_type: Mapped[str] = mapped_column(String(30), nullable=False)
|
|
214
|
+
source_file: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
215
|
+
module_name: Mapped[Optional[str]] = mapped_column(Text, index=True, nullable=True)
|
|
216
|
+
is_internal: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
217
|
+
docstring: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
218
|
+
|
|
219
|
+
is_protected: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
220
|
+
is_deprecated: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
221
|
+
is_projection: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
|
|
222
|
+
|
|
223
|
+
range_start_line: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
|
224
|
+
range_start_col: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
|
225
|
+
range_end_line: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
|
226
|
+
range_end_col: Mapped[Optional[int]] = mapped_column(Integer, nullable=True)
|
|
227
|
+
|
|
228
|
+
statement_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
229
|
+
declaration_signature: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
230
|
+
|
|
231
|
+
statement_group_id: Mapped[Optional[int]] = mapped_column(
|
|
232
|
+
Integer, ForeignKey("statement_groups.id"), nullable=True, index=True
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
type_signature_text: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
236
|
+
informal_description: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
237
|
+
|
|
238
|
+
lean_embedding: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
|
239
|
+
informal_description_embedding: Mapped[Optional[str]] = mapped_column(
|
|
240
|
+
Text, nullable=True
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
pagerank_score: Mapped[Optional[float]] = mapped_column(
|
|
244
|
+
Float, nullable=True, index=True
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
|
248
|
+
DateTime, default=datetime.datetime.utcnow, nullable=False
|
|
249
|
+
)
|
|
250
|
+
updated_at: Mapped[datetime.datetime] = mapped_column(
|
|
251
|
+
DateTime,
|
|
252
|
+
default=datetime.datetime.utcnow,
|
|
253
|
+
onupdate=datetime.datetime.utcnow,
|
|
254
|
+
nullable=False,
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
statement_group: Mapped[Optional["StatementGroup"]] = relationship(
|
|
258
|
+
"StatementGroup",
|
|
259
|
+
foreign_keys=[statement_group_id],
|
|
260
|
+
back_populates="declarations",
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
__table_args__ = (
|
|
264
|
+
Index("ix_declarations_source_file", "source_file"),
|
|
265
|
+
Index("ix_declarations_is_protected", "is_protected"),
|
|
266
|
+
Index("ix_declarations_is_deprecated", "is_deprecated"),
|
|
267
|
+
Index("ix_declarations_is_projection", "is_projection"),
|
|
268
|
+
Index("ix_declarations_is_internal", "is_internal"),
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
def __repr__(self) -> str:
|
|
272
|
+
"""Provides a developer-friendly string representation."""
|
|
273
|
+
group_id_str = (
|
|
274
|
+
f", group_id={self.statement_group_id}" if self.statement_group_id else ""
|
|
275
|
+
)
|
|
276
|
+
return (
|
|
277
|
+
f"<Declaration(id={self.id}, lean_name='{self.lean_name}', "
|
|
278
|
+
f"type='{self.decl_type}'{group_id_str})>"
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class Dependency(Base):
|
|
283
|
+
"""Represents a dependency link between two Lean declarations.
|
|
284
|
+
|
|
285
|
+
Each row signifies that a 'source' declaration depends on a 'target'
|
|
286
|
+
declaration, forming an edge in the dependency graph. The nature of this
|
|
287
|
+
dependency is described by `dependency_type`.
|
|
288
|
+
|
|
289
|
+
Attributes:
|
|
290
|
+
id: Primary key identifier for the dependency link.
|
|
291
|
+
source_decl_id: Foreign key to the `Declaration` that depends on another.
|
|
292
|
+
target_decl_id: Foreign key to the `Declaration` that is depended upon.
|
|
293
|
+
dependency_type: String describing the type of dependency (e.g., 'Direct').
|
|
294
|
+
context: Optional string providing context for the dependency.
|
|
295
|
+
created_at: Timestamp of record creation.
|
|
296
|
+
"""
|
|
297
|
+
|
|
298
|
+
__tablename__ = "dependencies"
|
|
299
|
+
|
|
300
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
301
|
+
source_decl_id: Mapped[int] = mapped_column(
|
|
302
|
+
Integer,
|
|
303
|
+
ForeignKey("declarations.id", ondelete="CASCADE"),
|
|
304
|
+
nullable=False,
|
|
305
|
+
index=True,
|
|
306
|
+
)
|
|
307
|
+
target_decl_id: Mapped[int] = mapped_column(
|
|
308
|
+
Integer,
|
|
309
|
+
ForeignKey("declarations.id", ondelete="CASCADE"),
|
|
310
|
+
nullable=False,
|
|
311
|
+
index=True,
|
|
312
|
+
)
|
|
313
|
+
dependency_type: Mapped[str] = mapped_column(String(30), nullable=False)
|
|
314
|
+
context: Mapped[Optional[str]] = mapped_column(String(30), nullable=True)
|
|
315
|
+
|
|
316
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
|
317
|
+
DateTime, default=datetime.datetime.utcnow, nullable=False
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
__table_args__ = (
|
|
321
|
+
UniqueConstraint(
|
|
322
|
+
"source_decl_id",
|
|
323
|
+
"target_decl_id",
|
|
324
|
+
"dependency_type",
|
|
325
|
+
name="uq_dependency_link",
|
|
326
|
+
),
|
|
327
|
+
Index("ix_dependencies_source_target", "source_decl_id", "target_decl_id"),
|
|
328
|
+
)
|
|
329
|
+
|
|
330
|
+
def __repr__(self) -> str:
|
|
331
|
+
"""Provides a developer-friendly string representation."""
|
|
332
|
+
return (
|
|
333
|
+
f"<Dependency(id={self.id}, source={self.source_decl_id}, "
|
|
334
|
+
f"target={self.target_decl_id}, type='{self.dependency_type}')>"
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
class StatementGroupDependency(Base):
|
|
339
|
+
"""Represents a dependency link between two StatementGroups.
|
|
340
|
+
|
|
341
|
+
Each row signifies that a 'source' statement group depends on a 'target'
|
|
342
|
+
statement group. This allows for a higher-level dependency graph.
|
|
343
|
+
|
|
344
|
+
Attributes:
|
|
345
|
+
id: Primary key identifier for the group dependency link.
|
|
346
|
+
source_statement_group_id: Foreign key to the `StatementGroup` that
|
|
347
|
+
depends on another.
|
|
348
|
+
target_statement_group_id: Foreign key to the `StatementGroup` that
|
|
349
|
+
is depended upon.
|
|
350
|
+
dependency_type: String describing the type of group dependency
|
|
351
|
+
(e.g., 'DerivedFromDecl').
|
|
352
|
+
created_at: Timestamp of record creation.
|
|
353
|
+
source_group: SQLAlchemy relationship to the source StatementGroup.
|
|
354
|
+
target_group: SQLAlchemy relationship to the target StatementGroup.
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
__tablename__ = "statement_group_dependencies"
|
|
358
|
+
|
|
359
|
+
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
|
360
|
+
source_statement_group_id: Mapped[int] = mapped_column(
|
|
361
|
+
Integer,
|
|
362
|
+
ForeignKey("statement_groups.id", ondelete="CASCADE"),
|
|
363
|
+
nullable=False,
|
|
364
|
+
index=True,
|
|
365
|
+
)
|
|
366
|
+
target_statement_group_id: Mapped[int] = mapped_column(
|
|
367
|
+
Integer,
|
|
368
|
+
ForeignKey("statement_groups.id", ondelete="CASCADE"),
|
|
369
|
+
nullable=False,
|
|
370
|
+
index=True,
|
|
371
|
+
)
|
|
372
|
+
dependency_type: Mapped[str] = mapped_column(
|
|
373
|
+
String(50), nullable=False, default="DerivedFromDecl"
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
created_at: Mapped[datetime.datetime] = mapped_column(
|
|
377
|
+
DateTime, default=datetime.datetime.utcnow, nullable=False
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
# Relationships back to StatementGroup
|
|
381
|
+
source_group: Mapped["StatementGroup"] = relationship(
|
|
382
|
+
foreign_keys=[source_statement_group_id],
|
|
383
|
+
back_populates="dependencies_as_source",
|
|
384
|
+
)
|
|
385
|
+
target_group: Mapped["StatementGroup"] = relationship(
|
|
386
|
+
foreign_keys=[target_statement_group_id],
|
|
387
|
+
back_populates="dependencies_as_target",
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
__table_args__ = (
|
|
391
|
+
UniqueConstraint(
|
|
392
|
+
"source_statement_group_id",
|
|
393
|
+
"target_statement_group_id",
|
|
394
|
+
"dependency_type", # Consider if type is part of uniqueness
|
|
395
|
+
name="uq_stmt_group_dependency_link",
|
|
396
|
+
),
|
|
397
|
+
Index(
|
|
398
|
+
"ix_stmt_group_deps_source_target",
|
|
399
|
+
"source_statement_group_id",
|
|
400
|
+
"target_statement_group_id",
|
|
401
|
+
),
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
def __repr__(self) -> str:
|
|
405
|
+
"""Provides a developer-friendly string representation."""
|
|
406
|
+
return (
|
|
407
|
+
f"<StatementGroupDependency(id={self.id}, "
|
|
408
|
+
f"source_sg_id={self.source_statement_group_id}, "
|
|
409
|
+
f"target_sg_id={self.target_statement_group_id}, "
|
|
410
|
+
f"type='{self.dependency_type}')>"
|
|
411
|
+
)
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lean-explore
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A project to explore and rank Lean mathematical declarations.
|
|
5
|
+
Author-email: Justin Asher <justinchadwickasher@gmail.com>
|
|
6
|
+
License: Apache License
|
|
7
|
+
Version 2.0, January 2004
|
|
8
|
+
http://www.apache.org/licenses/
|
|
9
|
+
|
|
10
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
11
|
+
|
|
12
|
+
1. Definitions.
|
|
13
|
+
|
|
14
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
15
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
16
|
+
|
|
17
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
18
|
+
the copyright owner that is granting the License.
|
|
19
|
+
|
|
20
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
21
|
+
other entities that control, are controlled by, or are under common
|
|
22
|
+
control with that entity. For the purposes of this definition,
|
|
23
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
24
|
+
direction or management of such entity, whether by contract or
|
|
25
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
26
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
27
|
+
|
|
28
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
29
|
+
exercising permissions granted by this License.
|
|
30
|
+
|
|
31
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
32
|
+
including but not limited to software source code, documentation
|
|
33
|
+
source, and configuration files.
|
|
34
|
+
|
|
35
|
+
"Object" form shall mean any form resulting from mechanical
|
|
36
|
+
transformation or translation of a Source form, including but
|
|
37
|
+
not limited to compiled object code, generated documentation,
|
|
38
|
+
and conversions to other media types.
|
|
39
|
+
|
|
40
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
41
|
+
Object form, made available under the License, as indicated by a
|
|
42
|
+
copyright notice that is included in or attached to the work
|
|
43
|
+
(an example is provided in the Appendix below).
|
|
44
|
+
|
|
45
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
46
|
+
form, that is based on (or derived from) the Work and for which the
|
|
47
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
48
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
49
|
+
of this License, Derivative Works shall not include works that remain
|
|
50
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
51
|
+
the Work and Derivative Works thereof.
|
|
52
|
+
|
|
53
|
+
"Contribution" shall mean any work of authorship, including
|
|
54
|
+
the original version of the Work and any modifications or additions
|
|
55
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
56
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
57
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
58
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
59
|
+
means any form of electronic, verbal, or written communication sent
|
|
60
|
+
to the Licensor or its representatives, including but not limited to
|
|
61
|
+
communication on electronic mailing lists, source code control systems,
|
|
62
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
63
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
64
|
+
excluding communication that is conspicuously marked or otherwise
|
|
65
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
66
|
+
|
|
67
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
68
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
69
|
+
subsequently incorporated within the Work.
|
|
70
|
+
|
|
71
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
72
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
73
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
74
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
75
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
76
|
+
Work and such Derivative Works in Source or Object form.
|
|
77
|
+
|
|
78
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
79
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
80
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
81
|
+
(except as stated in this section) patent license to make, have made,
|
|
82
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
83
|
+
where such license applies only to those patent claims licensable
|
|
84
|
+
by such Contributor that are necessarily infringed by their
|
|
85
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
86
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
87
|
+
institute patent litigation against any entity (including a
|
|
88
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
89
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
90
|
+
or contributory patent infringement, then any patent licenses
|
|
91
|
+
granted to You under this License for that Work shall terminate
|
|
92
|
+
as of the date such litigation is filed.
|
|
93
|
+
|
|
94
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
95
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
96
|
+
modifications, and in Source or Object form, provided that You
|
|
97
|
+
meet the following conditions:
|
|
98
|
+
|
|
99
|
+
(a) You must give any other recipients of the Work or
|
|
100
|
+
Derivative Works a copy of this License; and
|
|
101
|
+
|
|
102
|
+
(b) You must cause any modified files to carry prominent notices
|
|
103
|
+
stating that You changed the files; and
|
|
104
|
+
|
|
105
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
106
|
+
that You distribute, all copyright, patent, trademark, and
|
|
107
|
+
attribution notices from the Source form of the Work,
|
|
108
|
+
excluding those notices that do not pertain to any part of
|
|
109
|
+
the Derivative Works; and
|
|
110
|
+
|
|
111
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
112
|
+
distribution, then any Derivative Works that You distribute must
|
|
113
|
+
include a readable copy of the attribution notices contained
|
|
114
|
+
within such NOTICE file, excluding those notices that do not
|
|
115
|
+
pertain to any part of the Derivative Works, in at least one
|
|
116
|
+
of the following places: within a NOTICE text file distributed
|
|
117
|
+
as part of the Derivative Works; within the Source form or
|
|
118
|
+
documentation, if provided along with the Derivative Works; or,
|
|
119
|
+
within a display generated by the Derivative Works, if and
|
|
120
|
+
wherever such third-party notices normally appear. The contents
|
|
121
|
+
of the NOTICE file are for informational purposes only and
|
|
122
|
+
do not modify the License. You may add Your own attribution
|
|
123
|
+
notices within Derivative Works that You distribute, alongside
|
|
124
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
125
|
+
that such additional attribution notices cannot be construed
|
|
126
|
+
as modifying the License.
|
|
127
|
+
|
|
128
|
+
You may add Your own copyright statement to Your modifications and
|
|
129
|
+
may provide additional or different license terms and conditions
|
|
130
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
131
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
132
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
133
|
+
the conditions stated in this License.
|
|
134
|
+
|
|
135
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
136
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
137
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
138
|
+
this License, without any additional terms or conditions.
|
|
139
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
140
|
+
the terms of any separate license agreement you may have executed
|
|
141
|
+
with Licensor regarding such Contributions.
|
|
142
|
+
|
|
143
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
144
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
145
|
+
except as required for reasonable and customary use in describing the
|
|
146
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
147
|
+
|
|
148
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
149
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
150
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
151
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
152
|
+
implied, including, without limitation, any warranties or conditions
|
|
153
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
154
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
155
|
+
appropriateness of using or redistributing the Work and assume any
|
|
156
|
+
risks associated with Your exercise of permissions under this License.
|
|
157
|
+
|
|
158
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
159
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
160
|
+
unless required by applicable law (such as deliberate and grossly
|
|
161
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
162
|
+
liable to You for damages, including any direct, indirect, special,
|
|
163
|
+
incidental, or consequential damages of any character arising as a
|
|
164
|
+
result of this License or out of the use or inability to use the
|
|
165
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
166
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
167
|
+
other commercial damages or losses), even if such Contributor
|
|
168
|
+
has been advised of the possibility of such damages.
|
|
169
|
+
|
|
170
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
171
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
172
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
173
|
+
or other liability obligations and/or rights consistent with this
|
|
174
|
+
License. However, in accepting such obligations, You may act only
|
|
175
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
176
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
177
|
+
defend, and hold each Contributor harmless for any liability
|
|
178
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
179
|
+
of your accepting any such warranty or additional liability.
|
|
180
|
+
|
|
181
|
+
END OF TERMS AND CONDITIONS
|
|
182
|
+
|
|
183
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
184
|
+
|
|
185
|
+
To apply the Apache License to your work, attach the following
|
|
186
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
187
|
+
replaced with your own identifying information. (Don't include
|
|
188
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
189
|
+
comment syntax for the file format. We also recommend that a
|
|
190
|
+
file or class name and description of purpose be included on the
|
|
191
|
+
same "printed page" as the copyright notice for easier
|
|
192
|
+
identification within third-party archives.
|
|
193
|
+
|
|
194
|
+
Copyright 2025 LeanExplore Contributors
|
|
195
|
+
|
|
196
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
197
|
+
you may not use this file except in compliance with the License.
|
|
198
|
+
You may obtain a copy of the License at
|
|
199
|
+
|
|
200
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
201
|
+
|
|
202
|
+
Unless required by applicable law or agreed to in writing, software
|
|
203
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
204
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
205
|
+
See the License for the specific language governing permissions and
|
|
206
|
+
limitations under the License.
|
|
207
|
+
|
|
208
|
+
Project-URL: Homepage, https://www.leanexplore.com/
|
|
209
|
+
Project-URL: Repository, https://github.com/justincasher/lean-explore
|
|
210
|
+
Keywords: lean,lean4,search,formal methods,theorem prover,math,AI
|
|
211
|
+
Classifier: Development Status :: 3 - Alpha
|
|
212
|
+
Classifier: Intended Audience :: Developers
|
|
213
|
+
Classifier: Intended Audience :: Science/Research
|
|
214
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
215
|
+
Classifier: Programming Language :: Python :: 3
|
|
216
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
217
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
218
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
219
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
220
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
221
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
222
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
223
|
+
Classifier: Topic :: Text Processing :: Indexing
|
|
224
|
+
Requires-Python: >=3.8
|
|
225
|
+
Description-Content-Type: text/markdown
|
|
226
|
+
License-File: LICENSE
|
|
227
|
+
Requires-Dist: sqlalchemy>=2.0
|
|
228
|
+
Requires-Dist: numpy>=1.20
|
|
229
|
+
Requires-Dist: faiss-cpu>=1.7
|
|
230
|
+
Requires-Dist: sentence-transformers>=2.2.0
|
|
231
|
+
Requires-Dist: rapidfuzz>=3.0.0
|
|
232
|
+
Requires-Dist: filelock>=3.0.0
|
|
233
|
+
Requires-Dist: httpx>=0.23.0
|
|
234
|
+
Requires-Dist: pydantic>=2.0
|
|
235
|
+
Requires-Dist: typer[all]>=0.9.0
|
|
236
|
+
Requires-Dist: toml>=0.10.0
|
|
237
|
+
Requires-Dist: openai-agents>=0.0.16
|
|
238
|
+
Requires-Dist: mcp>=1.9.0
|
|
239
|
+
Requires-Dist: tqdm>=4.60
|
|
240
|
+
Dynamic: license-file
|
|
241
|
+
|
|
242
|
+
# LeanExplore
|
|
243
|
+
|
|
244
|
+
A search engine for Lean 4 declarations. This project provides tools and resources for exploring the Lean 4 ecosystem.
|
|
245
|
+
|
|
246
|
+
**For full documentation, please visit: [https://www.leanexplore.com/docs](https://www.leanexplore.com/docs)**
|
|
247
|
+
|
|
248
|
+
The current indexed projects include:
|
|
249
|
+
|
|
250
|
+
* Batteries
|
|
251
|
+
* Lean
|
|
252
|
+
* Mathlib
|
|
253
|
+
* PhysLean
|
|
254
|
+
* Std
|
|
255
|
+
|
|
256
|
+
This code is distributed under an Apache License (see [LICENSE](LICENSE)).
|
|
257
|
+
|
|
258
|
+
### Cite
|
|
259
|
+
|
|
260
|
+
If you use LeanExplore in your research or work, please cite it as follows:
|
|
261
|
+
|
|
262
|
+
**General Citation:**
|
|
263
|
+
|
|
264
|
+
Justin Asher. (2025). *LeanExplore: A search engine for Lean 4 declarations*. LeanExplore.com. Retrieved from [http://www.leanexplore.com](http://www.leanexplore.com) (GitHub: [https://github.com/justincasher/lean-explore](https://github.com/justincasher/lean-explore)).
|
|
265
|
+
|
|
266
|
+
**BibTeX Entry:**
|
|
267
|
+
|
|
268
|
+
```bibtex
|
|
269
|
+
@software{Asher_LeanExplore_2025,
|
|
270
|
+
author = {Asher, Justin},
|
|
271
|
+
title = {{LeanExplore: A search engine for Lean 4 declarations}},
|
|
272
|
+
year = {2025},
|
|
273
|
+
publisher = {LeanExplore.com},
|
|
274
|
+
url = {http://www.leanexplore.com},
|
|
275
|
+
note = {GitHub repository: https://github.com/justincasher/lean-explore}
|
|
276
|
+
}
|
|
277
|
+
```
|