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

相关推荐
好焊孙辉7 分钟前
一条产线省下 30 个电机位:Z 轴和 R 轴,该合成一个了
开发语言·r语言
布莱克6058 分钟前
Swift 中的逃逸闭包与非逃逸闭包:@escaping 到底在做什么
开发语言·ios·swift·闭包·逃逸
郝学胜-神的一滴24 分钟前
Effective STL 条款 14:用扩容函数避免重新分配
linux·开发语言·网络·数据结构·c++·单片机
吃我一窝jio1 小时前
Java IO流核心分类与应用
java·开发语言·笔记
不一样的少年_2 小时前
受够了当人肉传话筒:我把这 9 个 Agent 塞进了同一个聊天框
前端·agent·ai编程
Kari112 小时前
医药和制造行业的外文文档批量翻译,排版怎么保住?
开发语言·c#·制造
狗头大军之江苏分军3 小时前
《潮水漫过十七岁》 加一个蛋,顺便说一下我解放了
前端·后端
Captaincc3 小时前
掘金AI用量迎来重大更新!全新AI用量
前端·后端
天若有情6734 小时前
开源|纯前端·条码&二维码在线生成器,支持拖拽缩放、复制生成码图片
前端·javascript·开源·html·二维码·条形码
布莱克6056 小时前
Swift 可选链详解:从语法到实战
开发语言·ios·swift·可选链