1

我正在尝试使用精益证明一个代数定理。我的代码是

 import algebra.group
import algebra.ring
open algebra

variable {A : Type}

variables [s : ring A] (a b c : A)
include s

theorem clown (a b c d e : A) : 
(a + b  + e) * ( c + d) =   a * c + (b * c + e* c) + (a * d + b * d + e * d)   :=
calc

(a + b  + e) * ( c + d) = (a + (b + e))* (c +d)   : !add.assoc
                    ... = (a + (b + e)) * c + (a + (b + e)) * d   : by rewrite  left_distrib
                    ... =  a * c + (b + e) * c + (a + ( b + e)) * d : by rewrite right_distrib
                    ... =  a * c + (b * c + e* c) + (a + (b + e)) * d : by rewrite right_distrib
                    ... =  a * c + (b * c + e* c) + (a * d + (b + e) * d) : by rewrite right_distrib
                    ... =  a * c + (b * c + e* c) + (a * d + (b * d + e * d) ) : by rewrite right_distrib
                    ... =  a * c + (b * c + e* c) + (a * d + b * d + e * d ) :  !add.assoc

 check clown

请让我知道如何消除最后的括号。也就是说,我只想获得

a * c + b * c + e* c + a * d + b * d + e * d

非常感谢。

4

3 回答 3

2

这看起来像精益 2 语法。除非您专门将精益 2 用于同伦类型理论模式,否则我强烈建议升级到自 2017 年初推出的精益 3。

默认情况下,操作 + 和 * 关联到左侧。即,a * c + b * c + e* c + a * d + b * d + e * d与 相同(((((a * c + b * c) + e* c) + a * d) + b * d) + e * d)add.assoc你可以用足够多的(add_assoc在精益 3 中重命名)的应用来证明这个最终的相等性。by simp在精益 3 中,您可以使用或来证明它by simp only [add_assoc]

于 2018-10-26T14:36:44.080 回答
1

如果你不介意假设你的环是可交换的,你也可以使用这个ring策略。

import tactic.ring

variables {A : Type} [comm_ring A]

theorem clown (a b c d e : A) : 
  (a + b + e) * (c + d) = a * c + (b * c + e * c) + (a * d + b * d + e * d) :=
by ring
于 2019-03-29T13:34:28.230 回答
0

使用以下代码获得可能的解决方案

 import algebra.group
import algebra.ring
open algebra

variable {A : Type}

variables [s : ring A] (a b c : A)
include s

theorem clown (a b c d e : A)  : 
(a + b  + e) * ( c + d) =  a * c + a * d + b*c + b*d +e*c+e*d :=
calc

(a + b  + e) * ( c + d) = a*(c + d) + b*(c + d) + e*(c + d)   : by rewrite distrib_three_right
                   ...  = a * c + a * d + b*(c+d)+e*(c+d) : by rewrite *left_distrib
                   ...  = a * c + a* d + (b*c + b*d) +e*(c+d) : by rewrite *left_distrib
                   ... =  a * c + a* d + (b*c + b*d) +(e*c+e*d): by rewrite left_distrib
                   ... = a * c + a* d + b*c + b*d + (e*c+e*d) :  !add.assoc
                   ... = a * c + a* d + b*c + b*d + e*c+e*d :  !add.assoc

check clown

其他示例

 import algebra.group
import algebra.ring
open algebra

variable {A : Type}

variables [s : ring A] (a b c : A)
include s

theorem clown (a b c d e f: A)  : 
(a + b  + e + f) * ( c + d) =  a * c + a * d + b*c + b*d +e*c+e*d  + f * c + f * d:=
calc

(a + b  + e + f) * ( c + d) = a*(c + d) + b*(c + d) + e*(c + d) + f*(c +d)  : by rewrite *right_distrib
                   ...  = a * c + a * d + b*(c+d)+e*(c+d) + f * (c + d): by rewrite *left_distrib
                   ...  = a * c + a* d + (b*c + b*d) +e*(c+d) + f*(c+d): by rewrite *left_distrib
                   ... =  a * c + a* d + (b*c + b*d) +(e*c+e*d)+ f*(c+d): by rewrite left_distrib
                   ... =  a * c + a* d + (b*c + b*d) +(e*c+e*d)+ (f*c+ f*d): by rewrite left_distrib
                   ... = a * c + a* d + b*c + b*d + (e*c+e*d)+ (f*c+f*d) :  !add.assoc
                   ... = a * c + a* d + b*c + b*d + e*c+e*d + (f*c + f*d):  !add.assoc
                   ... = a * c + a* d + b*c + b*d + e*c+e*d + f*c + f*d  :  !add.assoc

check clown

同样的例子,但减少了

    variable {A : Type}

variables [s : ring A] 
include s

    theorem clown (a b c d e f: A)  : 
    (a + b  + e + f) * ( c + d) =  a * c + a * d + b*c + b*d +e*c+e*d  + f * c + f * d:=
    calc

    (a + b  + e + f) * ( c + d) = a*(c + d) + b*(c + d) + e*(c + d) + f*(c +d)  : by rewrite *right_distrib

                       ... =  a * c + a* d + (b*c + b*d) +(e*c+e*d)+ (f*c+ f*d): by rewrite *left_distrib

                       ... = a * c + a* d + b*c + b*d + e*c+e*d + f*c + f*d  :  by rewrite *add.assoc

    check clown

其他示例

 import algebra.ring
open algebra
check mul_sub_left_distrib 
check add.assoc
variable {A : Type}

variables [s : ring A] 
include s

theorem clown (a b c d : A)  : 
    (a + b ) * ( c - d) =  a*c-a*d+ b*c- b*d:=
    calc

    (a + b) * ( c  -d) = a*(c-d) +b*(c-d) : by rewrite *right_distrib
                   ... = a*(c + -d) + b*(c-d) : rfl
                   ... = a*c  + a*-d+b*(c-d) : by rewrite left_distrib
                   ... = a*c + a*-d + (b*c - b*d): by rewrite mul_sub_left_distrib 
                   ... = a*c + a*-d + b*c - b*d : add.assoc
                   ... = a*c + -(a*d)+  b*c - b*d : by rewrite mul_neg_eq_neg_mul_symm
                   ... = a*c - a*d + b*c - b*d : rfl
 check clown  

其他示例

import algebra.group
import algebra.ring
open algebra
variable {A : Type}

variables [s : ring A] 
include s

theorem clown (a b c d e : A)  : 
    (a + b + e ) * ( c - d) =  a*c -a*d + b*c - b*d + e*c - e*d:=
    calc
(a + b + e) * ( c - d) = a*(c-d) +b*(c-d) + e*(c-d) : by rewrite *right_distrib
                   ... = a*(c + -d) + b*(c+ -d) + e*(c-d): rfl
                   ... = a*c  + a*-d+(b*c +b*-d) + e*(c-d) : by rewrite *left_distrib
                   ... = a*c + a*-d + (b*c +b*-d)+ (e*c -e*d) : by rewrite *mul_sub_left_distrib 
                   ... = a*c + a*-d  + b*c + b*-d + (e*c - e*d) : !add.assoc
                   ... = a*c + a*-d + b*c + b*-d + e*c - e*d : !add.assoc
                   ... = a*c + -(a*d) + b*c +-(b*d) + e*c - e*d : by rewrite *mul_neg_eq_neg_mul_symm
                   ... = a*c - a*d + b*c - b*d + e*c - e*d : rfl
 check clown

其他示例

import algebra.group
import algebra.ring
open algebra
variable {A : Type}

variables [s : ring A] 
include s

theorem clown (a b c d e f  : A)  : 
    (a + b + e + f) * ( c - d) =  a*c -a*d + b*c - b*d + e*c - e*d + f*c - f*d:=
    calc
(a + b + e + f) * ( c - d) = a*(c-d) +b*(c-d) + e*(c-d) + f*(c - d) : by rewrite *right_distrib
                   ... = a*(c + -d) + b*(c+ -d) + e*(c + -d) + f *(c-d): rfl
                   ... = a*c  + a*-d+(b*c +b*-d) + (e*c + e*-d)+ f*(c-d) : by rewrite *left_distrib
                   ... = a*c + a*-d + (b*c +b*-d)+ (e*c + e*-d) + (f*c - f*d) : by rewrite *mul_sub_left_distrib 
                   ... = a*c + a*-d  + b*c + b*-d + (e*c + e*-d) + (f*c -f*d): !add.assoc
                   ... = a*c + a*-d + b*c + b*-d + e*c + e*-d  + (f*c - f*d): !add.assoc
                   ... = a*c + a*-d + b*c + b*-d + e*c + e*-d  + f*c - f*d: !add.assoc
                   ... = a*c + -(a*d) + b*c +-(b*d) + e*c + - (e*d) + f*c - f*d : by rewrite *mul_neg_eq_neg_mul_symm
                   ... = a*c - a*d + b*c - b*d + e*c - e*d  + f*c - f*d : rfl
 check clown 

其他示例

    import algebra.group
import algebra.ring
open algebra
variable {A : Type}

variables [s : ring A] 
include s

theorem clown (a b c d e f  : A)  : 
    (a + b - e  - f) * ( c - d) =  a*c -a*d + b*c -b*d -e*c + e*d - f*c + f*d :=
    calc
(a + b - e - f) * ( c - d) =(a + b + -e + -f)*(c-d) : rfl
                   ... = a*(c-d) +b*(c-d) + -e*(c-d) + -f*(c - d) : by rewrite *right_distrib
                   ... = a*(c + -d) + b*(c+ -d) + -e*(c + -d) + -f *(c-d): rfl
                   ... = a*c  + a*-d+(b*c +b*-d) + (-e*c + -e*-d)+ -f*(c-d) : by rewrite *left_distrib
                   ... = a*c + a*-d + (b*c +b*-d)+ (-e*c + -e*-d) + (-f*c - -f*d) : by rewrite *mul_sub_left_distrib 
                   ... = a*c + a*-d  + b*c + b*-d + (-e*c + -e*-d) + (-f*c - -f*d): !add.assoc
                   ... = a*c + a*-d + b*c + b*-d + -e*c + -e*-d  + (-f*c - -f*d): !add.assoc
                   ... = a*c + a*-d + b*c + b*-d + -e*c + -e*-d  + -f*c - -f*d: !add.assoc
                   ... = a*c + -(a*d) + b*c +-(b*d) + -e*c + - (-e*d) + -f*c - -f*d : by rewrite *mul_neg_eq_neg_mul_symm
                   ... = a*c - a*d + b*c -b*d + -e*c + - (-e*d) + -f*c  - -f*d : rfl
                   ... =a*c - a*d + b*c -b*d + -(e*c) + - -(e*d) + -(f*c)  - -(f*d) : by rewrite  *neg_mul_eq_neg_mul_symm
                   ... =a*c - a*d + b*c -b*d - e*c + - -(e*d) - f*c  - -(f*d) : rfl
                   ... = a*c - a*d + b*c -b*d - e*c + (e*d) - f*c  - -(f*d) : by rewrite neg_neg
                   ... = a*c - a*d + b*c -b*d - e*c + e*d - f*c +  - -(f*d) : rfl
                   ... = a*c - a*d + b*c -b*d - e*c + e*d - f*c +  (f*d) : by rewrite neg_neg
                   ... = a*c - a*d + b*c -b*d - e*c + e*d - f*c +  f*d : rfl

 check clown 
于 2018-10-26T18:44:19.467 回答