Re: [sage-support] Re: factorial

2020-11-30 Thread Samuel Lelièvre
Le lun. 30 nov. 2020 à 13:37, Dima Pasechnik  a écrit :
>
> On Mon, Nov 30, 2020 at 9:16 AM Vincent Delecroix
> <20100.delecr...@gmail.com> wrote:
> >
> > Le 30/11/2020 à 00:48, slelievre a écrit :
> > > 2020-11-29 21:23:36 UTC, Guillermo:
> > >>
> > >> I wonder what would be wrong with replacing '!' → '.factorial()'
> > >
> > > Interesting idea. Just be careful with `!=` of course.
> > >
> >
> > Indeed the expression "3!=3" is ambiguous... Of course one can choose
> > a priority (3!)=(3) or (3)!=(3) but that would be much more error
> > prone than using .factorial() from the start.
>
> I think .factorial() will do. Perhaps this can be combined with
> looking for deprecation issues vs factorial() and Python 3.9.
>
> From python 3.9 docs:
>
> Currently math.factorial() accepts float instances with non-negative
> integer values (like 5.0).
> It raises a ValueError for non-integral and negative floats. It is now
> deprecated.
> In future Python versions it will raise a TypeError for all floats.
> (Contributed by Serhiy Storchaka in bpo-37315.)
> https://bugs.python.org/issue37315

Dealing with that deprecation is the object of:

- Sage Trac ticket 30764
  Adapt to float factorial deprecation in Python 3.9
  https://trac.sagemath.org/ticket/30764

in case anyone wants to give it a go.

Preparsing `!` to `.factorial()` is orthogonal enough
that I think it deserves its own ticket. I opened

- Sage Trac ticket 30982
  Preparse ! for factorial
  https://trac.sagemath.org/ticket/30982

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAEcArF1ZXTbzQb2_scKfO9QyAHh_oXR-QBmXUDL9%2BqG-4__3yA%40mail.gmail.com.


Re: [sage-support] Re: factorial

2020-11-30 Thread Dima Pasechnik
On Mon, Nov 30, 2020 at 9:16 AM Vincent Delecroix
<20100.delecr...@gmail.com> wrote:
>
> Le 30/11/2020 à 00:48, slelievre a écrit :
> > 2020-11-29 21:23:36 UTC, Guillermo:
> >>
> >> I wonder what would be wrong with replacing '!' → '.factorial()'
> >
> > Interesting idea. Just be careful with `!=` of course.
> >
>
> Indeed the expression "3!=3" is ambiguous... Of course one can choose
> a priority (3!)=(3) or (3)!=(3) but that would be much more error
> prone than using .factorial() from the start.

I think .factorial() will do. Perhaps this can be combined with
looking for deprecation issues vs factorial() and Python 3.9.

>From python 3.9 docs:

Currently math.factorial() accepts float instances with non-negative
integer values (like 5.0).
It raises a ValueError for non-integral and negative floats. It is now
deprecated.
In future Python versions it will raise a TypeError for all floats.
(Contributed by Serhiy Storchaka in bpo-37315.)
https://bugs.python.org/issue37315

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CAAWYfq0VpFoR4%2B4FNSKwM21rHtTqqcxCz%3DUtT%3D-2m39dE6virw%40mail.gmail.com.


Re: [sage-support] Re: factorial

2020-11-30 Thread Vincent Delecroix

Le 30/11/2020 à 00:48, slelievre a écrit :

2020-11-29 21:23:36 UTC, Guillermo:


I wonder what would be wrong with replacing '!' → '.factorial()'


Interesting idea. Just be careful with `!=` of course.



Indeed the expression "3!=3" is ambiguous... Of course one can choose
a priority (3!)=(3) or (3)!=(3) but that would be much more error
prone than using .factorial() from the start.

--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/aa010f4a-da9b-a2f2-26b2-83d06c56e693%40gmail.com.


Re: [sage-support] Re: factorial

2020-11-30 Thread Nils Bruin

On Sunday, November 29, 2020 at 1:23:36 PM UTC-8 list...@gmail.com wrote:

>
> I agree with you, but at the same time I wonder what would be wrong with 
> replacing
> '!' → '.factorial()'
>
> Good observation: python already has postfix operators! I still don't like 
factorial notation; not even in math writing because it clashes with the 
custom of punctuation on math expressions that are part of a sentence, but 
technically that should cover most (all?) cases. 

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/b0bdd33b-65c4-43c2-89fd-bdfc302e4b51n%40googlegroups.com.


Re: [sage-support] Re: factorial

2020-11-29 Thread slelievre
2020-11-29 21:23:36 UTC, Guillermo:
>
> I wonder what would be wrong with replacing '!' → '.factorial()'

Interesting idea. Just be careful with `!=` of course.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/7b1ec8ed-22c0-442d-be9c-332efb5c3022n%40googlegroups.com.


Re: [sage-support] Re: factorial

2020-11-29 Thread G. M.-S.
Hi Nils.

I agree with you, but at the same time I wonder what would be wrong with
replacing
'!' → '.factorial()'

Best regards,

Guillermo

On Sun, 29 Nov 2020 at 22:02, Nils Bruin  wrote:

> With the current regexp-based rewriting we'd need a pattern of the kind
> '!' -> 'factorial( are doing an operator substitution already '^' -> '**" but that's very
> basic and doesn't need any context. To change an implicit unary postfix
> operator to an explicitly parenthesized prefix operator need almost
> complete parsing. Had the factorial been explicitly parenthesized as well,
> it would be a little easier, since now you could do it with parenthesis
> counting -- still not regex territory, but possibly reasonably efficiently
> done if one concentrates on the case where the expected string before the !
> is short.
>
> Insisting on parens does not satisfy the people who'd request this, I
> imagine. Writing (5)! instead of 5! doesn't really do the trick.
>
> I consider this weird postfix notation as a peculiarity that works
> somewhat OK in written math but, just as implicit multiplication, as bad in
> CAS use. So I'm not in favour of it. I estimate that the number of
> arguments against it is at least 3!
>
> On Sunday, November 29, 2020 at 5:32:30 AM UTC-8 Simon King wrote:
>
>> On 2020-11-29, Simon King  wrote:
>> > Hi Emmanuel,
>> >
>> > On 2020-10-28, Emmanuel Charpentier  wrote:
>> >> Nope. This syntactic sugar is provided by `Maxima`'s and
>> `Mathematica`'s
>> >> readers, but not by Sage preparser.
>> >
>> > Would it be nice (and easy) to have in Sage? What prevents the
>> preparser
>> > from understanding "!"?
>>
>> To be more precise: If I understand correctly, the preparser can be made
>> to accept any syntax, provided that this syntax is in no conflict with
>> valid Python syntax.
>>
>> There is a special meaning of "?" and "??" in Python, but I think there
>> isn't a special meaning to "!". Sage accepts "!" at the beginning of a
>> line, meaning that it executes a shell command, such as
>> sage: !ls
>> But it should be possible that the preparser could turn "(expression)!"
>> into
>> "gamma(expression+1)".
>>
>> Do people agree? Unfortunately I do not volonteer to implement it, I'
>> not familiar with the innards of the preparser.
>>
>> Best regards,
>> Simon
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "sage-support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to sage-support+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sage-support/0f70ad8a-bf21-4352-a863-0b8d596e509cn%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/CANnG18_HN6QkQWFEjVzmF20bH2veMwHFiadt9WHwK6bP%3DbaqoA%40mail.gmail.com.


[sage-support] Re: factorial

2020-11-29 Thread Simon King
Hi Nils,

fair enough. I didn't deeply think about it, my naive impression was
that what the preparser does to
  R. = QQ[]
is at least as complicated as dealing with the exclamation mark. But
I guess you're right: It isn't.

Best regards,
Simon

On 2020-11-29, Nils Bruin  wrote:
> With the current regexp-based rewriting we'd need a pattern of the kind 
> '!' -> 'factorial( are doing an operator substitution already '^' -> '**" but that's very 
> basic and doesn't need any context. To change an implicit unary postfix 
> operator to an explicitly parenthesized prefix operator need almost 
> complete parsing. Had the factorial been explicitly parenthesized as well, 
> it would be a little easier, since now you could do it with parenthesis 
> counting -- still not regex territory, but possibly reasonably efficiently 
> done if one concentrates on the case where the expected string before the ! 
> is short.
>
> Insisting on parens does not satisfy the people who'd request this, I 
> imagine. Writing (5)! instead of 5! doesn't really do the trick.
>
> I consider this weird postfix notation as a peculiarity that works somewhat 
> OK in written math but, just as implicit multiplication, as bad in CAS use. 
> So I'm not in favour of it. I estimate that the number of arguments against 
> it is at least 3!
>
> On Sunday, November 29, 2020 at 5:32:30 AM UTC-8 Simon King wrote:
>
>> On 2020-11-29, Simon King  wrote:
>> > Hi Emmanuel,
>> >
>> > On 2020-10-28, Emmanuel Charpentier  wrote:
>> >> Nope. This syntactic sugar is provided by `Maxima`'s and 
>> `Mathematica`'s 
>> >> readers, but not by Sage preparser.
>> >
>> > Would it be nice (and easy) to have in Sage? What prevents the preparser
>> > from understanding "!"?
>>
>> To be more precise: If I understand correctly, the preparser can be made
>> to accept any syntax, provided that this syntax is in no conflict with
>> valid Python syntax.
>>
>> There is a special meaning of "?" and "??" in Python, but I think there
>> isn't a special meaning to "!". Sage accepts "!" at the beginning of a
>> line, meaning that it executes a shell command, such as
>> sage: !ls
>> But it should be possible that the preparser could turn "(expression)!" 
>> into
>> "gamma(expression+1)".
>>
>> Do people agree? Unfortunately I do not volonteer to implement it, I'
>> not familiar with the innards of the preparser.
>>
>> Best regards,
>> Simon
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/rq12u7%244h1%241%40ciao.gmane.io.


[sage-support] Re: factorial

2020-11-29 Thread Nils Bruin
With the current regexp-based rewriting we'd need a pattern of the kind 
'!' -> 'factorial( '**" but that's very 
basic and doesn't need any context. To change an implicit unary postfix 
operator to an explicitly parenthesized prefix operator need almost 
complete parsing. Had the factorial been explicitly parenthesized as well, 
it would be a little easier, since now you could do it with parenthesis 
counting -- still not regex territory, but possibly reasonably efficiently 
done if one concentrates on the case where the expected string before the ! 
is short.

Insisting on parens does not satisfy the people who'd request this, I 
imagine. Writing (5)! instead of 5! doesn't really do the trick.

I consider this weird postfix notation as a peculiarity that works somewhat 
OK in written math but, just as implicit multiplication, as bad in CAS use. 
So I'm not in favour of it. I estimate that the number of arguments against 
it is at least 3!

On Sunday, November 29, 2020 at 5:32:30 AM UTC-8 Simon King wrote:

> On 2020-11-29, Simon King  wrote:
> > Hi Emmanuel,
> >
> > On 2020-10-28, Emmanuel Charpentier  wrote:
> >> Nope. This syntactic sugar is provided by `Maxima`'s and 
> `Mathematica`'s 
> >> readers, but not by Sage preparser.
> >
> > Would it be nice (and easy) to have in Sage? What prevents the preparser
> > from understanding "!"?
>
> To be more precise: If I understand correctly, the preparser can be made
> to accept any syntax, provided that this syntax is in no conflict with
> valid Python syntax.
>
> There is a special meaning of "?" and "??" in Python, but I think there
> isn't a special meaning to "!". Sage accepts "!" at the beginning of a
> line, meaning that it executes a shell command, such as
> sage: !ls
> But it should be possible that the preparser could turn "(expression)!" 
> into
> "gamma(expression+1)".
>
> Do people agree? Unfortunately I do not volonteer to implement it, I'
> not familiar with the innards of the preparser.
>
> Best regards,
> Simon
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/0f70ad8a-bf21-4352-a863-0b8d596e509cn%40googlegroups.com.


[sage-support] Re: factorial

2020-11-29 Thread Simon King
On 2020-11-29, Simon King  wrote:
> Hi Emmanuel,
>
> On 2020-10-28, Emmanuel Charpentier  wrote:
>> Nope. This syntactic sugar is provided by `Maxima`'s and `Mathematica`'s 
>> readers, but not by Sage preparser.
>
> Would it be nice (and easy) to have in Sage? What prevents the preparser
> from understanding "!"?

To be more precise: If I understand correctly, the preparser can be made
to accept any syntax, provided that this syntax is in no conflict with
valid Python syntax.

There is a special meaning of "?" and "??" in Python, but I think there
isn't a special meaning to "!". Sage accepts "!" at the beginning of a
line, meaning that it executes a shell command, such as
  sage: !ls
But it should be possible that the preparser could turn "(expression)!" into
"gamma(expression+1)".

Do people agree? Unfortunately I do not volonteer to implement it, I'
not familiar with the innards of the preparser.

Best regards,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/rq07t2%24o75%242%40ciao.gmane.io.


[sage-support] Re: factorial

2020-11-29 Thread Simon King
Hi Emmanuel,

On 2020-10-28, Emmanuel Charpentier  wrote:
> Nope. This syntactic sugar is provided by `Maxima`'s and `Mathematica`'s 
> readers, but not by Sage preparser.

Would it be nice (and easy) to have in Sage? What prevents the preparser
from understanding "!"?

Best regards,
Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/rq032t%24ev3%242%40ciao.gmane.io.


[sage-support] Re: factorial

2020-10-28 Thread Emmanuel Charpentier
Nope. This syntactic sugar is provided by `Maxima`'s and `Mathematica`'s 
readers, but not by Sage preparser.

BTW, I'd write `gamma(3/2)` rather than `factorial(/2)`...

Le mercredi 28 octobre 2020 à 09:56:24 UTC+1, HG a écrit :

> Hi,
>
> I would like to know if it is possible to use ! instead factorial like 
> in maths ?
>
> factorial(1/2) = (1/2)!
>
> Any help welcome
>
> Henri
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/85956640-3eb5-461d-b893-135bac38cc64n%40googlegroups.com.


[sage-support] Re: Factorial Carry Value in Python

2013-11-13 Thread Juan Grados
0<= u_i <= l-i


2013/11/13 Juan Grados 

> Let be s between 1 and l!-1 an integer value then s can expressed uniquely
> than:
>
> s = u1*(l-1)! + u2*(l-2)!+ ... ul*0
>
> Is there any function to find the values u1, u2, ..., ul in SAGE or python?
>
> --
> -
> MSc. Juan del Carmen Grados Vásquez
> Laboratório Nacional de Computação Científica
> Tel: +55 24 2233-6260
> (http://www.lncc.br/)
> http://juaninf.blogspot.com
> -
>



-- 
-
MSc. Juan del Carmen Grados Vásquez
Laboratório Nacional de Computação Científica
Tel: +55 24 2233-6260
(http://www.lncc.br/)
http://juaninf.blogspot.com
-

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/groups/opt_out.