diff --git a/xml/chapter3/section3/subsection4.xml b/xml/chapter3/section3/subsection4.xml
index 9d5ca6f62..311d55674 100755
--- a/xml/chapter3/section3/subsection4.xml
+++ b/xml/chapter3/section3/subsection4.xml
@@ -570,21 +570,6 @@ function logical_and(s1, s2) {
}
-
- logical_or
-
-function logical_or(s1, s2) {
- return s1 === 0 && s2 === 0
- ? 0
- : s1 === 0 || s1 === 1
- ? s2 === 0 || s2 === 1
- ? 1
- : error(s2, "invalid signal")
- : error(s1, "invalid signal");
-}
-
-
-
@@ -673,12 +658,32 @@ function and_gate(a1, a2, output) {
and_gate.
-
- or_gate
- get_signal
- after_delay
- logical_or
-
+
+
+
+ logical_or
+
+// contributed by GitHub user clean99
+
+function logical_or(s1, s2) {
+ return s1 === 0 && s2 === 0
+ ? 0
+ : s1 === 0 || s1 === 1
+ ? s2 === 0 || s2 === 1
+ ? 1
+ : error(s2, "invalid signal")
+ : error(s1, "invalid signal");
+}
+
+
+
+ or_gate
+ get_signal
+ after_delay
+ logical_or
+
+// contributed by GitHub user clean99
+
function or_gate(a1, a2, output) {
function or_action_function() {
const new_value = logical_or(get_signal(a1),
@@ -690,9 +695,9 @@ function or_gate(a1, a2, output) {
add_action(a2, or_action_function);
return "ok";
}
-
-
-
+
+
+
diff --git a/xml/chapter3/section3/subsection5.xml b/xml/chapter3/section3/subsection5.xml
index ab5b57998..c20841f95 100755
--- a/xml/chapter3/section3/subsection5.xml
+++ b/xml/chapter3/section3/subsection5.xml
@@ -1561,6 +1561,53 @@ const answer = v_prod(v_sum("a", "b"), v_sum("c", "d"));
expression-oriented style in terms of the imperative implementation,
it is very difficult to do the converse.
+
+
+ make_connector
+ has_value
+ for_each_except
+ inform_about_value
+ multiplier_2
+ adder
+ constant
+
+// Solution provided by GitHub user clean99
+
+function cminus(x, y) {
+ const z = make_connector();
+ const u = make_connector();
+ const v = make_connector();
+ constant(-1, u);
+ multiplier(u, y, v);
+ adder(x, v, z);
+ return z;
+}
+
+function cmul(x, y) {
+ const z = make_connector();
+ multiplier(x, y, z);
+ return z;
+}
+
+function cdiv(x, y) {
+ const z = make_connector();
+ const u = make_connector();
+ const v = make_connector();
+ constant(1, v);
+ // y * u = 1 -> u = 1 / y
+ multiplier(y, u, v);
+ multiplier(x, u, z);
+ return z;
+}
+
+function cv(val) {
+ const x = make_connector();
+ constant(val, x);
+ return x;
+}
+
+
+
propagation of constraints