Skip to content

Commit cccc2ac

Browse files
authored
1 parent aebf675 commit cccc2ac

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

xml/chapter3/section3/subsection5.xml

+47
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,53 @@ const answer = v_prod(v_sum("a", "b"), v_sum("c", "d"));
15611561
expression-oriented style in terms of the imperative implementation,
15621562
it is very difficult to do the converse.</FOOTNOTE>
15631563
<LABEL NAME="ex:3_37"/>
1564+
<SOLUTION>
1565+
<SNIPPET>
1566+
<REQUIRES>make_connector</REQUIRES>
1567+
<REQUIRES>has_value</REQUIRES>
1568+
<REQUIRES>for_each_except</REQUIRES>
1569+
<REQUIRES>inform_about_value</REQUIRES>
1570+
<REQUIRES>multiplier_2</REQUIRES>
1571+
<REQUIRES>adder</REQUIRES>
1572+
<REQUIRES>constant</REQUIRES>
1573+
<JAVASCRIPT>
1574+
// Solution provided by GitHub user clean99
1575+
1576+
function cminus(x, y) {
1577+
const z = make_connector();
1578+
const u = make_connector();
1579+
const v = make_connector();
1580+
constant(-1, u);
1581+
multiplier(u, y, v);
1582+
adder(x, v, z);
1583+
return z;
1584+
}
1585+
1586+
function cmul(x, y) {
1587+
const z = make_connector();
1588+
multiplier(x, y, z);
1589+
return z;
1590+
}
1591+
1592+
function cdiv(x, y) {
1593+
const z = make_connector();
1594+
const u = make_connector();
1595+
const v = make_connector();
1596+
constant(1, v);
1597+
// y * u = 1 -> u = 1 / y
1598+
multiplier(y, u, v);
1599+
multiplier(x, u, z);
1600+
return z;
1601+
}
1602+
1603+
function cv(val) {
1604+
const x = make_connector();
1605+
constant(val, x);
1606+
return x;
1607+
}
1608+
</JAVASCRIPT>
1609+
</SNIPPET>
1610+
</SOLUTION>
15641611
</EXERCISE>
15651612

15661613
<INDEX>propagation of constraints<CLOSE/></INDEX>

0 commit comments

Comments
 (0)