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

相关推荐
格子惊蛰版几秒前
🪲正在开发后台管理系统的同学 UnoCSS 一定要用起来
前端·css
Aniugel2 分钟前
JavaScript高级面试题
javascript·设计模式·面试
Postkarte不想说话2 分钟前
使用WebGL绘制一个三角形
前端
꧁坚持很酷꧂3 分钟前
配置Ubuntu18.04中的Qt Creator为中文(图文详解)
开发语言·qt·ubuntu
醋醋5 分钟前
vue2源码记录4
前端·vue.js
ccattempt6 分钟前
夯实基础-迭代器与生成器
前端
我怎么能这么帅气7 分钟前
拯救排版焦虑!CSS省略号的终极指南:单行、多行、生效与失效场景全解析
前端·css
迷路的小绅士19 分钟前
常见网络安全攻击类型深度剖析(四):跨站脚本攻击(XSS)——分类、漏洞利用与前端安全防护
前端·安全·web安全
不当菜虚困20 分钟前
JAVA设计模式——(四)门面模式
java·开发语言·设计模式
ruyingcai66666620 分钟前
用python进行OCR识别
开发语言·python·ocr