Shortcut for a polynomial of the form $a_nx^n+ldots+a_1x+a_0$
I currently taking a course in Algebra, and I find myself typing the polynomial
$a_nx^n+ldots+a_1x+a_0$
over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.
I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.
math-mode macros shortcut
New contributor
add a comment |
I currently taking a course in Algebra, and I find myself typing the polynomial
$a_nx^n+ldots+a_1x+a_0$
over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.
I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.
math-mode macros shortcut
New contributor
Welcome to TeX.SE!
– Mico
12 hours ago
Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order alwaysn
(w/n>1
, right?) and is the lowest order always0
, i.e., a constant?
– Mico
12 hours ago
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
12 hours ago
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
8 hours ago
add a comment |
I currently taking a course in Algebra, and I find myself typing the polynomial
$a_nx^n+ldots+a_1x+a_0$
over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.
I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.
math-mode macros shortcut
New contributor
I currently taking a course in Algebra, and I find myself typing the polynomial
$a_nx^n+ldots+a_1x+a_0$
over and over again, and I was wondering if I could create a shortcut for such a polynomial form, such that I can control what coefficients and variables I want.
I know the polynomial package exists, but I cannot seem to incorporate the "ldots" in the commands it offers.
math-mode macros shortcut
math-mode macros shortcut
New contributor
New contributor
edited 43 mins ago
Riker
1033
1033
New contributor
asked 12 hours ago
KamKam
383
383
New contributor
New contributor
Welcome to TeX.SE!
– Mico
12 hours ago
Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order alwaysn
(w/n>1
, right?) and is the lowest order always0
, i.e., a constant?
– Mico
12 hours ago
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
12 hours ago
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
8 hours ago
add a comment |
Welcome to TeX.SE!
– Mico
12 hours ago
Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order alwaysn
(w/n>1
, right?) and is the lowest order always0
, i.e., a constant?
– Mico
12 hours ago
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
12 hours ago
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
8 hours ago
Welcome to TeX.SE!
– Mico
12 hours ago
Welcome to TeX.SE!
– Mico
12 hours ago
Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always
n
(w/ n>1
, right?) and is the lowest order always 0
, i.e., a constant?– Mico
12 hours ago
Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always
n
(w/ n>1
, right?) and is the lowest order always 0
, i.e., a constant?– Mico
12 hours ago
2
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
12 hours ago
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
12 hours ago
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
8 hours ago
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
8 hours ago
add a comment |
2 Answers
2
active
oldest
votes
I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n
and 0
, respectively.) The macro called pn
in the following example satisfies these criteria.
Incidentally, the typographic ellipsis used between binary operators (such as +
) is usually of the form cdots
, not ldots
. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}
begin{document}
$pn{a}{x}$
$pn{lambda}{z}$
$pn{alpha}{xi}$
end{document}
Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n
, but that it's true that most polynomials are, in fact, order n
. In that case, it makes sense to modify the pn
macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n
by default.
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}
begin{document}
$pn{a}{x}$ % use default order (n) of polynomial
$pn[4]{lambda}{z}$
$pn[q]{alpha}{xi}$
end{document}
1
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of thepn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value isn
.
– Mico
12 hours ago
2
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
1
+1 for generating enthusiasm :)
– jfbu
10 hours ago
|
show 2 more comments
With a fairly simple syntax:
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}
keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}
cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff
begin{document}
$poly$
$poly[var=z]$
$poly[var=t,degree=m,coef=b]$
$poly[var=t,degree=m,coef=b,reverse]$
end{document}
The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are
var = x
degree = n
coef = a
You can also make shorthands with, say
newcommand{polybtn}{poly[var=t,coef=b,degree=n]}
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
1
@Mico Fairly simple user syntax.
– egreg
3 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Kam is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f471846%2fshortcut-for-a-polynomial-of-the-form-a-nxn-ldotsa-1xa-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n
and 0
, respectively.) The macro called pn
in the following example satisfies these criteria.
Incidentally, the typographic ellipsis used between binary operators (such as +
) is usually of the form cdots
, not ldots
. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}
begin{document}
$pn{a}{x}$
$pn{lambda}{z}$
$pn{alpha}{xi}$
end{document}
Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n
, but that it's true that most polynomials are, in fact, order n
. In that case, it makes sense to modify the pn
macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n
by default.
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}
begin{document}
$pn{a}{x}$ % use default order (n) of polynomial
$pn[4]{lambda}{z}$
$pn[q]{alpha}{xi}$
end{document}
1
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of thepn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value isn
.
– Mico
12 hours ago
2
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
1
+1 for generating enthusiasm :)
– jfbu
10 hours ago
|
show 2 more comments
I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n
and 0
, respectively.) The macro called pn
in the following example satisfies these criteria.
Incidentally, the typographic ellipsis used between binary operators (such as +
) is usually of the form cdots
, not ldots
. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}
begin{document}
$pn{a}{x}$
$pn{lambda}{z}$
$pn{alpha}{xi}$
end{document}
Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n
, but that it's true that most polynomials are, in fact, order n
. In that case, it makes sense to modify the pn
macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n
by default.
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}
begin{document}
$pn{a}{x}$ % use default order (n) of polynomial
$pn[4]{lambda}{z}$
$pn[q]{alpha}{xi}$
end{document}
1
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of thepn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value isn
.
– Mico
12 hours ago
2
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
1
+1 for generating enthusiasm :)
– jfbu
10 hours ago
|
show 2 more comments
I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n
and 0
, respectively.) The macro called pn
in the following example satisfies these criteria.
Incidentally, the typographic ellipsis used between binary operators (such as +
) is usually of the form cdots
, not ldots
. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}
begin{document}
$pn{a}{x}$
$pn{lambda}{z}$
$pn{alpha}{xi}$
end{document}
Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n
, but that it's true that most polynomials are, in fact, order n
. In that case, it makes sense to modify the pn
macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n
by default.
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}
begin{document}
$pn{a}{x}$ % use default order (n) of polynomial
$pn[4]{lambda}{z}$
$pn[q]{alpha}{xi}$
end{document}
I think that what you need is a macro that takes two arguments: the "name" of the coefficients, and the "name" of the base of the power terms. The names will, in general, be single letters, right? (You've indicated, in a comment, that the highest and lowest order of the polynomial are always n
and 0
, respectively.) The macro called pn
in the following example satisfies these criteria.
Incidentally, the typographic ellipsis used between binary operators (such as +
) is usually of the form cdots
, not ldots
. (The letters "c" and "l" refer to either centered (on the math line) or low (on the typographic baseline).
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[2]{#1_n #2^n + cdots + #1_1 #2 + #1_0}
begin{document}
$pn{a}{x}$
$pn{lambda}{z}$
$pn{alpha}{xi}$
end{document}
Addendum to address the OP's follow-up request: Suppose that not all polynomials are of order n
, but that it's true that most polynomials are, in fact, order n
. In that case, it makes sense to modify the pn
macro that it takes 3 rather than 2 arguments, with additional argument taking on the value n
by default.
documentclass{article}
%% The following macro must be used only in math mode:
newcommandpn[3][n]{#2_{#1} #3^{#1} + cdots + #2_1 #3 + #2_0}
begin{document}
$pn{a}{x}$ % use default order (n) of polynomial
$pn[4]{lambda}{z}$
$pn[q]{alpha}{xi}$
end{document}
edited 12 hours ago
answered 12 hours ago
MicoMico
276k30374765
276k30374765
1
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of thepn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value isn
.
– Mico
12 hours ago
2
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
1
+1 for generating enthusiasm :)
– jfbu
10 hours ago
|
show 2 more comments
1
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of thepn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value isn
.
– Mico
12 hours ago
2
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
1
+1 for generating enthusiasm :)
– jfbu
10 hours ago
1
1
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Thank you so much!!! This is great :) (I would upvote, but I need 15 rep pts haha, as soon as I get them I'll take care of it!
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the
pn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n
.– Mico
12 hours ago
@Kam - Please see the addendum I just posted. In this addendum, I changed the structure of the
pn
macro so that it takes, in addition to the usual two mandatory arguments, an optional argument (to denote the highest order of the polynomial) whose default value is n
.– Mico
12 hours ago
2
2
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
Eternally Grateful! Thanks again :)
– Kam
12 hours ago
1
1
+1 for generating enthusiasm :)
– jfbu
10 hours ago
+1 for generating enthusiasm :)
– jfbu
10 hours ago
|
show 2 more comments
With a fairly simple syntax:
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}
keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}
cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff
begin{document}
$poly$
$poly[var=z]$
$poly[var=t,degree=m,coef=b]$
$poly[var=t,degree=m,coef=b,reverse]$
end{document}
The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are
var = x
degree = n
coef = a
You can also make shorthands with, say
newcommand{polybtn}{poly[var=t,coef=b,degree=n]}
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
1
@Mico Fairly simple user syntax.
– egreg
3 hours ago
add a comment |
With a fairly simple syntax:
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}
keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}
cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff
begin{document}
$poly$
$poly[var=z]$
$poly[var=t,degree=m,coef=b]$
$poly[var=t,degree=m,coef=b,reverse]$
end{document}
The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are
var = x
degree = n
coef = a
You can also make shorthands with, say
newcommand{polybtn}{poly[var=t,coef=b,degree=n]}
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
1
@Mico Fairly simple user syntax.
– egreg
3 hours ago
add a comment |
With a fairly simple syntax:
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}
keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}
cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff
begin{document}
$poly$
$poly[var=z]$
$poly[var=t,degree=m,coef=b]$
$poly[var=t,degree=m,coef=b,reverse]$
end{document}
The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are
var = x
degree = n
coef = a
You can also make shorthands with, say
newcommand{polybtn}{poly[var=t,coef=b,degree=n]}
With a fairly simple syntax:
documentclass{article}
usepackage{amsmath}
usepackage{xparse}
ExplSyntaxOn
NewDocumentCommand{poly}{O{}}
{
group_begin:
keys_set:nn { poly } { #1 }
kam_poly:
group_end:
}
keys_define:nn { poly }
{
degree .tl_set:N = l__poly_degree_tl,
var .tl_set:N = l__poly_var_tl,
coef .tl_set:N = l__poly_coef_tl,
reverse .bool_set:N = l__poly_reverse_bool,
degree .initial:n = n,
var .initial:n = x,
coef .initial:n = a,
reverse .default:n = true,
}
cs_new_protected:Nn kam_poly:
{
bool_if:NTF l__poly_reverse_bool
{
l__poly_coef_tl sb { 0 } +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
dots +
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl }
}
{
l__poly_coef_tl sb { l__poly_degree_tl }
l__poly_var_tl sp { l__poly_degree_tl } +
dots +
l__poly_coef_tl sb { 1 } l__poly_var_tl +
l__poly_coef_tl sb { 0 }
}
}
ExplSyntaxOff
begin{document}
$poly$
$poly[var=z]$
$poly[var=t,degree=m,coef=b]$
$poly[var=t,degree=m,coef=b,reverse]$
end{document}
The keys can be specified in any order, freeing you from the need to remember which parameter goes first; the default values are
var = x
degree = n
coef = a
You can also make shorthands with, say
newcommand{polybtn}{poly[var=t,coef=b,degree=n]}
answered 10 hours ago
egregegreg
715k8618983185
715k8618983185
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
1
@Mico Fairly simple user syntax.
– egreg
3 hours ago
add a comment |
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
1
@Mico Fairly simple user syntax.
– egreg
3 hours ago
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
+1 for "fairly simple syntax". :-)
– Mico
3 hours ago
1
1
@Mico Fairly simple user syntax.
– egreg
3 hours ago
@Mico Fairly simple user syntax.
– egreg
3 hours ago
add a comment |
Kam is a new contributor. Be nice, and check out our Code of Conduct.
Kam is a new contributor. Be nice, and check out our Code of Conduct.
Kam is a new contributor. Be nice, and check out our Code of Conduct.
Kam is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f471846%2fshortcut-for-a-polynomial-of-the-form-a-nxn-ldotsa-1xa-0%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to TeX.SE!
– Mico
12 hours ago
Please tell us more about the "canonical form" of the polynomials you find yourself writing repeatedly. E.g., is the highest order always
n
(w/n>1
, right?) and is the lowest order always0
, i.e., a constant?– Mico
12 hours ago
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
12 hours ago
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
8 hours ago