@@ -29,20 +29,123 @@ function form_value() {
29
29
} ;
30
30
}
31
31
32
+ function proofweb ( e ) {
33
+ return e . replace ( / & / g, "/\\" ) . replace ( / \| / g, "\\/" ) . replace ( / ! / g, "~" ) ;
34
+ }
35
+
36
+ function natural_ded ( atoms , ex , n ) {
37
+
38
+ var m = [ "Require Import ProofWeb." ,
39
+ "(* TEMPLATE DA TEORIA DE DEDUÇÃO NATURAL: *)" ,
40
+ "Parameter " ] . join ( '\n\n' ) ;
41
+
42
+ m += atoms . join ( ' ' ) ;
43
+
44
+ m += ": Prop.\n\n" ;
45
+
46
+ var k = 0 ;
47
+
48
+ for ( i in ex . premises ) {
49
+ m += "Hypothesis P" + k + " : " ;
50
+ m += proofweb ( ex . premises [ i ] ) + ".\n\n" ;
51
+ k = k + 1 ;
52
+ }
53
+
54
+ m += "Theorem T" + n + " : " + proofweb ( ex . conclusion ) + ".\n\n" ;
55
+
56
+ m += [ "Proof." ,
57
+ "(* Prova aqui *)" ,
58
+ "Qed." ] . join ( "\n\n" ) ;
59
+
60
+ return m ;
61
+ }
62
+
63
+ function semantic ( atoms , ex , n ) {
64
+
65
+ var m = [ "Require Import Semantics." ,
66
+ "(* Exemplo de VERIFICAÇÂO DE UM CONTRA-MODELO: *)" ,
67
+ "Parameter " ] . join ( '\n\n' ) ;
68
+
69
+ m += atoms . join ( ' ' ) ;
70
+
71
+ m += ": Prop.\n\n" ;
72
+
73
+ var k = 0 ;
74
+
75
+ for ( i in atoms ) {
76
+ m += "(* Hypothesis P" + k + " : (v ?? " ;
77
+ m += atoms [ i ] + "). *)\n\n" ;
78
+ k = k + 1 ;
79
+ }
80
+
81
+ var r = ex . premises . map ( function ( d ) { return proofweb ( d ) ; } ) ;
82
+
83
+ var p = ' ( ' + r . join ( ' /\\ ' ) + ' ) -> ' + proofweb ( ex . conclusion ) ;
84
+
85
+ m += "Theorem T" + n + " : (v ||-/- " + p + ".\n\n" ;
86
+
87
+ m += [ "Proof." ,
88
+ "(* Prova aqui *)" ,
89
+ "Qed." ] . join ( "\n\n" ) ;
90
+
91
+ return m ;
92
+ }
93
+
94
+ function shuffle ( array ) {
95
+ var tmp , current , top = array . length ;
96
+
97
+ if ( top ) while ( -- top ) {
98
+ current = Math . floor ( Math . random ( ) * ( top + 1 ) ) ;
99
+ tmp = array [ current ] ;
100
+ array [ current ] = array [ top ] ;
101
+ array [ top ] = tmp ;
102
+ }
103
+
104
+ return array ;
105
+ }
106
+
107
+ function combine ( res ) {
108
+ var a = shuffle ( res . exercises . valid . concat ( res . exercises . invalid ) ) ;
109
+
110
+ console . log ( a ) ;
111
+
112
+ var r = { } ;
113
+
114
+ $ . each ( students , function ( i , val ) {
115
+ r [ val ] = { nd : [ ] , sem : [ ] } ;
116
+
117
+ var l = r [ val ] ;
118
+
119
+ var j ;
120
+
121
+ for ( j = 0 ; j < res . request . num_exercises / num_students ; j ++ ) {
122
+ console . log ( i + " " + j ) ;
123
+ l . nd [ j ] = natural_ded ( res . request . atoms , a [ i * j ] , j ) ;
124
+ l . sem [ j ] = semantic ( res . request . atoms , a [ i * j ] , j ) ;
125
+ }
126
+ } ) ;
127
+
128
+ return r ;
129
+ } ;
130
+
131
+
132
+ //console.log(natural_ded(s.request.atoms, s.exercises.valid[0], 0));
133
+ //console.log(semantic(s.request.atoms, s.exercises.valid[0], 0));
134
+
32
135
function select ( nome ) {
33
136
$ ( '#side .tab' ) . hide ( ) ;
34
137
$ ( '#side .tab#c_' + nome ) . show ( ) ;
35
138
$ ( '#menu .selected' ) . removeClass ( 'selected' ) ;
36
139
$ ( '#menu #' + nome ) . addClass ( 'selected' ) ;
37
140
}
38
141
142
+ var test ;
143
+
39
144
$ ( document ) . ready ( function ( ) {
40
145
41
146
$ ( "a#send" ) . click ( function ( ev ) {
42
147
$ ( 'a#send' ) . toggle ( ) ;
43
148
44
- console . log ( form_value ( ) ) ;
45
-
46
149
$ . ajax ( {
47
150
url :"generate.php" ,
48
151
type : "POST" ,
@@ -53,9 +156,11 @@ $(document).ready(function () {
53
156
alert ( "Erro ao enviar os dados: " + status ) ;
54
157
} ,
55
158
success : function ( data ) {
56
- console . log ( $ ( '#c_detalhes' ) ) ;
57
159
$ ( '#c_detalhes' ) . show ( ) . html ( '<pre>' + JSON . stringify ( data , null , 4 ) ) ;
58
- console . log ( data ) ;
160
+ $ ( '#c_exerc' ) . show ( ) . html ( '<pre>' + JSON . stringify ( combine ( data ) , null , 4 ) ) ;
161
+
162
+ test = data ;
163
+
59
164
$ ( 'a#send' ) . toggle ( ) ;
60
165
$ ( '#menu' ) . show ( ) ;
61
166
$ ( '#menu #exerc' ) . trigger ( 'click' ) ;
@@ -81,4 +186,4 @@ $(document).ready(function () {
81
186
. trigger ( 'blur' ) ;
82
187
83
188
84
- } ) ;
189
+ } ) ;
0 commit comments