├── lean-toolchain ├── REPL.lean ├── REPL ├── Lean │ ├── ContextInfo.lean │ ├── Environment.lean │ ├── InfoTree │ │ └── ToJson.lean │ └── InfoTree.lean ├── Util │ ├── Path.lean │ └── Pickle.lean ├── Frontend.lean ├── JSON.lean ├── Snapshots.lean └── Main.lean ├── lakefile.lean ├── test.sh ├── lake-manifest.json ├── readme.md ├── pass_rate_new.py ├── pass_rate_output.txt └── test └── test.lean /lean-toolchain: -------------------------------------------------------------------------------- 1 | leanprover/lean4:v4.7.0-rc2 2 | -------------------------------------------------------------------------------- /REPL.lean: -------------------------------------------------------------------------------- 1 | import REPL.Frontend 2 | import REPL.Lean.InfoTree 3 | import REPL.JSON 4 | import REPL.Main 5 | -------------------------------------------------------------------------------- /REPL/Lean/ContextInfo.lean: -------------------------------------------------------------------------------- 1 | import Lean 2 | 3 | namespace Lean.Elab.ContextInfo 4 | 5 | /-- Pretty print an expression in the given `ContextInfo` with the given `LocalContext`. -/ 6 | def ppExpr (ctx : ContextInfo) (lctx : LocalContext) (e : Expr) : IO Format := 7 | ctx.runMetaM lctx (do Meta.ppExpr (← instantiateMVars e)) 8 | 9 | end Lean.Elab.ContextInfo 10 | -------------------------------------------------------------------------------- /lakefile.lean: -------------------------------------------------------------------------------- 1 | import Lake 2 | open Lake DSL 3 | 4 | package REPL { 5 | -- add package configuration options here 6 | } 7 | 8 | lean_lib REPL { 9 | -- add library configuration options here 10 | } 11 | 12 | @[default_target] 13 | lean_exe repl where 14 | root := `REPL.Main 15 | supportInterpreter := true 16 | 17 | require mathlib from git "https://github.com/leanprover-community/mathlib4"@"3cecb823a74ed737c6ebc115e515eba649ec7715" 18 | -------------------------------------------------------------------------------- /REPL/Lean/Environment.lean: -------------------------------------------------------------------------------- 1 | import REPL.Util.Pickle 2 | import Lean.Replay 3 | 4 | open System (FilePath) 5 | 6 | namespace Lean.Environment 7 | 8 | /-- 9 | Pickle an `Environment` to disk. 10 | 11 | We only store: 12 | * the list of imports 13 | * the new constants from `Environment.constants` 14 | and when unpickling, we build a fresh `Environment` from the imports, 15 | and then add the new constants. 16 | -/ 17 | def pickle (env : Environment) (path : FilePath) : IO Unit := 18 | _root_.pickle path (env.header.imports, env.constants.map₂) 19 | 20 | /-- 21 | Unpickle an `Environment` from disk. 22 | 23 | We construct a fresh `Environment` with the relevant imports, 24 | and then replace the new constants. 25 | -/ 26 | def unpickle (path : FilePath) : IO (Environment × CompactedRegion) := unsafe do 27 | let ((imports, map₂), region) ← _root_.unpickle (Array Import × PHashMap Name ConstantInfo) path 28 | let env ← importModules imports {} 0 29 | return (← env.replay (HashMap.ofList map₂.toList), region) 30 | 31 | end Lean.Environment 32 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define the paths 4 | IN_DIR="test" 5 | EXPECTED_DIR="test" 6 | 7 | lake build 8 | 9 | # Iterate over each .in file in the test directory 10 | for infile in $IN_DIR/*.in; do 11 | # Extract the base filename without the extension 12 | base=$(basename "$infile" .in) 13 | 14 | # Define the path for the expected output file 15 | expectedfile="$EXPECTED_DIR/$base.expected.out" 16 | 17 | # Check if the expected output file exists 18 | if [[ ! -f $expectedfile ]]; then 19 | echo "Expected output file $expectedfile does not exist. Skipping $infile." 20 | continue 21 | fi 22 | 23 | # Run the command and store its output in a temporary file 24 | tmpfile=$(mktemp) 25 | .lake/build/bin/repl < "$infile" > "$tmpfile" 2>&1 26 | 27 | # Compare the output with the expected output 28 | if diff "$tmpfile" "$expectedfile"; then 29 | echo "$base: PASSED" 30 | # Remove the temporary file 31 | rm "$tmpfile" 32 | else 33 | echo "$base: FAILED" 34 | # Remove the temporary file 35 | rm "$tmpfile" 36 | exit 1 37 | fi 38 | 39 | done 40 | 41 | # Run the Mathlib tests 42 | cp lean-toolchain test/Mathlib/ 43 | cd test/Mathlib/ && ./test.sh 44 | -------------------------------------------------------------------------------- /REPL/Util/Path.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2022 Gabriel Ebner. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Gabriel Ebner 5 | -/ 6 | import Lean 7 | 8 | -- This has been duplicated from Std4 to avoid a dependency. 9 | 10 | /-! 11 | # `compile_time_search_path%` term elaborator. 12 | 13 | Use this as `searchPathRef.set compile_time_search_path%`. 14 | -/ 15 | 16 | open Lean System 17 | 18 | -- Ideally this instance would be constructed simply by `deriving instance ToExpr for FilePath` 19 | -- but for now we have decided not to upstream the `ToExpr` derive handler from `Mathlib`. 20 | -- https://leanprover.zulipchat.com/#narrow/stream/348111-std4/topic/ToExpr.20derive.20handler/near/386476438 21 | instance : ToExpr FilePath where 22 | toTypeExpr := mkConst ``FilePath 23 | toExpr path := mkApp (mkConst ``FilePath.mk) (toExpr path.1) 24 | 25 | /-- 26 | Term elaborator that retrieves the current `SearchPath`. 27 | 28 | Typical usage is `searchPathRef.set compile_time_search_path%`. 29 | 30 | This must not be used in files that are potentially compiled on another machine and then 31 | imported. 32 | (That is, if used in an imported file it will embed the search path from whichever machine 33 | compiled the `.olean`.) 34 | -/ 35 | elab "compile_time_search_path%" : term => 36 | return toExpr (← searchPathRef.get) 37 | -------------------------------------------------------------------------------- /REPL/Util/Pickle.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Mario Carneiro. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Mario Carneiro 5 | -/ 6 | import Lean.Environment 7 | 8 | /-! 9 | # Pickling and unpickling objects 10 | 11 | By abusing `saveModuleData` and `readModuleData` we can pickle and unpickle objects to disk. 12 | -/ 13 | 14 | open Lean System 15 | 16 | /-- 17 | Save an object to disk. 18 | If you need to write multiple objects from within a single declaration, 19 | you will need to provide a unique `key` for each. 20 | -/ 21 | def pickle {α : Type} (path : FilePath) (x : α) (key : Name := by exact decl_name%) : IO Unit := 22 | saveModuleData path key (unsafe unsafeCast x) 23 | 24 | /-- 25 | Load an object from disk. 26 | Note: The returned `CompactedRegion` can be used to free the memory behind the value 27 | of type `α`, using `CompactedRegion.free` (which is only safe once all references to the `α` are 28 | released). Ignoring the `CompactedRegion` results in the data being leaked. 29 | Use `withUnpickle` to call `CompactedRegion.free` automatically. 30 | 31 | This function is unsafe because the data being loaded may not actually have type `α`, and this 32 | may cause crashes or other bad behavior. 33 | -/ 34 | unsafe def unpickle (α : Type) (path : FilePath) : IO (α × CompactedRegion) := do 35 | let (x, region) ← readModuleData path 36 | pure (unsafeCast x, region) 37 | 38 | /-- Load an object from disk and run some continuation on it, freeing memory afterwards. -/ 39 | unsafe def withUnpickle [Monad m] [MonadLiftT IO m] {α β : Type} 40 | (path : FilePath) (f : α → m β) : m β := do 41 | let (x, region) ← unpickle α path 42 | let r ← f x 43 | region.free 44 | pure r 45 | -------------------------------------------------------------------------------- /REPL/Frontend.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Scott Morrison. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Scott Morrison 5 | -/ 6 | import Lean.Elab.Frontend 7 | 8 | open Lean Elab 9 | 10 | namespace Lean.Elab.IO 11 | 12 | /-- 13 | Wrapper for `IO.processCommands` that enables info states, and returns 14 | * the new command state 15 | * messages 16 | * info trees 17 | -/ 18 | def processCommandsWithInfoTrees 19 | (inputCtx : Parser.InputContext) (parserState : Parser.ModuleParserState) 20 | (commandState : Command.State) : IO (Command.State × List Message × List InfoTree) := do 21 | let commandState := { commandState with infoState.enabled := true } 22 | let s ← IO.processCommands inputCtx parserState commandState <&> Frontend.State.commandState 23 | pure (s, s.messages.msgs.toList, s.infoState.trees.toList) 24 | 25 | /-- 26 | Process some text input, with or without an existing command state. 27 | If there is no existing environment, we parse the input for headers (e.g. import statements), 28 | and create a new environment. 29 | Otherwise, we add to the existing environment. 30 | 31 | Returns the resulting command state, along with a list of messages and info trees. 32 | -/ 33 | def processInput (input : String) (cmdState? : Option Command.State) 34 | (opts : Options := {}) (fileName : Option String := none) : 35 | IO (Command.State × List Message × List InfoTree) := unsafe do 36 | Lean.initSearchPath (← Lean.findSysroot) 37 | enableInitializersExecution 38 | let fileName := fileName.getD "" 39 | let inputCtx := Parser.mkInputContext input fileName 40 | let (parserState, commandState) ← match cmdState? with 41 | | none => do 42 | let (header, parserState, messages) ← Parser.parseHeader inputCtx 43 | let (env, messages) ← processHeader header opts messages inputCtx 44 | pure (parserState, (Command.mkState env messages opts)) 45 | | some cmdState => do 46 | pure ({ : Parser.ModuleParserState }, cmdState) 47 | processCommandsWithInfoTrees inputCtx parserState commandState 48 | -------------------------------------------------------------------------------- /lake-manifest.json: -------------------------------------------------------------------------------- 1 | {"version": 7, 2 | "packagesDir": ".lake/packages", 3 | "packages": 4 | [{"url": "https://github.com/leanprover/std4", 5 | "type": "git", 6 | "subDir": null, 7 | "rev": "e5306c3b0edefe722370b7387ee9bcd4631d6c17", 8 | "name": "std", 9 | "manifestFile": "lake-manifest.json", 10 | "inputRev": "main", 11 | "inherited": true, 12 | "configFile": "lakefile.lean"}, 13 | {"url": "https://github.com/leanprover-community/quote4", 14 | "type": "git", 15 | "subDir": null, 16 | "rev": "fd760831487e6835944e7eeed505522c9dd47563", 17 | "name": "Qq", 18 | "manifestFile": "lake-manifest.json", 19 | "inputRev": "master", 20 | "inherited": true, 21 | "configFile": "lakefile.lean"}, 22 | {"url": "https://github.com/leanprover-community/aesop", 23 | "type": "git", 24 | "subDir": null, 25 | "rev": "8be30c25e3caa06937feeb62f7ca898370f80ee9", 26 | "name": "aesop", 27 | "manifestFile": "lake-manifest.json", 28 | "inputRev": "master", 29 | "inherited": true, 30 | "configFile": "lakefile.lean"}, 31 | {"url": "https://github.com/leanprover-community/ProofWidgets4", 32 | "type": "git", 33 | "subDir": null, 34 | "rev": "fb65c476595a453a9b8ffc4a1cea2db3a89b9cd8", 35 | "name": "proofwidgets", 36 | "manifestFile": "lake-manifest.json", 37 | "inputRev": "v0.0.30", 38 | "inherited": true, 39 | "configFile": "lakefile.lean"}, 40 | {"url": "https://github.com/leanprover/lean4-cli", 41 | "type": "git", 42 | "subDir": null, 43 | "rev": "be8fa79a28b8b6897dce0713ef50e89c4a0f6ef5", 44 | "name": "Cli", 45 | "manifestFile": "lake-manifest.json", 46 | "inputRev": "main", 47 | "inherited": true, 48 | "configFile": "lakefile.lean"}, 49 | {"url": "https://github.com/leanprover-community/import-graph.git", 50 | "type": "git", 51 | "subDir": null, 52 | "rev": "61a79185b6582573d23bf7e17f2137cd49e7e662", 53 | "name": "importGraph", 54 | "manifestFile": "lake-manifest.json", 55 | "inputRev": "main", 56 | "inherited": true, 57 | "configFile": "lakefile.lean"}, 58 | {"url": "https://github.com/leanprover-community/mathlib4", 59 | "type": "git", 60 | "subDir": null, 61 | "rev": "3cecb823a74ed737c6ebc115e515eba649ec7715", 62 | "name": "mathlib", 63 | "manifestFile": "lake-manifest.json", 64 | "inputRev": "3cecb823a74ed737c6ebc115e515eba649ec7715", 65 | "inherited": false, 66 | "configFile": "lakefile.lean"}], 67 | "name": "REPL", 68 | "lakeDir": ".lake"} 69 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Automatic Lean4 Compilation 2 | 3 | The **automatic-lean4-compilation** repository automates the compilation of Lean4 language statements stored in JSON files. Its primary goal is to ensure the grammatical correctness and logical consistency of statements and proofs in Lean4, while also providing compilation information. 4 | 5 | This repository builds upon the foundation of [repl](https://github.com/leanprover-community/repl), a tool designed to interface directly with the Lean4 compiler in the terminal. 6 | 7 | ## Prerequisites 8 | 9 | Before using this tool, ensure that the following prerequisites are met (Linux only): 10 | 11 | - Install [elan](https://github.com/leanprover/elan) by running the following command: 12 | 13 | ```bash 14 | curl https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh -sSf | sh 15 | ``` 16 | 17 | - Install dependencies using the following commands: 18 | 19 | - Linux 20 | 21 | ```bash 22 | wget -q https://raw.githubusercontent.com/leanprover-community/mathlib4/master/scripts/install_debian.sh && bash install_debian.sh ; rm -f install_debian.sh && source ~/.profile 23 | ``` 24 | 25 | For other platforms, refer to [Lean4 setup documentation](https://lean-lang.org/lean4/doc/setup.html) for more details. 26 | 27 | ## Installation 28 | 29 | To install **automatic-lean4-compilation**, follow these steps: 30 | 31 | 1. Clone the repository: 32 | 33 | ```bash 34 | git clone https://github.com/rookie-joe/automatic-lean4-compilation.git 35 | ``` 36 | 37 | 2. Navigate to the cloned directory: 38 | 39 | ```bash 40 | cd automatic-lean4-compilation 41 | ``` 42 | 43 | 3. Run `lake update` to install the corresponding version of mathlib, as specified in the `lakefile.lean` and `lake-manifest.json` files. 44 | 45 | 4. Test the installation: 46 | 47 | - Run the following command to verify the Lean compiler and the REPL repository: 48 | 49 | ```bash 50 | echo '{ "cmd" : "def f := 2" }'| lake exe repl 51 | ``` 52 | 53 | - Additionally, you can test whether mathlib is correctly installed: 54 | 55 | ```bash 56 | echo '{"path": "test/test.lean", "allTactics": true}' | lake exe repl 57 | ``` 58 | 59 | A successful installation will output `{"env": 0}` for both commands. 60 | 61 | Alternatively, you can run `test.sh` for a comprehensive check of the prerequisites. 62 | 63 | ## Usage 64 | 65 | The quickest way to use the tool is by running the following command: 66 | 67 | ```bash 68 | python3 pass_rate_new.py --input_path {input_path} --output_path {output_path} 69 | ``` 70 | 71 | - `input_path` should be a directory containing `*.json` files. Each JSON file must be named starting with a **digit** and should contain a dictionary with four keys: 72 | 1. `"statement_proof"`: Contains the Lean4-based language to be compiled. 73 | 2. `"working_file"`: Contains the predependencies of the `"statement_proof"` (e.g., importing mathlib). 74 | 3. `"statement"`: Can have a value of `None`. 75 | 4. `"content"`: Can have a value of `None`. 76 | 77 | 78 | - `output_path` is recommended to be a text file that will display the compilation process and the final compilation pass rate for all items in `input_path`. 79 | 80 | ## Contribution 81 | 82 | We're actively seeking more contributors to join our project! Your efforts are greatly appreciated and welcomed. 83 | 84 | 85 | -------------------------------------------------------------------------------- /REPL/Lean/InfoTree/ToJson.lean: -------------------------------------------------------------------------------- 1 | import REPL.Lean.InfoTree 2 | import REPL.Lean.ContextInfo 3 | 4 | /-! 5 | # Exporting an `InfoTree` as Json 6 | 7 | -/ 8 | 9 | namespace Lean.Elab 10 | 11 | structure InfoTreeNode (α : Type) where 12 | kind : String 13 | node : Option α 14 | children : List Json 15 | deriving ToJson 16 | 17 | deriving instance ToJson for Lean.Position 18 | 19 | structure Syntax.Range where 20 | synthetic : Bool 21 | start : Lean.Position 22 | finish : Lean.Position 23 | deriving ToJson 24 | 25 | structure Syntax.Json where 26 | pp : Option String 27 | -- raw : String 28 | range : Range 29 | deriving ToJson 30 | 31 | def _root_.Lean.Syntax.toRange (stx : Syntax) (ctx : ContextInfo) : Syntax.Range := 32 | let pos := stx.getPos?.getD 0 33 | let endPos := stx.getTailPos?.getD pos 34 | { start := ctx.fileMap.toPosition pos 35 | finish := ctx.fileMap.toPosition endPos 36 | synthetic := match stx.getHeadInfo with 37 | | .original .. => false 38 | | _ => true } 39 | 40 | def _root_.Lean.Syntax.toJson (stx : Syntax) (ctx : ContextInfo) (lctx : LocalContext) : IO Syntax.Json := do 41 | return { 42 | pp := match (← ctx.ppSyntax lctx stx).pretty with 43 | | "failed to pretty print term (use 'set_option pp.rawOnError true' for raw representation)" => none 44 | | pp => some pp 45 | -- raw := toString stx 46 | range := stx.toRange ctx } 47 | 48 | structure TacticInfo.Json where 49 | name : Option Name 50 | stx : Syntax.Json 51 | goalsBefore : List String 52 | goalsAfter : List String 53 | deriving ToJson 54 | 55 | -- Note: this is not responsible for converting the children to Json. 56 | def TacticInfo.toJson (i : TacticInfo) (ctx : ContextInfo) : IO TacticInfo.Json := do 57 | return { 58 | name := i.name? 59 | stx := 60 | { pp := Format.pretty (← i.pp ctx), 61 | -- raw := toString i.info.stx, 62 | range := i.stx.toRange ctx }, 63 | goalsBefore := (← i.goalState ctx).map Format.pretty, 64 | goalsAfter := (← i.goalStateAfter ctx).map Format.pretty } 65 | 66 | structure CommandInfo.Json where 67 | elaborator : Option Name 68 | stx : Syntax.Json 69 | deriving ToJson 70 | 71 | def CommandInfo.toJson (info : CommandInfo) (ctx : ContextInfo) : IO CommandInfo.Json := do 72 | return { 73 | elaborator := match info.elaborator with | .anonymous => none | n => some n, 74 | stx := ← info.stx.toJson ctx {} } 75 | 76 | structure TermInfo.Json where 77 | elaborator : Option Name 78 | stx : Syntax.Json 79 | expectedType? : Option String 80 | expr : String 81 | isBinder : Bool 82 | deriving ToJson 83 | 84 | def TermInfo.toJson (info : TermInfo) (ctx : ContextInfo) : IO TermInfo.Json := do 85 | return { 86 | elaborator := match info.elaborator with | .anonymous => none | n => some n, 87 | stx := ← info.stx.toJson ctx info.lctx, 88 | expectedType? := ← info.expectedType?.mapM fun ty => do 89 | pure (← ctx.ppExpr info.lctx ty).pretty 90 | expr := (← ctx.ppExpr info.lctx info.expr).pretty 91 | isBinder := info.isBinder } 92 | 93 | structure InfoTree.HoleJson where 94 | goalState : String 95 | deriving ToJson 96 | 97 | partial def InfoTree.toJson (t : InfoTree) (ctx? : Option ContextInfo) : IO Json := do 98 | match t with 99 | | .context ctx t => t.toJson (ctx.mergeIntoOuter? ctx?) 100 | | .node info children => 101 | if let some ctx := ctx? then 102 | let node : Option Json ← match info with 103 | | .ofTermInfo info => some <$> (do pure <| Lean.toJson (← info.toJson ctx)) 104 | | .ofCommandInfo info => some <$> (do pure <| Lean.toJson (← info.toJson ctx)) 105 | | .ofTacticInfo info => some <$> (do pure <| Lean.toJson (← info.toJson ctx)) 106 | | _ => pure none 107 | return Lean.toJson (InfoTreeNode.mk info.kind node (← children.toList.mapM fun t' => t'.toJson ctx)) 108 | else throw <| IO.userError "No `ContextInfo` available." 109 | | .hole mvarId => 110 | if let some ctx := ctx? then 111 | return Lean.toJson (InfoTree.HoleJson.mk (← ctx.runMetaM {} (do Meta.ppGoal mvarId)).pretty) 112 | else throw <| IO.userError "No `ContextInfo` available." 113 | 114 | end Lean.Elab 115 | -------------------------------------------------------------------------------- /pass_rate_new.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | from argparse import ArgumentParser 4 | import json 5 | from concurrent.futures import ThreadPoolExecutor 6 | from tqdm import tqdm 7 | import glob 8 | import tempfile 9 | 10 | def wrapped_function(item): 11 | results = [] 12 | passed = 0 13 | total = 0 14 | 15 | temp_dir = tempfile.gettempdir() 16 | temp_file = os.path.join(temp_dir, f"test.lean") 17 | 18 | with open(temp_file, "w") as f: 19 | f.write(item['cmd']) 20 | 21 | # Rest of the function code... 22 | # Process the item using the temporary file 23 | # ... 24 | 25 | # Clean up the temporary file 26 | data = '{"path": "%s", "allTactics": true}' %(temp_file) 27 | command = 'echo \'%s\' | lake exe repl' % data 28 | 29 | try: 30 | result = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 31 | stdout = result.stdout.decode('utf-8') 32 | stderr = result.stderr.decode('utf-8') 33 | # stdout = result.stdout.decode('utf-8') 34 | json_stdout = json.loads(stdout) 35 | if "messages" not in json_stdout.keys(): 36 | passed += 1 37 | # results.append({'item': item['content'], 'stdout': stdout, 'stderr': stderr, 'status': 'pass'}) 38 | results.append({ 'stdout': stdout, 'stderr': stderr, 'status': 'pass'}) 39 | except subprocess.CalledProcessError as e: 40 | # results.append({'item': item['content'], 'error': str(e), 'status': 'nopass'}) 41 | results.append({ 'error': str(e), 'status': 'nopass'}) 42 | total += 1 43 | 44 | pass_rate = passed / (passed + total) * 100 45 | 46 | 47 | return {'results': results, 'pass_rate': pass_rate} 48 | 49 | 50 | 51 | def multi(command_list, output_path): 52 | results = [] 53 | passed = 0 54 | total = 0 55 | def execute_command(item): 56 | temp_dir = './test' 57 | temp_file = os.path.join(temp_dir, f"test_{item['index']}.lean") # Ensure unique filenames 58 | with open(temp_file, "w") as f: 59 | f.write(item['cmd']) 60 | 61 | data = '{"path": "%s", "allTactics": true}' % temp_file 62 | command = f'echo \'{data}\' | lake exe repl' 63 | 64 | try: 65 | result = subprocess.run(command, shell=True, check=True,timeout=600, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 66 | stdout = result.stdout.decode('utf-8') 67 | stderr = result.stderr.decode('utf-8') 68 | 69 | if "messages" not in json.loads(stdout) and not len(stderr): 70 | return {'stdout': stdout, 'stderr': stderr, 'status': 'pass' , 'statement':item['statement'], 'content': item['content']} 71 | else: 72 | return {'stdout': stdout, 'stderr': stderr, 'status': 'nopass', 'statement':item['statement'] , 'content': item['content']} 73 | 74 | except subprocess.TimeoutExpired as e: 75 | return {'error': str(e), 'status': 'nopass_limit', 'statement':item['statement'], 'content': item['content']} 76 | 77 | except subprocess.CalledProcessError as e: 78 | return {'error': str(e), 'status': 'nopass_error', 'statement':item['statement'], 'content': item['content']} 79 | 80 | os.remove(temp_file) 81 | 82 | total = len(command_list) 83 | 84 | with ThreadPoolExecutor(max_workers=32) as executor: 85 | futures = [executor.submit(execute_command, {'index': i, 'cmd': cmd['cmd'], 'statement':cmd['statement'], 'content':cmd['content']}) for i, cmd in enumerate(command_list)] 86 | for future in tqdm(futures, total=total, desc="Processing Commands"): 87 | result = future.result() 88 | results.append(result) 89 | if result['status'] == 'pass': 90 | passed += 1 91 | 92 | pass_rate = (passed / total) * 100 93 | print(f"total test: {total}") 94 | print(f"Pass rate: {pass_rate}%") 95 | 96 | output_file = f"pass_rate_results/{output_path}" 97 | # Create the directory if it doesn't exist 98 | os.makedirs(os.path.dirname(output_file), exist_ok=True) 99 | 100 | with open(f"{output_file}", 'w') as f: 101 | json.dump({'results': results, 'pass_rate': pass_rate}, f, indent=2, ensure_ascii=False) 102 | 103 | import re 104 | def remove_simp_pattern_from_end(s): 105 | pattern = r'@\[simp\s*.*?\]$' 106 | return re.sub(pattern, '', s) 107 | 108 | def main(args): 109 | command_list = [] 110 | file_pattern = os.path.join(args.input_path, '[0-9]*.json') 111 | for file_path in glob.glob(file_pattern): 112 | with open(file_path, 'r', encoding='utf-8') as rf: 113 | for line in rf.readlines(): 114 | try: 115 | json_item = json.loads(line) 116 | json_item['cmd'] = '\n\n'.join([json_item['working_file'], json_item['statement_proof']]) 117 | except: 118 | import pdb 119 | pdb.set_trace() 120 | command_list.append(json_item) 121 | command_list = command_list 122 | multi(command_list, args.output_path) 123 | 124 | if __name__ == '__main__': 125 | arg_parser = ArgumentParser() 126 | arg_parser.add_argument('--input_path', type=str, default='') 127 | arg_parser.add_argument('--output_path', type=str, default='total.json') 128 | args = arg_parser.parse_args() 129 | main(args) 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /REPL/JSON.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Scott Morrison. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Scott Morrison 5 | -/ 6 | import Lean.Data.Json 7 | import Lean.Message 8 | import Lean.Elab.InfoTree.Main 9 | 10 | open Lean Elab InfoTree 11 | 12 | namespace REPL 13 | 14 | structure CommandOptions where 15 | allTactics : Option Bool := none 16 | /-- 17 | Should be "full", "tactics", "original", or "substantive". 18 | Anything else is ignored. 19 | -/ 20 | infotree : Option String 21 | 22 | /-- Run Lean commands. 23 | If `env = none`, starts a new session (in which you can use `import`). 24 | If `env = some n`, builds on the existing environment `n`. 25 | -/ 26 | structure Command extends CommandOptions where 27 | env : Option Nat 28 | cmd : String 29 | deriving ToJson, FromJson 30 | 31 | /-- Process a Lean file in a fresh environment. -/ 32 | structure File extends CommandOptions where 33 | path : System.FilePath 34 | deriving FromJson 35 | 36 | /-- 37 | Run a tactic in a proof state. 38 | -/ 39 | structure ProofStep where 40 | proofState : Nat 41 | tactic : String 42 | deriving ToJson, FromJson 43 | 44 | /-- Line and column information for error messages and sorries. -/ 45 | structure Pos where 46 | line : Nat 47 | column : Nat 48 | deriving ToJson, FromJson 49 | 50 | /-- Severity of a message. -/ 51 | inductive Severity 52 | | trace | info | warning | error 53 | deriving ToJson, FromJson 54 | 55 | /-- A Lean message. -/ 56 | structure Message where 57 | pos : Pos 58 | endPos : Option Pos 59 | severity : Severity 60 | data : String 61 | deriving ToJson, FromJson 62 | 63 | /-- Construct the JSON representation of a Lean message. -/ 64 | def Message.of (m : Lean.Message) : IO Message := do pure <| 65 | { pos := ⟨m.pos.line, m.pos.column⟩, 66 | endPos := m.endPos.map fun p => ⟨p.line, p.column⟩, 67 | severity := match m.severity with 68 | | .information => .info 69 | | .warning => .warning 70 | | .error => .error, 71 | data := (← m.data.toString).trim } 72 | 73 | /-- A Lean `sorry`. -/ 74 | structure Sorry where 75 | pos : Pos 76 | endPos : Pos 77 | goal : String 78 | /-- 79 | The index of the proof state at the sorry. 80 | You can use the `ProofStep` instruction to run a tactic at this state. 81 | -/ 82 | proofState : Option Nat 83 | deriving FromJson 84 | 85 | instance : ToJson Sorry where 86 | toJson r := Json.mkObj <| .join [ 87 | [("goal", r.goal)], 88 | [("proofState", toJson r.proofState)], 89 | if r.pos.line ≠ 0 then [("pos", toJson r.pos)] else [], 90 | if r.endPos.line ≠ 0 then [("endPos", toJson r.endPos)] else [], 91 | ] 92 | 93 | /-- Construct the JSON representation of a Lean sorry. -/ 94 | def Sorry.of (goal : String) (pos endPos : Lean.Position) (proofState : Option Nat) : Sorry := 95 | { pos := ⟨pos.line, pos.column⟩, 96 | endPos := ⟨endPos.line, endPos.column⟩, 97 | goal, 98 | proofState } 99 | 100 | structure Tactic where 101 | pos : Pos 102 | endPos : Pos 103 | goals : String 104 | tactic : String 105 | proofState : Option Nat 106 | deriving ToJson, FromJson 107 | 108 | /-- Construct the JSON representation of a Lean tactic. -/ 109 | def Tactic.of (goals tactic : String) (pos endPos : Lean.Position) (proofState : Option Nat) : Tactic := 110 | { pos := ⟨pos.line, pos.column⟩, 111 | endPos := ⟨endPos.line, endPos.column⟩, 112 | goals, 113 | tactic, 114 | proofState } 115 | 116 | /-- 117 | A response to a Lean command. 118 | `env` can be used in later calls, to build on the stored environment. 119 | -/ 120 | structure CommandResponse where 121 | env : Nat 122 | messages : List Message := [] 123 | sorries : List Sorry := [] 124 | tactics : List Tactic := [] 125 | infotree : Option Json := none 126 | deriving FromJson 127 | 128 | def Json.nonemptyList [ToJson α] (k : String) : List α → List (String × Json) 129 | | [] => [] 130 | | l => [⟨k, toJson l⟩] 131 | 132 | instance : ToJson CommandResponse where 133 | toJson r := Json.mkObj <| .join [ 134 | [("env", r.env)], 135 | Json.nonemptyList "messages" r.messages, 136 | Json.nonemptyList "sorries" r.sorries, 137 | Json.nonemptyList "tactics" r.tactics, 138 | match r.infotree with | some j => [("infotree", j)] | none => [] 139 | ] 140 | 141 | /-- 142 | A response to a Lean tactic. 143 | `proofState` can be used in later calls, to run further tactics. 144 | -/ 145 | structure ProofStepResponse where 146 | proofState : Nat 147 | goals : List String 148 | messages : List Message := [] 149 | sorries : List Sorry := [] 150 | traces : List String 151 | deriving ToJson, FromJson 152 | 153 | instance : ToJson ProofStepResponse where 154 | toJson r := Json.mkObj <| .join [ 155 | [("proofState", r.proofState)], 156 | [("goals", toJson r.goals)], 157 | Json.nonemptyList "messages" r.messages, 158 | Json.nonemptyList "sorries" r.sorries, 159 | Json.nonemptyList "traces" r.traces 160 | ] 161 | 162 | /-- Json wrapper for an error. -/ 163 | structure Error where 164 | message : String 165 | deriving ToJson, FromJson 166 | 167 | structure PickleEnvironment where 168 | env : Nat 169 | pickleTo : System.FilePath 170 | deriving ToJson, FromJson 171 | 172 | structure UnpickleEnvironment where 173 | unpickleEnvFrom : System.FilePath 174 | deriving ToJson, FromJson 175 | 176 | structure PickleProofState where 177 | proofState : Nat 178 | pickleTo : System.FilePath 179 | deriving ToJson, FromJson 180 | 181 | structure UnpickleProofState where 182 | unpickleProofStateFrom : System.FilePath 183 | env : Option Nat 184 | deriving ToJson, FromJson 185 | 186 | end REPL 187 | -------------------------------------------------------------------------------- /REPL/Lean/InfoTree.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Scott Morrison. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Scott Morrison 5 | -/ 6 | import Lean 7 | 8 | /-! 9 | Additional functions to deal with `InfoTree`. 10 | -/ 11 | 12 | open Lean Elab Meta 13 | 14 | namespace Lean.FileMap 15 | 16 | /-- Extract the range of a `Syntax` expressed as lines and columns. -/ 17 | -- Extracted from the private declaration `Lean.Elab.formatStxRange`, 18 | -- in `Lean.Elab.InfoTree.Main`. 19 | def stxRange (fileMap : FileMap) (stx : Syntax) : Position × Position := 20 | let pos := stx.getPos?.getD 0 21 | let endPos := stx.getTailPos?.getD pos 22 | (fileMap.toPosition pos, fileMap.toPosition endPos) 23 | 24 | end Lean.FileMap 25 | 26 | namespace Lean.Syntax 27 | 28 | /-- Check if a `Syntax` is an explicit invocation of the `sorry` tactic. -/ 29 | def isSorryTactic (stx : Syntax) : Bool := 30 | s!"{stx}" = "(Tactic.tacticSorry \"sorry\")" 31 | 32 | /-- Check if a `Syntax` is an explicit `sorry` term. -/ 33 | def isSorryTerm (stx : Syntax) : Bool := 34 | s!"{stx}" = "(Term.sorry \"sorry\")" 35 | 36 | end Lean.Syntax 37 | 38 | namespace Lean.Elab 39 | 40 | /-- Extract the range of a `Syntax` expressed as lines and columns. -/ 41 | -- Extracted from the private declaration `Lean.Elab.formatStxRange`, 42 | -- in `Lean.Elab.InfoTree.Main`. 43 | def stxRange (fileMap : FileMap) (stx : Syntax) : Position × Position := 44 | let pos := stx.getPos?.getD 0 45 | let endPos := stx.getTailPos?.getD pos 46 | (fileMap.toPosition pos, fileMap.toPosition endPos) 47 | 48 | end Lean.Elab 49 | 50 | namespace Lean.Elab.Info 51 | 52 | /-- The type of a `Lean.Elab.Info`, as a string. -/ 53 | def kind : Info → String 54 | | .ofTacticInfo _ => "TacticInfo" 55 | | .ofTermInfo _ => "TermInfo" 56 | | .ofCommandInfo _ => "CommmandInfo" 57 | | .ofMacroExpansionInfo _ => "MacroExpansionInfo" 58 | | .ofOptionInfo _ => "OptionInfo" 59 | | .ofFieldInfo _ => "FieldInfo" 60 | | .ofCompletionInfo _ => "CompletionInfo" 61 | | .ofUserWidgetInfo _ => "UserWidgetInfo" 62 | | .ofCustomInfo _ => "CustomInfo" 63 | | .ofFVarAliasInfo _ => "FVarAliasInfo" 64 | | .ofFieldRedeclInfo _ => "FieldRedeclInfo" 65 | | .ofOmissionInfo _ => "OmissionInfo" 66 | 67 | /-- The `Syntax` for a `Lean.Elab.Info`, if there is one. -/ 68 | def stx? : Info → Option Syntax 69 | | .ofTacticInfo info => info.stx 70 | | .ofTermInfo info => info.stx 71 | | .ofCommandInfo info => info.stx 72 | | .ofMacroExpansionInfo info => info.stx 73 | | .ofOptionInfo info => info.stx 74 | | .ofFieldInfo info => info.stx 75 | | .ofCompletionInfo info => info.stx 76 | | .ofUserWidgetInfo info => info.stx 77 | | .ofCustomInfo info => info.stx 78 | | .ofFVarAliasInfo _ => none 79 | | .ofFieldRedeclInfo info => info.stx 80 | | .ofOmissionInfo info => info.stx 81 | 82 | /-- Is the `Syntax` for this `Lean.Elab.Info` original, or synthetic? -/ 83 | def isOriginal (i : Info) : Bool := 84 | match i.stx? with 85 | | none => true -- Somewhat unclear what to do with `FVarAliasInfo`, so be conservative. 86 | | some stx => match stx.getHeadInfo with 87 | | .original .. => true 88 | | _ => false 89 | 90 | end Lean.Elab.Info 91 | namespace Lean.Elab.TacticInfo 92 | 93 | /-- Find the name for the outermost `Syntax` in this `TacticInfo`. -/ 94 | def name? (t : TacticInfo) : Option Name := 95 | match t.stx with 96 | | Syntax.node _ n _ => some n 97 | | _ => none 98 | 99 | /-- Decide whether a tactic is "substantive", 100 | or is merely a tactic combinator (e.g. `by`, `;`, multiline tactics, parenthesized tactics). -/ 101 | def isSubstantive (t : TacticInfo) : Bool := 102 | match t.name? with 103 | | none => false 104 | | some `null => false 105 | | some ``cdot => false 106 | | some ``cdotTk => false 107 | | some ``Lean.Parser.Term.byTactic => false 108 | | some ``Lean.Parser.Tactic.tacticSeq => false 109 | | some ``Lean.Parser.Tactic.tacticSeq1Indented => false 110 | | some ``Lean.Parser.Tactic.«tactic_<;>_» => false 111 | | some ``Lean.Parser.Tactic.paren => false 112 | | _ => true 113 | 114 | end Lean.Elab.TacticInfo 115 | 116 | namespace Lean.Elab.InfoTree 117 | 118 | /-- 119 | Keep `.node` nodes and `.hole` nodes satisfying predicates. 120 | 121 | Returns a `List InfoTree`, although in most situations this will be a singleton. 122 | -/ 123 | partial def filter (p : Info → Bool) (m : MVarId → Bool := fun _ => false) : 124 | InfoTree → List InfoTree 125 | | .context ctx tree => tree.filter p m |>.map (.context ctx) 126 | | .node info children => 127 | if p info then 128 | [.node info (children.toList.map (filter p m)).join.toPArray'] 129 | else 130 | (children.toList.map (filter p m)).join 131 | | .hole mvar => if m mvar then [.hole mvar] else [] 132 | 133 | /-- Discard all nodes besides `.context` nodes and `TacticInfo` nodes. -/ 134 | partial def retainTacticInfo (tree : InfoTree) : List InfoTree := 135 | tree.filter fun | .ofTacticInfo _ => true | _ => false 136 | 137 | /-- Retain only nodes with "original" syntax. -/ 138 | partial def retainOriginal (tree : InfoTree) : List InfoTree := 139 | tree.filter Info.isOriginal 140 | 141 | /-- Discard all TacticInfo nodes that are tactic combinators or structuring tactics. -/ 142 | -- There is considerable grey area here: what to do with `classical`? 143 | partial def retainSubstantive (tree : InfoTree) : List InfoTree := 144 | tree.filter fun | .ofTacticInfo i => i.isSubstantive | _ => true 145 | 146 | /-- Analogue of `Lean.Elab.InfoTree.findInfo?`, but that returns all results. -/ 147 | partial def findAllInfo (t : InfoTree) (ctx? : Option ContextInfo) (p : Info → Bool) : 148 | List (Info × Option ContextInfo) := 149 | match t with 150 | | context ctx t => t.findAllInfo (ctx.mergeIntoOuter? ctx?) p 151 | | node i ts => 152 | let info := if p i then [(i, ctx?)] else [] 153 | let rest := ts.toList.bind (fun t => t.findAllInfo ctx? p) 154 | info ++ rest 155 | | _ => [] 156 | 157 | /-- Return all `TacticInfo` nodes in an `InfoTree` with "original" syntax, 158 | each equipped with its relevant `ContextInfo`. -/ 159 | def findTacticNodes (t : InfoTree) : List (TacticInfo × ContextInfo) := 160 | let infos := t.findAllInfo none fun i => match i with 161 | | .ofTacticInfo i' => i.isOriginal && i'.isSubstantive 162 | | _ => false 163 | infos.filterMap fun p => match p with 164 | | (.ofTacticInfo i, some ctx) => (i, ctx) 165 | | _ => none 166 | 167 | /-- Return all `TacticInfo` nodes in an `InfoTree` 168 | corresponding to explicit invocations of the `sorry` tactic, 169 | each equipped with its relevant `ContextInfo`. -/ 170 | def findSorryTacticNodes (t : InfoTree) : List (TacticInfo × ContextInfo) := 171 | let infos := t.findAllInfo none fun i => match i with 172 | | .ofTacticInfo i => i.stx.isSorryTactic && !i.goalsBefore.isEmpty 173 | | _ => false 174 | infos.filterMap fun p => match p with 175 | | (.ofTacticInfo i, some ctx) => (i, ctx) 176 | | _ => none 177 | 178 | /-- Return all `TermInfo` nodes in an `InfoTree` 179 | corresponding to explicit `sorry` terms, 180 | each equipped with its relevant `ContextInfo`. -/ 181 | def findSorryTermNodes (t : InfoTree) : List (TermInfo × ContextInfo) := 182 | let infos := t.findAllInfo none fun i => match i with 183 | | .ofTermInfo i => i.stx.isSorryTerm 184 | | _ => false 185 | infos.filterMap fun p => match p with 186 | | (.ofTermInfo i, some ctx) => (i, ctx) 187 | | _ => none 188 | 189 | inductive SorryType 190 | | tactic : MVarId → SorryType 191 | | term : LocalContext → Option Expr → SorryType 192 | deriving Inhabited 193 | 194 | /-- 195 | Finds all appearances of `sorry` in an `InfoTree`, reporting 196 | * the `ContextInfo` at that point, 197 | * the `MVarId` for a goal that was closed by `sorry`, 198 | or the `Option Expr` expected type for a term supplied by `sorry` 199 | * and the start and end positions of the `sorry` in the file. 200 | -/ 201 | def sorries (t : InfoTree) : List (ContextInfo × SorryType × Position × Position) := 202 | (t.findSorryTacticNodes.map fun ⟨i, ctx⟩ => 203 | -- HACK: creating a child ngen 204 | ({ ctx with mctx := i.mctxBefore, ngen := ctx.ngen.mkChild.1 }, .tactic i.goalsBefore.head!, 205 | stxRange ctx.fileMap i.stx)) ++ 206 | (t.findSorryTermNodes.map fun ⟨i, ctx⟩ => 207 | (ctx, .term i.lctx i.expectedType?, stxRange ctx.fileMap i.stx)) 208 | 209 | def tactics (t : InfoTree) : List (ContextInfo × Syntax × List MVarId × Position × Position) := 210 | (t.findTacticNodes.map fun ⟨i, ctx⟩ => 211 | -- HACK: creating a child ngen 212 | ({ ctx with mctx := i.mctxBefore, ngen := ctx.ngen.mkChild.1 }, i.stx, i.goalsBefore, 213 | stxRange ctx.fileMap i.stx)) 214 | 215 | 216 | end Lean.Elab.InfoTree 217 | 218 | namespace Lean.Elab.TacticInfo 219 | 220 | /-- Return the range of the tactic, as a pair of file positions. -/ 221 | def range (info : TacticInfo) (ctx : ContextInfo) : Position × Position := ctx.fileMap.stxRange info.stx 222 | 223 | /-- Pretty print a tactic. -/ 224 | def pp (info : TacticInfo) (ctx : ContextInfo) : IO Format := 225 | ctx.runMetaM {} try 226 | Lean.PrettyPrinter.ppTactic ⟨info.stx⟩ 227 | catch _ => 228 | pure "" 229 | 230 | open Meta 231 | 232 | /-- Run a tactic on the goals stored in a `TacticInfo`. -/ 233 | def runMetaMGoalsBefore (info : TacticInfo) (ctx : ContextInfo) (x : List MVarId → MetaM α) : IO α := do 234 | ctx.runMetaM {} <| Meta.withMCtx info.mctxBefore <| x info.goalsBefore 235 | 236 | /-- Run a tactic on the after goals stored in a `TacticInfo`. -/ 237 | def runMetaMGoalsAfter (info : TacticInfo) (ctx : ContextInfo) (x : List MVarId → MetaM α) : IO α := do 238 | ctx.runMetaM {} <| Meta.withMCtx info.mctxAfter <| x info.goalsAfter 239 | 240 | /-- Run a tactic on the main goal stored in a `TacticInfo`. -/ 241 | def runMetaM (info : TacticInfo) (ctx : ContextInfo) (x : MVarId → MetaM α) : IO α := do 242 | match info.goalsBefore.head? with 243 | | none => throw <| IO.userError s!"No goals at {← info.pp ctx}" 244 | | some g => info.runMetaMGoalsBefore ctx fun _ => do g.withContext <| x g 245 | 246 | def mainGoal (info : TacticInfo) (ctx : ContextInfo) : IO Expr := 247 | info.runMetaM ctx (fun g => do instantiateMVars (← g.getType)) 248 | 249 | def formatMainGoal (info : TacticInfo) (ctx : ContextInfo) : IO Format := 250 | info.runMetaM ctx (fun g => do ppExpr (← instantiateMVars (← g.getType))) 251 | 252 | def goalState (info : TacticInfo) (ctx : ContextInfo) : IO (List Format) := do 253 | info.runMetaMGoalsBefore ctx (fun gs => gs.mapM fun g => do Meta.ppGoal g) 254 | 255 | def goalStateAfter (info : TacticInfo) (ctx : ContextInfo) : IO (List Format) := do 256 | info.runMetaMGoalsAfter ctx (fun gs => gs.mapM fun g => do Meta.ppGoal g) 257 | 258 | def ppExpr (info : TacticInfo) (ctx : ContextInfo) (e : Expr) : IO Format := 259 | info.runMetaM ctx (fun _ => do Meta.ppExpr (← instantiateMVars e)) 260 | 261 | end Lean.Elab.TacticInfo 262 | 263 | namespace Lean.Elab.InfoTree 264 | 265 | /-- 266 | Finds all tactic invocations in an `InfoTree`, 267 | ignoring structuring tactics (e.g. `by`, `;`, multiline tactics, parenthesized tactics). 268 | -/ 269 | def substantiveTactics (t : InfoTree) : List (TacticInfo × ContextInfo) := 270 | t.findTacticNodes.filter fun i => i.1.isSubstantive 271 | 272 | end Lean.Elab.InfoTree 273 | -------------------------------------------------------------------------------- /pass_rate_output.txt: -------------------------------------------------------------------------------- 1 | Running for input path: /opt/tiger/mariana/auto-info/generate_result/zero_shot/lean4_basic_test/generation/lean4_random_5k/2/1/ 2 | 3 | Processing Commands: 0%| | 0/1080 [00:00 x.run ctx s 19 | 20 | @[inline] def CommandElabM.toIO (x : CommandElabM α) (ctx : Context) (s : State) : IO (α × State) := do 21 | match (← (x.run ctx s).toIO') with 22 | | Except.error (Exception.error _ msg) => throw <| IO.userError (← msg.toString) 23 | | Except.error (Exception.internal id _) => throw <| IO.userError <| "internal exception #" ++ toString id.idx 24 | | Except.ok a => return a 25 | 26 | end Lean.Elab.Command 27 | 28 | namespace REPL 29 | 30 | /-- 31 | Bundled structure for the `State` and `Context` objects 32 | for the `CommandElabM` monad. 33 | -/ 34 | structure CommandSnapshot where 35 | cmdState : Command.State 36 | cmdContext : Command.Context 37 | 38 | namespace CommandSnapshot 39 | 40 | open Lean.Elab.Command 41 | 42 | /-- A copy of `Command.State` with the `Environment`, caches, and logging omitted. -/ 43 | structure CompactableCommandSnapshot where 44 | -- env : Environment 45 | scopes : List Scope := [{ header := "" }] 46 | nextMacroScope : Nat := firstFrontendMacroScope + 1 47 | maxRecDepth : Nat 48 | nextInstIdx : Nat := 1 -- for generating anonymous instance names 49 | ngen : NameGenerator := {} 50 | -- infoState : InfoState := {} 51 | -- traceState : TraceState := {} 52 | -- messages : MessageLog := {} 53 | 54 | open System (FilePath) 55 | 56 | /-- 57 | Run a `CommandElabM` monadic function in the current `ProofSnapshot`, 58 | updating the `Command.State`. 59 | -/ 60 | def runCommandElabM (p : CommandSnapshot) (t : CommandElabM α) : IO (α × CommandSnapshot) := do 61 | let (a, cmdState) ← (CommandElabM.toIO · p.cmdContext p.cmdState) do t 62 | return (a, { p with cmdState }) 63 | 64 | 65 | /-- 66 | Pickle a `CommandSnapshot`, discarding closures and non-essential caches. 67 | 68 | When pickling the `Environment`, we do so relative to its imports. 69 | -/ 70 | def pickle (p : CommandSnapshot) (path : FilePath) : IO Unit := do 71 | let env := p.cmdState.env 72 | let p' := { p with cmdState := { p.cmdState with env := ← mkEmptyEnvironment }} 73 | _root_.pickle path 74 | (env.header.imports, 75 | env.constants.map₂, 76 | ({ p'.cmdState with } : CompactableCommandSnapshot), 77 | p'.cmdContext) 78 | 79 | /-- 80 | Unpickle a `CommandSnapshot`. 81 | -/ 82 | def unpickle (path : FilePath) : IO (CommandSnapshot × CompactedRegion) := unsafe do 83 | let ((imports, map₂, cmdState, cmdContext), region) ← 84 | _root_.unpickle (Array Import × PHashMap Name ConstantInfo × CompactableCommandSnapshot × 85 | Command.Context) path 86 | let env ← (← importModules imports {} 0).replay (HashMap.ofList map₂.toList) 87 | let p' : CommandSnapshot := 88 | { cmdState := { cmdState with env } 89 | cmdContext } 90 | let (_, p'') ← p'.runCommandElabM do 91 | for o in ← getOpenDecls do 92 | if let .simple ns _ := o then do 93 | activateScoped ns 94 | return (p'', region) 95 | 96 | end CommandSnapshot 97 | 98 | /-- 99 | Bundled structure for the `State` and `Context` objects 100 | for the `CoreM`, `MetaM`, `TermElabM`, and `TacticM` monads. 101 | -/ 102 | structure ProofSnapshot where 103 | coreState : Core.State 104 | coreContext : Core.Context 105 | metaState : Meta.State 106 | metaContext : Meta.Context 107 | termState : Term.State 108 | termContext : Term.Context 109 | tacticState : Tactic.State 110 | tacticContext : Tactic.Context 111 | 112 | namespace ProofSnapshot 113 | 114 | open Lean Elab Tactic 115 | 116 | /-- New messages in a `ProofSnapshot`, relative to an optional previous `ProofSnapshot`. -/ 117 | def newMessages (new : ProofSnapshot) (old? : Option ProofSnapshot := none) : List Lean.Message := 118 | match old? with 119 | | none => new.coreState.messages.msgs.toList 120 | | some old => new.coreState.messages.msgs.toList.drop (old.coreState.messages.msgs.size) 121 | 122 | /-- New info trees in a `ProofSnapshot`, relative to an optional previous `ProofSnapshot`. -/ 123 | def newInfoTrees (new : ProofSnapshot) (old? : Option ProofSnapshot := none) : List InfoTree := 124 | let infoState := new.coreState.infoState 125 | let trees := match old? with 126 | | none => infoState.trees.toList 127 | | some old => infoState.trees.toList.drop (old.coreState.infoState.trees.size) 128 | trees.map fun t => t.substitute infoState.assignment 129 | 130 | /-- Run a `CoreM` monadic function in the current `ProofSnapshot`, updating the `Core.State`. -/ 131 | def runCoreM (p : ProofSnapshot) (t : CoreM α) : IO (α × ProofSnapshot) := do 132 | let (a, coreState) ← (Lean.Core.CoreM.toIO · p.coreContext p.coreState) do t 133 | return (a, { p with coreState }) 134 | 135 | /-- Run a `MetaM` monadic function in the current `ProofSnapshot`, updating the `Meta.State`. -/ 136 | def runMetaM (p : ProofSnapshot) (t : MetaM α) : IO (α × ProofSnapshot) := do 137 | let ((a, metaState), p') ← 138 | p.runCoreM (Lean.Meta.MetaM.run (ctx := p.metaContext) (s := p.metaState) do t) 139 | return (a, { p' with metaState }) 140 | 141 | /-- Run a `TermElabM` monadic function in the current `ProofSnapshot`, updating the `Term.State`. -/ 142 | def runTermElabM (p : ProofSnapshot) (t : TermElabM α) : IO (α × ProofSnapshot) := do 143 | let ((a, termState), p') ← p.runMetaM (Lean.Elab.Term.TermElabM.run (s := p.termState) 144 | (do let r ← t; Term.synthesizeSyntheticMVarsNoPostponing; pure r)) 145 | return (a, { p' with termState }) 146 | 147 | /-- Run a `TacticM` monadic function in the current `ProofSnapshot`, updating the `Tactic.State`. -/ 148 | def runTacticM (p : ProofSnapshot) (t : TacticM α) : IO (α × ProofSnapshot) := do 149 | let ((a, tacticState), p') ← p.runTermElabM (t p.tacticContext |>.run p.tacticState) 150 | return (a, { p' with tacticState }) 151 | 152 | /-- 153 | Run a `TacticM` monadic function in the current `ProofSnapshot`, updating the `Tactic.State`, 154 | and discarding the return value. 155 | -/ 156 | def runTacticM' (p : ProofSnapshot) (t : TacticM α) : IO ProofSnapshot := 157 | Prod.snd <$> p.runTacticM t 158 | 159 | /-- New traces in a `ProofSnapshot`, relative to an optional previous `ProofSnapshot`. -/ 160 | def newTraces (new : ProofSnapshot) (old? : Option ProofSnapshot := none) : IO (List String) := 161 | match old? with 162 | | none => (·.1) <$> new.runCoreM (do 163 | (← getTraces).toList.mapM fun t => do pure (← t.msg.toString).trim) 164 | | some old => do 165 | let oldCount ← (·.1) <$> old.runCoreM (return (← getTraces).size) 166 | (·.1) <$> new.runCoreM (do 167 | ((← getTraces).toList.drop oldCount).mapM fun t => do pure (← t.msg.toString).trim) 168 | 169 | /-- 170 | Evaluate a `Syntax` into a `TacticM` tactic, and run it in the current `ProofSnapshot`. 171 | -/ 172 | def runSyntax (p : ProofSnapshot) (t : Syntax) : IO ProofSnapshot := 173 | Prod.snd <$> p.runTacticM (evalTactic t) 174 | 175 | /-- 176 | Parse a string into a `Syntax`, evaluate it as a `TacticM` tactic, 177 | and run it in the current `ProofSnapshot`. 178 | -/ 179 | def runString (p : ProofSnapshot) (t : String) : IO ProofSnapshot := 180 | match Parser.runParserCategory p.coreState.env `tactic t with 181 | | .error e => throw (IO.userError e) 182 | | .ok stx => p.runSyntax stx 183 | 184 | /-- Pretty print the current goals in the `ProofSnapshot`. -/ 185 | def ppGoals (p : ProofSnapshot) : IO (List Format) := 186 | Prod.fst <$> p.runMetaM do p.tacticState.goals.mapM (Meta.ppGoal ·) 187 | /-- 188 | Construct a `ProofSnapshot` from a `ContextInfo` and optional `LocalContext`, and a list of goals. 189 | 190 | For convenience, we also allow a list of `Expr`s, and these are appended to the goals 191 | as fresh metavariables with the given types. 192 | -/ 193 | def create (ctx : ContextInfo) (lctx? : Option LocalContext) (env? : Option Environment) 194 | (goals : List MVarId) (types : List Expr := []) : IO ProofSnapshot := do 195 | ctx.runMetaM (lctx?.getD {}) do 196 | let goals := goals ++ (← types.mapM fun t => Expr.mvarId! <$> Meta.mkFreshExprMVar (some t)) 197 | goals.head!.withContext do 198 | let s ← getThe Core.State 199 | let s := match env? with 200 | | none => s 201 | | some env => { s with env } 202 | pure <| 203 | { coreState := s 204 | coreContext := ← readThe Core.Context 205 | metaState := ← getThe Meta.State 206 | metaContext := ← readThe Meta.Context 207 | termState := {} 208 | termContext := {} 209 | tacticState := { goals } 210 | tacticContext := { elaborator := .anonymous } } 211 | 212 | open Lean.Core in 213 | /-- A copy of `Core.State` with the `Environment`, caches, and logging omitted. -/ 214 | structure CompactableCoreState where 215 | -- env : Environment 216 | nextMacroScope : MacroScope := firstFrontendMacroScope + 1 217 | ngen : NameGenerator := {} 218 | -- traceState : TraceState := {} 219 | -- cache : Core.Cache := {} 220 | -- messages : MessageLog := {} 221 | -- infoState : Elab.InfoState := {} 222 | 223 | open Lean.Meta in 224 | /-- A copy of `Meta.Context` with closures omitted. -/ 225 | structure CompactableMetaContext where 226 | config : Config := {} 227 | lctx : LocalContext := {} 228 | localInstances : LocalInstances := #[] 229 | defEqCtx? : Option DefEqContext := none 230 | synthPendingDepth : Nat := 0 231 | -- canUnfold? : Option (Config → ConstantInfo → CoreM Bool) := none 232 | 233 | /-- A copy of `Term.Context` with closures and a cache omitted. -/ 234 | structure CompactableTermContext where 235 | declName? : Option Name := none 236 | auxDeclToFullName : FVarIdMap Name := {} 237 | macroStack : MacroStack := [] 238 | mayPostpone : Bool := true 239 | errToSorry : Bool := true 240 | autoBoundImplicit : Bool := false 241 | autoBoundImplicits : PArray Expr := {} 242 | -- autoBoundImplicitForbidden : Name → Bool := fun _ => false 243 | sectionVars : NameMap Name := {} 244 | sectionFVars : NameMap Expr := {} 245 | implicitLambda : Bool := true 246 | isNoncomputableSection : Bool := false 247 | ignoreTCFailures : Bool := false 248 | inPattern : Bool := false 249 | -- tacticCache? : Option (IO.Ref Tactic.Cache) := none 250 | saveRecAppSyntax : Bool := true 251 | holesAsSyntheticOpaque : Bool := false 252 | 253 | open System (FilePath) 254 | 255 | /-- 256 | Pickle a `ProofSnapshot`, discarding closures and non-essential caches. 257 | 258 | When pickling the `Environment`, we do so relative to its imports. 259 | -/ 260 | def pickle (p : ProofSnapshot) (path : FilePath) : IO Unit := do 261 | let env := p.coreState.env 262 | let p' := { p with coreState := { p.coreState with env := ← mkEmptyEnvironment }} 263 | _root_.pickle path 264 | (env.header.imports, 265 | env.constants.map₂, 266 | ({ p'.coreState with } : CompactableCoreState), 267 | p'.coreContext, 268 | p'.metaState, 269 | ({ p'.metaContext with } : CompactableMetaContext), 270 | p'.termState, 271 | ({ p'.termContext with } : CompactableTermContext), 272 | p'.tacticState, 273 | p'.tacticContext) 274 | 275 | /-- 276 | Unpickle a `ProofSnapshot`. 277 | -/ 278 | def unpickle (path : FilePath) (cmd? : Option CommandSnapshot) : 279 | IO (ProofSnapshot × CompactedRegion) := unsafe do 280 | let ((imports, map₂, coreState, coreContext, metaState, metaContext, termState, termContext, 281 | tacticState, tacticContext), region) ← 282 | _root_.unpickle (Array Import × PHashMap Name ConstantInfo × CompactableCoreState × 283 | Core.Context × Meta.State × CompactableMetaContext × Term.State × CompactableTermContext × 284 | Tactic.State × Tactic.Context) path 285 | let env ← match cmd? with 286 | | none => 287 | enableInitializersExecution 288 | (← importModules imports {} 0).replay (HashMap.ofList map₂.toList) 289 | | some cmd => 290 | cmd.cmdState.env.replay (HashMap.ofList map₂.toList) 291 | let p' : ProofSnapshot := 292 | { coreState := { coreState with env } 293 | coreContext 294 | metaState 295 | metaContext := { metaContext with } 296 | termState 297 | termContext := { termContext with } 298 | tacticState 299 | tacticContext } 300 | let (_, p'') ← p'.runCoreM do 301 | for o in ← getOpenDecls do 302 | if let .simple ns _ := o then 303 | activateScoped ns 304 | return (p'', region) 305 | 306 | end ProofSnapshot 307 | -------------------------------------------------------------------------------- /REPL/Main.lean: -------------------------------------------------------------------------------- 1 | /- 2 | Copyright (c) 2023 Scott Morrison. All rights reserved. 3 | Released under Apache 2.0 license as described in the file LICENSE. 4 | Authors: Scott Morrison 5 | -/ 6 | import REPL.JSON 7 | import REPL.Frontend 8 | import REPL.Util.Path 9 | import REPL.Lean.ContextInfo 10 | import REPL.Lean.Environment 11 | import REPL.Lean.InfoTree 12 | import REPL.Lean.InfoTree.ToJson 13 | import REPL.Snapshots 14 | 15 | /-! 16 | # A REPL for Lean. 17 | 18 | Communicates via JSON on stdin and stdout. Commands should be separated by blank lines. 19 | 20 | Commands may be of the form 21 | ``` 22 | { "cmd" : "import Mathlib.Data.List.Basic\ndef f := 2" } 23 | ``` 24 | or 25 | ``` 26 | { "cmd" : "example : f = 2 := rfl", "env" : 3 } 27 | ``` 28 | 29 | The `env` field, if present, 30 | must contain a number received in the `env` field of a previous response, 31 | and causes the command to be run in the existing environment. 32 | 33 | If there is no `env` field, a new environment is created. 34 | 35 | You can only use `import` commands when you do not specify the `env` field. 36 | 37 | You can backtrack simply by using earlier values for `env`. 38 | 39 | The results are of the form 40 | ``` 41 | {"sorries": 42 | [{"pos": {"line": 1, "column": 18}, 43 | "endPos": {"line": 1, "column": 23}, 44 | "goal": "\n⊢ Nat"}], 45 | "messages": 46 | [{"severity": "error", 47 | "pos": {"line": 1, "column": 23}, 48 | "endPos": {"line": 1, "column": 26}, 49 | "data": 50 | "type mismatch\n rfl\nhas type\n f = f : Prop\nbut is expected to have type\n f = 2 : Prop"}], 51 | "env": 6} 52 | ``` 53 | showing any messages generated, or sorries with their goal states. 54 | Information is generated for tactic mode sorries, but not for term mode sorries. 55 | -/ 56 | 57 | open Lean Elab 58 | 59 | namespace REPL 60 | 61 | /-- The monadic state for the Lean REPL. -/ 62 | structure State where 63 | /-- 64 | Environment snapshots after complete declarations. 65 | The user can run a declaration in a given environment using `{"cmd": "def f := 37", "env": 17}`. 66 | -/ 67 | cmdStates : Array CommandSnapshot := #[] 68 | /-- 69 | Proof states after individual tactics. 70 | The user can run a tactic in a given proof state using `{"tactic": "exact 42", "proofState": 5}`. 71 | Declarations with containing `sorry` record a proof state at each sorry, 72 | and report the numerical index for the recorded state at each sorry. 73 | -/ 74 | proofStates : Array ProofSnapshot := #[] 75 | 76 | /-- 77 | The Lean REPL monad. 78 | 79 | We only use this with `m := IO`, but it is set up as a monad transformer for flexibility. 80 | -/ 81 | abbrev M (m : Type → Type) := StateT State m 82 | 83 | variable [Monad m] [MonadLiftT IO m] 84 | 85 | /-- Record an `CommandSnapshot` into the REPL state, returning its index for future use. -/ 86 | def recordCommandSnapshot (state : CommandSnapshot) : M m Nat := do 87 | let id := (← get).cmdStates.size 88 | modify fun s => { s with cmdStates := s.cmdStates.push state } 89 | return id 90 | 91 | /-- Record a `ProofSnapshot` into the REPL state, returning its index for future use. -/ 92 | def recordProofSnapshot (proofState : ProofSnapshot) : M m Nat := do 93 | let id := (← get).proofStates.size 94 | modify fun s => { s with proofStates := s.proofStates.push proofState } 95 | return id 96 | 97 | def sorries (trees : List InfoTree) (env? : Option Environment) : M m (List Sorry) := 98 | trees.bind InfoTree.sorries |>.mapM 99 | fun ⟨ctx, g, pos, endPos⟩ => do 100 | let (goal, proofState) ← match g with 101 | | .tactic g => do 102 | let s ← ProofSnapshot.create ctx none env? [g] 103 | pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s) 104 | | .term lctx (some t) => do 105 | let s ← ProofSnapshot.create ctx lctx env? [] [t] 106 | pure ("\n".intercalate <| (← s.ppGoals).map fun s => s!"{s}", some s) 107 | | .term _ none => unreachable! 108 | let proofStateId ← proofState.mapM recordProofSnapshot 109 | return Sorry.of goal pos endPos proofStateId 110 | 111 | def ppTactic (ctx : ContextInfo) (stx : Syntax) : IO Format := 112 | ctx.runMetaM {} try 113 | Lean.PrettyPrinter.ppTactic ⟨stx⟩ 114 | catch _ => 115 | pure "" 116 | 117 | def tactics (trees : List InfoTree) : M m (List Tactic) := 118 | trees.bind InfoTree.tactics |>.mapM 119 | fun ⟨ctx, stx, goals, pos, endPos⟩ => do 120 | let proofState := some (← ProofSnapshot.create ctx none none goals) 121 | let goals := s!"{(← ctx.ppGoals goals)}".trim 122 | let tactic := Format.pretty (← ppTactic ctx stx) 123 | let proofStateId ← proofState.mapM recordProofSnapshot 124 | return Tactic.of goals tactic pos endPos proofStateId 125 | 126 | /-- Record a `ProofSnapshot` and generate a JSON response for it. -/ 127 | def createProofStepReponse (proofState : ProofSnapshot) (old? : Option ProofSnapshot := none) : 128 | M m ProofStepResponse := do 129 | let messages := proofState.newMessages old? 130 | let messages ← messages.mapM fun m => Message.of m 131 | let traces ← proofState.newTraces old? 132 | let trees := proofState.newInfoTrees old? 133 | let trees ← match old? with 134 | | some old => do 135 | let (ctx, _) ← old.runMetaM do return { ← CommandContextInfo.save with } 136 | let ctx := PartialContextInfo.commandCtx ctx 137 | pure <| trees.map fun t => InfoTree.context ctx t 138 | | none => pure trees 139 | -- For debugging purposes, sometimes we print out the trees here: 140 | -- trees.forM fun t => do IO.println (← t.format) 141 | let sorries ← sorries trees none 142 | let id ← recordProofSnapshot proofState 143 | return { 144 | proofState := id 145 | goals := (← proofState.ppGoals).map fun s => s!"{s}" 146 | messages 147 | sorries 148 | traces } 149 | 150 | /-- Pickle a `CommandSnapshot`, generating a JSON response. -/ 151 | def pickleCommandSnapshot (n : PickleEnvironment) : M m (CommandResponse ⊕ Error) := do 152 | match (← get).cmdStates[n.env]? with 153 | | none => return .inr ⟨"Unknown environment."⟩ 154 | | some env => 155 | discard <| env.pickle n.pickleTo 156 | return .inl { env := n.env } 157 | 158 | /-- Unpickle a `CommandSnapshot`, generating a JSON response. -/ 159 | def unpickleCommandSnapshot (n : UnpickleEnvironment) : M IO CommandResponse := do 160 | let (env, _) ← CommandSnapshot.unpickle n.unpickleEnvFrom 161 | let env ← recordCommandSnapshot env 162 | return { env } 163 | 164 | /-- Pickle a `ProofSnapshot`, generating a JSON response. -/ 165 | -- This generates a new identifier, which perhaps is not what we want? 166 | def pickleProofSnapshot (n : PickleProofState) : M m (ProofStepResponse ⊕ Error) := do 167 | match (← get).proofStates[n.proofState]? with 168 | | none => return .inr ⟨"Unknown proof State."⟩ 169 | | some proofState => 170 | discard <| proofState.pickle n.pickleTo 171 | return .inl (← createProofStepReponse proofState) 172 | 173 | /-- Unpickle a `ProofSnapshot`, generating a JSON response. -/ 174 | def unpickleProofSnapshot (n : UnpickleProofState) : M IO (ProofStepResponse ⊕ Error) := do 175 | let (cmdSnapshot?, notFound) ← do match n.env with 176 | | none => pure (none, false) 177 | | some i => do match (← get).cmdStates[i]? with 178 | | some env => pure (some env, false) 179 | | none => pure (none, true) 180 | if notFound then 181 | return .inr ⟨"Unknown environment."⟩ 182 | let (proofState, _) ← ProofSnapshot.unpickle n.unpickleProofStateFrom cmdSnapshot? 183 | Sum.inl <$> createProofStepReponse proofState 184 | 185 | /-- 186 | Run a command, returning the id of the new environment, and any messages and sorries. 187 | -/ 188 | def runCommand (s : Command) : M IO (CommandResponse ⊕ Error) := do 189 | let (cmdSnapshot?, notFound) ← do match s.env with 190 | | none => pure (none, false) 191 | | some i => do match (← get).cmdStates[i]? with 192 | | some env => pure (some env, false) 193 | | none => pure (none, true) 194 | if notFound then 195 | return .inr ⟨"Unknown environment."⟩ 196 | let initialCmdState? := cmdSnapshot?.map fun c => c.cmdState 197 | let (cmdState, messages, trees) ← try 198 | IO.processInput s.cmd initialCmdState? 199 | catch ex => 200 | return .inr ⟨ex.toString⟩ 201 | let messages ← messages.mapM fun m => Message.of m 202 | -- For debugging purposes, sometimes we print out the trees here: 203 | -- trees.forM fun t => do IO.println (← t.format) 204 | let sorries ← sorries trees (initialCmdState?.map (·.env)) 205 | let tactics ← match s.allTactics with 206 | | some true => tactics trees 207 | | _ => pure [] 208 | let cmdSnapshot := 209 | { cmdState 210 | cmdContext := (cmdSnapshot?.map fun c => c.cmdContext).getD 211 | { fileName := "", fileMap := default, tacticCache? := none } } 212 | let env ← recordCommandSnapshot cmdSnapshot 213 | let jsonTrees := match s.infotree with 214 | | some "full" => trees 215 | | some "tactics" => trees.bind InfoTree.retainTacticInfo 216 | | some "original" => trees.bind InfoTree.retainTacticInfo |>.bind InfoTree.retainOriginal 217 | | some "substantive" => trees.bind InfoTree.retainTacticInfo |>.bind InfoTree.retainSubstantive 218 | | _ => [] 219 | let infotree := if jsonTrees.isEmpty then 220 | none 221 | else 222 | some <| Json.arr (← jsonTrees.toArray.mapM fun t => t.toJson none) 223 | return .inl 224 | { env, 225 | messages, 226 | sorries, 227 | tactics 228 | infotree } 229 | 230 | def processFile (s : File) : M IO (CommandResponse ⊕ Error) := do 231 | try 232 | let cmd ← IO.FS.readFile s.path 233 | runCommand { s with env := none, cmd } 234 | catch e => 235 | pure <| .inr ⟨e.toString⟩ 236 | 237 | /-- 238 | Run a single tactic, returning the id of the new proof statement, and the new goals. 239 | -/ 240 | -- TODO detect sorries? 241 | def runProofStep (s : ProofStep) : M IO (ProofStepResponse ⊕ Error) := do 242 | match (← get).proofStates[s.proofState]? with 243 | | none => return .inr ⟨"Unknown proof state."⟩ 244 | | some proofState => 245 | try 246 | let proofState' ← proofState.runString s.tactic 247 | return .inl (← createProofStepReponse proofState' proofState) 248 | catch ex => 249 | return .inr ⟨"Lean error:\n" ++ ex.toString⟩ 250 | 251 | end REPL 252 | 253 | open REPL 254 | 255 | /-- Get lines from stdin until a blank line is entered. -/ 256 | partial def getLines : IO String := do 257 | let line ← (← IO.getStdin).getLine 258 | if line.trim.isEmpty then 259 | return line 260 | else 261 | return line ++ (← getLines) 262 | 263 | instance [ToJson α] [ToJson β] : ToJson (α ⊕ β) where 264 | toJson x := match x with 265 | | .inl a => toJson a 266 | | .inr b => toJson b 267 | 268 | /-- Commands accepted by the REPL. -/ 269 | inductive Input 270 | | command : REPL.Command → Input 271 | | file : REPL.File → Input 272 | | proofStep : REPL.ProofStep → Input 273 | | pickleEnvironment : REPL.PickleEnvironment → Input 274 | | unpickleEnvironment : REPL.UnpickleEnvironment → Input 275 | | pickleProofSnapshot : REPL.PickleProofState → Input 276 | | unpickleProofSnapshot : REPL.UnpickleProofState → Input 277 | 278 | /-- Parse a user input string to an input command. -/ 279 | def parse (query : String) : IO Input := do 280 | let json := Json.parse query 281 | match json with 282 | | .error e => throw <| IO.userError <| toString <| toJson <| 283 | (⟨"Could not parse JSON:\n" ++ e⟩ : Error) 284 | | .ok j => match fromJson? j with 285 | | .ok (r : REPL.ProofStep) => return .proofStep r 286 | | .error _ => match fromJson? j with 287 | | .ok (r : REPL.PickleEnvironment) => return .pickleEnvironment r 288 | | .error _ => match fromJson? j with 289 | | .ok (r : REPL.UnpickleEnvironment) => return .unpickleEnvironment r 290 | | .error _ => match fromJson? j with 291 | | .ok (r : REPL.PickleProofState) => return .pickleProofSnapshot r 292 | | .error _ => match fromJson? j with 293 | | .ok (r : REPL.UnpickleProofState) => return .unpickleProofSnapshot r 294 | | .error _ => match fromJson? j with 295 | | .ok (r : REPL.Command) => return .command r 296 | | .error _ => match fromJson? j with 297 | | .ok (r : REPL.File) => return .file r 298 | | .error e => throw <| IO.userError <| toString <| toJson <| 299 | (⟨"Could not parse as a valid JSON command:\n" ++ e⟩ : Error) 300 | 301 | /-- Read-eval-print loop for Lean. -/ 302 | unsafe def repl : IO Unit := 303 | StateT.run' loop {} 304 | where loop : M IO Unit := do 305 | let query ← getLines 306 | if query = "" then 307 | return () 308 | if query.startsWith "#" || query.startsWith "--" then loop else 309 | IO.println <| toString <| ← match ← parse query with 310 | | .command r => return toJson (← runCommand r) 311 | | .file r => return toJson (← processFile r) 312 | | .proofStep r => return toJson (← runProofStep r) 313 | | .pickleEnvironment r => return toJson (← pickleCommandSnapshot r) 314 | | .unpickleEnvironment r => return toJson (← unpickleCommandSnapshot r) 315 | | .pickleProofSnapshot r => return toJson (← pickleProofSnapshot r) 316 | | .unpickleProofSnapshot r => return toJson (← unpickleProofSnapshot r) 317 | IO.println "" -- easier to parse the output if there are blank lines 318 | loop 319 | 320 | /-- Main executable function, run as `lake exe repl`. -/ 321 | unsafe def main (_ : List String) : IO Unit := do 322 | initSearchPath (← Lean.findSysroot) 323 | repl 324 | -------------------------------------------------------------------------------- /test/test.lean: -------------------------------------------------------------------------------- 1 | import Mathlib.MeasureTheory.Measure.GiryMonad 2 | import Mathlib.Dynamics.Ergodic.MeasurePreserving 3 | import Mathlib.MeasureTheory.Integral.Lebesgue 4 | import Mathlib.MeasureTheory.Measure.OpenPos 5 | import Mathlib.Analysis.Normed.Group.Basic 6 | import Mathlib.MeasureTheory.Function.AEMeasurableSequence 7 | import Mathlib.MeasureTheory.Group.Arithmetic 8 | import Mathlib.MeasureTheory.Order.Lattice 9 | import Mathlib.Topology.Instances.EReal 10 | import Mathlib.Topology.MetricSpace.Thickening 11 | import Mathlib.Topology.GDelta 12 | import Mathlib.Topology.Order.Lattice 13 | import Mathlib.Topology.Semicontinuous 14 | import Mathlib.Analysis.SpecificLimits.Basic 15 | import Mathlib.MeasureTheory.PiSystem 16 | import Mathlib.Data.Countable.Basic 17 | import Mathlib.Data.Fin.VecNotation 18 | import Mathlib.MeasureTheory.Measure.Content 19 | import Mathlib.MeasureTheory.Group.Prod 20 | import Mathlib.Topology.Algebra.Group.Compact 21 | import Mathlib.Dynamics.Ergodic.MeasurePreserving 22 | import Mathlib.LinearAlgebra.Determinant 23 | import Mathlib.LinearAlgebra.Matrix.Diagonal 24 | import Mathlib.LinearAlgebra.Matrix.Transvection 25 | import Mathlib.MeasureTheory.Constructions.Pi 26 | import Mathlib.MeasureTheory.Measure.Stieltjes 27 | import Mathlib.MeasureTheory.Measure.Haar.OfBasis 28 | import Mathlib.Data.Finset.Update 29 | import Mathlib.Data.Prod.TProd 30 | import Mathlib.GroupTheory.Coset 31 | import Mathlib.Logic.Equiv.Fin 32 | import Mathlib.MeasureTheory.MeasurableSpace.Defs 33 | import Mathlib.Order.Filter.SmallSets 34 | import Mathlib.Order.LiminfLimsup 35 | import Mathlib.Data.Set.UnionLift 36 | import Mathlib.Analysis.NormedSpace.BoundedLinearMaps 37 | import Mathlib.MeasureTheory.Measure.WithDensity 38 | import Mathlib.MeasureTheory.Function.SimpleFuncDense 39 | import Mathlib.Topology.Algebra.Module.FiniteDimension 40 | import Mathlib.MeasureTheory.Function.AEEqFun.DomAct 41 | import Mathlib.MeasureTheory.Function.LpSpace 42 | import Mathlib.Analysis.SpecialFunctions.Pow.NNReal 43 | import Mathlib.MeasureTheory.Constructions.BorelSpace.Complex 44 | import Mathlib.MeasureTheory.Function.ConditionalExpectation.CondexpL1 45 | import Mathlib.Analysis.NormedSpace.IndicatorFunction 46 | import Mathlib.MeasureTheory.Function.EssSup 47 | import Mathlib.MeasureTheory.Function.AEEqFun 48 | import Mathlib.MeasureTheory.Function.SpecialFunctions.Basic 49 | import Mathlib.Topology.Instances.ENNReal 50 | import Mathlib.MeasureTheory.Measure.Dirac 51 | import Mathlib.Probability.Notation 52 | import Mathlib.Probability.Process.Stopping 53 | import Mathlib.Probability.Independence.Kernel 54 | import Mathlib.MeasureTheory.Integral.Bochner 55 | import Mathlib.MeasureTheory.Measure.GiryMonad 56 | import Mathlib.Algebra.Module.Hom 57 | import Mathlib.Algebra.Module.Prod 58 | import Mathlib.Algebra.Module.Submodule.Ker 59 | import Mathlib.Data.Set.Finite 60 | import Mathlib.Order.ConditionallyCompleteLattice.Basic 61 | import Mathlib.LinearAlgebra.RootSystem.Defs 62 | import Mathlib.LinearAlgebra.Matrix.Adjugate 63 | import Mathlib.RingTheory.PolynomialAlgebra 64 | import Mathlib.Algebra.AddTorsor 65 | import Mathlib.GroupTheory.Perm.Sign 66 | import Mathlib.Data.Fintype.Perm 67 | import Mathlib.LinearAlgebra.Multilinear.Basis 68 | import Mathlib.Data.Finsupp.Fintype 69 | import Mathlib.LinearAlgebra.TensorProduct.Basis 70 | import Mathlib.RingTheory.Finiteness 71 | import Mathlib.LinearAlgebra.FreeModule.Basic 72 | import Mathlib.Algebra.RingQuot 73 | import Mathlib.LinearAlgebra.TensorAlgebra.Basic 74 | import Mathlib.LinearAlgebra.QuadraticForm.Isometry 75 | import Mathlib.LinearAlgebra.QuadraticForm.IsometryEquiv 76 | import Mathlib.Algebra.Module.Submodule.Bilinear 77 | import Mathlib.GroupTheory.Congruence 78 | import Mathlib.LinearAlgebra.Basic 79 | import Mathlib.Tactic.SuppressCompilation 80 | import Mathlib.LinearAlgebra.Matrix.Determinant 81 | import Mathlib.LinearAlgebra.Matrix.SesquilinearForm 82 | import Mathlib.LinearAlgebra.Matrix.Symmetric 83 | import Mathlib.Algebra.Algebra.Basic 84 | import Mathlib.Algebra.BigOperators.Order 85 | import Mathlib.Data.Fintype.BigOperators 86 | import Mathlib.Data.Fintype.Sort 87 | import Mathlib.Data.List.FinRange 88 | import Mathlib.LinearAlgebra.Pi 89 | import Mathlib.LinearAlgebra.CliffordAlgebra.Basic 90 | import Mathlib.LinearAlgebra.Alternating.Basic 91 | import Mathlib.Algebra.Algebra.Spectrum 92 | import Mathlib.LinearAlgebra.GeneralLinearGroup 93 | import Mathlib.LinearAlgebra.FiniteDimensional 94 | import Mathlib.Algebra.FreeAlgebra 95 | import Mathlib.Algebra.RingQuot 96 | import Mathlib.Algebra.TrivSqZeroExt 97 | import Mathlib.Algebra.Algebra.Operations 98 | import Mathlib.LinearAlgebra.Multilinear.Basic 99 | import Mathlib.Algebra.Algebra.Tower 100 | import Mathlib.LinearAlgebra.FiniteDimensional 101 | import Mathlib.LinearAlgebra.LinearIndependent 102 | import Mathlib.LinearAlgebra.FreeModule.Finite.Basic 103 | import Mathlib.LinearAlgebra.Matrix.Charpoly.Coeff 104 | import Mathlib.FieldTheory.Minpoly.Field 105 | import Mathlib.Init.Logic 106 | import Mathlib.Init.Function 107 | import Mathlib.Init.Algebra.Classes 108 | import Std.Util.LibraryNote 109 | import Std.Tactic.Lint.Basic 110 | import Mathlib.Init.Order.Defs 111 | import Mathlib.Logic.Nontrivial.Defs 112 | import Mathlib.Tactic.Attr.Register 113 | import Mathlib.Data.Prod.Basic 114 | import Mathlib.Data.Subtype 115 | import Mathlib.Logic.Function.Basic 116 | import Mathlib.Logic.Unique 117 | import Mathlib.Data.Bool.Basic 118 | import Mathlib.Data.Option.Defs 119 | import Mathlib.Data.Prod.Basic 120 | import Mathlib.Data.Sigma.Basic 121 | import Mathlib.Data.Subtype 122 | import Mathlib.Data.Sum.Basic 123 | import Mathlib.Init.Data.Sigma.Basic 124 | import Mathlib.Logic.Equiv.Defs 125 | import Mathlib.Logic.Function.Conjugate 126 | import Mathlib.Tactic.Lift 127 | import Mathlib.Tactic.Convert 128 | import Mathlib.Tactic.Contrapose 129 | import Mathlib.Tactic.GeneralizeProofs 130 | import Mathlib.Tactic.SimpRw 131 | import Mathlib.Logic.Equiv.Nat 132 | import Mathlib.Data.PNat.Basic 133 | import Mathlib.Order.Directed 134 | import Mathlib.Data.Countable.Defs 135 | import Mathlib.Order.RelIso.Basic 136 | import Mathlib.Data.Fin.Basic 137 | import Mathlib.Logic.Small.Defs 138 | import Mathlib.Logic.Equiv.Set 139 | import Mathlib.Logic.Nonempty 140 | import Mathlib.Init.Set 141 | import Mathlib.Logic.Basic 142 | import Mathlib.Data.Option.Basic 143 | import Mathlib.Data.Prod.PProd 144 | import Mathlib.Logic.Equiv.Basic 145 | import Mathlib.Analysis.Calculus.TangentCone 146 | import Mathlib.Analysis.NormedSpace.OperatorNorm.Asymptotics 147 | import Mathlib.Analysis.Calculus.Deriv.Add 148 | import Mathlib.Analysis.InnerProductSpace.Dual 149 | import Mathlib.Analysis.Calculus.FDeriv.Basic 150 | import Mathlib.Analysis.Calculus.Deriv.Basic 151 | import Mathlib.Analysis.Calculus.ContDiff.Basic 152 | import Mathlib.Analysis.NormedSpace.FiniteDimension 153 | import Mathlib.Analysis.Calculus.Deriv.Comp 154 | import Mathlib.Analysis.Calculus.Deriv.Add 155 | import Mathlib.Analysis.Calculus.Deriv.Mul 156 | import Mathlib.Analysis.Calculus.Deriv.Slope 157 | import Mathlib.Analysis.Calculus.FDeriv.Basic 158 | import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace 159 | import Mathlib.Analysis.Calculus.ContDiff.Defs 160 | import Mathlib.Analysis.Calculus.FDeriv.Add 161 | import Mathlib.Analysis.Calculus.FDeriv.Mul 162 | import Mathlib.Analysis.Calculus.Deriv.Inverse 163 | import Mathlib.Algebra.DirectSum.Module 164 | import Mathlib.Analysis.Complex.Basic 165 | import Mathlib.Analysis.Convex.Uniform 166 | import Mathlib.Analysis.NormedSpace.Completion 167 | import Mathlib.Analysis.NormedSpace.BoundedLinearMaps 168 | import Mathlib.Algebra.Algebra.NonUnitalSubalgebra 169 | import Mathlib.Algebra.Algebra.Subalgebra.Basic 170 | import Mathlib.Analysis.Normed.Group.Basic 171 | import Mathlib.GroupTheory.OrderOfElement 172 | import Mathlib.Topology.Instances.NNReal 173 | import Mathlib.Topology.MetricSpace.DilationEquiv 174 | import Mathlib.Algebra.Order.Group.TypeTags 175 | import Mathlib.Analysis.Normed.Field.Basic 176 | import Mathlib.Analysis.Normed.Group.Seminorm 177 | import Mathlib.Order.LiminfLimsup 178 | import Mathlib.Topology.Instances.Rat 179 | import Mathlib.Topology.MetricSpace.Algebra 180 | import Mathlib.Topology.MetricSpace.IsometricSMul 181 | import Mathlib.Topology.Sequences 182 | import Mathlib.Analysis.SpecialFunctions.Exp 183 | import Mathlib.Data.Nat.Factorization.Basic 184 | import Mathlib.Analysis.NormedSpace.Real 185 | import Mathlib.Analysis.SpecialFunctions.Exp 186 | import Mathlib.Tactic.Positivity.Core 187 | import Mathlib.MeasureTheory.Integral.ExpDecay 188 | import Mathlib.Analysis.SpecialFunctions.ImproperIntegrals 189 | import Mathlib.Analysis.MellinTransform 190 | import Mathlib.Analysis.Convex.Basic 191 | import Mathlib.Analysis.Convex.Hull 192 | import Mathlib.Analysis.NormedSpace.Basic 193 | import Mathlib.Topology.Bornology.Absorbs 194 | import Mathlib.Analysis.NormedSpace.Dual 195 | import Mathlib.Analysis.NormedSpace.Star.Basic 196 | import Mathlib.Analysis.Complex.Basic 197 | import Mathlib.Analysis.InnerProductSpace.Adjoint 198 | import Mathlib.Algebra.Star.Subalgebra 199 | import Mathlib.Analysis.BoxIntegral.Partition.Filter 200 | import Mathlib.Analysis.BoxIntegral.Partition.Measure 201 | import Mathlib.Topology.UniformSpace.Compact 202 | import Mathlib.Init.Data.Bool.Lemmas 203 | import Mathlib.Algebra.BigOperators.Option 204 | import Mathlib.Analysis.BoxIntegral.Box.Basic 205 | import Mathlib.Data.Set.Pairwise.Lattice 206 | import Mathlib.Data.Set.Intervals.Monotone 207 | import Mathlib.Topology.MetricSpace.Basic 208 | import Mathlib.Topology.MetricSpace.Bounded 209 | import Mathlib.Topology.Order.MonotoneConvergence 210 | import Mathlib.Data.Complex.Module 211 | import Mathlib.Data.Complex.Order 212 | import Mathlib.Data.Complex.Exponential 213 | import Mathlib.Data.RCLike.Basic 214 | import Mathlib.Topology.Algebra.InfiniteSum.Module 215 | import Mathlib.Topology.Instances.RealVectorSpace 216 | import Mathlib.Analysis.Complex.Circle 217 | import Mathlib.Analysis.NormedSpace.BallAction 218 | import Mathlib.Data.Fintype.Parity 219 | import Mathlib.LinearAlgebra.Matrix.SpecialLinearGroup 220 | import Mathlib.Analysis.Complex.Basic 221 | import Mathlib.GroupTheory.GroupAction.Defs 222 | import Mathlib.LinearAlgebra.Matrix.GeneralLinearGroup 223 | import Mathlib.Tactic.LinearCombination 224 | import Mathlib.Algebra.GeomSum 225 | import Mathlib.Order.Filter.Archimedean 226 | import Mathlib.Order.Iterate 227 | import Mathlib.Topology.Instances.ENNReal 228 | import Mathlib.Topology.Algebra.Algebra 229 | import Mathlib.Algebra.Order.Module.OrderedSMul 230 | import Mathlib.Analysis.Convex.Star 231 | import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace 232 | import Mathlib.Analysis.Convex.Hull 233 | import Mathlib.LinearAlgebra.AffineSpace.Independent 234 | import Mathlib.Analysis.Convex.Hull 235 | import Mathlib.Analysis.Convex.Slope 236 | import Mathlib.Analysis.SpecialFunctions.Pow.Real 237 | import Mathlib.Tactic.LinearCombination 238 | import Mathlib.Algebra.Algebra.Pi 239 | import Mathlib.Algebra.Algebra.RestrictScalars 240 | import Mathlib.Analysis.Normed.Field.Basic 241 | import Mathlib.Analysis.Normed.MulAction 242 | import Mathlib.Analysis.NormedSpace.OperatorNorm.NormedSpace 243 | import Mathlib.Topology.Algebra.Module.Multilinear.Basic 244 | import Mathlib.Algebra.Algebra.Tower 245 | import Mathlib.Analysis.LocallyConvex.WithSeminorms 246 | import Mathlib.Topology.Algebra.Module.StrongTopology 247 | import Mathlib.Analysis.NormedSpace.LinearIsometry 248 | import Mathlib.Analysis.NormedSpace.ContinuousLinearMap 249 | import Mathlib.Tactic.SuppressCompilation 250 | import Mathlib.Analysis.Normed.Group.Hom 251 | import Mathlib.Analysis.NormedSpace.Basic 252 | import Mathlib.Analysis.NormedSpace.LinearIsometry 253 | import Mathlib.Algebra.Star.SelfAdjoint 254 | import Mathlib.Algebra.Star.Subalgebra 255 | import Mathlib.Algebra.Star.Unitary 256 | import Mathlib.Topology.Algebra.Module.Star 257 | import Mathlib.Analysis.Calculus.FormalMultilinearSeries 258 | import Mathlib.Analysis.SpecificLimits.Normed 259 | import Mathlib.Logic.Equiv.Fin 260 | import Mathlib.Topology.Algebra.InfiniteSum.Module 261 | import Mathlib.CategoryTheory.Sites.Sheaf 262 | import Mathlib.Topology.Category.CompHaus.EffectiveEpi 263 | import Mathlib.Data.Fin.VecNotation 264 | import Mathlib.SetTheory.Cardinal.Basic 265 | import Mathlib.ModelTheory.Syntax 266 | import Mathlib.ModelTheory.Semantics 267 | import Mathlib.ModelTheory.Algebra.Ring.Basic 268 | import Mathlib.Algebra.Field.MinimalAxioms 269 | import Mathlib.ModelTheory.Syntax 270 | import Mathlib.ModelTheory.Semantics 271 | import Mathlib.Algebra.Ring.Equiv 272 | import Mathlib.Init.Control.Combinators 273 | import Mathlib.Init.Function 274 | import Mathlib.Tactic.CasesM 275 | import Mathlib.Tactic.Attr.Core 276 | import Mathlib.Logic.Equiv.Defs 277 | import Mathlib.Data.Option.Defs 278 | import Mathlib.Control.Functor 279 | import Mathlib.Control.Bifunctor 280 | import Mathlib.Control.Traversable.Basic 281 | import Mathlib.Init.Order.LinearOrder 282 | import Mathlib.Data.Prod.Basic 283 | import Mathlib.Data.Subtype 284 | import Mathlib.Tactic.Spread 285 | import Mathlib.Tactic.Convert 286 | import Mathlib.Tactic.SimpRw 287 | import Mathlib.Tactic.Cases 288 | import Mathlib.Order.Notation 289 | import Mathlib.Logic.Equiv.Option 290 | import Mathlib.Order.RelIso.Basic 291 | import Mathlib.Order.Disjoint 292 | import Mathlib.Order.WithBot 293 | import Mathlib.Tactic.Monotonicity.Attr 294 | import Mathlib.Util.AssertExists 295 | import Mathlib.Data.SetLike.Basic 296 | import Mathlib.Data.Set.Intervals.OrdConnected 297 | import Mathlib.Data.Set.Intervals.OrderIso 298 | import Mathlib.Data.Set.Lattice 299 | import Mathlib.Order.PropInstances 300 | import Mathlib.Data.Set.Finite 301 | import Mathlib.Logic.Function.Iterate 302 | import Mathlib.Init.Data.Int.Order 303 | import Mathlib.Order.Compare 304 | import Mathlib.Order.Max 305 | import Mathlib.Order.RelClasses 306 | import Mathlib.Tactic.Choose 307 | import Mathlib.Order.CompleteLattice 308 | import Mathlib.Order.Cover 309 | import Mathlib.Order.Iterate 310 | import Mathlib.Init.Algebra.Classes 311 | import Mathlib.Data.FunLike.Basic 312 | import Mathlib.Logic.Embedding.Basic 313 | import Mathlib.Order.RelClasses 314 | import Mathlib.Order.Atoms 315 | import Mathlib.Order.OrderIsoNat 316 | import Mathlib.Order.RelIso.Set 317 | import Mathlib.Order.SupClosed 318 | import Mathlib.Order.SupIndep 319 | import Mathlib.Order.Zorn 320 | import Mathlib.Data.Finset.Order 321 | import Mathlib.Data.Set.Intervals.OrderIso 322 | import Mathlib.Data.Finite.Set 323 | import Mathlib.Tactic.TFAE 324 | import Mathlib.Order.Bounds.Basic 325 | import Mathlib.Order.WellFounded 326 | import Mathlib.Data.Set.Image 327 | import Mathlib.Data.Set.Intervals.Basic 328 | import Mathlib.Data.Set.Lattice 329 | import Mathlib.Data.Set.Intervals.Basic 330 | import Mathlib.Data.Set.NAry 331 | import Mathlib.Order.Directed 332 | import Mathlib.Data.Sum.Order 333 | import Mathlib.Order.InitialSeg 334 | import Mathlib.SetTheory.Cardinal.Basic 335 | import Mathlib.Tactic.PPWithUniv 336 | import Mathlib.Data.Set.Lattice 337 | import Mathlib.Logic.Small.Basic 338 | import Mathlib.Logic.Function.OfArity 339 | import Mathlib.Order.WellFounded 340 | import Mathlib.Data.Int.Basic 341 | import Mathlib.SetTheory.Game.PGame 342 | import Mathlib.Tactic.Abel 343 | import Mathlib.Algebra.Order.Hom.Monoid 344 | import Mathlib.SetTheory.Game.Ordinal 345 | import Mathlib.Algebra.Module.Basic 346 | import Mathlib.Data.Fintype.BigOperators 347 | import Mathlib.Data.Finsupp.Defs 348 | import Mathlib.Data.Set.Countable 349 | import Mathlib.Logic.Small.Set 350 | import Mathlib.Order.ConditionallyCompleteLattice.Basic 351 | import Mathlib.Order.SuccPred.CompleteLinearOrder 352 | import Mathlib.SetTheory.Cardinal.SchroederBernstein 353 | import Mathlib.Tactic.PPWithUniv 354 | import Mathlib.Algebra.Group.Equiv.TypeTags 355 | import Mathlib.Algebra.Module.Basic 356 | import Mathlib.Algebra.Module.LinearMap.Basic 357 | import Mathlib.Algebra.MonoidAlgebra.Basic 358 | import Mathlib.LinearAlgebra.Dual 359 | import Mathlib.LinearAlgebra.Contraction 360 | import Mathlib.RingTheory.TensorProduct.Basic 361 | import Mathlib.Algebra.Category.GroupCat.Basic 362 | import Mathlib.CategoryTheory.SingleObj 363 | import Mathlib.CategoryTheory.Limits.FunctorCategory 364 | import Mathlib.CategoryTheory.Limits.Preserves.Basic 365 | import Mathlib.CategoryTheory.Adjunction.Limits 366 | import Mathlib.CategoryTheory.Conj 367 | import Mathlib.Algebra.Homology.Opposite 368 | import Mathlib.Algebra.Homology.ShortComplex.HomologicalComplex 369 | import Mathlib.RepresentationTheory.GroupCohomology.Resolution 370 | import Mathlib.CategoryTheory.Limits.HasLimits 371 | import Mathlib.CategoryTheory.Limits.Connected 372 | import Mathlib.CategoryTheory.Limits.Constructions.Over.Products 373 | import Mathlib.CategoryTheory.Limits.Constructions.Over.Connected 374 | import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers 375 | import Mathlib.CategoryTheory.Limits.Constructions.Equalizers 376 | import Mathlib.CategoryTheory.Limits.Shapes.RegularMono 377 | import Mathlib.CategoryTheory.Limits.Shapes.Kernels 378 | import Mathlib.CategoryTheory.Limits.Preserves.Basic 379 | import Mathlib.CategoryTheory.NatIso 380 | import Mathlib.CategoryTheory.Limits.Constructions.Pullbacks 381 | import Mathlib.CategoryTheory.Preadditive.Biproducts 382 | import Mathlib.CategoryTheory.Limits.Shapes.Images 383 | import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers 384 | import Mathlib.CategoryTheory.Abelian.NonPreadditive 385 | import Mathlib.CategoryTheory.Subobject.MonoOver 386 | import Mathlib.CategoryTheory.Skeletal 387 | import Mathlib.CategoryTheory.ConcreteCategory.Basic 388 | import Mathlib.Tactic.ApplyFun 389 | import Mathlib.Tactic.CategoryTheory.Elementwise 390 | import Mathlib.CategoryTheory.EqToHom 391 | import Mathlib.CategoryTheory.Functor.Const 392 | import Mathlib.CategoryTheory.Opposites 393 | import Mathlib.Data.Prod.Basic 394 | import Mathlib.CategoryTheory.CommSq 395 | import Mathlib.Algebra.BigOperators.Basic 396 | import Mathlib.Algebra.Group.Hom.Defs 397 | import Mathlib.Algebra.Module.Basic 398 | import Mathlib.CategoryTheory.Endomorphism 399 | import Mathlib.CategoryTheory.Limits.Shapes.Kernels 400 | import Mathlib.CategoryTheory.Preadditive.Opposite 401 | import Mathlib.Algebra.Category.ModuleCat.Basic 402 | import Mathlib.Algebra.Category.GroupCat.Preadditive 403 | import Mathlib.CategoryTheory.Functor.Category 404 | import Mathlib.CategoryTheory.Functor.FullyFaithful 405 | import Mathlib.CategoryTheory.Functor.ReflectsIso 406 | import Mathlib.CategoryTheory.EqToHom 407 | import Mathlib.CategoryTheory.NatIso 408 | import Mathlib.CategoryTheory.Products.Basic 409 | import Mathlib.Algebra.Group.Basic 410 | import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero 411 | import Mathlib.CategoryTheory.Monoidal.End 412 | import Mathlib.CategoryTheory.Monoidal.Discrete 413 | import Mathlib.CategoryTheory.Equivalence 414 | import Mathlib.CategoryTheory.FinCategory.Basic 415 | import Mathlib.CategoryTheory.Limits.Cones 416 | import Mathlib.CategoryTheory.Limits.Shapes.FiniteLimits 417 | import Mathlib.CategoryTheory.Adjunction.Basic 418 | import Mathlib.CategoryTheory.Category.Preorder 419 | import Mathlib.CategoryTheory.Category.ULift 420 | import Mathlib.CategoryTheory.PEmpty 421 | import Mathlib.CategoryTheory.Monoidal.Types.Symmetric 422 | import Mathlib.CategoryTheory.Monoidal.Types.Coyoneda 423 | import Mathlib.CategoryTheory.Monoidal.Center 424 | import Mathlib.Tactic.ApplyFun 425 | import Mathlib.CategoryTheory.Abelian.Basic 426 | import Mathlib.CategoryTheory.EqToHom 427 | import Mathlib.CategoryTheory.Iso 428 | import Mathlib.CategoryTheory.Functor.Category 429 | import Mathlib.CategoryTheory.EqToHom 430 | import Mathlib.CategoryTheory.Whiskering 431 | import Mathlib.CategoryTheory.Functor.FullyFaithful 432 | import Mathlib.CategoryTheory.NatIso 433 | import Mathlib.CategoryTheory.Extensive 434 | import Mathlib.CategoryTheory.Sites.Coverage 435 | import Mathlib.CategoryTheory.EffectiveEpi.Basic 436 | import Mathlib.CategoryTheory.Adjunction.Limits 437 | import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Products 438 | import Mathlib.CategoryTheory.Limits.Shapes.Biproducts 439 | import Mathlib.CategoryTheory.Shift.Basic 440 | import Mathlib.CategoryTheory.Types 441 | import Mathlib.CategoryTheory.Functor.EpiMono 442 | import Mathlib.CategoryTheory.Limits.Constructions.EpiMono 443 | import Mathlib.CategoryTheory.Monoidal.Free.Coherence 444 | import Mathlib.CategoryTheory.Monoidal.Discrete 445 | import Mathlib.CategoryTheory.Monoidal.NaturalTransformation 446 | import Mathlib.CategoryTheory.Monoidal.Opposite 447 | import Mathlib.Tactic.CategoryTheory.Coherence 448 | import Mathlib.CategoryTheory.CommSq 449 | import Mathlib.CategoryTheory.Monoidal.Functor 450 | import Mathlib.CategoryTheory.ChosenFiniteProducts 451 | import Mathlib.CategoryTheory.Limits.Shapes.Types 452 | import Mathlib.Logic.Equiv.Fin 453 | import Mathlib.CategoryTheory.Monoidal.Functor 454 | import Mathlib.CategoryTheory.Monoidal.Free.Coherence 455 | import Mathlib.Tactic.CategoryTheory.Coherence 456 | import Mathlib.CategoryTheory.Closed.Monoidal 457 | import Mathlib.Tactic.ApplyFun 458 | import Mathlib.CategoryTheory.Monoidal.Category 459 | import Mathlib.CategoryTheory.Limits.Shapes.BinaryProducts 460 | import Mathlib.CategoryTheory.PEmpty 461 | import Mathlib.CategoryTheory.Preadditive.Basic 462 | import Mathlib.Algebra.Module.LinearMap.Basic 463 | import Mathlib.Algebra.Algebra.Basic 464 | import Mathlib.CategoryTheory.Category.Init 465 | import Mathlib.Combinatorics.Quiver.Basic 466 | import Mathlib.Tactic.PPWithUniv 467 | import Mathlib.Tactic.Common 468 | import Mathlib.CategoryTheory.Limits.Shapes.Products 469 | import Mathlib.Data.Fintype.Basic 470 | import Mathlib.CategoryTheory.DiscreteCategory 471 | import Mathlib.CategoryTheory.Opposites 472 | import Mathlib.CategoryTheory.Category.ULift 473 | import Mathlib.CategoryTheory.Category.Basic 474 | import Mathlib.CategoryTheory.Comma.StructuredArrow 475 | import Mathlib.CategoryTheory.Limits.Shapes.Equivalence 476 | import Mathlib.CategoryTheory.FintypeCat 477 | import Mathlib.CategoryTheory.Limits.Constructions.LimitsOfProductsAndEqualizers 478 | import Mathlib.CategoryTheory.Limits.FintypeCat 479 | import Mathlib.CategoryTheory.Limits.MonoCoprod 480 | import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Terminal 481 | import Mathlib.CategoryTheory.Limits.Shapes.Types 482 | import Mathlib.CategoryTheory.Limits.Shapes.ConcreteCategory 483 | import Mathlib.CategoryTheory.Limits.Shapes.Diagonal 484 | import Mathlib.CategoryTheory.SingleObj 485 | import Mathlib.Data.Finite.Card 486 | import Mathlib.CategoryTheory.Groupoid 487 | import Mathlib.Combinatorics.Quiver.Basic 488 | import Mathlib.LinearAlgebra.StdBasis 489 | import Mathlib.Tactic.Linarith 490 | import Mathlib.Data.Finset.PiAntidiagonal 491 | import Mathlib.Data.MvPolynomial.Basic 492 | import Mathlib.Tactic.FinCases 493 | import Mathlib.Data.Nat.Choose.Sum 494 | import Mathlib.LinearAlgebra.Finsupp 495 | import Mathlib.Algebra.GroupPower.Order 496 | import Mathlib.RingTheory.Ideal.Operations 497 | import Mathlib.Tactic.TFAE 498 | import Mathlib.RingTheory.Adjoin.Basic 499 | import Mathlib.Algebra.Ring.Equiv 500 | import Mathlib.Algebra.Ring.Prod 501 | import Mathlib.Data.Set.Finite 502 | import Mathlib.GroupTheory.Submonoid.Membership 503 | import Mathlib.GroupTheory.Subsemigroup.Membership 504 | import Mathlib.GroupTheory.Subsemigroup.Centralizer 505 | import Mathlib.Algebra.EuclideanDomain.Basic 506 | import Mathlib.Data.Nat.Factors 507 | import Mathlib.RingTheory.Coprime.Basic 508 | import Mathlib.RingTheory.PrincipalIdealDomain 509 | import Mathlib.Algebra.CharP.ExpChar 510 | import Mathlib.Algebra.GeomSum 511 | import Mathlib.Data.MvPolynomial.CommRing 512 | import Mathlib.Data.MvPolynomial.Equiv 513 | import Mathlib.RingTheory.Polynomial.Content 514 | import Mathlib.RingTheory.UniqueFactorizationDomain 515 | import Mathlib.Algebra.NeZero 516 | import Mathlib.Algebra.Polynomial.BigOperators 517 | import Mathlib.RingTheory.RootsOfUnity.Complex 518 | import Mathlib.Data.Polynomial.Lifts 519 | import Mathlib.Data.Polynomial.Splits 520 | import Mathlib.FieldTheory.RatFunc 521 | import Mathlib.NumberTheory.ArithmeticFunction 522 | import Mathlib.RingTheory.RootsOfUnity.Basic 523 | import Mathlib.Data.Polynomial.Derivative 524 | import Mathlib.Data.Nat.Parity 525 | import Mathlib.Data.Nat.Factorial.DoubleFactorial 526 | import Mathlib.RingTheory.EisensteinCriterion 527 | import Mathlib.RingTheory.Polynomial.ScaleRoots 528 | import Mathlib.Algebra.GroupPower.Ring 529 | import Mathlib.Algebra.Ring.Divisibility.Basic 530 | import Mathlib.Algebra.Ring.Hom.Defs 531 | import Mathlib.GroupTheory.GroupAction.Units 532 | import Mathlib.Logic.Basic 533 | import Mathlib.Tactic.Ring 534 | import Mathlib.RingTheory.Noetherian 535 | import Mathlib.Algebra.DirectSum.Module 536 | import Mathlib.Algebra.DirectSum.Finsupp 537 | import Mathlib.Algebra.Module.Projective 538 | import Mathlib.Algebra.Module.Injective 539 | import Mathlib.Algebra.Module.CharacterModule 540 | import Mathlib.LinearAlgebra.DirectSum.TensorProduct 541 | import Mathlib.LinearAlgebra.FreeModule.Basic 542 | import Mathlib.Algebra.Module.Projective 543 | import Mathlib.GroupTheory.Subgroup.Basic 544 | import Mathlib.RingTheory.Subsemiring.Basic 545 | import Mathlib.Algebra.Algebra.Operations 546 | import Mathlib.Algebra.Algebra.Subalgebra.Tower 547 | import Mathlib.LinearAlgebra.Prod 548 | import Mathlib.LinearAlgebra.Finsupp 549 | import Mathlib.Algebra.Module.Basic 550 | import Mathlib.Algebra.Ring.Equiv 551 | import Mathlib.Algebra.Ring.Prod 552 | import Mathlib.Algebra.GroupRingAction.Subobjects 553 | import Mathlib.Data.Set.Finite 554 | import Mathlib.GroupTheory.Submonoid.Centralizer 555 | import Mathlib.GroupTheory.Submonoid.Membership 556 | import Mathlib.RingTheory.NonUnitalSubsemiring.Basic 557 | import Mathlib.GroupTheory.MonoidLocalization 558 | import Mathlib.Algebra.GroupWithZero.NonZeroDivisors 559 | import Mathlib.RingTheory.OreLocalization.OreSet 560 | import Mathlib.Tactic.NoncommRing 561 | import Mathlib.Algebra.Function.Support 562 | import Mathlib.Order.WellFoundedSet 563 | import Mathlib.RingTheory.Ideal.Over 564 | import Mathlib.RingTheory.Polynomial.RationalRoot 565 | import Mathlib.Algebra.CharP.Basic 566 | import Mathlib.Data.Polynomial.AlgebraMap 567 | import Mathlib.Data.MvPolynomial.Degrees 568 | import Mathlib.LinearAlgebra.FinsuppVectorSpace 569 | import Mathlib.LinearAlgebra.FreeModule.Finite.Basic 570 | import Mathlib.Algebra.DirectSum.Algebra 571 | import Mathlib.Algebra.DirectSum.Decomposition 572 | import Mathlib.Algebra.DirectSum.Internal 573 | import Mathlib.Algebra.DirectSum.Ring 574 | import Mathlib.Algebra.Algebra.Tower 575 | import Mathlib.Algebra.GroupWithZero.NonZeroDivisors 576 | import Mathlib.GroupTheory.MonoidLocalization 577 | import Mathlib.RingTheory.Ideal.Basic 578 | import Mathlib.GroupTheory.GroupAction.Ring 579 | import Mathlib.Init.Data.Int.CompLemmas 580 | import Mathlib.RingTheory.UniqueFactorizationDomain 581 | import Mathlib.RingTheory.Localization.Basic 582 | import Mathlib.Algebra.CharP.Two 583 | import Mathlib.Algebra.CharP.Reduced 584 | import Mathlib.Algebra.NeZero 585 | import Mathlib.Data.Polynomial.RingDivision 586 | import Mathlib.GroupTheory.SpecificGroups.Cyclic 587 | import Mathlib.NumberTheory.Divisors 588 | import Mathlib.RingTheory.IntegralDomain 589 | import Mathlib.Tactic.Zify 590 | import Mathlib.LinearAlgebra.FiniteDimensional 591 | import Mathlib.LinearAlgebra.TensorProduct.Tower 592 | import Mathlib.RingTheory.Adjoin.Basic 593 | import Mathlib.LinearAlgebra.DirectSum.Finsupp 594 | import Mathlib.Data.MvPolynomial.Counit 595 | import Mathlib.Data.MvPolynomial.Invertible 596 | import Mathlib.RingTheory.WittVector.Defs 597 | import Mathlib.RingTheory.MvPowerSeries.Basic 598 | import Mathlib.Data.Polynomial.Basic 599 | import Mathlib.Data.Polynomial.AlgebraMap 600 | import Mathlib.RingTheory.PrincipalIdealDomain 601 | import Mathlib.RingTheory.Ideal.LocalRing 602 | import Mathlib.RingTheory.Valuation.PrimeMultiplicity 603 | import Mathlib.LinearAlgebra.AdicCompletion 604 | import Mathlib.GroupTheory.Subgroup.Basic 605 | import Mathlib.RingTheory.NonUnitalSubsemiring.Basic 606 | import Mathlib.RingTheory.Localization.Integer 607 | import Mathlib.RingTheory.Localization.Submodule 608 | import Mathlib.Algebra.Group.Conj 609 | import Mathlib.Algebra.Group.Pi.Lemmas 610 | import Mathlib.Data.Set.Image 611 | import Mathlib.GroupTheory.Submonoid.Centralizer 612 | import Mathlib.Order.Atoms 613 | import Mathlib.Tactic.ApplyFun 614 | import Mathlib.Algebra.Group.Prod 615 | import Mathlib.Algebra.Group.Units.Equiv 616 | import Mathlib.Algebra.GroupPower.IterateHom 617 | import Mathlib.Logic.Equiv.Set 618 | import Mathlib.Algebra.Module.BigOperators 619 | import Mathlib.Data.Fintype.Perm 620 | import Mathlib.GroupTheory.Perm.Finite 621 | import Mathlib.GroupTheory.Perm.List 622 | import Mathlib.Algebra.Group.Hom.Defs 623 | import Mathlib.Algebra.Group.Units 624 | import Mathlib.GroupTheory.Subsemigroup.Basic 625 | import Mathlib.Algebra.PUnitInstances 626 | import Mathlib.GroupTheory.Subgroup.Basic 627 | import Mathlib.GroupTheory.Congruence 628 | import Mathlib.GroupTheory.Submonoid.Membership 629 | import Mathlib.Data.Fintype.Card 630 | import Mathlib.GroupTheory.GroupAction.Defs 631 | import Mathlib.GroupTheory.GroupAction.Group 632 | import Mathlib.Data.Setoid.Basic 633 | import Mathlib.Data.Set.Pointwise.SMul 634 | import Mathlib.GroupTheory.Subgroup.Basic 635 | import Mathlib.Algebra.Group.Opposite 636 | import Mathlib.Algebra.Group.Pi.Lemmas 637 | import Mathlib.GroupTheory.GroupAction.Defs 638 | import Mathlib.Algebra.Group.Hom.Defs 639 | import Mathlib.Data.Set.Lattice 640 | import Mathlib.Data.SetLike.Basic 641 | import Mathlib.Data.Fintype.Basic 642 | import Mathlib.Data.List.Sublists 643 | import Mathlib.Data.List.InsertNth 644 | import Mathlib.GroupTheory.Subgroup.Basic 645 | import Mathlib.Algebra.Group.TypeTags 646 | import Mathlib.Algebra.Ring.Defs 647 | import Mathlib.Data.Int.Cast.Basic 648 | import Mathlib.Order.Monotone.Basic 649 | import Mathlib.Data.Nat.Order.Basic 650 | import Mathlib.Data.Int.Basic 651 | import Mathlib.Algebra.Order.Group.Abs 652 | import Mathlib.Algebra.Order.Ring.CharZero 653 | import Mathlib.Algebra.Divisibility.Basic 654 | import Mathlib.Init.Data.Nat.Lemmas 655 | import Mathlib.Data.Int.Cast.Defs 656 | import Mathlib.Algebra.Group.Basic 657 | import Mathlib.Data.Int.Order.Basic 658 | import Mathlib.Data.Nat.Cast.Order 659 | import Mathlib.Algebra.Ring.Divisibility.Basic 660 | import Mathlib.Data.DList.Defs 661 | import Mathlib.Tactic.TypeStar 662 | import Mathlib.Mathport.Rename 663 | import Mathlib.Data.Nat.SuccPred 664 | import Mathlib.Algebra.CharZero.Lemmas 665 | import Mathlib.Algebra.Order.Sub.WithTop 666 | import Mathlib.Algebra.Order.Ring.WithTop 667 | import Mathlib.Data.Real.Sqrt 668 | import Mathlib.Analysis.NormedSpace.Star.Basic 669 | import Mathlib.Analysis.NormedSpace.ContinuousLinearMap 670 | import Mathlib.Analysis.NormedSpace.Basic 671 | import Mathlib.Init.ZeroOne 672 | import Mathlib.Data.Set.Defs 673 | import Mathlib.Order.Basic 674 | import Mathlib.Order.SymmDiff 675 | import Mathlib.Tactic.Tauto 676 | import Mathlib.Tactic.ByContra 677 | import Mathlib.Util.Delaborators 678 | import Mathlib.Data.Set.Function 679 | import Mathlib.Logic.Relation 680 | import Mathlib.Logic.Pairwise 681 | import Mathlib.Algebra.Group.Equiv.Basic 682 | import Mathlib.Algebra.Group.Units.Hom 683 | import Mathlib.Algebra.GroupPower.Basic 684 | import Mathlib.Algebra.GroupWithZero.Basic 685 | import Mathlib.Algebra.Opposites 686 | import Mathlib.Data.Nat.Order.Basic 687 | import Mathlib.Data.Set.Lattice 688 | import Mathlib.Tactic.Common 689 | import Mathlib.Order.MinMax 690 | import Mathlib.Data.Set.Basic 691 | import Mathlib.Tactic.Says 692 | import Mathlib.Data.List.Lex 693 | import Mathlib.Data.Char 694 | import Mathlib.Logic.Function.Basic 695 | import Mathlib.Tactic.MkIffOfInductiveProp 696 | import Mathlib.Data.PNat.Defs 697 | import Mathlib.Data.Nat.Bits 698 | import Mathlib.Data.Nat.Order.Basic 699 | import Mathlib.Data.Set.Basic 700 | import Mathlib.Algebra.GroupWithZero.Divisibility 701 | import Mathlib.Algebra.Order.Positive.Ring 702 | import Mathlib.Order.Hom.Basic 703 | import Mathlib.Data.W.Basic 704 | import Mathlib.Control.Functor.Multivariate 705 | import Mathlib.Data.PFunctor.Univariate.Basic 706 | import Mathlib.Init.Function 707 | import Mathlib.Logic.Function.Basic 708 | import Mathlib.Tactic.Inhabit 709 | import Mathlib.Algebra.Module.LinearMap.Basic 710 | import Mathlib.Algebra.BigOperators.Basic 711 | import Mathlib.Data.Set.Finite 712 | import Mathlib.GroupTheory.Submonoid.Membership 713 | import Mathlib.GroupTheory.GroupAction.BigOperators 714 | import Mathlib.Data.Finset.Preimage 715 | import Lean.Linter.Deprecated 716 | import Mathlib.Mathport.Rename 717 | import Mathlib.Init.Data.Nat.Bitwise 718 | import Mathlib.Init.Data.Int.Basic 719 | import Mathlib.Init.ZeroOne 720 | import Mathlib.Logic.Equiv.List 721 | import Mathlib.Init.Function 722 | import Mathlib.Logic.Function.Basic 723 | import Mathlib.Algebra.Algebra.Tower 724 | import Mathlib.Algebra.GroupPower.Ring 725 | import Mathlib.Algebra.Regular.Pow 726 | import Mathlib.Algebra.MonoidAlgebra.Support 727 | import Mathlib.Data.Finsupp.Antidiagonal 728 | import Mathlib.Order.SymmDiff 729 | import Mathlib.RingTheory.Adjoin.Basic 730 | import Mathlib.Control.Traversable.Equiv 731 | import Mathlib.Control.Traversable.Instances 732 | import Std.Data.LazyList 733 | import Mathlib.Lean.Thunk 734 | import Mathlib.Logic.Relation 735 | import Mathlib.Order.GaloisConnection 736 | import Mathlib.Data.Vector 737 | import Mathlib.Data.List.Nodup 738 | import Mathlib.Data.List.OfFn 739 | import Mathlib.Data.List.InsertNth 740 | import Mathlib.Control.Applicative 741 | import Mathlib.Control.Traversable.Basic 742 | import Mathlib.Algebra.GroupPower.Ring 743 | import Mathlib.Algebra.MonoidAlgebra.Basic 744 | import Mathlib.Data.Finset.Sort 745 | import Mathlib.RingTheory.Finiteness 746 | import Mathlib.Data.Polynomial.AlgebraMap 747 | import Std.Tactic.Alias 748 | import Mathlib.Algebra.BigOperators.Finsupp 749 | import Mathlib.Algebra.Regular.SMul 750 | import Mathlib.Data.Finset.Preimage 751 | import Mathlib.Data.Rat.BigOperators 752 | import Mathlib.GroupTheory.GroupAction.Hom 753 | import Mathlib.Data.Set.Basic 754 | import Mathlib.Data.Finset.Attr 755 | import Mathlib.Data.Multiset.Bind 756 | import Mathlib.Data.Multiset.FinsetOps 757 | import Mathlib.Data.Set.Lattice 758 | import Mathlib.Order.Cover 759 | import Mathlib.Order.LocallyFinite 760 | import Mathlib.Data.Set.Intervals.Monoid 761 | import Mathlib.Algebra.Group.TypeTags 762 | import Mathlib.Algebra.Ring.Defs 763 | import Mathlib.Algebra.GroupWithZero.Defs 764 | import Mathlib.Algebra.Order.Monoid.WithZero 765 | import Mathlib.Algebra.Order.Ring.Canonical 766 | import Mathlib.Data.Nat.Basic 767 | import Mathlib.Data.Nat.Defs 768 | import Mathlib.Tactic.GCongr.Core 769 | import Mathlib.Tactic.Common 770 | import Mathlib.Tactic.Monotonicity.Attr 771 | import Mathlib.Algebra.GroupPower.Basic 772 | import Mathlib.Algebra.GroupWithZero.Divisibility 773 | import Mathlib.Data.Nat.Order.Lemmas 774 | import Mathlib.Tactic.NthRewrite 775 | import Mathlib.Algebra.Divisibility.Basic 776 | import Mathlib.Algebra.Group.Equiv.Basic 777 | import Mathlib.Algebra.Group.TypeTags 778 | import Mathlib.Algebra.Ring.Hom.Defs 779 | import Mathlib.Data.Nat.Basic 780 | import Mathlib.Init.Data.Nat.Lemmas 781 | import Mathlib.Init.Data.Nat.Bitwise 782 | import Mathlib.Data.Nat.GCD.Basic 783 | import Mathlib.Logic.Function.Iterate 784 | import Mathlib.Data.Finset.NatAntidiagonal 785 | import Mathlib.Algebra.BigOperators.Basic 786 | import Mathlib.Tactic.Ring 787 | import Mathlib.Tactic.Zify 788 | import Mathlib.Data.Nat.Factorial.Basic 789 | import Mathlib.Order.Monotone.Basic 790 | import Mathlib.Algebra.BigOperators.Finsupp 791 | import Mathlib.Data.Finsupp.Multiset 792 | import Mathlib.Data.Nat.PrimeFin 793 | import Mathlib.NumberTheory.Padics.PadicVal 794 | import Mathlib.Data.Nat.GCD.BigOperators 795 | import Mathlib.Data.Nat.Interval 796 | import Mathlib.Tactic.IntervalCases 797 | import Mathlib.Algebra.GroupPower.Order 798 | import Mathlib.Data.Set.Basic 799 | import Mathlib.Tactic.Monotonicity.Attr 800 | import Mathlib.Tactic.SetLike 801 | import Mathlib.Algebra.NeZero 802 | import Mathlib.Order.RelIso.Basic 803 | import Mathlib.Data.Nat.Order.Basic 804 | import Mathlib.Order.Hom.Set 805 | import Std.Data.Fin.Lemmas 806 | import Mathlib.Data.Fin.OrderHom 807 | import Mathlib.Data.Pi.Lex 808 | import Mathlib.Data.Set.Intervals.Basic 809 | import Mathlib.Algebra.Star.Basic 810 | import Mathlib.Algebra.Order.CauSeq.Completion 811 | import Mathlib.Algebra.CharP.Basic 812 | import Mathlib.RingTheory.Ideal.Operations 813 | import Mathlib.Data.Fintype.Units 814 | import Mathlib.Data.Nat.Parity 815 | import Mathlib.Tactic.FinCases 816 | import Mathlib.Logic.Function.Basic 817 | import Mathlib.Util.CompileInductive 818 | import Mathlib.Algebra.Algebra.Opposite 819 | import Mathlib.Algebra.Algebra.Pi 820 | import Mathlib.Algebra.BigOperators.Pi 821 | import Mathlib.Algebra.BigOperators.Ring 822 | import Mathlib.Algebra.BigOperators.RingEquiv 823 | import Mathlib.Algebra.Module.LinearMap.Basic 824 | import Mathlib.Algebra.Module.Pi 825 | import Mathlib.Algebra.Star.BigOperators 826 | import Mathlib.Algebra.Star.Module 827 | import Mathlib.Algebra.Star.Pi 828 | import Mathlib.Data.Fintype.BigOperators 829 | import Mathlib.GroupTheory.GroupAction.BigOperators 830 | import Mathlib.Init.Data.Nat.Lemmas 831 | import Mathlib.Init.Function 832 | import Mathlib.Data.Semiquot 833 | import Mathlib.Data.Nat.Size 834 | import Mathlib.Tactic.Ring.RingNF 835 | import Mathlib.Data.Set.Card 836 | import Mathlib.Order.Minimal 837 | import Mathlib.Data.Matroid.Init 838 | import Mathlib.Data.Set.List 839 | import Mathlib.Data.List.Perm 840 | import Mathlib.Init.Quot -- Porting note: added import 841 | import Mathlib.Order.Hom.Basic 842 | import Mathlib.Mathport.Rename 843 | import Mathlib.Data.PFunctor.Univariate.M 844 | import Mathlib.Data.PFunctor.Multivariate.Basic 845 | import Mathlib.Init.Control.Combinators 846 | import Mathlib.Data.Option.Defs 847 | import Mathlib.Logic.IsEmpty 848 | import Mathlib.Logic.Relator 849 | import Mathlib.Util.CompileInductive 850 | import Aesop 851 | import Mathlib.Algebra.Order.Ring.WithTop 852 | import Mathlib.Algebra.Order.Sub.WithTop 853 | import Mathlib.Data.Real.NNReal 854 | import Mathlib.Data.Set.Intervals.WithBotTop 855 | import Mathlib.Data.Bool.Basic 856 | import Mathlib.Data.Nat.Defs 857 | import Mathlib.Data.Option.Basic 858 | import Mathlib.Data.List.Defs 859 | import Mathlib.Init.Data.List.Basic 860 | import Mathlib.Init.Data.List.Instances 861 | import Mathlib.Init.Data.List.Lemmas 862 | import Mathlib.Logic.Unique 863 | import Mathlib.Order.Basic 864 | import Std.Data.List.Lemmas 865 | import Mathlib.Tactic.Common 866 | import Mathlib.Logic.Equiv.Nat 867 | import Mathlib.Logic.Equiv.Fin 868 | import Mathlib.Data.Countable.Defs 869 | import Mathlib.Data.Multiset.Basic 870 | import Mathlib.Data.Vector.Basic 871 | import Mathlib.Data.Setoid.Basic 872 | import Mathlib.Tactic.ApplyFun 873 | import Mathlib.Init.Align 874 | import Mathlib.Data.Fintype.Powerset 875 | import Mathlib.Data.Fintype.Prod 876 | import Mathlib.Data.Fintype.Sigma 877 | import Mathlib.Data.Fintype.Sum 878 | import Mathlib.Data.Fintype.Vector 879 | import Mathlib.Algebra.CharZero.Lemmas 880 | import Mathlib.Algebra.GroupPower.Ring 881 | import Mathlib.Algebra.GroupWithZero.Bitwise 882 | import Mathlib.Data.Real.Basic 883 | import Mathlib.Data.Set.Image 884 | import Mathlib.Algebra.Ring.Hom.Defs -- FIXME: This import is bogus 885 | import Mathlib.Data.Finset.Image 886 | import Mathlib.Data.Fin.OrderHom 887 | import Mathlib.Algebra.Category.Ring.FilteredColimits 888 | import Mathlib.Geometry.RingedSpace.SheafedSpace 889 | import Mathlib.Topology.Sheaves.Stalks 890 | import Mathlib.Algebra.Category.Ring.Colimits 891 | import Mathlib.Algebra.Category.Ring.Limits 892 | import Mathlib.Analysis.InnerProductSpace.Projection 893 | import Mathlib.Geometry.Euclidean.PerpBisector 894 | import Mathlib.Algebra.QuadraticDiscriminant 895 | import Mathlib.Analysis.Convex.StrictConvexBetween 896 | import Mathlib.Geometry.Euclidean.Basic 897 | import Mathlib.Analysis.InnerProductSpace.Basic 898 | import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse 899 | import Mathlib.Analysis.InnerProductSpace.TwoDim 900 | import Mathlib.Geometry.Euclidean.Angle.Unoriented.Basic 901 | import Mathlib.Analysis.Normed.Group.AddTorsor 902 | import Mathlib.Analysis.InnerProductSpace.Basic 903 | import Mathlib.Geometry.Manifold.MFDeriv.Defs 904 | import Mathlib.Geometry.Manifold.ContMDiff.Defs 905 | import Mathlib.Geometry.Manifold.LocalInvariantProperties 906 | import Mathlib.Topology.Sheaves.LocalPredicate 907 | import Mathlib.Geometry.Manifold.ContMDiff.Atlas 908 | import Mathlib.Geometry.Manifold.VectorBundle.FiberwiseLinear 909 | import Mathlib.Topology.VectorBundle.Constructions 910 | import Mathlib.Data.Seq.Seq 911 | import Mathlib.Algebra.Field.Defs 912 | import Mathlib.Algebra.Order.Floor 913 | import Mathlib.Algebra.ContinuedFractions.Basic 914 | import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Zero 915 | import Mathlib.Algebra.Group.Basic 916 | import Mathlib.Algebra.Group.Hom.Defs 917 | import Mathlib.Algebra.GroupWithZero.NeZero 918 | import Mathlib.Algebra.Opposites 919 | import Mathlib.Algebra.Ring.Defs 920 | import Mathlib.Algebra.Divisibility.Basic 921 | import Mathlib.Algebra.Group.Units.Hom 922 | import Mathlib.Algebra.GroupWithZero.InjSurj 923 | import Mathlib.Algebra.Ring.Hom.Defs 924 | import Mathlib.Data.Set.Basic 925 | import Mathlib.Algebra.Divisibility.Basic 926 | import Mathlib.Algebra.Group.Equiv.Basic 927 | import Mathlib.Algebra.Ring.Defs 928 | import Mathlib.Algebra.Associated 929 | import Mathlib.Algebra.Ring.Regular 930 | import Mathlib.Tactic.Common 931 | import Mathlib.Algebra.BigOperators.Multiset.Lemmas 932 | import Mathlib.Algebra.BigOperators.Multiset.Order 933 | import Mathlib.Algebra.Function.Indicator 934 | import Mathlib.Algebra.Ring.Opposite 935 | import Mathlib.Data.Finset.Powerset 936 | import Mathlib.Data.Finset.Preimage 937 | import Mathlib.Data.Finset.Sigma 938 | import Mathlib.Data.Finset.Sum 939 | import Mathlib.Data.Fintype.Pi 940 | import Mathlib.Data.Int.Cast.Lemmas 941 | import Mathlib.Data.Set.Image 942 | import Mathlib.Algebra.BigOperators.List.Defs 943 | import Mathlib.Data.List.Forall2 944 | import Mathlib.Algebra.Divisibility.Basic 945 | import Mathlib.Algebra.Ring.Commute 946 | import Mathlib.Data.Nat.Order.Basic 947 | import Mathlib.Data.Int.Basic 948 | import Mathlib.Algebra.Group.Hom.Basic 949 | import Mathlib.Algebra.GroupPower.Hom 950 | import Mathlib.Algebra.BigOperators.List.Basic 951 | import Mathlib.Data.Multiset.Basic 952 | import Mathlib.Algebra.CharZero.Lemmas 953 | import Mathlib.Algebra.Module.Submodule.Ker 954 | import Mathlib.Algebra.Module.Submodule.RestrictScalars 955 | import Mathlib.Algebra.Module.ULift 956 | import Mathlib.RingTheory.Subring.Basic 957 | import Mathlib.Algebra.Algebra.Basic 958 | import Mathlib.Data.Set.UnionLift 959 | import Mathlib.LinearAlgebra.Finsupp 960 | import Mathlib.RingTheory.Ideal.Operations 961 | import Mathlib.Algebra.Order.Monoid.Defs 962 | import Mathlib.Algebra.Group.InjSurj 963 | import Mathlib.Order.Hom.Basic 964 | import Mathlib.Logic.Basic 965 | import Mathlib.Tactic.Positivity.Basic 966 | import Mathlib.Algebra.Order.AbsoluteValue 967 | import Mathlib.Algebra.Order.Field.Basic 968 | import Mathlib.Algebra.Order.Group.MinMax 969 | import Mathlib.Algebra.Ring.Pi 970 | import Mathlib.GroupTheory.GroupAction.Pi 971 | import Mathlib.GroupTheory.GroupAction.Ring 972 | import Mathlib.Init.Align 973 | import Mathlib.Tactic.GCongr 974 | import Mathlib.Tactic.Ring 975 | import Mathlib.Algebra.Group.Equiv.Basic 976 | import Mathlib.Algebra.Ring.Basic 977 | import Mathlib.Algebra.Order.Sub.Defs 978 | import Mathlib.Order.Hom.Basic 979 | import Mathlib.Algebra.Field.Basic 980 | import Mathlib.Algebra.GroupWithZero.Units.Equiv 981 | import Mathlib.Algebra.Order.Field.Defs 982 | import Mathlib.Algebra.Order.Ring.Abs 983 | import Mathlib.Order.Bounds.OrderIso 984 | import Mathlib.Tactic.Positivity.Core 985 | import Mathlib.Algebra.Order.Field.Canonical.Defs 986 | import Mathlib.Algebra.Field.Defs 987 | import Mathlib.Algebra.GroupWithZero.Units.Lemmas 988 | import Mathlib.Algebra.Ring.Commute 989 | import Mathlib.Algebra.Ring.Hom.Defs 990 | import Mathlib.Algebra.Invertible.GroupWithZero 991 | import Mathlib.Algebra.Group.Commute.Units 992 | import Mathlib.Algebra.Group.Hom.Defs 993 | import Mathlib.Algebra.Group.Units 994 | import Mathlib.Algebra.GroupPower.Basic 995 | import Mathlib.Algebra.GroupWithZero.Units.Basic 996 | import Mathlib.Algebra.Ring.Defs 997 | import Mathlib.Data.Bracket 998 | import Mathlib.LinearAlgebra.Basic 999 | import Mathlib.Algebra.Ring.Divisibility.Lemmas 1000 | import Mathlib.Algebra.Lie.Nilpotent 1001 | import Mathlib.Algebra.Lie.Engel 1002 | import Mathlib.LinearAlgebra.Eigenspace.Triangularizable 1003 | import Mathlib.RingTheory.Artinian 1004 | import Mathlib.LinearAlgebra.Trace 1005 | import Mathlib.LinearAlgebra.FreeModule.PID 1006 | import Mathlib.Data.DFinsupp.Basic 1007 | import Mathlib.GroupTheory.Submonoid.Operations 1008 | import Mathlib.Algebra.GroupWithZero.Units.Lemmas 1009 | import Mathlib.Algebra.Ring.Equiv 1010 | import Mathlib.GroupTheory.GroupAction.Group 1011 | import Mathlib.RingTheory.UniqueFactorizationDomain 1012 | import Mathlib.Algebra.GroupPower.Basic 1013 | import Mathlib.Algebra.Group.Hom.Defs 1014 | import Mathlib.Algebra.BigOperators.List.Basic 1015 | import Mathlib.GroupTheory.GroupAction.Defs 1016 | import Mathlib.Algebra.Module.Basic 1017 | import Mathlib.Algebra.Order.Archimedean 1018 | import Mathlib.Algebra.Order.Group.Instances 1019 | import Mathlib.Data.Int.ModEq 1020 | import Mathlib.Data.Nat.Multiplicity 1021 | import Mathlib.Data.Nat.Choose.Sum 1022 | import Mathlib.Data.Nat.Cast.Prod 1023 | import Mathlib.Algebra.Group.ULift 1024 | import Mathlib.GroupTheory.OrderOfElement 1025 | import Mathlib.Algebra.Lie.OfAssociative 1026 | import Mathlib.Algebra.Category.MonCat.Basic 1027 | import Mathlib.CategoryTheory.Endomorphism 1028 | import Mathlib.Algebra.Category.GroupCat.Preadditive 1029 | import Mathlib.CategoryTheory.Conj 1030 | import Mathlib.CategoryTheory.Linear.Basic 1031 | import Mathlib.CategoryTheory.Preadditive.AdditiveFunctor 1032 | import Mathlib.LinearAlgebra.Basic 1033 | import Mathlib.Algebra.Category.ModuleCat.Basic 1034 | import Mathlib.LinearAlgebra.TensorProduct.Basic 1035 | import Mathlib.CategoryTheory.Monoidal.Linear 1036 | import Mathlib.Algebra.Algebra.Subalgebra.Basic 1037 | import Mathlib.Algebra.FreeAlgebra 1038 | import Mathlib.Algebra.Category.Ring.Basic 1039 | import Mathlib.Algebra.Category.ModuleCat.Basic 1040 | import Mathlib.CategoryTheory.ConcreteCategory.BundledHom 1041 | import Mathlib.Algebra.PUnitInstances 1042 | import Mathlib.CategoryTheory.Functor.ReflectsIso 1043 | import Mathlib.Algebra.PEmptyInstances 1044 | import Mathlib.Algebra.Group.Equiv.Basic 1045 | import Mathlib.CategoryTheory.ConcreteCategory.BundledHom 1046 | import Mathlib.CategoryTheory.Functor.ReflectsIso 1047 | import Mathlib.Algebra.Category.GroupCat.Basic 1048 | import Mathlib.CategoryTheory.ConcreteCategory.ReflectsIso 1049 | import Mathlib.Algebra.Ring.Equiv 1050 | import Mathlib.CategoryTheory.Monoidal.Rigid.Basic 1051 | import Mathlib.CategoryTheory.Monoidal.Subcategory 1052 | import Mathlib.LinearAlgebra.Coevaluation 1053 | import Mathlib.LinearAlgebra.FreeModule.Finite.Matrix 1054 | import Mathlib.Algebra.Category.ModuleCat.Monoidal.Closed 1055 | import Mathlib.Algebra.Group.Commute.Basic 1056 | import Mathlib.Algebra.GroupWithZero.Defs 1057 | import Mathlib.Data.Int.Defs 1058 | import Mathlib.Tactic.Common 1059 | import Mathlib.Algebra.GroupPower.CovariantClass 1060 | import Mathlib.Algebra.Order.Monoid.WithTop 1061 | import Mathlib.Algebra.SMulWithZero 1062 | import Mathlib.Order.Hom.Basic 1063 | import Mathlib.Data.Nat.Order.Basic 1064 | import Mathlib.Algebra.EuclideanDomain.Defs 1065 | import Mathlib.Algebra.Ring.Divisibility.Basic 1066 | import Mathlib.Algebra.Ring.Regular 1067 | import Mathlib.Algebra.GroupWithZero.Divisibility 1068 | import Mathlib.Algebra.Ring.Basic 1069 | import Mathlib.Algebra.Function.Indicator 1070 | import Mathlib.Algebra.SMulWithZero 1071 | import Mathlib.Data.Int.Basic 1072 | import Mathlib.Data.NNRat.Defs 1073 | import Mathlib.GroupTheory.GroupAction.Group 1074 | import Mathlib.GroupTheory.GroupAction.Pi 1075 | import Mathlib.Logic.Basic 1076 | import Mathlib.Tactic.Abel 1077 | import Mathlib.GroupTheory.GroupAction.SubMulAction 1078 | import Mathlib.GroupTheory.Submonoid.Membership 1079 | import Mathlib.Algebra.Module.Pi 1080 | import Mathlib.Algebra.Ring.CompTypeclasses 1081 | import Mathlib.Algebra.Star.Basic 1082 | import Mathlib.GroupTheory.GroupAction.DomAct.Basic 1083 | import Mathlib.GroupTheory.GroupAction.Hom 1084 | import Mathlib.Algebra.Algebra.Equiv 1085 | import Mathlib.Algebra.Algebra.NonUnitalHom 1086 | import Mathlib.Algebra.BigOperators.Finsupp 1087 | import Mathlib.Algebra.Module.BigOperators 1088 | import Mathlib.LinearAlgebra.Finsupp 1089 | import Mathlib.Algebra.Group.Commute.Defs 1090 | import Mathlib.Algebra.Group.Units 1091 | import Mathlib.Algebra.Order.Monoid.Lemmas 1092 | import Mathlib.Tactic.NthRewrite 1093 | import Aesop 1094 | import Mathlib.Algebra.Group.Defs 1095 | import Mathlib.Logic.Function.Basic 1096 | import Mathlib.Tactic.Cases 1097 | import Mathlib.Tactic.SimpRw 1098 | import Mathlib.Tactic.SplitIfs 1099 | import Mathlib.Algebra.Group.Semiconj.Defs 1100 | import Mathlib.Algebra.Group.Basic 1101 | import Mathlib.Algebra.Group.Basic 1102 | import Mathlib.Algebra.Group.Hom.Defs 1103 | import Mathlib.Algebra.Group.Defs 1104 | import Mathlib.Data.Prod.Basic 1105 | import Mathlib.Data.Sum.Basic 1106 | import Mathlib.Logic.Unique 1107 | import Mathlib.Tactic.Spread 1108 | import Mathlib.Algebra.Group.Equiv.Basic 1109 | import Mathlib.Algebra.Group.WithOne.Defs 1110 | import Mathlib.Data.Option.Basic 1111 | import Mathlib.Algebra.Group.Hom.Basic 1112 | import Mathlib.Data.FunLike.Equiv 1113 | import Mathlib.Logic.Equiv.Basic 1114 | import Mathlib.Algebra.Group.Commute.Defs 1115 | import Mathlib.Algebra.Group.Semiconj.Basic 1116 | import Mathlib.Algebra.Field.Opposite 1117 | import Mathlib.Algebra.Invertible.Defs 1118 | import Mathlib.Algebra.Ring.Aut 1119 | import Mathlib.Algebra.Ring.CompTypeclasses 1120 | import Mathlib.Algebra.Field.Opposite 1121 | import Mathlib.Algebra.Invertible.Defs 1122 | import Mathlib.Data.NNRat.Defs 1123 | import Mathlib.Data.Rat.Cast.Defs 1124 | import Mathlib.Data.SetLike.Basic 1125 | import Mathlib.GroupTheory.GroupAction.Opposite 1126 | import Mathlib.Algebra.Group.Basic 1127 | import Mathlib.Algebra.GroupWithZero.NeZero 1128 | import Mathlib.Algebra.Group.OrderSynonym 1129 | import Mathlib.Algebra.GroupWithZero.Basic 1130 | import Mathlib.Algebra.Group.Units 1131 | import Mathlib.Tactic.Nontriviality 1132 | import Mathlib.Util.AssertExists 1133 | import Mathlib.Tactic.Contrapose 1134 | import Mathlib.CategoryTheory.Category.Grpd 1135 | import Mathlib.CategoryTheory.Groupoid 1136 | import Mathlib.Topology.Category.TopCat.Basic 1137 | import Mathlib.Topology.Homotopy.Path 1138 | import Mathlib.Data.Set.Basic 1139 | import Mathlib.RingTheory.IntegralClosure 1140 | import Mathlib.FieldTheory.Normal 1141 | import Mathlib.FieldTheory.Perfect 1142 | import Mathlib.RingTheory.Localization.Integral 1143 | import Mathlib.FieldTheory.Separable 1144 | import Mathlib.RingTheory.IntegralDomain 1145 | import Mathlib.Algebra.CharP.Reduced 1146 | import Mathlib.Tactic.ApplyFun 1147 | import Lean 1148 | import Std 1149 | import Mathlib.Tactic.PPWithUniv 1150 | import Mathlib.Tactic.ExtendDoc 1151 | import Mathlib.Tactic.Lemma 1152 | import Mathlib.Tactic.TypeStar 1153 | import Lean.Elab.Tactic.SolveByElim 1154 | import Mathlib.Tactic.Monotonicity.Attr 1155 | import Lean.Elab.Tactic.Simp 1156 | import Lean.Elab.App 1157 | import Mathlib.Tactic.Simps.NotationClass 1158 | import Std.Data.String.Basic 1159 | import Std.Util.LibraryNote 1160 | import Mathlib.Lean.Expr.Basic 1161 | import Mathlib.Tactic.NormNum.Inv 1162 | import Mathlib.Tactic.NormNum.Pow 1163 | import Mathlib.Util.AtomM 1164 | import Mathlib.Data.Rat.Order 1165 | import Mathlib.Tactic.NormNum.Core 1166 | import Mathlib.Tactic.HaveI 1167 | import Mathlib.Data.Nat.Cast.Commute 1168 | import Mathlib.Data.Int.Basic 1169 | import Mathlib.Algebra.Invertible.Basic 1170 | import Mathlib.Tactic.Clear! 1171 | import Mathlib.Data.Nat.Cast.Basic 1172 | import Mathlib.Algebra.GroupPower.Order 1173 | import Mathlib.Data.Int.CharZero 1174 | import Mathlib.Data.Int.Order.Basic 1175 | import Mathlib.Data.Nat.Factorial.Basic 1176 | import Mathlib.Data.Rat.Order 1177 | import Mathlib.Tactic.Positivity.Core 1178 | import Qq 1179 | import Std.Data.Rat.Lemmas 1180 | import Mathlib.Mathport.Rename 1181 | import Mathlib.Mathport.Rename 1182 | import Std.Logic 1183 | import Mathlib.Mathport.Rename 1184 | import Mathlib.Mathport.Rename 1185 | import Mathlib.Init.Data.Nat.Notation 1186 | import Std.Data.List.Basic 1187 | import Mathlib.Init.ZeroOne 1188 | import Mathlib.Init.Data.Nat.Notation 1189 | import Mathlib.Util.CompileInductive 1190 | import Mathlib.Init.Data.Nat.Notation 1191 | import Mathlib.Mathport.Rename 1192 | import Mathlib.Mathport.Rename 1193 | import Std.Data.Bool 1194 | import Mathlib.AlgebraicGeometry.AffineScheme 1195 | import Mathlib.AlgebraicGeometry.Pullbacks 1196 | import Mathlib.CategoryTheory.MorphismProperty 1197 | import Mathlib.Data.List.TFAE 1198 | import Mathlib.LinearAlgebra.Finsupp 1199 | import Mathlib.RingTheory.Ideal.Over 1200 | import Mathlib.RingTheory.Ideal.Prod 1201 | import Mathlib.RingTheory.Ideal.MinimalPrime 1202 | import Mathlib.RingTheory.Localization.Away.Basic 1203 | import Mathlib.RingTheory.Nilpotent 1204 | import Mathlib.Topology.Sets.Closeds 1205 | import Mathlib.Topology.Sober 1206 | import Mathlib.Data.Set.Function 1207 | import Mathlib.Logic.Function.Iterate 1208 | import Mathlib.GroupTheory.Perm.Basic 1209 | import Mathlib.Algebra.BigOperators.Basic 1210 | import Mathlib.Dynamics.FixedPoints.Basic 1211 | import Mathlib.Algebra.Function.Support 1212 | import Mathlib.Order.Filter.Lift 1213 | import Mathlib.Topology.Defs.Filter 1214 | import Mathlib.Order.SetNotation 1215 | import Mathlib.Tactic.Continuity 1216 | import Mathlib.Tactic.FunProp 1217 | import Mathlib.Topology.Order.ProjIcc 1218 | import Mathlib.Topology.ContinuousFunction.Ordered 1219 | import Mathlib.Topology.CompactOpen 1220 | import Mathlib.Topology.UnitInterval 1221 | import Mathlib.Analysis.NormedSpace.BoundedLinearMaps 1222 | import Mathlib.Topology.FiberBundle.Basic 1223 | import Mathlib.Data.Set.Image 1224 | import Mathlib.Order.SuccPred.Relation 1225 | import Mathlib.Topology.Clopen 1226 | import Mathlib.Topology.Irreducible 1227 | import Mathlib.CategoryTheory.ConcreteCategory.BundledHom 1228 | import Mathlib.CategoryTheory.Elementwise 1229 | import Mathlib.Topology.ContinuousFunction.Basic 1230 | import Mathlib.Topology.Category.TopCat.Basic 1231 | import Mathlib.CategoryTheory.Limits.Types 1232 | import Mathlib.Topology.Category.CompHaus.Basic 1233 | import Mathlib.Topology.LocallyConstant.Basic 1234 | import Mathlib.CategoryTheory.FintypeCat 1235 | import Mathlib.Topology.Category.Profinite.Basic 1236 | import Mathlib.CategoryTheory.Limits.ConcreteCategory 1237 | import Mathlib.Topology.ExtremallyDisconnected 1238 | import Mathlib.Topology.Category.CompHaus.Projective 1239 | import Mathlib.Topology.Category.Profinite.Basic 1240 | import Mathlib.CategoryTheory.Adjunction.Reflective 1241 | import Mathlib.Topology.StoneCech 1242 | import Mathlib.CategoryTheory.Monad.Limits 1243 | import Mathlib.Topology.UrysohnsLemma 1244 | import Mathlib.Topology.Category.TopCat.Limits.Basic 1245 | import Mathlib.Data.Set.Basic 1246 | import Mathlib.Order.Filter.SmallSets 1247 | import Mathlib.Tactic.Monotonicity 1248 | import Mathlib.Topology.Compactness.Compact 1249 | import Mathlib.Topology.NhdsSet 1250 | import Mathlib.Algebra.Group.Defs 1251 | import Mathlib.Data.Set.Intervals.Pi 1252 | import Mathlib.Data.Set.Pointwise.Basic 1253 | import Mathlib.Order.Filter.Interval 1254 | import Mathlib.Tactic.TFAE 1255 | import Mathlib.Tactic.NormNum 1256 | import Mathlib.Topology.Order.LeftRight 1257 | import Mathlib.Topology.Order.OrderClosed 1258 | import Mathlib.Order.Hom.Basic 1259 | import Mathlib.Topology.ContinuousFunction.Basic 1260 | import Mathlib.Topology.Algebra.Ring.Basic 1261 | import Mathlib.Topology.Algebra.MulAction 1262 | import Mathlib.Topology.Algebra.UniformGroup 1263 | import Mathlib.Topology.ContinuousFunction.Basic 1264 | import Mathlib.Topology.UniformSpace.UniformEmbedding 1265 | import Mathlib.Algebra.Algebra.Basic 1266 | import Mathlib.LinearAlgebra.Projection 1267 | import Mathlib.LinearAlgebra.Pi 1268 | import Mathlib.LinearAlgebra.Finsupp 1269 | import Mathlib.Topology.Algebra.Module.Basic 1270 | import Mathlib.LinearAlgebra.Multilinear.Basic 1271 | import Mathlib.LinearAlgebra.Alternating.Basic 1272 | import Mathlib.LinearAlgebra.BilinearMap 1273 | import Mathlib.Topology.Algebra.Module.Multilinear.Basic 1274 | import Mathlib.GroupTheory.Subgroup.Basic 1275 | import Mathlib.Topology.Algebra.OpenSubgroup 1276 | import Mathlib.Topology.Algebra.Ring.Basic 1277 | import Mathlib.Algebra.Ring.Prod 1278 | import Mathlib.RingTheory.Subring.Basic 1279 | import Mathlib.Topology.Algebra.Group.Basic 1280 | import Mathlib.Topology.Algebra.InfiniteSum.Defs 1281 | import Mathlib.Data.Fintype.BigOperators 1282 | import Mathlib.Topology.Algebra.Monoid 1283 | import Mathlib.GroupTheory.GroupAction.ConjAct 1284 | import Mathlib.GroupTheory.GroupAction.Quotient 1285 | import Mathlib.GroupTheory.QuotientGroup 1286 | import Mathlib.Topology.Algebra.Monoid 1287 | import Mathlib.Topology.Algebra.Constructions 1288 | import Mathlib.Data.Nat.Interval 1289 | import Mathlib.Data.ENNReal.Real 1290 | import Mathlib.Topology.UniformSpace.Pi 1291 | import Mathlib.Topology.UniformSpace.UniformConvergence 1292 | import Mathlib.Topology.UniformSpace.UniformEmbedding 1293 | import Mathlib.Algebra.Function.Indicator 1294 | import Mathlib.Tactic.FinCases 1295 | import Mathlib.Topology.Sets.Closeds 1296 | import Mathlib.Order.Filter.Cofinite 1297 | import Mathlib.Topology.MetricSpace.ProperSpace 1298 | import Mathlib.Topology.MetricSpace.Basic 1299 | import Mathlib.Topology.FiberBundle.Trivialization 1300 | import Mathlib.Data.Set.UnionLift 1301 | import Mathlib.Topology.Homeomorph 1302 | import Mathlib.Algebra.GeomSum 1303 | import Mathlib.RingTheory.Ideal.Quotient 1304 | import Mathlib.Algebra.Associated 1305 | import Mathlib.RingTheory.Int.Basic 1306 | import Mathlib.Tactic.Ring 1307 | import Mathlib.Algebra.Star.Unitary 1308 | import Mathlib.Algebra.DirectSum.Algebra 1309 | import Mathlib.Analysis.Complex.UpperHalfPlane.FunctionsBoundedAtInfty 1310 | import Mathlib.Analysis.Complex.UpperHalfPlane.Manifold 1311 | import Mathlib.Geometry.Manifold.MFDeriv.SpecificFunctions 1312 | import Mathlib.NumberTheory.ModularForms.SlashInvariantForms 1313 | import Mathlib.NumberTheory.ModularForms.SlashInvariantForms 1314 | import Mathlib.NumberTheory.ModularForms.CongruenceSubgroups 1315 | import Mathlib.Data.Int.Parity 1316 | import Mathlib.RingTheory.DedekindDomain.IntegralClosure 1317 | import Mathlib.Algebra.GCDMonoid.Finset 1318 | import Mathlib.Algebra.GroupPower.Ring 1319 | import Mathlib.Data.Nat.Parity 1320 | import Mathlib.Data.Rat.Defs 1321 | import Mathlib.Tactic.Positivity.Basic 1322 | import Mathlib.Tactic.TFAE 1323 | import Mathlib.Analysis.PSeries 1324 | import Mathlib.NumberTheory.ArithmeticFunction 1325 | import Mathlib.Analysis.NormedSpace.FiniteDimension 1326 | import Mathlib.Init.Core 1327 | import Mathlib.RingTheory.Polynomial.Cyclotomic.Roots 1328 | import Mathlib.NumberTheory.NumberField.Basic 1329 | import Mathlib.FieldTheory.Galois 1330 | import Mathlib.Analysis.Calculus.MeanValue 1331 | import Mathlib.Analysis.Calculus.Deriv.Polynomial 1332 | import Mathlib.Data.Polynomial.DenomsClearable 1333 | import Mathlib.Data.Real.Irrational 1334 | import Mathlib.Topology.Algebra.Polynomial 1335 | import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic 1336 | import Mathlib.Data.Fintype.Parity 1337 | import Mathlib.NumberTheory.LegendreSymbol.ZModChar 1338 | import Mathlib.FieldTheory.Finite.Basic 1339 | import Mathlib.Algebra.Periodic 1340 | import Mathlib.Data.ZMod.Units 1341 | import Mathlib.NumberTheory.LegendreSymbol.MulCharacter 1342 | import Mathlib.Analysis.Normed.Field.InfiniteSum 1343 | import Mathlib.Analysis.SpecificLimits.Normed 1344 | import Mathlib.NumberTheory.ArithmeticFunction 1345 | import Mathlib.NumberTheory.SmoothNumbers 1346 | import Lean.Meta.Tactic.Rewrite 1347 | import Std.Lean.Expr 1348 | import Std.Lean.Name 1349 | import Std.Data.Rat.Basic 1350 | import Std.Data.List.Basic 1351 | import Std.Lean.Name 1352 | import Std.Logic 1353 | import Mathlib.Lean.Meta 1354 | import Lean.Meta.AppBuilder 1355 | import Lean.Meta.Basic 1356 | import Mathlib.Data.Opposite 1357 | import Mathlib.Tactic.Cases 1358 | import Mathlib.Combinatorics.SimpleGraph.Init 1359 | import Mathlib.Data.Rel 1360 | import Mathlib.Data.Set.Finite 1361 | import Mathlib.Data.Sym.Sym2 1362 | import Mathlib.Algebra.GroupPower.Order 1363 | import Mathlib.Combinatorics.SimpleGraph.Clique 1364 | import Mathlib.Data.Finset.Sym 1365 | import Mathlib.Tactic.GCongr 1366 | import Mathlib.Tactic.Positivity 1367 | import Mathlib.Dynamics.FixedPoints.Basic 1368 | import Mathlib.GroupTheory.Perm.Option 1369 | import Mathlib.Logic.Equiv.Defs 1370 | import Mathlib.Logic.Equiv.Option 1371 | import Mathlib.Combinatorics.Hall.Finite 1372 | import Mathlib.CategoryTheory.CofilteredSystem 1373 | import Mathlib.Data.Rel 1374 | 1375 | --------------------------------------------------------------------------------