我最近asked a question并通过rewrite
策略的一些应用解决了该问题。然后,我决定回顾一下my other questions上的代码审查,要求对我为形式化Hilbert(基于Euclid的)几何图形的尝试进行审查。
从第一个问题中,我了解到命题相等与布尔相等和命题相等之间是有区别的。回顾我为希尔伯特飞机写的一些公理,我广泛地使用了布尔等式。尽管我不确定100%,但根据收到的答案,我怀疑我不想使用布尔相等。
例如,采用以下公理:
-- There exists 3 non-colinear points.
three_non_colinear_pts : (a : point ** b : point ** c : point **
(colinear a b c = False,
(a /= b) = True,
(b /= c) = True,
(a /= c) = True))
我尝试将其重写为不涉及= True
:
-- There exists 3 non-colinear points.
three_non_colinear_pts : (a : point ** b : point ** c : point **
(colinear a b c = False,
(a /= b),
(b /= c),
(a /= c)))
总而言之,我从关于codereview的问题中获取了代码,删除了==
并删除了= True
:
interface Plane line point where
-- Abstract notion for saying three points lie on the same line.
colinear : point -> point -> point -> Bool
coplanar : point -> point -> point -> Bool
contains : line -> point -> Bool
-- Intersection between two lines
intersects_at : line -> line -> point -> Bool
-- If two lines l and m contain a point a, they intersect at that point.
intersection_criterion : (l : line) ->
(m : line) ->
(a : point) ->
(contains l a = True) ->
(contains m a = True) ->
(intersects_at l m a = True)
-- If l and m intersect at a point a, then they both contain a.
intersection_result : (l : line) ->
(m : line) ->
(a : point) ->
(intersects_at l m a = True) ->
(contains l a = True, contains m a = True)
-- For any two distinct points there is a line that contains them.
line_contains_two_points : (a :point) ->
(b : point) ->
(a /= b) ->
(l : line ** (contains l a = True, contains l b = True ))
-- If two points are contained by l and m then l = m
two_pts_define_line : (l : line) ->
(m : line) ->
(a : point) ->
(b : point) ->
(a /= b) ->
contains l a = True ->
contains l b = True ->
contains m a = True ->
contains m b = True ->
(l = m)
same_line_same_pts : (l : line) ->
(m : line) ->
(a : point) ->
(b : point) ->
(l /= m) ->
contains l a = True ->
contains l b = True ->
contains m a = True ->
contains m b = True ->
(a = b)
-- There exists 3 non-colinear points.
three_non_colinear_pts : (a : point ** b : point ** c : point **
(colinear a b c = False,
(a /= b),
(b /= c),
(a /= c)))
-- Any line contains at least two points.
contain_two_pts : (l : line) ->
(a : point ** b : point **
(contains l a = True, contains l b = True))
-- If two lines intersect at a point and they are not identical, that is the o-
-- nly point they intersect at.
intersect_at_most_one_point : Plane line point =>
(l : line) -> (m : line) -> (a : point) -> (b : point) ->
(l /= m) ->
(intersects_at l m a = True) ->
(intersects_at l m b = True) ->
(a = b)
intersect_at_most_one_point l m a b l_not_m int_at_a int_at_b =
same_line_same_pts
l
m
a
b
l_not_m
(fst (intersection_result l m a int_at_a))
(fst (intersection_result l m b int_at_b))
(snd (intersection_result l m a int_at_a))
(snd (intersection_result l m b int_at_b))
出现错误:
|
1 | interface Plane line point where
| ~~~~~~~~~~~~~~~~
When checking type of Main.line_contains_two_points:
Type mismatch between
Bool (Type of _ /= _)
and
Type (Expected type)
/home/dair/scratch/hilbert.idr:68:29:
|
68 | intersect_at_most_one_point : Plane line point =>
| ^
When checking type of Main.intersect_at_most_one_point:
No such variable Plane
因此,看来/=
仅适用于布尔值。我一直找不到像这样的“命题” /=
:
data (/=) : a -> b -> Type where
命题不等于存在吗?还是我想从布尔型转换为命题式相等?
答案 0 :(得分:3)
与布尔值a /= b
等效的命题为a = b -> Void
。 Void
是没有构造函数的类型。因此,每当您有contra : Void
时,就会出问题。因此,a = b -> Void
可以理解为:如果您有a = b
,则存在矛盾。通常写为Not (a = b)
,这只是简写(Not a = a -> Void
)。
您有权改变命题平等。您甚至可以将contains : line -> point -> Bool
之类的布尔属性更改为Contains : line -> point -> Type
。随后contains l p = True
至Contains l p
,以及contains l p = False
至Not (Contains l p)
。
这是boolean blindness的情况,即使用prf : contains l p = True
时,我们唯一知道的是contains l p
是True
(并且编译器需要查看一下contains
来猜测为什么是True
)。另一方面,对于prf : Contains l p
,您有一个构造的证明prf
为什么命题Contains l p
成立。