Motivation
I'm trying to calculate different probabilities 'automatically', given only some variables such as the number of cards in a sample and the number of cards drawn.
Code
The following code consists of a combination of the code from "Reducing Fractions Automatically Using LaTeX3" and "Command for Multiplying Integers".
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Nn \svend_gcd:nn
{
\int_compare:nNnTF {#2} = { 0 } {#1}
{ \svend_gcd:ff {#2} { \int_mod:nn {#1} {#2} } }
}
\cs_generate_variant:Nn \svend_gcd:nn { ff }
\int_new:N \l__svend_tmp_int
\cs_new:Nn \svend_reduced:nn
{
\int_set:Nn \l__svend_tmp_int { \svend_gcd:nn {#1} {#2} }
\frac { \svend_reduced_wrap:n { \int_eval:n { #1 / \l__svend_tmp_int } } }
{ \svend_reduced_wrap:n { \int_eval:n { #2 / \l__svend_tmp_int } } }
}
\cs_new:Nn \svend_reduced_use_wrapper:N
{ \cs_set_eq:NN \svend_reduced_wrap:n #1 }
\svend_reduced_use_wrapper:N \use:n
\msg_new:nnn { svend } { malformed-fraction }
{
The~input~you~have~provided~is~malformed.~
Please~provide~input~in~the~form~of~`p/q'.
}
\NewDocumentCommand \ReducedFractionWrapper { m }
{ \svend_reduced_use_wrapper:N #1 }
\NewDocumentCommand \ReducedFraction { o > { \SplitList { / } } m }
{
\group_begin:
\IfValueT{#1}{\ReducedFractionWrapper{#1}}
\int_compare:nTF { \tl_count:n {#2} = 2 }
{ \svend_reduced:nn #2 }
{ \msg_error:nn { svend } { malformed-fraction } }
\group_end:
}
\NewExpandableDocumentCommand \produkt { m m }
{ \svend_multiply:nn {#1} {#2} }
\cs_new:Npn \svend_multiply:nn #1#2
{
\int_eval:n
{ 1 \int_step_function:nnN {#1} {#2} __svend_multiply:n }
}
\cs_new:Npn __svend_multiply:n #1 { * #1 }
\ExplSyntaxOff
\usepackage{siunitx}
\begin{document}
\def\roed{5}
\def\sort{9}
\newcommand*\kortTotal{\fpeval{\roed+\sort}}
\def\udtraek{10}
\begin{equation}
\ReducedFraction[\num]
{(\produkt{\kortTotal-\udtraek+1}{\kortTotal}-\produkt{1}{\udtraek})
/\produkt{\kortTotal-\udtraek+1}{\kortTotal}}
\end{equation}
\end{document}
Error
I get the error
! Arithmetic overflow.
<recently read> \__int_eval_end:
l.66 ...\produkt{\kortTotal-\udtraek+1}{\kortTotal}}
When I change \def\udtraek{10} to \def\udtraek{9}, it compiles just fine. The number is obviously too big (which is also indicated by Arithmetic overflow) but I don't know how to adjust the code so that I can use larger numbers.
Question
How do I change the code so that I can use larger input integers?
countregister size/expression. You could usebigintcalcfor the work (we have some unreleasedexpl3that does some but not all of the same). But as mentioned already, perhaps the question could do with some motivation. – Joseph Wright Mar 13 '24 at 13:55xintexprcould also be used to implement the arbitrary precision required – Joseph Wright Mar 13 '24 at 13:57xintexpr. If you have an elegant implementation, I'd be happy to see your solution. – Svend Tveskæg Mar 13 '24 at 14:04