Skip to content

fixes #807 #1013

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 3, 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
31 changes: 31 additions & 0 deletions xml/chapter2/section5/subsection3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,37 @@ head(tail(tail(tail(mul(p1, p2)))));
subtraction of polynomials.
(Hint: You may find it helpful to define a generic negation operation.)
<LABEL NAME="ex:sub-poly"/>
<SOLUTION>
<SNIPPET EVAL="no">
<NAME>ex_2_88_solution</NAME>
<JAVASCRIPT>
function sub_terms(L1, L2) {
if (is_empty_termlist(L1)) {
return L2;
} else if (is_empty_termlist(L2)) {
return L1;
} else {
const t1 = first_term(L1);
const t2 = first_term(L2);
return order(t1) &gt; order(t2)
? adjoin_term(t1, sub_terms(rest_terms(L1), L2))
: order(t1) &lt; order(t2)
? adjoin_term(t2, sub_terms(L1, rest_terms(L2)))
: adjoin_term(make_term(order(t1),
sub(coeff(t1), coeff(t2))),
sub_terms(rest_terms(L1),
rest_terms(L2)));
}
}
function sub_poly(p1, p2) {
return is_same_variable(variable(p1), variable(p2))
? make_poly(variable(p1),
sub_terms(term_list(p1), term_list(p2)))
: error(list(p1, p2), "polys not in same var -- sub_poly");
}
</JAVASCRIPT>
</SNIPPET>
</SOLUTION>
</EXERCISE>

<EXERCISE>
Expand Down
Loading