Skip to main content
expanded "computer algebra system system"
Source Link
Federico Poloni
  • 10.7k
  • 6
  • 44
  • 59

In many CAS-systemscomputer algebra systems, one can sum a sequence of numbers using the syntax
  sum(a(k), k, kStart, kEnd) for a sequence a(k) (of real and integer values) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}

In many CAS-systems, one can sum a sequence of numbers using the syntax
  sum(a(k), k, kStart, kEnd) for a sequence a(k) (of real and integer values) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}

In many computer algebra systems, one can sum a sequence of numbers using the syntax sum(a(k), k, kStart, kEnd) for a sequence a(k) (of real and integer values) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}
Became Hot Network Question
added 31 characters in body
Source Link
cis
  • 13.5k
  • 3
  • 28
  • 69

In many CAS-systems, one can sum a sequence of numbers using the syntax
sum(a(k), k, kStart, kEnd) for a sequence a(k) (of real and integer values) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}

In many CAS-systems, one can sum a sequence of numbers using the syntax
sum(a(k), k, kStart, kEnd) for a sequence a(k) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}

In many CAS-systems, one can sum a sequence of numbers using the syntax
sum(a(k), k, kStart, kEnd) for a sequence a(k) (of real and integer values) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}
Source Link
cis
  • 13.5k
  • 3
  • 28
  • 69

Best ways to calculate sums in LaTeX

In many CAS-systems, one can sum a sequence of numbers using the syntax
sum(a(k), k, kStart, kEnd) for a sequence a(k) with the variable k.

What's the best and fastest way to do this with LaTeX?

For example, when you want to calculate thousands of values ​​for a table.

I've developed a MWE using foreach and fpeval.

enter image description here

\documentclass[margin=5pt, varwidth]{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\newcommand\Sum[4]{%
\def\mysum{0}%
\foreach #2 in {#3,...,#4}{% 
   \def\psum{\fpeval{(#1)}}%
   \xdef\mysum{\fpeval{\mysum+\psum}}%
}\mysum}

\begin{document}
Test 1: $\displaystyle\sum\limits_{k=1}^{100} k = \Sum{\k}{\k}{1}{100}$

\newcommand\binomial[2]{\fpeval{fact(#1)/(fact(#2)*fact(#1-#2))}}
Test 2: $\displaystyle\sum\limits_{k=0}^{5} \dbinom{5}{k}
= \Sum{  \binomial{5}{\k}  }{\k}{0}{5} =2^5 = \fpeval{2^5}$
\end{document}