Re: [sage-devel] bug in cos ?!

2017-09-17 Thread Bruno Le Floch
Thank you Thierry,
I had stupidly only looked at the doctests for cos in Sage 7.2.
Bruno

On 09/16/2017 06:16 PM, Thierry wrote:
> Hi,
> 
> this might be related to:
> 
> https://trac.sagemath.org/ticket/20752
> https://trac.sagemath.org/ticket/20742
> 
> (and it is doctested).
> 
> Ciao,
> Thierry
> 
> 
> 
> On Sat, Sep 16, 2017 at 03:17:27PM -0400, Bruno Le Floch wrote:
>> Hello,
>>
>> In fact, it seems that in Sage 7.2, cos((p/q)*pi) gets reduced mod pi
>> instead of 2pi, at least in cases where it does not simplify to square
>> roots:
>>
>> sage: [cos(pi*(i+13)/13) - cos(pi*i/13)
>>for i in range(0,50) if i%13!=0] == [0]*46
>> True
>>
>> It would be good to know what fixed that bug.  It might be a Ginac bug.
>> Perhaps cos(14*pi/9) should be added as a test of the cos function?
>>
>> Bruno
>>
>> On 09/16/2017 07:43 AM, John Cremona wrote:
>>> You should upgrade to a more recent version:
>>>
>>> ┌┐
>>> │ SageMath version 8.0, Release Date: 2017-07-21 │
>>> │ Type "notebook()" for the browser-based notebook interface.│
>>> │ Type "help()" for help.│
>>> └┘
>>> sage: float(cos(14*pi/9))
>>> 0.17364817766693041
>>>
>>>
>>>
>>> On 16 September 2017 at 12:27, Mickael Pechaud  
>>> wrote:
>>>>  Hello,
>>>>
>>>> I'm running SageMath 7.2, on a 64bits laptop with a Ubuntu 16.04.2 LTS
>>>> (xenial). I got a wrong answer from cos :
>>>>
>>>> sage: float(cos(14*pi/9))
>>>> -0.17364817766693041
>>>>
>>>> It should be positive - and it's inconsistent with the following lines :
>>>>
>>>> sage: float(cos(14*pi/9-2*pi))
>>>> 0.17364817766693041
>>>>
>>>>
>>>> sage: float(14*pi/9)
>>>> 4.886921905584122
>>>>
>>>> sage: float(cos(4.886921905584122))
>>>> 0.17364817766692953
>>>>
>>>> Am I missing something, or is there an actual problem here ?
>>>>
>>>> Thanks in advance,
>>>>
>>>> Mickaël
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google Groups
>>>> "sage-devel" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send an
>>>> email to sage-devel+unsubscr...@googlegroups.com.
>>>> To post to this group, send email to sage-devel@googlegroups.com.
>>>> Visit this group at https://groups.google.com/group/sage-devel.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "sage-devel" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to sage-devel+unsubscr...@googlegroups.com.
>> To post to this group, send email to sage-devel@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sage-devel.
>> For more options, visit https://groups.google.com/d/optout.
> 

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


Re: [sage-devel] bug in cos ?!

2017-09-16 Thread Bruno Le Floch
Hello,

In fact, it seems that in Sage 7.2, cos((p/q)*pi) gets reduced mod pi
instead of 2pi, at least in cases where it does not simplify to square
roots:

sage: [cos(pi*(i+13)/13) - cos(pi*i/13)
   for i in range(0,50) if i%13!=0] == [0]*46
True

It would be good to know what fixed that bug.  It might be a Ginac bug.
Perhaps cos(14*pi/9) should be added as a test of the cos function?

Bruno

On 09/16/2017 07:43 AM, John Cremona wrote:
> You should upgrade to a more recent version:
> 
> ┌┐
> │ SageMath version 8.0, Release Date: 2017-07-21 │
> │ Type "notebook()" for the browser-based notebook interface.│
> │ Type "help()" for help.│
> └┘
> sage: float(cos(14*pi/9))
> 0.17364817766693041
> 
> 
> 
> On 16 September 2017 at 12:27, Mickael Pechaud  
> wrote:
>>  Hello,
>>
>> I'm running SageMath 7.2, on a 64bits laptop with a Ubuntu 16.04.2 LTS
>> (xenial). I got a wrong answer from cos :
>>
>> sage: float(cos(14*pi/9))
>> -0.17364817766693041
>>
>> It should be positive - and it's inconsistent with the following lines :
>>
>> sage: float(cos(14*pi/9-2*pi))
>> 0.17364817766693041
>>
>>
>> sage: float(14*pi/9)
>> 4.886921905584122
>>
>> sage: float(cos(4.886921905584122))
>> 0.17364817766692953
>>
>> Am I missing something, or is there an actual problem here ?
>>
>> Thanks in advance,
>>
>> Mickaël
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "sage-devel" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to sage-devel+unsubscr...@googlegroups.com.
>> To post to this group, send email to sage-devel@googlegroups.com.
>> Visit this group at https://groups.google.com/group/sage-devel.
>> For more options, visit https://groups.google.com/d/optout.
> 

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


Re: [sage-devel] Re: LaTeX code to Sage expression?

2011-05-14 Thread Bruno Le Floch
> http://moralfiber.org/eylon/berkeley/cs282/

Thank you, this was an interesting read, which motivates me to revise
my current approach slightly. I think that I need to keep more
information in a first pass, in order to correctly handle subscripts
and superscripts. I still don't know how to place the closing
parenthesis at the right place in constructions such as \sin a \, bc.
A difficult problem, as you mention.

I think that the first two passes (expanding macros and removing
spurious left braces) should be done within TeX for more robustness:
it is not true that only \ and { and } matter. Perhaps some of the
other steps may be done in TeX as well, although having a dictionary
of symbols would not be too easy within TeX.

The study seems quite old (1997). Are you aware of more recent developpments?

Regards,
Bruno

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: LaTeX code to Sage expression?

2011-05-14 Thread Bruno Le Floch
@Mike: I couldn't find precise info about the cadabra TeX input, but I
found odd things: "x^{2x+1}" is interpreted as "x^{2+x+1}". I may be
misunderstanding something, though.

@Dan: I just had to add the rule ")(" => ")*(" that I had forgotten
yesterday, and here is what I get:

(((x-1)*(x**(4)*(1-y)-(x-1))+sqrt((x-1)*(x-1+x**(4)*(y-1))*(-x**(4)*(x-1)*(1-
y)-(3*x-1)*(x+1/(2*x**(2)*(x-1+x**(4)*(y-1

And it wasn't too difficult to add some code to keep track of which
variables appear in the expression, giving var("x,y"). I still need to
polish and comment the code, but it shouldn't take too long. Do you
have harder cases? What is the correct expression (if any) in Sage for
the following?

\sum_{1 < k < n} k
\sum_{\substack{1 < j < n \\ 1 < k < m}} j^k
\sum_{k=0}^{\infty} \frac{x^k}{k!}

> We might also talk with the jsmath/mathjax developer, Davide Cervone.
> IIRC, he already converts from latex to MathML, so there is some sort of
> tex processing that he is doing in javascript.  We've talked with him
> about a way to convert from latex/mathjax back to Sage code before.

For general TeX code, containing user-defined macros etc, the only way
I think is to use TeX to expand macros (my parser currently does that
when encountering an unknown control sequence). For code generated by
Sage, it is probably easier.

> For your application, I wonder if it would be easy to somehow encode
> annotations in the latex output, so that you could delimit
> subexpressions with the code that originally created them. If we output
> mathml instead of latex for mathjax, I suppose that encoding such
> annotations would be easier.  Especially if it was Content MathML
> instead of just Presentation MathML.

To be frank, I only know TeX inside out, so I would naturally choose
TeX, but the main question is whether jsmath/mathjax have some kind of
"reverse search" feature (going from the display to the LaTeX). Should
we contact David Cervone on this? --- I wasn't planning to look into
this so soon.

Regards,
Bruno

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: LaTeX code to Sage expression?

2011-05-13 Thread Bruno Le Floch
On 5/13/11, Jason Grout  wrote:
> On 5/12/11 11:38 PM, Dan Drake wrote:
>> If I have a Sage expression, I can do
>>
>> latex(foo)
>>
>> to get LaTeX code. Is there an inverse to that function?
>>
>> Frequently, I do a calculation in Sage and get something complicated. I
>> find it easier to look at when typeset by TeX, so I call latex(), paste
>> the result into a document, then typeset.
>>
>> Conversely, sometimes I write something in LaTeX and would like to do
>> some calculations with it. So I'd like to call...something, paste the
>> result into Sage, and compute.
>>
>> I'm generally working with reasonably simple symbolic expressions. Is
>> this possible? I know that a full parser is practically impossible, but
>> it seems like a relatively simple parser could work pretty well.
>>
>> I think I'm asking for a complement to Rob Beezer's tex2sws. Thoughts?
>
> If we had this, it would be a lot simpler to do a web-based equation editor.
>
> Jason

I don't think it exists yet, Dan. However, it should be feasible in
simple cases. I have a few ideas on how to do it using TeX (probably
not the fastest, but that's the language I know best). Can you please
post a couple of typical short-but-thorough examples of LaTeX
equations, and the desired output? Don't hesitate to go for "hard"
cases, such as matrices, or slightly "dirty" TeX code: anything you
may realistically wish to use in practice.

I'll try to give the possibility of using a config file to set some
defaults (e.g. maybe \Gamma often represents the Gamma function for
you, maybe \Gamma is a constant for someone else), and try to make it
possible to override them locally. My idea is to write a LaTeX package
which when loaded would convert math expressions to a Sage input,
stored in an external file.

I'm very keen on trying this, as it is related to a recent idea of
mine. Start from a Sage symbolic expression, and convert it using
latex(). Then given a subexpression in the LaTeX code, be able to go
back to the Sage subexpression. The goal would be in the long term to
provide reverse search from the jsmath/mathjax displayed equation back
to the Sage code. Then it may be possible to e.g. select a
subexpression and apply some transformations (i.e. .simplify(), or
.collect(...) to the subexpression rather than the whole expression).
But that's probably a longer term project.

Anyway, give me some examples, and one or two weeks, and I'll try to
produce a prototype.

Regards,
Bruno

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] How to target Mathematica on Google - I'll pay !!!

2011-02-26 Thread Bruno Le Floch
> 1) The most common search region is Greece
> 2) The most common search city is Cambridge, MA, USA.
> 3) The most common search language is Greek
>
> I must admit, the first and third surprise me a bit.

In greek, "mathematics" is "Μαθηματικά", i.e. "Mathematica". So that
result is in fact hardly surprising. I don't know how to avoid that
spurious result, though.

Regards,
-- 
Bruno

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: sage thoughts

2011-02-10 Thread Bruno Le Floch
>> Let me phrase it like this: There are different interpretations of the
>> term "consistent".

@Simon: You are right to distinguish the two kinds of consistencies.
And I can understand that sometimes it is preferable to have the
algebraic consistency. I tend to care about elements of the objects
more than the objects of the category (i.e. individual rational
numbers rather than the field/PID/quotient field QQ), and thus I tend
towards subring consistency.


> You could have both consistencies. That depends on how you define gcd
> and lcm:
>
> - Quotient fields as described by Bruno.
> - Fields:  zero if both elements are zero. A non-zero element
> otherwise (most fields would choose 1 here).
> - PID: a generator of the corresponding ideal.

I don't see how this brings in both consistencies. Algebraic
consistency requires gcd and lcm on QQ to have different outputs
depending on whether QQ is seen a Field, a PID, a Quotient Field... Is
there a clear way for the user to indicate "which QQ" he wants?

Or we could have (I don't really know how this is done ;-) )

lcm(10/21, 14/15, type="PID") = 1
lcm(10/21, 14/15, type="Field") = 1
lcm(10/21, 15/14, type="quotient-of-ZZ") = 30/7

I doubt that the "field" version is useful at all: the lcm is
basically always 1 (except when one of the arguments is zero). lcm and
gcd should only be defined for PIDs, where they are interesting (or
for factorization rings? I can't remember my undergrad).

> http://groups.google.com/group/sage-devel/browse_thread/thread/12524b18d2325633/7b8af907c3c45c8b?lnk=gst&q=gcd+and+lcm+for+field+elements#7b8af907c3c45c8b

Interesting read, thanks.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org


Re: [sage-devel] Re: sage thoughts

2011-02-10 Thread Bruno Le Floch
Hi all,

> So, a coercion from QQ to ZZ would presumably be a morphism from QQ to
> ZZ in the category of unital rings - which doesn't exist.

Agreed.

> So, I think it is by far better to have a consistent notion than to
> have to *guess* whether a user really means the integer 2 if s/he
> write 4/2 (which in the first place is a rational, not an integer).
> Bugs that are result of guesswork are the most ugly, IMHO.

True. But in the case of Q (and more generally in the case of the
quotient field of a (principal?) ring), we can be consistent with the
ring of integers, without any guess-work.

(*) This is a white lie (see below).
Every rational number has a unique(*) form Product(p^(a_p), p prime)
for some integer powers a_p. The rational is an integer iff all a_p
are non-negative. In that case,

gcd(Product(p^(a_p)), Product(p^(b_p))) = Product(p^(min(a_p,b_p)))

and lcm is defined with max(a_p,b_p). But actually this definition
does not rely at all on the fact that the a_p and b_p are positive. So
we have a definition of the gcd and lcm for free on the quotient field
of any (principal?) ring. Then, gcd(x,y).lcm(x,y)=x.y; the notion
reduces to the one for integers, etc. This definition amounts to the
definition of lcm(x,y) as the smallest integer multiple of x which is
also an integer multiple of y.

(*) In fact, there is the issue of the sign, or more generally units
(elements that are invertible in the ring (here, ZZ) ). For this,
there has to be some arbitrariness on the sign of gcd and lcm of
negative numbers.

Note that for RDF and its colleagues, this does not apply (since they
are not the quotient field of any sensible ring), and we should stick
with the definition gcd(x,y)=1, however much x and y look like
integers.

Regards,
Bruno

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org