Skip to content

Commit

Permalink
fixes #837 (#1026)
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-henz authored Jul 9, 2024
1 parent aebf675 commit cccc2ac
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions xml/chapter3/section3/subsection5.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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.</FOOTNOTE>
<LABEL NAME="ex:3_37"/>
<SOLUTION>
<SNIPPET>
<REQUIRES>make_connector</REQUIRES>
<REQUIRES>has_value</REQUIRES>
<REQUIRES>for_each_except</REQUIRES>
<REQUIRES>inform_about_value</REQUIRES>
<REQUIRES>multiplier_2</REQUIRES>
<REQUIRES>adder</REQUIRES>
<REQUIRES>constant</REQUIRES>
<JAVASCRIPT>
// 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;
}
</JAVASCRIPT>
</SNIPPET>
</SOLUTION>
</EXERCISE>

<INDEX>propagation of constraints<CLOSE/></INDEX>
Expand Down

0 comments on commit cccc2ac

Please sign in to comment.