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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
/-
Copyright 2025 The Formal Conjectures Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-/
module

public meta import FormalConjecturesUtil.Attributes.Basic
public import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
public import Mathlib.NumberTheory.FLT.Basic
public import Mathlib.RingTheory.Algebraic.Defs

@[expose] public section


-- The `Category` and `ProblemSubject` attributes

#guard_msgs in
@[category test]
theorem test : 1 + 1 = 2 := by
  sorry

#guard_msgs in
@[category research solved, AMS 11]
theorem FLT : FermatLastTheorem := by
  sorry

#guard_msgs in
open scoped Real in
@[category research open, AMS 11 33]
theorem an_open_problem : Transcendental ℝ (π + rexp 1) := by
  sorry

#guard_msgs in
@[category research solved,
  formal_proof using lean4 at "https://palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002"]
theorem a_formally_solved_problem : 2 + 2 = 4 := by
  rfl

-- The `question` attribute

#guard_msgs in
/-- Is `2 + 2` equal to `4`? -/
@[category research solved, question, AMS 11]
theorem a_question : 2 + 2 = 4 := by
  rfl

-- The attribute is independent of the order of attributes.
#guard_msgs in
@[question, category research open]
theorem a_question_first : 2 + 2 = 4 := by
  sorry

-- `question` is not a keyword.
#guard_msgs in
example (question : Nat) : question = question := rfl

/--
error: the `question` attribute only applies to theorems, but the type of 'not_a_theorem' is not a proposition
-/
#guard_msgs in
@[question]
def not_a_theorem : Prop := True

-- The unknown of a value question is a definition `<theorem>.answer`.
def a_value_question_with_def.answer : Nat := sorry

#guard_msgs in
/-- What is `2 + 2`? -/
@[category research open, question value, AMS 11]
theorem a_value_question_with_def : 2 + 2 = a_value_question_with_def.answer := by
  sorry

-- The form is checked against the statement, in both directions.
def a_value_question_with_def_tagged_yes_no.answer : Nat := sorry

/--
error: the statement of 'a_value_question_with_def_tagged_yes_no' refers to the unknown of a value question; use `question value`
-/
#guard_msgs in
@[category research open, question, AMS 11]
theorem a_value_question_with_def_tagged_yes_no : 2 + 2 = a_value_question_with_def_tagged_yes_no.answer := by
  sorry

/--
error: `question value` requires the statement of 'a_yes_no_question_tagged_value' to refer to the definition `a_yes_no_question_tagged_value.answer`; for a yes-or-no question use `question`
-/
#guard_msgs in
@[category research open, question value, AMS 11]
theorem a_yes_no_question_tagged_value : 2 + 2 = 4 := by
  sorry

open ProblemAttributes

/-- info: some QuestionKind.yesNo -/
#guard_msgs in
#eval show Lean.CoreM _ from getQuestionKind? `a_question

/-- info: some QuestionKind.yesNo -/
#guard_msgs in
#eval show Lean.CoreM _ from getQuestionKind? `a_question_first

/-- info: some QuestionKind.value -/
#guard_msgs in
#eval show Lean.CoreM _ from getQuestionKind? `a_value_question_with_def

-- An untagged theorem has no kind.
/-- info: none -/
#guard_msgs in
#eval show Lean.CoreM _ from getQuestionKind? `a_formally_solved_problem

-- A question belongs to a research problem, whichever attribute comes first.
/--
error: the `question` attribute belongs to a `research open` or `research solved` problem, but 'question_on_test' is categorised as `test`
-/
#guard_msgs in
@[category test, question]
theorem question_on_test : 1 + 1 = 2 := by
  rfl

/--
error: the `question` attribute belongs to a `research open` or `research solved` problem, but 'question_on_api' is categorised as `API`
-/
#guard_msgs in
@[question, category API]
theorem question_on_api : 1 + 1 = 2 := by
  rfl

/--
error: the `question` attribute belongs to a `research open` or `research solved` problem, but 'question_on_textbook' is categorised as `textbook`
-/
#guard_msgs in
@[category textbook, question]
theorem question_on_textbook : 1 + 1 = 2 := by
  rfl

-- The check also covers the `attribute` command.
#guard_msgs in
@[category test]
theorem later_question_on_test : 1 + 1 = 2 := by
  rfl

/--
error: the `question` attribute belongs to a `research open` or `research solved` problem, but 'later_question_on_test' is categorised as `test`
-/
#guard_msgs in
attribute [question] later_question_on_test

#guard_msgs in
@[category research open]
theorem later_question : 1 + 1 = 2 := by
  sorry

#guard_msgs in
attribute [question] later_question

/-- info: some QuestionKind.yesNo -/
#guard_msgs in
#eval show Lean.CoreM _ from getQuestionKind? `later_question

-- formal_proof on non-research categories
#guard_msgs in
@[category textbook, AMS 11, formal_proof using lean4 at "https://github.com/example/proof"]
theorem a_graduate_problem_with_formal_proof : 1 + 1 = 2 := by
  rfl

#guard_msgs in
@[category test, formal_proof using formal_conjectures at ""]
theorem a_test_with_formal_proof : 3 + 3 = 6 := by
  rfl

#guard_msgs in
theorem conditional_formal_proof_hypothesis : 0 = 0 := by
  sorry

#guard_msgs in
theorem another_conditional_formal_proof_hypothesis : 1 = 1 := by
  sorry

#guard_msgs in
@[category research solved,
  conditional formal_proof using lean4 at
    "https://palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002"
    assuming conditional_formal_proof_hypothesis]
theorem a_conditionally_formally_solved_problem : 4 + 4 = 8 := by
  rfl

#guard_msgs in
@[category research solved,
  conditional formal_proof using lean4 at
    "https://palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002"
    assuming conditional_formal_proof_hypothesis another_conditional_formal_proof_hypothesis]
theorem a_conditionally_formally_solved_problem_with_two_hypotheses : 5 + 5 = 10 := by
  rfl

run_meta do
  let conditions ← ProblemAttributes.getProofConditions ``a_conditionally_formally_solved_problem
  unless conditions = [``conditional_formal_proof_hypothesis] do
    throwError "unexpected proof conditions for a_conditionally_formally_solved_problem"

run_meta do
  let conditions ← ProblemAttributes.getProofConditions
    ``a_conditionally_formally_solved_problem_with_two_hypotheses
  unless conditions = [``conditional_formal_proof_hypothesis,
      ``another_conditional_formal_proof_hypothesis] do
    throwError
      "unexpected proof conditions for a_conditionally_formally_solved_problem_with_two_hypotheses"

/--
error: a `conditional` formal proof must name the hypotheses it assumes: state each hypothesis as
a declaration in this file (with a `sorry` proof) and reference it as
`conditional formal_proof using <kind> at "<link>" assuming <decl>`.
-/
#guard_msgs in
@[category research solved,
  conditional formal_proof using lean4 at "https://github.com/example/missing-hypothesis"]
theorem conditional_formal_proof_without_assuming : 6 + 6 = 12 := by
  rfl

/--
error: an `assuming` clause requires the `conditional` modifier:
`conditional formal_proof using <kind> at "<link>" assuming <decl>`.
-/
#guard_msgs in
@[category research solved,
  formal_proof using lean4 at "https://github.com/example/not-conditional"
    assuming conditional_formal_proof_hypothesis]
theorem assuming_without_conditional_formal_proof : 7 + 7 = 14 := by
  rfl

-- A `formal_proof` link is validated: external kinds must link to the proof, and
-- any link that is given must be a URL.

/--
warning: A `lean4` or `other_system` `formal_proof` should include a link to the proof.
-/
#guard_msgs in
@[category test, formal_proof using lean4 at ""]
theorem a_lean4_proof_with_empty_link : 4 + 4 = 8 := by
  rfl

/--
warning: A `formal_proof` link should be a URL (http:// or https://), but got: "not-a-url".
-/
#guard_msgs in
@[category test, formal_proof using lean4 at "not-a-url"]
theorem a_formal_proof_with_malformed_link : 5 + 5 = 10 := by
  rfl

-- Open research problems retain their existing warning for non-Palomar links.

/--
warning: A `formal_proof` annotation on a `research open` problem is suspicious. If a formal proof exists, the problem should not be categorised as `open`.
-/
#guard_msgs in
@[category research open, formal_proof using lean4 at "https://github.com/example/proof"]
theorem an_open_problem_with_formal_proof : True := by
  sorry

-- Solved research problems require Palomar entries, in either attribute order.

#guard_msgs in
@[category research solved,
  formal_proof using lean4 at
    "https://palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002&version=1"]
theorem a_solved_problem_with_palomar_proof : True := by
  sorry

#guard_msgs in
@[formal_proof using other_system at
    "https://palomar-registry.org/entry.html?version=1&id=PALOMAR-2026-10-05-000002",
  category research solved]
theorem a_solved_problem_with_palomar_proof_first : True := by
  sorry

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
@[category research solved, formal_proof using lean4 at "https://github.com/example/proof"]
theorem a_solved_problem_with_non_palomar_proof : True := by
  sorry

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
@[formal_proof using other_system at "https://github.com/example/proof", category research solved]
theorem a_solved_problem_with_non_palomar_proof_first : True := by
  sorry

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
@[category research solved, formal_proof using formal_conjectures at ""]
theorem a_solved_problem_with_empty_proof_link : True := by
  sorry

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
@[category research solved,
  conditional formal_proof using lean4 at "https://github.com/example/conditional-proof"
    assuming conditional_formal_proof_hypothesis]
theorem a_solved_problem_with_non_palomar_conditional_proof : True := by
  sorry

-- Applying either attribute later must enforce the same restriction.

#guard_msgs in
theorem an_uncategorised_problem_with_palomar_proof : True := by
  sorry

#guard_msgs in
attribute [formal_proof using formal_conjectures at
  "https://palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002"]
  an_uncategorised_problem_with_palomar_proof

#guard_msgs in
attribute [category research solved] an_uncategorised_problem_with_palomar_proof

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
attribute [formal_proof using lean4 at "https://github.com/example/proof"] FLT

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
attribute [category research solved] a_graduate_problem_with_formal_proof

-- The opt-out is local and does not disable the other link checks.

#guard_msgs in
set_option linter.style.formal_proof_palomar false in
@[category research solved, formal_proof using lean4 at "https://github.com/example/proof"]
theorem a_solved_problem_with_palomar_check_disabled : True := by
  sorry

#guard_msgs in
set_option linter.style.formal_proof_palomar false in
@[formal_proof using other_system at "https://github.com/example/proof", category research solved]
theorem a_solved_problem_with_palomar_check_disabled_first : True := by
  sorry

#guard_msgs in
set_option linter.style.formal_proof_palomar false in
@[category research solved,
  conditional formal_proof using lean4 at "https://github.com/example/conditional-proof"
    assuming conditional_formal_proof_hypothesis]
theorem a_conditional_proof_with_palomar_check_disabled : True := by
  sorry

/--
warning: A `lean4` or `other_system` `formal_proof` should include a link to the proof.
-/
#guard_msgs in
set_option linter.style.formal_proof_palomar false in
@[category research solved, formal_proof using lean4 at ""]
theorem a_solved_problem_with_empty_link_and_palomar_check_disabled : True := by
  sorry

/--
warning: A `formal_proof` link should be a URL (http:// or https://), but got: "not-a-url".
-/
#guard_msgs in
set_option linter.style.formal_proof_palomar false in
@[category research solved, formal_proof using lean4 at "not-a-url"]
theorem a_solved_problem_with_malformed_link_and_palomar_check_disabled : True := by
  sorry

/--
error: A `formal_proof` annotation on a `research solved` problem must link to a Palomar entry (https://palomar-registry.org/entry.html?id=...).
-/
#guard_msgs in
@[category research solved, formal_proof using lean4 at "https://github.com/example/proof"]
theorem a_solved_problem_after_local_palomar_opt_out : True := by
  sorry

-- Check URL boundaries without relying on the registry being reachable.
run_meta do
  let invalidLinks := [
    "https://palomar-registry.org/",
    "https://palomar-registry.org/entry.html",
    "https://palomar-registry.org/entry.html?id=",
    "https://palomar-registry.org/entry.html?version=1",
    "https://palomar-registry.org/entry.html#?id=PALOMAR-2026-10-05-000002",
    "https://palomar-registry.org.evil.example/entry.html?id=PALOMAR-2026-10-05-000002",
    "https://palomar-registry.org@evil.example/entry.html?id=PALOMAR-2026-10-05-000002",
    "https://example.com/palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002",
    "ftp://palomar-registry.org/entry.html?id=PALOMAR-2026-10-05-000002"]
  for link in invalidLinks do
    let rejected ← try
      ProblemAttributes.checkFormalProofLink (.research .solved) link
      pure false
    catch _ => pure true
    unless rejected do
      throwError "unexpectedly accepted Palomar entry link: {link}"

-- The `optimization_constant` attribute

#guard_msgs in
@[optimization_constant "1a"]
noncomputable def anOptimizationConstant : ℝ := 1

#guard_msgs in
@[optimization_constant "21a"]
def anotherOptimizationConstant : ℕ := 4

/--
warning: An `optimization_constant` id should be the name of the entry's page `https://teorth.github.io/optimizationproblems/constants/<id>.html`. This is one or more digits followed by one lowercase letter (e.g. "1a" or "21a"). The letter is required even when the database table shows only the number. Got: "21".
-/
#guard_msgs in
@[optimization_constant "21"]
def anOptimizationConstantWithoutLetter : ℕ := 4

run_meta do
  let tags ← ProblemAttributes.getOptimizationConstants ``anOptimizationConstant
  unless tags.map (·.constantId) = #["1a"] do
    throwError "unexpected optimization constant tags for anOptimizationConstant"

/--
warning: An `optimization_constant` id should be the name of the entry's page `https://teorth.github.io/optimizationproblems/constants/<id>.html`. This is one or more digits followed by one lowercase letter (e.g. "1a" or "21a"). The letter is required even when the database table shows only the number. Got: "a1".
-/
#guard_msgs in
@[optimization_constant "a1"]
noncomputable def anOptimizationConstantWithMalformedId : ℝ := 3

/--
warning: An `optimization_constant` annotation should be applied to the definition of the constant, but `an_optimization_constant_theorem` is not a definition. Theorems about the constant (e.g. bounds) should not carry this attribute.
-/
#guard_msgs in
@[category research open, AMS 11, optimization_constant "1a"]
theorem an_optimization_constant_theorem : 3 + 3 = 6 := by
  sorry

-- The `#AMS` command

/--
info: 0 General and overarching topics
1 History and biography
3 Mathematical logic and foundations
5 Combinatorics
6 Order, lattices, ordered algebraic structures
8 General algebraic systems
11 Number theory
12 Field theory and polynomials
13 Commutative algebra
14 Algebraic geometry
15 Linear and multilinear algebra; matrix theory
16 Associative rings and algebras
17 Nonassociative rings and algebras
18 Category theory; homological algebra
19 K-theory
20 Group theory and generalizations
22 Topological groups, Lie groups
26 Real functions
28 Measure and integration
30 Functions of a complex variable
31 Potential theory
32 Several complex variables and analytic spaces
33 Special functions
34 Ordinary differential equations
35 Partial differential equations
37 Dynamical systems and ergodic theory
39 Difference and functional equations
40 Sequences, series, summability
41 Approximations and expansions
42 Harmonic analysis on Euclidean spaces
43 Abstract harmonic analysis
44 Integral transforms, operational calculus
45 Integral equations
46 Functional analysis
47 Operator theory
49 Calculus of variations and optimal control; optimization
51 Geometry
52 Convex and discrete geometry
53 Differential geometry
54 General topology
55 Algebraic topology
57 Manifolds and cell complexes
58 Global analysis, analysis on manifolds
60 Probability theory and stochastic processes
62 Statistics
65 Numerical analysis
68 Computer science
70 Mechanics of particles and systems
74 Mechanics of deformable solids
76 Fluid mechanics
78 Optics, electromagnetic theory
80 Classical thermodynamics, heat transfer
81 Quantum theory
82 Statistical mechanics, structure of matter
83 Relativity and gravitational theory
85 Astronomy and astrophysics
86 Geophysics
90 Operations research, mathematical programming
91 Game theory, economics, social and behavioral sciences
92 Biology and other natural sciences
93 Systems theory; control
94 Information and communication, circuits
97 Mathematics education
-/
#guard_msgs in
#AMS