/
Predicate.pm6
executable file
·124 lines (95 loc) · 2.93 KB
/
Predicate.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use v6.c;
unit class Slang::Predicate:ver<0.0.1>;
=begin pod
=head1 NAME
Slang::Predicate - Predicates in perl6
=head1 SYNOPSIS
use Slang::Predicate;
my (\α, \β) = (T, F);
say ((α → β) ∧ α) → β;
=head1 DESCRIPTION
Slang::Predicate adds operators common to predicate logic directly to perl6.
Exported terms and operators are:
=begin table
Terms | Term | Example
======================
True | T | T ~~ True
False | F | F ~~ False
=end table
=begin table
Infix | operator | Example
======================
True | T | T ~~ True
False | F | F ~~ False
Disjunction | ∨ | T ∨ F ~~ True
Conjunction | ∧ | T ∧ F ~~ False
Exclusive disjunction | ⊻ or ⊕ | T ⊻ F ~~ True
Conditional | → or ⇒ or ⊃ | T → F ~~ False
Biconditional | ↔ or ⇔ or ≡ | T ↔ F ~~ False
=end table
=begin table
Prefix | operator | Example
======================
Negation | ¬ | ¬T ~~ False
Verum | ⊤ | ⊤F ~~ True
Falsum | ⊥ | ⊥T ~~ False
=end table
=head1 AUTHOR
Sam Gillespie <samgwise@gmail.com>
=head1 COPYRIGHT AND LICENSE
Copyright 2017 Sam Gillespie
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.
=end pod
#
# Alias Booleans to T and F
#
constant T is export = True;
constant F is export = False;
# Disjunction ∨
sub infix:<∨>(Bool \α, Bool \β --> Bool) is tighter(&infix:<or>) is assoc<chain> is export {
α or β
}
# Conjunction ∧
sub infix:<∧>(Bool \α, Bool \β --> Bool) is tighter(&infix:<and>) is assoc<chain> is export {
α and β
}
# Negation ¬ (or ! or not)
sub prefix:<¬>(Bool \α --> Bool) is tighter(&prefix:<!>) is export {
not α
}
# Verum ⊤ (or T or True)
sub prefix:<⊤>(Bool $ --> Bool) is tighter(&prefix:<!>) is export {
True
}
# Falsum ⊥ (or T or True)
sub prefix:<⊥>(Bool $ --> Bool) is tighter(&prefix:<!>) is export {
False
}
# Exclusive disjunction ⊻ or ⊕ (or xor)
sub infix:<⊻>(Bool \α, Bool \β --> Bool) is tighter(&infix:<xor>) is assoc<chain> is export {
(α ∨ β) ∧ ¬(α ∧ β)
}
sub infix:<⊕>(Bool \α, Bool \β --> Bool) is tighter(&infix:<xor>) is assoc<chain> is export {
α ⊻ β
}
# Conditional → or ⇒ or ⊃
sub infix:<→>(Bool \α, Bool \β --> Bool) is tighter(&infix:<or>) is export {
¬α ∨ β
# ¬(α ∧ ¬β)
}
sub infix:<⇒>(Bool \α, Bool \β --> Bool) is tighter(&infix:<or>) is export {
α → β
}
sub infix:<⊃>(Bool \α, Bool \β --> Bool) is tighter(&infix:<or>) is export {
α → β
}
# Biconditional ↔ or ⇔ or ≡
sub infix:<↔>(Bool \α, Bool \β --> Bool) is tighter(&infix:<and>) is export {
¬(α ⊻ β)
}
sub infix:<⇔>(Bool \α, Bool \β --> Bool) is tighter(&infix:<and>) is export {
α ↔ β
}
sub infix:<≡>(Bool \α, Bool \β --> Bool) is tighter(&infix:<and>) is export {
α ↔ β
}