人工智能数学验证工具LEAN4【入门介绍6】算法世界-机器人的思维跳步,如何自定义高级证明策略,还有逆否命题的使用

视频点赞过10会继续出下一期哦:人工智能数学验证工具LEAN4【入门介绍6】算法世界-机器人的思维跳步,如何自定义高级证明策略,还有逆否命题的使用_哔哩哔哩_bilibili

import Game.Levels.Algorithm.L07succ_ne_succ

import Game.MyNat.DecidableEq

World "Algorithm"

Level 8

Title "decide"

TheoremTab "Peano"

namespace MyNat

/--

Summary

`decide` will attempt to solve a goal if it can find an algorithm which it

can run to solve it.

Example

A term of type `DecidableEq ℕ` is an algorithm to decide whether two naturals

are equal or different. Hence, once this term is made and made into an `instance`,

the `decide` tactic can use it to solve goals of the form `a = b` or `a ≠ b`.

-/

TacticDoc decide

NewTactic decide

Introduction

"

Implementing the algorithm for equality of naturals, and the proof that it is correct,

looks like this:

```

instance instDecidableEq : DecidableEq ℕ

| 0, 0 => isTrue <| by

show 0 = 0

rfl

| succ m, 0 => isFalse <| by

show succ m ≠ 0

exact succ_ne_zero m

| 0, succ n => isFalse <| by

show 0 ≠ succ n

exact zero_ne_succ n

| succ m, succ n =>

match instDecidableEq m n with

| isTrue (h : m = n) => isTrue <| by

show succ m = succ n

rw [h]

rfl

| isFalse (h : m ≠ n) => isFalse <| by

show succ m ≠ succ n

exact succ_ne_succ m n h

```

This Lean code is a formally verified algorithm for deciding equality

between two naturals. I've typed it in already, behind the scenes.

Because the algorithm is formally verified to be correct, we can

use it in Lean proofs. You can run the algorithm with the `decide` tactic.

"

/-- 20+20=40. -/

Statement : (20 : ℕ) + 20 = 40 := by

decide

Conclusion "You can read more about the `decide` tactic by clicking

on it in the top right."

相关推荐
郝学胜-神的一滴几秒前
Linux C++ 守护进程开发指南
linux·运维·服务器·开发语言·c++·程序人生·性能优化
暴富的Tdy2 分钟前
【脚手架创建 Vue3 公共组件库】
前端·npm·npm发布
_dindong4 分钟前
笔试强训:Week -8
开发语言·c++·算法
AI_56784 分钟前
Jupyter交互式数据分析的效率革命
开发语言·python
技术宅小温5 分钟前
< 前端大小事: 2025年近期CSDN前端技术热点分析 >
前端
superman超哥6 分钟前
仓颉语言中并发集合的实现深度剖析与高性能实践
开发语言·后端·python·c#·仓颉
superman超哥7 分钟前
仓颉语言中原子操作的封装深度剖析与无锁编程实践
c语言·开发语言·后端·python·仓颉
知了清语9 分钟前
pkg.pr.new 快速验证第三方包-最新修复
前端
iFlow_AI9 分钟前
知识驱动开发:用iFlow工作流构建本地知识库
前端·ai·rag·mcp·iflow·iflow cli·iflowcli
wordbaby10 分钟前
TanStack Router 文件命名约定
前端