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
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
Welcome to TeX.SE!
– Mico
Jan 25 at 14:14
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
Jan 25 at 14:16
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
Jan 25 at 14:16
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
Jan 25 at 18:14
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
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
edited Jan 26 at 2:12
Riker
1033
1033
asked Jan 25 at 13:58
KamKam
685
685
Welcome to TeX.SE!
– Mico
Jan 25 at 14:14
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
Jan 25 at 14:16
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
Jan 25 at 14:16
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
Jan 25 at 18:14
add a comment |
Welcome to TeX.SE!
– Mico
Jan 25 at 14:14
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
Jan 25 at 14:16
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
Jan 25 at 14:16
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
Jan 25 at 18:14
Welcome to TeX.SE!
– Mico
Jan 25 at 14:14
Welcome to TeX.SE!
– Mico
Jan 25 at 14:14
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
Jan 25 at 14:16
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
Jan 25 at 14:16
2
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
Jan 25 at 14:16
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
Jan 25 at 14:16
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
Jan 25 at 18:14
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
Jan 25 at 18:14
add a comment |
3 Answers
3
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}
2
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
Jan 25 at 14:29
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
@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
Jan 25 at 14:54
2
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
1
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
|
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
Jan 25 at 23:17
2
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
add a comment |
I would propose poly{ax^n}
newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}
You can use poly{ax}
or poly{ax^n}
.
Thank you very much!
– Kam
Jan 27 at 14:26
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
});
}
});
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
3 Answers
3
active
oldest
votes
3 Answers
3
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}
2
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
Jan 25 at 14:29
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
@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
Jan 25 at 14:54
2
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
1
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
|
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}
2
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
Jan 25 at 14:29
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
@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
Jan 25 at 14:54
2
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
1
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
|
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 Jan 25 at 14:52
answered Jan 25 at 14:28
MicoMico
279k31380769
279k31380769
2
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
Jan 25 at 14:29
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
@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
Jan 25 at 14:54
2
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
1
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
|
show 2 more comments
2
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
Jan 25 at 14:29
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
@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
Jan 25 at 14:54
2
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
1
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
2
2
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
Jan 25 at 14:29
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
Jan 25 at 14:29
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
Question, if I want to change the variable "n", how should I proceed? I am sorry to bother you again
– Kam
Jan 25 at 14:36
@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
Jan 25 at 14:54
@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
Jan 25 at 14:54
2
2
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
Eternally Grateful! Thanks again :)
– Kam
Jan 25 at 14:56
1
1
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
+1 for generating enthusiasm :)
– user4686
Jan 25 at 15:59
|
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
Jan 25 at 23:17
2
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
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
Jan 25 at 23:17
2
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
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 Jan 25 at 16:03
egregegreg
720k8719093208
720k8719093208
+1 for "fairly simple syntax". :-)
– Mico
Jan 25 at 23:17
2
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
add a comment |
+1 for "fairly simple syntax". :-)
– Mico
Jan 25 at 23:17
2
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
+1 for "fairly simple syntax". :-)
– Mico
Jan 25 at 23:17
+1 for "fairly simple syntax". :-)
– Mico
Jan 25 at 23:17
2
2
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
@Mico Fairly simple user syntax.
– egreg
Jan 25 at 23:19
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
Thank you for taking the time to answer my post! I will definitely look into this as well :) where might you suggest I start properly learning about writing in Latex? I'm bewildered by what it seems to offer!
– Kam
Jan 26 at 5:50
add a comment |
I would propose poly{ax^n}
newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}
You can use poly{ax}
or poly{ax^n}
.
Thank you very much!
– Kam
Jan 27 at 14:26
add a comment |
I would propose poly{ax^n}
newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}
You can use poly{ax}
or poly{ax^n}
.
Thank you very much!
– Kam
Jan 27 at 14:26
add a comment |
I would propose poly{ax^n}
newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}
You can use poly{ax}
or poly{ax^n}
.
I would propose poly{ax^n}
newcommandpoly[1]{dopoly#1^n^relax}
defdopoly#1#2^#3^#4relax{#1_{#3}#2^{#3} + dots + #1_{1}#2 + #1_{0}}
You can use poly{ax}
or poly{ax^n}
.
answered Jan 26 at 11:08
ManuelManuel
21.4k846107
21.4k846107
Thank you very much!
– Kam
Jan 27 at 14:26
add a comment |
Thank you very much!
– Kam
Jan 27 at 14:26
Thank you very much!
– Kam
Jan 27 at 14:26
Thank you very much!
– Kam
Jan 27 at 14:26
add a comment |
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
Jan 25 at 14:14
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
Jan 25 at 14:16
2
Exactly as you say! and thank you for the warm welcome :) @Mico
– Kam
Jan 25 at 14:16
Of course, the correct form for a polynomial is $(cdots(a_nx+a_{n-1})x+cdots+a_1)x+a_0$ ;-)
– John Kormylo
Jan 25 at 18:14