Topic: New math functions std::gcd and std::lcm


Author: greeshmabalabadra@gmail.com
Date: Thu, 18 Sep 2014 08:58:29 -0700 (PDT)
Raw View
------=_Part_37_1584667330.1411055909466
Content-Type: text/plain; charset=UTF-8

Yes,
we can also include
bool isPrime(int a);
for checking whether the given number is prime or not.
Many basic mathematical functions can be included as the user never has to
write every small function when ever he/she needs.

On Wednesday, June 6, 2012 7:29:26 PM UTC+5:30, Martin Desharnais wrote:
>
> As std::ratio<> require it and user could want to use this facility to
> create their own compile time arithmetic, I suggest to include in the C++
> Standard those two new math functions.
>
> template<class Integral>
> constexpr Integral gcd(Integral a, Integral b);
>
> template<class Integral>
> constexpr Integral lcm(Integral a, Integral b);
>

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_37_1584667330.1411055909466
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Yes,<div>we can also include&nbsp;</div><div>bool isPrime(=
int a);</div><div>for checking whether the given number is prime or not.</d=
iv><div>Many basic mathematical functions can be included as the user never=
 has to write every small function when ever he/she needs.</div><div><br>On=
 Wednesday, June 6, 2012 7:29:26 PM UTC+5:30, Martin Desharnais wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;">As std::ratio&lt;&gt; require it an=
d user could want to use this facility to create their own compile time ari=
thmetic, I suggest to include in the C++ Standard those two new math functi=
ons.<br><br>template&lt;class Integral&gt;<br>constexpr Integral gcd(Integr=
al a, Integral b);<br><br>template&lt;class Integral&gt;<br>
constexpr Integral lcm(Integral a, Integral b);<br></blockquote></div></div=
>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_37_1584667330.1411055909466--

.


Author: Ville Voutilainen <ville.voutilainen@gmail.com>
Date: Thu, 18 Sep 2014 19:25:12 +0300
Raw View
On 6 June 2012 16:59, Martin Desharnais <martin.desharnais@gmail.com> wrote:
> As std::ratio<> require it and user could want to use this facility to
> create their own compile time arithmetic, I suggest to include in the C++
> Standard those two new math functions.
>
> template<class Integral>
> constexpr Integral gcd(Integral a, Integral b);
>
> template<class Integral>
> constexpr Integral lcm(Integral a, Integral b);

See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4061.pdf

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Myriachan <myriachan@gmail.com>
Date: Thu, 18 Sep 2014 17:29:04 -0700 (PDT)
Raw View
------=_Part_2957_2115131678.1411086544251
Content-Type: text/plain; charset=UTF-8

On Thursday, September 18, 2014 9:25:14 AM UTC-7, Ville Voutilainen wrote:
>
>
> See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4061.pdf
>

Perhaps it should include the Extended Euclidean algorithm?  GCD alone
isn't useful to the implementation of RSA, contrary to N4061's introduction
- RSA needs the cofactors in order to implement modular inversion.

This spec needs to note its boundary conditions.  Mathematically,
gcd(-(2^31), -1) is 1, but in N4061, gcd<int, int>(INT_MIN, 1) is
undefined, due to -INT_MIN inside abs being undefined.

The nice thing about templating is that big number (arbitrary-precision)
library support is implicit by just dropping in a big number class, and can
be optimized with specialization.  (I mean from other providers; I'm not
suggesting big number support in STL.)


On Thursday, September 18, 2014 8:36:07 AM UTC-7, greeshma...@gmail.com
wrote:
>
> Yes,
> we can also include
> bool isPrime(int a);
> for checking whether the given number is prime or not.
> Many basic mathematical functions can be included as the user never has to
> write every small function when ever he/she needs.
>
>
Primality checking is quite specialized, with a lot of tuning for larger
numbers; it may not make sense for it to be in a standard library.  I
suppose that for, say, std::uint128_t as a maximum, it wouldn't be too bad,
but for arbitrary-precision specializations, what would it do?  Provably
prime with a cheaply-verifiable certificate?  Provably prime at all?
Probably prime to some tolerance?  Which algorithm?  ...

Melissa

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_2957_2115131678.1411086544251
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Thursday, September 18, 2014 9:25:14 AM UTC-7, Ville Vo=
utilainen wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><br>See <a hre=
f=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4061.pdf" tar=
get=3D"_blank" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75ht=
tp%3A%2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2014%2Fn=
4061.pdf\46sa\75D\46sntz\0751\46usg\75AFQjCNETPq9Z5T8bnAG04ALu-veCYMmRrw';r=
eturn true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%=
2F%2Fwww.open-std.org%2Fjtc1%2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2014%2Fn4061.p=
df\46sa\75D\46sntz\0751\46usg\75AFQjCNETPq9Z5T8bnAG04ALu-veCYMmRrw';return =
true;">http://www.open-std.org/jtc1/<wbr>sc22/wg21/docs/papers/2014/<wbr>n4=
061.pdf</a>
<br></blockquote><div><br>Perhaps it should include the Extended Euclidean =
algorithm?&nbsp; GCD alone isn't useful to the implementation of RSA, contr=
ary to N4061's introduction - RSA needs the cofactors in order to implement=
 modular inversion.<br><br>This spec needs to note its boundary conditions.=
&nbsp; Mathematically, gcd(-(2^31), -1) is 1, but in N4061, <span style=3D"=
font-family: courier new,monospace;">gcd&lt;int, int&gt;(INT_MIN, 1)</span>=
 is undefined, due to <span style=3D"font-family: courier new,monospace;">-=
INT_MIN</span> inside <span style=3D"font-family: courier new,monospace;">a=
bs</span> being undefined.<br><br>The nice thing about templating is that b=
ig number (arbitrary-precision) library support is implicit by just droppin=
g in a big number class, and can be optimized with specialization.&nbsp; (I=
 mean from other providers; I'm not suggesting big number support in STL.)<=
br><br><br>On Thursday, September 18, 2014 8:36:07 AM UTC-7, greeshma...@gm=
ail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>Yes,<div>we can also include&nbsp;</div><div>bool isPrime(int a);</div><di=
v>for checking whether the given number is prime or not.</div><div>Many bas=
ic mathematical functions can be included as the user never has to write ev=
ery small function when ever he/she needs.</div><br></div></blockquote><br>=
Primality checking is quite specialized, with a lot of tuning for larger nu=
mbers; it may not make sense for it to be in a standard library.&nbsp; I su=
ppose that for, say, <span style=3D"font-family: courier new,monospace;">st=
d::uint128_t</span> as a maximum, it wouldn't be too bad, but for arbitrary=
-precision specializations, what would it do?&nbsp; Provably prime with a c=
heaply-verifiable certificate?&nbsp; Provably prime at all?&nbsp; Probably =
prime to some tolerance?&nbsp; Which algorithm?&nbsp; ...<br><br>Melissa<br=
></div></div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2957_2115131678.1411086544251--

.


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Sat, 20 Sep 2014 09:00:05 -0700 (PDT)
Raw View
------=_Part_156_1738740489.1411228805440
Content-Type: text/plain; charset=UTF-8



On Wednesday, 6 June 2012 14:59:26 UTC+1, Martin Desharnais wrote:
>
> As std::ratio<> require it and user could want to use this facility to
> create their own compile time arithmetic, I suggest to include in the C++
> Standard those two new math functions.
>
> template<class Integral>
> constexpr Integral gcd(Integral a, Integral b);
>
> template<class Integral>
> constexpr Integral lcm(Integral a, Integral b);
>

I like it.  Why not have an arbitrary number of parameters?

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_156_1738740489.1411228805440
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, 6 June 2012 14:59:26 UTC+1, Martin D=
esharnais  wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">As std::ratio=
&lt;&gt; require it and user could want to use this facility to create thei=
r own compile time arithmetic, I suggest to include in the C++ Standard tho=
se two new math functions.<br><br>template&lt;class Integral&gt;<br>constex=
pr Integral gcd(Integral a, Integral b);<br><br>template&lt;class Integral&=
gt;<br>
constexpr Integral lcm(Integral a, Integral b);<br></blockquote><div><br>I =
like it.&nbsp; Why not have an arbitrary number of parameters? <br></div></=
div>

<p></p>

-- <br />
<br />
--- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_156_1738740489.1411228805440--

.