Skip to content

fixes #837 #1026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading