There is no coercion from string and Integer to a common structure. That 
should be obvious, but we can also check it explicitly:

sage: cm = get_coercion_model()
sage: cm.explain('i', ZZ(0), operator.eq)
Left operand is not Sage element, will try _sage_.
Unknown result parent.

Hence the comparison is by memory position, which is essentially random 
(and very much platform-dependent).




On Tuesday, July 22, 2014 12:57:13 PM UTC-4, Clemens Heuberger wrote:
>
> Can anyone help me understanding the following behaviour: 
>
> A doctest (0 < 'I'; see below) passes when called directly and fails when 
> called 
> via a Makefile, reproduced under sage 6.3.beta6, 6.2, 5.10 (running Linux 
> Mint). 
>
> As pointed out in 
>         
> https://groups.google.com/d/topic/sage-support/KNSzU0JpZgQ/discussion , 
> comparison between str and Integer falls back to comparison between the 
> types. 
>
> Does that simply mean that cmp(str, sage.rings.integer.Integer) is random? 
>
> Is the behaviour reproducible on other systems? 
>
> This problem turned up when trying to find out why Volker Braun has 
> problems 
> with doctests in #16580 which I cannot reproduce. There, we need to 
> somehow sort 
> transitions in a finite state machine; the order itself does not really 
> matter, 
> but for doctests, it is important to always have the same order. 
>
>
> $ cat test-cmp.sage 
> """ 
> :: 
>     sage: a = 0 
>     sage: b = 'I' 
>     sage: type(a) 
>     <type 'sage.rings.integer.Integer'> 
>     sage: type(b) 
>     <type 'str'> 
>     sage: cmp(type(a), type(b)) 
>     -1 
>     sage: a < b 
>     True 
> """ 
> $ cat Makefile 
>
> doctest: 
>         sage -t test-cmp.sage 
>
> $ LANG=C make 
> sage -t test-cmp.sage 
> Running doctests with ID 2014-07-22-18-46-45-0e337b53. 
> Doctesting 1 file. 
> sage -t test-cmp.sage 
> ********************************************************************** 
> File "test-cmp.sage", line 9, in test-cmp 
> Failed example: 
>     cmp(type(a), type(b)) 
> Expected: 
>     -1 
> Got: 
>     1 
> ********************************************************************** 
> File "test-cmp.sage", line 11, in test-cmp 
> Failed example: 
>     a < b 
> Expected: 
>     True 
> Got: 
>     False 
> ********************************************************************** 
> 1 item had failures: 
>    2 of   7 in test-cmp 
>     [6 tests, 2 failures, 0.00 s] 
> ---------------------------------------------------------------------- 
> sage -t test-cmp.sage  # 2 doctests failed 
> ---------------------------------------------------------------------- 
> Total time for all tests: 0.0 seconds 
>     cpu time: 0.0 seconds 
>     cumulative wall time: 0.0 seconds 
> make: *** [doctest] Error 1 
>
> $ sage -t test-cmp.sage 
> Running doctests with ID 2014-07-22-18-47-10-577db6a3. 
> Doctesting 1 file. 
> sage -t test-cmp.sage 
>     [6 tests, 0.00 s] 
> ---------------------------------------------------------------------- 
> All tests passed! 
> ---------------------------------------------------------------------- 
> Total time for all tests: 0.0 seconds 
>     cpu time: 0.0 seconds 
>     cumulative wall time: 0.0 seconds 
>
>

-- 
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 http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to