-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplify_reduction.R
100 lines (61 loc) · 2.07 KB
/
simplify_reduction.R
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
simplify_reduction <- function(A, B, C, D, attributes, pos_id, verbose = FALSE) {
negC <- negate(C)
AcapnegC <- A * negC
A_orig <- A
B_orig <- B
C_orig <- C
D_orig <- D
if (sum(AcapnegC) > 0) {
x_candidates <- which(as.matrix(AcapnegC) > 0)
if (.subset(D, B)[1]) {
for (x in x_candidates) {
Anotx <- A
Anotx[x] <- 0
Cnotxbar <- C
Cnotxbar[negate_id(x, pos_id)] <- 0
if (.subset(Anotx, Cnotxbar)[1]) {
C <- Cnotxbar
if (.equal_sets(Anotx, C)[1]) {
B <- .difference2(B, D)
}
if (verbose) {
cat("^ Applied [Red]\n")
cat("^ Changed A -> B:\n")
cat("^ from:", .implication_to_string(A_orig, B_orig, attributes), "\n")
cat("^ to: ", .implication_to_string(A, B, attributes), "\n")
cat("^ Changed C -> D:\n")
cat("^ from:", .implication_to_string(C_orig, D_orig, attributes), "\n")
cat("^ to: ", .implication_to_string(C, D, attributes), "\n")
}
return(list(A, B, C, D, TRUE))
}
}
} else {
if (.subset(B, D)[1]) {
for (x in x_candidates) {
Anotx <- A
Anotx[x] <- 0
Cnotxbar <- C
Cnotxbar[negate_id(x, pos_id)] <- 0
if (.subset(Cnotxbar, Anotx)[1]) {
A <- Anotx
if (.equal_sets(A, Cnotxbar)[1]) {
D <- .difference2(D, B)
}
if (verbose) {
cat("^ Applied [Red]\n")
cat("^ Changed A -> B:\n")
cat("^ from:", .implication_to_string(A_orig, B_orig, attributes), "\n")
cat("^ to: ", .implication_to_string(A, B, attributes), "\n")
cat("^ Changed C -> D:\n")
cat("^ from:", .implication_to_string(C_orig, D_orig, attributes), "\n")
cat("^ to: ", .implication_to_string(C, D, attributes), "\n")
}
return(list(A, B, C, D, TRUE))
}
}
}
}
}
return(list(A, B, C, D, FALSE))
}