-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullAdder.sh
executable file
·196 lines (141 loc) · 3.29 KB
/
FullAdder.sh
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/sh
#SBATCH --job-name="BCDLt_4x5"
#SBATCH --output="RESULTS/%j.BCDLt_4x5.%N.out"
#SBATCH --partition=compute
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --export=ALL
#SBATCH -t 47:59:59
FormulaName="BCDLt"
AtomsNum=8
CrossbarR=4
CrossbarC=5
FILE="${FormulaName}_${CrossbarR}x${CrossbarC}.smt2"
LiteralsNum=`expr $AtomsNum \* 2`
LowerHalfLow=0
LowerHalfHigh=`expr $AtomsNum - 1`
UpperHalfLow=`expr $AtomsNum`
UpperHalfHigh=`expr $LiteralsNum - 1`
#THE ATOMS AND THEIR NEGATIONS
AtomsAndNegations=""
twoPow=1
for i in `seq 0 $(expr $AtomsNum - 1)`;
do
AtomsAndNegations="$AtomsAndNegations
(define-const a$i (AndClause) (_ bv$twoPow $LiteralsNum) )"
twoPow=`expr $twoPow + $twoPow`
done
for i in `seq 0 $(expr $AtomsNum - 1)`;
do
AtomsAndNegations="$AtomsAndNegations
(define-const na$i (AndClause) (_ bv$twoPow $LiteralsNum) )"
twoPow=`expr $twoPow + $twoPow`
done
#declaration of the memristors
memristorNum=`expr $CrossbarR \* $CrossbarC`
memristorsDecs=""
for i in `seq 0 $(expr $memristorNum - 1)`
do
memristorDecs="$memristorDecs
(declare-const m$i (AndClause) )"
done
memristorLegVals=""
#Legal values for the memristors
for i in `seq 0 $(expr $memristorNum - 1)`
do
memristorLegVals="$memristorLegVals
(assert (or
(= m$i TRUE)
(= m$i FALSE)"
for m in `seq 0 $(expr $AtomsNum - 1)`
do
memristorLegVals="$memristorLegVals
(= m$i a$m )
(= m$i na$m)"
done
memristorLegVals="$memristorLegVals
))
"
done
maxR=`expr $CrossbarR - 1`
SneakPaths=$(cat "SNEAKPATHS/${CrossbarR}x${CrossbarC}_r$maxR")
SneakPathsNum=$(wc -l < "SNEAKPATHS/${CrossbarR}x${CrossbarC}_r$maxR")
#wc -l <<<"$SneakPaths"
#SneakPathsNum=`wc -l <<< "$SneakPaths"`
Formula=$(cat "FORMULAS/$FormulaName")
FormulaNum=`wc -l < "FORMULAS/$FormulaName"`
#Map Paths to AndClauses
mapPath2Formula=""
for p in `seq 0 $(expr $SneakPathsNum - 1)`
do
mapPath2Formula="$mapPath2Formula
(assert (or"
for f in `seq 0 $(expr $FormulaNum - 1)`
do
mapPath2Formula="$mapPath2Formula
(= P$p F$f)"
done
mapPath2Formula="$mapPath2Formula
(IsFALSE P$p)
))
"
done
#Map AndClauses to Paths
mapFormula2Path=""
for f in `seq 0 $(expr $FormulaNum - 1)`
do
mapFormula2Path="$mapFormula2Path
(assert (or"
for p in `seq 0 $(expr $SneakPathsNum - 1)`
do
mapFormula2Path="$mapFormula2Path
(= F$f P$p)"
done
mapFormula2Path="$mapFormula2Path
))
"
done
memristorsList=""
for m in `seq 0 $(expr $memristorNum - 1)`
do
memristorsList="${memristorsList}m$m "
done
/bin/cat <<EOM >$FILE
; #THE LITERALS
(define-sort AndClause () (_ BitVec $LiteralsNum) )
(define-const FALSE (AndClause) (bvnot (_ bv0 $LiteralsNum)) ) ; #All ones!
(define-const TRUE (AndClause) (_ bv0 $LiteralsNum) )
(define-fun IsFALSE ((clause AndClause)) Bool
(not
(=
(_ bv0 $AtomsNum) ; #All zeros
(bvand
((_ extract $UpperHalfHigh $UpperHalfLow) clause)
((_ extract $LowerHalfHigh $LowerHalfLow ) clause)
)
)
)
)
; #THE ATOMS AND THEIR NEGATIONS
$AtomsAndNegations
; #THE MEMRISTORS
$memristorDecs
; #LEGAL VALUES FOR THE MEMRISTORS ***SUSPICIOUS***
$memristorLegVals
; #THE SNEAK PATHS
$SneakPaths
; #Formula's And Clauses
$Formula
; #The Mapping
$mapPath2Formula
; #The mapping should be onto
$mapFormula2Path
; #Output
(check-sat)
(get-value (
$memristorsList
))
EOM
date
./z3 $FILE
date