-
Notifications
You must be signed in to change notification settings - Fork 0
/
testEquiv.html
206 lines (169 loc) · 6.57 KB
/
testEquiv.html
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
197
198
199
200
201
202
203
204
205
206
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<meta title="Semantic Math Processor Client Demo" />
<!--Katex CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"
integrity="sha256-uT5rNa8r/qorzlARiO7fTBE7EWQiX/umLlXsq7zyQP8=" crossorigin="anonymous">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css"
integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
<script src="node_modules/semantic-math-editor/index.bundle.js"></script>
<script src="dist/index.bundle.js"></script>
<style>
.auto-height {
height: auto !important;
}
</style>
</head>
<body>
<div class="px-3 pt-md-5 mx-auto text-center">
<h1 class="display-4">Semantic Math Processor Client Demo</h1>
<p class="lead">Please type two math expressions to check for equivalence</p>
</div>
<div class="container">
<div class="row">
<div class="col">
<div class="container">
<div class="row">
<div class="col">
<form>
<div class="input-group mb-3" aria-label="Editor 1">
<div id="ed1" class="form-control editor-field auto-height" tabindex="1"
ontouchstart="openKeyboard1();"></div>
<div class="input-group-append">
<button class="btn btn-outline-secondary full-height" type="button"
onclick="openKeyboard1();">keyboard</button>
</div>
</div>
<small id="errors1" class="form-text text-muted">Type math formula here. Press "\" to start a context assistant.</small>
<br />
<div class="input-group mb-3" aria-label="Editor 2">
<div id="ed2" class="form-control editor-field auto-height" tabindex="1"
ontouchstart="openKeyboard2();"></div>
<div class="input-group-append">
<button class="btn btn-outline-secondary full-height" type="button"
onclick="openKeyboard2();">keyboard</button>
</div>
</div>
<small id="errors2" class="form-text text-muted">Type math formula here. Press "\" to start a context assistant.</small>
</form>
</div>
</div>
<br />
<div class="row">
<div class="col-md-auto">
<span id="sympy_state" class="badge badge-secondary">No equivavlence</span>
<span id="sympy_simpler" class="badge badge-secondary"></span>
</div>
<div class="col">
</div>
</div>
<br />
<div class="row">
<div class="col-md-auto">
<button class="btn btn-outline-secondary" type="button" onclick="checkEquivalence();">Check
equivalence</button>
</div>
<div class="col">
</div>
</div>
</div>
</div>
</div>
</div>
<script>
const sympyClient = new SemanticMathProcessorClient.SympyClient("https://math-processor.math-editor.com");
var sympyState = document.getElementById("sympy_state");
var sympySimpler = document.getElementById("sympy_simpler");
var el1 = document.getElementById("ed1");
var editor1 = SemanticMathEditor.createEditor(el1, true);
var el2 = document.getElementById("ed2");
var editor2 = SemanticMathEditor.createEditor(el2, true);
var validation1 = SemanticMathEditor.setupDefaultErrorDecoration(
editor1,
document.getElementById("errors1"),
{
noErrorsHtml: "Type math formula here"
});
var validation2 = SemanticMathEditor.setupDefaultErrorDecoration(
editor2,
document.getElementById("errors2"),
{
noErrorsHtml: "Type math formula here"
});
function openKeyboard1() {
SemanticMathEditor.showKeyboard(editor1);
}
function openKeyboard2() {
SemanticMathEditor.showKeyboard(editor2);
}
function setSucessMessage(elem, mes) {
elem.classList.remove('badge-secondary');
elem.classList.add('badge-success');
elem.innerHTML = mes;
}
function setFailureMessage(elem, mes) {
elem.classList.remove('badge-success');
elem.classList.add('badge-secondary');
elem.innerHTML = mes;
}
function checkEquivalence() {
var hasErrors = false;
if (!validation1()) {
hasErrors = true;
}
if (!validation2()) {
hasErrors = true;
}
if (!hasErrors) {
var semantic1 = editor1.getSemantic();
var semantic2 = editor2.getSemantic();
doSympyCheck(semantic1.semantic, semantic2.semantic);
function doSympyCheck(mn1, mn2) {
const e1 = sympyClient.prepareCompute(mn1);
const e2 = sympyClient.prepareCompute(mn2);
if (e1 instanceof SemanticMathProcessorClient.PreparedSympyCall && e2 instanceof SemanticMathProcessorClient.PreparedSympyCall) {
sympyClient.checkEquivalence(e1, e2).then(
(equiv) => {
if (equiv.eq != 'different') {
setSucessMessage(sympyState, "Sympy equivavlence: "+equiv.eq);
}
else {
setFailureMessage(sympyState, "No Sympy equivavlence");
}
if (equiv.si == "none" || equiv.si == "unknown") {
setFailureMessage(sympySimpler, "");
}
else {
if(equiv.si == "first") {
setSucessMessage(sympySimpler, "Sympy: first expression is simpler");
}
else {
setSucessMessage(sympySimpler, "Sympy: second expression is simpler");
}
}
}
).catch(
(error) => {
console.log("ERROR:" + JSON.stringify(error));
setFailureMessage(sympyState, "error. see log for details");
}
);
}
else {
setFailureMessage(sympyState, "Can't convert to sympy");
}
}
}
else {
setFailureMessage(sympyState, "No equivavlence");
setFailureMessage(sympySimpler, "");
}
}
</script>
</body>
</html>