人工智能数学验证工具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."

相关推荐
因吹斯汀21 分钟前
一饭封神:当AI厨神遇上你的冰箱,八大菜系大师在线battle!
前端·vue.js·ai编程
再学一点就睡26 分钟前
NATAPP 内网穿透指南:让本地项目轻松 “走出去”
前端
拜无忧26 分钟前
2025最新React项目架构指南:从零到一,为前端小白打造
前端·react.js·typescript
稻草人不怕疼27 分钟前
记一次从“按钮点不动”到“窗口派发缺失”的排查过程
前端
土了个豆子的35 分钟前
02.继承MonoBehaviour的单例模式基类
开发语言·visualstudio·单例模式·c#·里氏替换原则
qq_1728055941 分钟前
Go 自建库的使用教程与测试
开发语言·后端·golang
irving同学462381 小时前
TypeORM 列装饰器完整总结
前端·后端·nestjs
久绊A1 小时前
Hydra-SSH 破解安全防范
开发语言·php
彭于晏爱编程1 小时前
你真的了解 Map、Set 嘛
前端
崔璨1 小时前
详解Vue3的响应式系统
前端·vue.js