A second question. Is the a way to do something like intersection([1 ;
2];[1.5 ; 5]) and union([1 ; 2];[1.5 ; 5]) where [a ; b]:={x |
a<=x<=b}?
Best regards.
Christophe
Luke a écrit :
Hello here is a first try fopr working with sets. This code has been
writing directly as I was thinking of what I neede. I think that it
could be better. I'll work on unions of intervals : ythis would be
simply a list of single intervals with additional methods so as to
simplify a union. For the moment, only the intersection has been made. I
hope that I didn't forget something.
Every kind of suggestion is welcome.
Christophe.
Christophe.
PS : sorry for my english because I speak it like a french cow... ;-)
How about using '[' for closed and ']' instead of 'o' and 'c'? I find
'[]' or '][' a bit more intuitive, as it took a bit time to figure out
that 'oo' means open-open interval, not infinity..
So: cc = '[]', oc = ']]', oo = '][' and co = '[['.
> Hello here is a first try fopr working with sets. This code has been
> writing directly as I was thinking of what I neede. I think that it
> could be better. I'll work on unions of intervals : ythis would be
> simply a list of single intervals with additional methods so as to
> simplify a union. For the moment, only the intersection has been made. I
> hope that I didn't forget something.
>
> Every kind of suggestion is welcome.
Some of the comments below are influenced by "PEP 8 -- Style Guide for
Python Code" - http://www.python.org/dev/peps/pep-0008/ :)
> #!/usr/bin/env python
> #coding=utf-8
>
>
> # Code writing by BAL Christophe
> # Mail : proj...@club.fr
>
> class Interval():
> def __init__(self, a, b, endpoints ='cc'):
> if endpoints not in ['cc', 'oc', 'co', 'oo']:
> raise Exception, 'Unkown endpoints of interval : "' + str(endpoints) + '"'
please use raise Exception (...)
...and note the grammar and typo.
>
> self.endpoints = endpoints
>
> if a>b:
Please use proper spacing here: a > b...
> self.min,self.max = b,a
...and here...
> self.endpoints_min, self.endpoints_max = endpoints[1], endpoints[0]
> else:
> self.min = a
> self.max = b
> self.endpoints_min = endpoints[0]
> self.endpoints_max = endpoints[1]
self.endpoints handling looks broken - they are not reversed here ^^
>
> def __str__(self):
> if self.min == self.max:
> if self.endpoints == 'cc':
> return '{' + str(self.min) + '}'
Should we use [ or { ??
> else:
> return 'Empty Set'
>
> if self.endpoints_min=='c':
..spacing..
> t = '['
> else:
> t =']'
>
> t+=str(self.min) + ';' + str(self.max)
...
> if self.endpoints_max=='c':
spacing
> t += ']'
> else:
> t +='['
>
> return t
>
> def intersection(self, otherInterval):
Please add docstring...
> # The intersection is empty.
> if self.min == self.max or otherInterval.min == otherInterval.max:
> return Interval(0, 0, 'oo')
>
> maxOfMins = max(self.min, otherInterval.min)
> minOfMaxs = min(self.max, otherInterval.max)
>
> if maxOfMins > minOfMaxs:
> return Interval(0, 0, 'oo')
>
> if self.min == self.max or otherInterval.min == otherInterval.max:
> return Interval(0, 0, 'oo')
>
> # The intersection could be a set with a single element.
> if minOfMaxs == maxOfMins:
> if self.max == minOfMaxs:
> if self.endpoints_max == 'o' or otherInterval.endpoints_min =='o':
> return Interval(0, 0, 'oo')
> else:
> return Interval(minOfMaxs, minOfMaxs)
>
> else:
> if self.endpoints_min == 'o' or otherInterval.endpoints_max =='o':
> return Interval(0, 0, 'oo')
> else:
> return Interval(minOfMaxs, minOfMaxs)
>
> # Wath is the endpoints of the intersection ?
> answerendpoints_min = 'c'
>
> if self.min == maxOfMins :
spacing...
> answerendpoints_min = self.endpoints_min
>
> if otherInterval.min == maxOfMins and answerendpoints_min == 'c':
> answerendpoints_min = otherInterval.endpoints_min
>
> answerendpoints_max = 'c'
>
> if self.max == minOfMaxs :
spacing..
> answerendpoints_max = self.endpoints_max
>
> if otherInterval.max == minOfMaxs and answerendpoints_max == 'c':
> answerendpoints_max = otherInterval.endpoints_max
>
> return Interval(maxOfMins, minOfMaxs, answerendpoints_min+answerendpoints_max)
spacing...
Also, I would prefer to have lower-case variables:
minOfMaxs vs min_of_max
Cheers,
Priit :)
Then I will do a more cleaner code so as to be add to sympy. As you can
see for the moment my code is a stande alone one, it is not a part of
sympy, it is just to test what I have to do.
Thanks a lot for your very good comments.
Christophe.
>
> Ühel kenal päeval, T, 2009-07-07 kell 13:28, kirjutas Christophe:
>> Aaron S. Meurer a écrit :
>>>
>>> Interval(3, 4, endpoints='oc'), which would create (3, 4] ('oc'
>>> stands
>>> for open-closed).
>
> How about using '[' for closed and ']' instead of 'o' and 'c'? I find
> '[]' or '][' a bit more intuitive, as it took a bit time to figure out
> that 'oo' means open-open interval, not infinity..
> So: cc = '[]', oc = ']]', oo = '][' and co = '[['.
You're probably right. According to http://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals
, there is a different notation based on whether you are in America or
in Europe. I think we can allow multiple different notations for the
arguments of the function. For example, also allow the use of a
bracket to denote open and a parenthesis to denote closed as is the
standard notation, so open-closed would be '(]', and so on.
As to printing, I think we need to decide. I have never seen
the ]3,4] notation, but I guess that is used. What do you think? I
guess we can include to option to have both, but we still need a
default option.
>
>
>> Hello here is a first try fopr working with sets. This code has been
>> writing directly as I was thinking of what I neede. I think that it
>> could be better. I'll work on unions of intervals : ythis would be
>> simply a list of single intervals with additional methods so as to
>> simplify a union. For the moment, only the intersection has been
>> made. I
>> hope that I didn't forget something.
>>
>> Every kind of suggestion is welcome.
>
> Some of the comments below are influenced by "PEP 8 -- Style Guide for
> Python Code" - http://www.python.org/dev/peps/pep-0008/ :)
>
>> #!/usr/bin/env python
>> #coding=utf-8
>>
>>
>> # Code writing by BAL Christophe
>> # Mail : proj...@club.fr
>>
>> class Interval():
>> def __init__(self, a, b, endpoints ='cc'):
>> if endpoints not in ['cc', 'oc', 'co', 'oo']:
>> raise Exception, 'Unkown endpoints of interval : "' +
>> str(endpoints) + '"'
> please use raise Exception (...)
> ...and note the grammar and typo.
Actually, this should be TypeError, not Exception. Also, the typo he
is referring to is the misspelling of "Unknown".
>>
>> self.endpoints = endpoints
>>
>> if a>b:
> Please use proper spacing here: a > b...
>> self.min,self.max = b,a
> ...and here...
>> self.endpoints_min, self.endpoints_max = endpoints[1],
>> endpoints[0]
>> else:
>> self.min = a
>> self.max = b
>> self.endpoints_min = endpoints[0]
>> self.endpoints_max = endpoints[1]
> self.endpoints handling looks broken - they are not reversed here ^^
>>
>> def __str__(self):
>> if self.min == self.max:
>> if self.endpoints == 'cc':
>> return '{' + str(self.min) + '}'
> Should we use [ or { ??
I am unfamiliar with the European notation, as I mentioned above, but
usually '{' is reserved for finite sets, like {1, 2, 3}, or set
builder notation, like {x | 1 < x < 2}.
Please change to: # What are the endpoints of the intersection?
>> answerendpoints_min = 'c'
>>
>> if self.min == maxOfMins :
> spacing...
>> answerendpoints_min = self.endpoints_min
>>
>> if otherInterval.min == maxOfMins and answerendpoints_min ==
>> 'c':
>> answerendpoints_min = otherInterval.endpoints_min
>>
>> answerendpoints_max = 'c'
>>
>> if self.max == minOfMaxs :
> spacing..
>> answerendpoints_max = self.endpoints_max
>>
>> if otherInterval.max == minOfMaxs and answerendpoints_max ==
>> 'c':
>> answerendpoints_max = otherInterval.endpoints_max
>>
>> return Interval(maxOfMins, minOfMaxs, answerendpoints_min
>> +answerendpoints_max)
> spacing...
>
> Also, I would prefer to have lower-case variables:
> minOfMaxs vs min_of_max
Yes, this is the standard naming in Python.
Aaron Meurer
>
> Cheers,
> Priit :)
>>> class Interval():
>>> def __init__(self, a, b, endpoints ='cc'):
>>> if endpoints not in ['cc', 'oc', 'co', 'oo']:
>>> raise Exception, 'Unkown endpoints of interval : "' +
>>> str(endpoints) + '"'
>>>
>>
>> please use raise Exception (...)
>> ...and note the grammar and typo.
>>
> Actually, this should be TypeError, not Exception. Also, the typo he
> is referring to is the misspelling of "Unknown".
>
Sorry for my english but I try to do my best. Ok for changing of the
error that must be raised.
>>> def __str__(self):
>>> if self.min == self.max:
>>> if self.endpoints == 'cc':
>>> return '{' + str(self.min) + '}'
>>>
>> Should we use [ or { ??
>>
> I am unfamiliar with the European notation, as I mentioned above, but
> usually '{' is reserved for finite sets, like {1, 2, 3}, or set
> builder notation, like {x | 1 < x < 2}.
>
Here we have an interval like [3,3] which is equal to {3}. No ?
Is sympy is able to work with inequalities like 3<oo ?
>
> Aaron S. Meurer a écrit :
>> You're probably right. According to http://en.wikipedia.org/wiki/Interval_(mathematics)#Notations_for_intervals
>> , there is a different notation based on whether you are in America
>> or
>> in Europe. I think we can allow multiple different notations for the
>> arguments of the function. For example, also allow the use of a
>> bracket to denote open and a parenthesis to denote closed as is the
>> standard notation, so open-closed would be '(]', and so on.
>>
>> As to printing, I think we need to decide. I have never seen
>> the ]3,4] notation, but I guess that is used. What do you think? I
>> guess we can include to option to have both, but we still need a
>> default option.
>>
> ]3;4] is the french standard notation of (3,4]. I could add an
> optional
> argument lang. The choice lang='fr' will write ]3;4] and other value
> of
> lang will write (3,4].
According to the Wikipedia article, that notation is based on ISO
31-11 and is used in Europe and South America. I think maybe the
argument should be notation="American" for (3,4], and
notation="European" for ]3, 4], with "American" as the default.
>
>>>> class Interval():
>>>> def __init__(self, a, b, endpoints ='cc'):
>>>> if endpoints not in ['cc', 'oc', 'co', 'oo']:
>>>> raise Exception, 'Unkown endpoints of interval : "' +
>>>> str(endpoints) + '"'
>>>>
>>>
>>> please use raise Exception (...)
>>> ...and note the grammar and typo.
>>>
>> Actually, this should be TypeError, not Exception. Also, the typo he
>> is referring to is the misspelling of "Unknown".
>>
> Sorry for my english but I try to do my best. Ok for changing of the
> error that must be raised.
>
>
>>>> def __str__(self):
>>>> if self.min == self.max:
>>>> if self.endpoints == 'cc':
>>>> return '{' + str(self.min) + '}'
>>>>
>>> Should we use [ or { ??
>>>
>> I am unfamiliar with the European notation, as I mentioned above, but
>> usually '{' is reserved for finite sets, like {1, 2, 3}, or set
>> builder notation, like {x | 1 < x < 2}.
>>
> Here we have an interval like [3,3] which is equal to {3}. No ?
I see. Yes, you are correct, in that case, maybe it should return
set(3). Or maybe SymPy should have a special Set class with its own
printer that uses "{". The same for something like (3,3) or [4, 3],
which should return the empty set.
>
> Is sympy is able to work with inequalities like 3<oo ?
It looks like it:
>>> 3 < oo
True
Aaron Meurer
To confuse the matter further: there is also Czech notation: (3,4> :)
r.
Christophe
Not sure. IMHO it's just a such cosmetic issue - I wonder what Chinese
use, and am pretty happy with both [] and (] systems so do not bother much.
cheers,
r.
Chrisotphe.
Any suggestion is welcome.
Christophe
Well, we are still working on it, but look for example into
sympy/core/basic.py, then run:
$ bin/coverage_doctest.py sympy/core/basic.py
----------------------------------------------------------------------
sympy/core/basic.py
Missing documentation:
* is_hypergeometric(self, k)
* is_polynomial(self, *syms)
* search(expr)
* search(expr)
* conjugate(self)
* removeO(self)
* getO(e)
* as_powers_dict(self)
* as_base_exp(self)
* as_coeff_terms(self, x=None)
* as_coeff_factors(self, x=None)
* as_numer_denom(self)
* normal(self)
* diff(self, *symbols, **assumptions)
* fdiff(self, *indices)
* integrate(self, *args, **kwargs)
* pattern_match(pattern, expr, repl_dict)
* as_numer_denom(self)
* count_ops(self, symbolic=True)
* doit(self, **hints)
* is_number(self)
* cls_new(cls)
* cls_getnewargs(self)
Missing doctests:
* solve4linearsymbol(eqn, rhs, symbols = None)
* expand(self, deep=True, power_base=True, power_exp=True, mul=True,
\ log=True, multinomial=True, basic=True, **hints)
* series(self, x, point=0, n=6, dir="+")
* lseries(self, x, x0)
* nseries(self, x, x0, n)
* limit(self, x, xlim, direction='+')
* as_coeff_exponent(self, x)
SCORE sympy/core/basic.py: 50% (30 of 60)
----------------------------------------------------------------------
And ignore all the methods that the coverage script reported. Then
look at the other methods (the other 50%), they should have a
reasonable docstring.
>
> Any suggestion is welcome.
Try to use git --- just create a new branch and publish it on github.
Then it's easy for other people to try it and send patches to you with
improvements. Think about this from my perspective --- I don't mind
spending 2 minutes sending you a patch with some docstring, or fixing
some stuff, but it has to be easy for me to contribute -- with git, I
just do git pull, hack on it for 2 minutes, commit and send a patch.
If you send the files in the email, I would have to download them by
hand, put them somewhere, put them to git, create a patch etc.
If you need help with git, I am on IRC (#sympy at freenode) to help out.
Ondrej
Yes, just use this:
http://code.google.com/p/msysgit
Ondrej
Christophe.
I don't understand what you mean by "propose". To create a new
package, just use "git init", to clone a package, use "git clone".
Ondrej
Is the idea to use GIT and then to give the link to my GIT location ?
Best regards.
Christophe.
Yes, exactly. You can follow some video tutorials that I created:
http://code.google.com/p/sympy/wiki/GitTutorials
and follow the links at the bottom of the page for more documentation.
Ondrej
Thanks for the informations and the video.
Christophe.
Awesome. If you have any questions, definitely let me know, I'll try
to improve the videos, so that it can get new people up and going
quickly.
Ondrej
Chrisophe.