-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproc.rb
More file actions
58 lines (47 loc) · 1021 Bytes
/
proc.rb
File metadata and controls
58 lines (47 loc) · 1021 Bytes
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
class Proc
include Latex::Inspectable
class << self
def predicate(p=nil, &b)
p ||= b #TODO
p.nil? and raise "Predicate expected"
p
end
def unary(f=nil, &b)
f ||= b
f.nil? and raise "Unary function expected"
f
end
end
def inspect_domain_latex
p = parameters.map{|_, s| Latex.quote(s) }
case p.size
when 0
'\\varnothing'
when 1
p[0]
else
"(#{p.join(', ')})"
end
end
def inspect_latex
"f(#{parameters.map{|_, s| Latex.quote(s) }.join(', ')})"
end
def invertible?
false
end
def inverse
raise NotImplementedError
end
def ~@
proc{|x| !self[x] }
end
def &(p)
proc{|x| self[x] && p[x] }
end
def |(p)
proc{|x| self[x] || p[x] }
end
def ^(p)
proc{|x| self[x] ^ p[x] }
end
end