e) works.
>
> Aaron Meurer
>
>
> On Mon, Nov 23, 2015 at 2:32 PM, Duane Nykamp > wrote:
> > I'm trying to create a subclass of Symbol that returns a subclass of
> > Function when called. The only reason is to customize the
> is_commutative
> >
I'm trying to create a subclass of Symbol that returns a subclass of
Function when called. The only reason is to customize the is_commutative
property so that an expression like P(A)/P(Eq(x,1)) will output with the
P(x=1) in the denominator rather than as P^-1(x=1), which might confuse my
stu
>
> >> That's definitely a bug. Subclassing any class without changing
> >> anything shouldn't break anything. There are unfortunately several
> >> instances of this issue (see
> >> https://github.com/sympy/sympy/issues/6751). Probably somewhere
OK, I'm pretty sure this is a bug. I don't have to change Add at all to
get this infinite recursion, just create any subclass
In [7]: Add(3,3,evaluate=False).evalf()
Out[7]: 6.00
In [8]: class Add2(Add):
...: pass
...:
In [9]: Add2(3,3,evaluate=False).evalf()
RuntimeErro
I created an AddUnsort class that doesn't change the order of its
argument. Now, I discovered I get an infinite recursion when I evalf.
But, I'm having trouble figuring out how to prevent this infinite recursion.
The still get the infinite recursion even with this stripped down class
that doe
this behavior and the source of what appears to be a bug.
Any ideas?
Duane Nykamp
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sympy+unsubs
Yes, it turned out to mess it up for my use case. It would just confuse
folks using my application if And(a>2, a<3) ended up always being true when
a is symbolic.
My solution was to make a derived class off And and add the methods
def __nonzero__(self):
raise TypeError("cannot dete
x27;t it have the same behavior as this form of the same condition?
In [12]: a>2 and a<3
[snip]
TypeError: cannot determine truth value of
a > 2
On Thursday, May 14, 2015 at 8:42:27 PM UTC-5, Duane Nykamp wrote:
>
> I don't think this is the desired behavior.
>
> In [3]:
I don't think this is the desired behavior.
In [3]: a=Symbol('a')
In [4]: bool(And(2>a, a>2))
Out[4]: True
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to sympy+unsu
else:
ncpart.append(factor)
On Tuesday, March 31, 2015 at 5:04:37 PM UTC-5, Duane Nykamp wrote:
>
> The sort key seems insufficient for sorting unevaluated expressions.
>
> In [37]: Add(x, Mul(x,x,x,evaluate=False), x, evaluate=False)
> Out[37]: x + x⋅x⋅x + x
>
> With a
The sort key seems insufficient for sorting unevaluated expressions.
In [37]: Add(x, Mul(x,x,x,evaluate=False), x, evaluate=False)
Out[37]: x + x⋅x⋅x + x
With a slight change, it works as expected:
In [38]: Add(x, Mul(x,y,x,evaluate=False), x, evaluate=False)
Out[38]: x⋅x⋅y + x + x
It seems tha
Comparisons that are undetermined depending on values of Symbols are not
supposed to return a truth value. E.q., the following works correctly:
In [2]: bool(Eq(x,5))
---
TypeError Traceback (
issue as the break is occurring far away
from the correct 5. Standard python rounding get it right:
In [4]: round(123.6)
Out[4]: 124.0
In [5]: round(-123.6)
Out[5]: -124.0
Duane
On Saturday, September 6, 2014 1:42:33 PM UTC-5, Duane Nykamp wrote:
>
> Thanks for fixing this!
>
p2, p3, p4)
def is_collinear(*points):
.
points = [Point(a) for a in points]
and, I'm not sure what to replace Point with in these cases.
Duane
On Saturday, December 6, 2014 4:17:15 PM UTC-6, Duane Nykamp wrote:
>
> The Point class, for numerous functions, such as .
The Point class, for numerous functions, such as .evalf, returns a hard
coded Point class. This means that for a derived class, these functions
end up returning the original Point class not the derived class. I assume
there must be a way to code it differently so these functions return the
de
ing A and B to be commutative=False.
>
> Aaron Meurer
>
> On Tue, Nov 18, 2014 at 5:00 PM, Duane Nykamp > wrote:
>
>> I just posted this bug on github:
>>
>> https://github.com/sympy/sympy/issues/8470
>>
>> Here's a horrible example that shows what c
I just posted this bug on github:
https://github.com/sympy/sympy/issues/8470
Here's a horrible example that shows what can happen
In [9]: latex(parse_expr("-B*A",evaluate=False))
Out[9]: 'A - B'
Fixing this problem is urgent for me. I have students entering answers like
this, and my website g
; and then
> foo.startswith("(") and foo.endswith(")") can be used with confidence.
>
> On Tuesday, November 18, 2014 11:43:02 AM UTC-6, Duane Nykamp wrote:
>>
>> In python, entering "1,2" or "(1,2)" gives a tuple, which is what happens
>
In python, entering "1,2" or "(1,2)" gives a tuple, which is what happens
for parse_expr. However, I am using sympy to parse student answers to
questions. Sometimes, I want the answer to be a list of answers. For
example if the solutions is x=1 or x=2, I write x = [[blank]] and I want
them t
;
> On Fri, Oct 24, 2014 at 7:55 AM, Duane Nykamp > wrote:
> > The following throws an error
> >
> > In [27]: f=Function('f')
> >
> > In [28]: parse_expr('af(t)', local_dict={'f': f },
> &
The following throws an error
In [27]: f=Function('f')
In [28]: parse_expr('af(t)', local_dict={'f': f },
transformations=(auto_symbol, auto_number, split_symbols,
implicit_multiplication))
---
TypeError
uldn't be slower than the
default, should it?
Thanks,
Duane
On Monday, October 20, 2014 5:48:47 AM UTC-5, Mateusz Paprocki wrote:
>
> Hi,
>
> On 19 October 2014 05:40, Duane Nykamp >
> wrote:
> > Here's my solution for a customized sort key. Does this seem
&g
Given changes with booleans as discussed in
https://groups.google.com/forum/#!topic/sympy/82ls0doW6Nk, I'm trying to
develop a new approach to testing the number of True's in Tuple.
With earlier versions of sympy, if
thelist=Tuple(False, True, False)
the following worked
sum(thelist)==1
mpify(item)
except:
pass
else:
if x.is_real:
return ((1, 0, 'Number'), (0, ()), (), x)
return default_sort_key(item,order)
On Saturday, October 18, 2014 8:52:50 PM UTC-5, Duane Nykamp wrote:
>
> I was using sympy's default_sort_ord
I was using sympy's default_sort_order to sort objects. However, I
realized that it does not sort numerical quantities in order:
In [15]: sorted([-1, -1-sqrt(2),1+sqrt(2), pi, 4], key=default_sort_key)
Out[15]: [-1, 4, pi, 1 + sqrt(2), -sqrt(2) - 1]
The default sort key, lex, works in this case
Regards
> Sudhanshu Mishra
>
> On Sun, Oct 19, 2014 at 5:36 AM, Duane Nykamp > wrote:
>
>> Is this intentional behavior?
>>
>>
>> In [1]: from sympy import Tuple
>>
>> In [2]: sum(
Is this intentional behavior?
In [1]: from sympy import Tuple
In [2]: sum( (True, False, False))
Out[2]: 1
In [3]: sum(Tuple(True, False, False))
---
TypeError Traceback (most recent call las
another file in the same module
in one case but not the other. I don't get it. But, hey, if this is fixed
in the git version, all is well!
Duane
On Tuesday, October 7, 2014 4:47:22 PM UTC-5, Duane Nykamp wrote:
>
> I am mystified as to why a minus sign changes bottom_up behavior when
I am mystified as to why a minus sign changes bottom_up behavior when
applying evalf.
(I have modified bottom_up only by getting rid of the condition "if args !=
rv.args:" as otherwise it won't evalf integers. See below)
With the function
def initial_evalf(w):
try:
r
and
> alias it to log (and also change the printers to print "log"). This
> way is probably simpler, though, as you only have to override the one
> evalf method rather than several printer methods.
>
> Aaron Meurer
>
> On Sat, Sep 6, 2014 at 3:09 PM, Duane N
:12 PM UTC-5, Aaron Meurer wrote:
>
> SymPy automatically defines evaluation based on mpmath function names.
> I think you can get around it by defining an empty _eval_evalf(self,
> prec) function.
>
> Aaron Meurer
>
> On Sat, Sep 6, 2014 at 1:50 PM, Duane Nykamp > wr
I really like the evaluate=False flag on parse_expr. But, since log(0.1)
automatically evaluates to a float, I'm trying to create an unevaluated
version of log. However, I'm getting strange results where log is
implicitly defined.
As shown below, once I define a function log that does nothi
Thanks for fixing this!
On Wednesday, September 3, 2014 8:32:34 PM UTC-5, Chris Smith wrote:
>
> It should work now in the most recent build. Thanks for reporting the
> issue.
>
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this
Is this the intended result of rounding to one decimal place? Sympy needs
to go back to school on rounding. :)
In [13]: S(0.06).round(1)
Out[13]: 0.e-1
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving
I really like how unevaluated operators are working. However, one
confusing aspect is that, on display, the operands are reordered to some
standard order, but on comparison, the operator order matters.
n [3]: Add(3,2,evaluate=False)
Out[3]: 2 + 3
In [4]: Add(2,3,evaluate=False)
Out[4]: 2 + 3
I'd like to "fix" bottom_up so that the command
bottom_up(sympify("2.0*x"), lambda w: w if not w.is_Number else
Integer(w.round()), atoms=True)
yields 2*x rather than 2.0*x.
The problem is that for this case, the actual value is not changed so the
modification is thrown out by the check
; everywhere. There's no direct option
> > to do this from the API, but since the printing system is completely
> > extensible, and it's all open source, you can do what you want with
> > little work.
> >
> > Aaron Meurer
> >
> > On Sat, Oct 2
I'm writing a sympy expression to a javascript snippet in an html page that
is then interpreted by Geogebra to set parameters in an embedded applet.
I'm just using the string printer, as I'm not having sympy actually output
javascript code, just the mathematical expression like "3x**2+2."
Un
I'm using parse_expr to parse student input to online quizzes. Since I
want them to be able to type in an answer as "xe^x" for x*exp(x) I have
tried to do the following transformations.
transformations=standard_transformations+(convert_xor, split_symbols,
implicit_multiplication)
The result i
Is this intended behavior of evalf or N? It evaluates to the precision
specified, but future calculations involving the number return to the
previous precision.
In [56]: x=Float("1.234567")
In [57]: y=N(x,2)
In [58]: y
Out[58]: 1.2
In [59]: y*1.0
Out[59]: 1.234375
I was thinking it
Is this the desired behavior of parse_expr?
In [16]: parse_expr("2log(x)", transformations=(standard_transformations+
(implicit_multiplication,)))
Out[16]: 2⋅og⋅x
In [17]: parse_expr("2log(x)", transformations=(standard_transformations+
(implicit_multiplication_application,)))
Out[17]: 2⋅g⋅o⋅x
AM, Aaron Meurer
> > wrote:
>
>> The idea from https://code.google.com/p/sympy/issues/detail?id=3613
>> might also interest you. It's not simple to implement, but I think it
>> wouldn't be too hard.
>>
>> Aaron Meurer
>>
>> On Wed, Mar 13, 2013
If implicit_application is included as a transformation, then
_implicit_application checks the global_dict to see if a given token is a
function before applying its logic. Is there a reason that it uses
global_dict and not check first to see if a token is in local_dict? One
might put a functi
Thanks.
On Thursday, April 25, 2013 9:51:46 AM UTC-5, smichr wrote:
>
> OK, here's something else that might be useful:
>
> >>> Poly(x**3-x+Rational('1/4')).real_roots()
> [RootOf(4*x**3 - 4*x + 1, 0), RootOf(4*x**3 - 4*x + 1, 1), RootOf(4*x**3 -
> 4*x +
> 1, 2)]
> >>> [w.n() for w in _]
> [-1.1
Roots seems to work well finding real roots of polynomials with float
coefficients.
In [90]: roots(x**3-x+0.25, filter='R')
Out[90]: {-1.10715987168877: 1, 0.269594436405445: 1, 0.837565435283323: 1}
In [91]: roots(4*x**3-4*x+1., filter='R')
Out[91]: {-1.10715987168877: 1, 0.269594436405445: 1,
Yes, combining bottom_up with Float-via-string does exactly what I need.
Now, if a student types in the numbers as given in the solution, they will
get that the answer is correct. That will lead to less grief.
Thanks so much!
Duane
On Thursday, April 18, 2013 9:27:10 PM UTC-5, smichr wrote:
he first
> 0. So h - h2 to 4 digits of precision is not 0.
>
> If you really want something like "2 decimal points", you should take
> the difference and compare it against 1e-2
>
> In [297]: abs(h - h2) < 1e-2
> Out[297]: True
>
> Aaron Meurer
>
>
>
> A workaround would be to take out all Float instances, round them off
> and substitute them:
>
> your_expression.subs([(orig_float, orig_float.evalf(3))
> for orig_float in expr.atoms(Float)])
>
> On 18 April 2013 22:12, Duane Nyk
No, not at all. I guess I'm being unclear.
((5.333*x-1.234)*(2.251*x+5.234)).evalf(3)
returns
(2.25*x + 5.23)*(5.33*x - 1.23)
which evaluates the numerical coefficients to a precision of three digits.
So I was hoping that
exp(5.3533*x).evalf(3)
should return
exp(5.35*x)
which is the sam
On Thursday, April 18, 2013 1:19:11 PM UTC-5, Aaron Meurer wrote:
>
> On Thu, Apr 18, 2013 at 12:10 PM, Duane Nykamp
> >
> wrote:
> > Another suggestion is to expose .evalf() on the Tuple class. Right now,
> I
> > have to treat it as a special case.
Another suggestion is to expose .evalf() on the Tuple class. Right now, I
have to treat it as a special case. No big deal, but it would be
consistent if a Tuple had an .evalf() method.
if self._n_digits:
try:
if isinstance(expression,Tuple):
Thanks for the suggestions. Silly me, since I think of evalf as converting
to a float, I didn't think it would work for symbolic expressions. It
seems to work fine with polynomials, but it doesn't recurse into functions
like sin(x) and exp(x).
In [14]: expr=3.21513*sin(2352.23432*x)+(x-3.2598
First of all, thanks for sympy and the help on this forum. I've been using
sympy to create problems that automatically correct students answers. So
far, it has been working pretty well, and I've succeeded in making
questions such as these:
http://mathinsight.org/assess/sample_questions
I've
Great. That's good news.
On Monday, April 15, 2013 12:24:16 PM UTC-5, Tom Bachmann wrote:
>
> This is actually just about to being fixed :-).
>
> https://github.com/sympy/sympy/pull/1981
>
> On 15.04.2013 17:46, Duane Nykamp wrote:
> > The latex printer formats
The latex printer formats functions using "operatorname" even for functions
of a single character.
In [36]: f=Function('f')
In [37]: x=Symbol('x')
In [38]: latex(f(x))
Out[38]: '\\operatorname{f}{\\left (x \\right )}'
which causes the f to be displayed so that it isn't italics. At least in
t
I opened an issue at
http://code.google.com/p/sympy/issues/detail?id=3738
On Monday, April 8, 2013 5:40:30 PM UTC-5, Aaron Meurer wrote:
>
> Yeah, they are bugs. Can you open an issue in our issue tracker for them?
>
> Aaron Meurer
>
> On Mon, Apr 8, 2013 at 11:3
I think these are bugs in parse_expr. Sorry, my python expertise is
insufficient to determine what is going on.
In [80]:
transformations=standard_transformations+(convert_xor,implicit_multiplication_application)
In [81]: parse_expr("sin^2 (3x*E^(x))", transformations=transformations)
Out[81]:
If I enter
ex1=sympify("(x,y)")
then ex1 is a standard python tuple of sympy Symbols, which it gets from
parse_expr
However, if I apply sympify a second time to those results
ex2=sympify(sympify("(x,y)"))
then ex2 is a sympy Tuple, and I can do things like
ex2.subs(Symbol('x'),3)
It's easy enough
On Thursday, March 14, 2013 1:19:36 AM UTC-5, Aaron Meurer wrote:
>
>
> You can also mimic a whitelist by blacklisting everything you don't
> want. For example:
>
> all_names = {}
> good_names = {'cos': cos, ...}
> exec "from sympy import *" in all_names
> bad_names_set = set(all_names.keys(
Thanks,
Duane
On Tuesday, March 26, 2013 3:18:13 PM UTC-5, Mateusz Paprocki wrote:
>
> Hi,
>
> On 26 March 2013 21:00, Duane Nykamp >
> wrote:
> > I'd like to delay evaluation of functions like gcd so that I can have
> users
> > enter an expression like
I'd like to delay evaluation of functions like gcd so that I can have users
enter an expression like gcd(a,b), where a and b will be replaced by
numbers. If I just enter gcd(a,b), it finds the gcd of the polynomials a
and b, which is one. Based on earlier feedback I receive here and by trial
to
have folks enter. (I was quite confused for awhile as x < y didn't
evaluate right away but x==y did. But, eventually, I realized I could use
Eq(x,y), .)
Thanks,
Duane
On Tuesday, March 26, 2013 2:17:51 PM UTC-5, Aaron Meurer wrote:
>
> On Tue, Mar 26, 2013 at 9:42 AM, Duane N
I'm trying to understand how equality works with symbols. In particular,
this behavior confuses me:
In [70]: from sympy.abc import x
In [71]: bool(x != x)
Out[71]: False
In [72]: bool(Not(x==x))
Out[72]: False
In [73]: bool(Not(Eq(x,x)))
Out[73]: True
In [74]: bool(Eq(x,x))
Out[74]: True
Wh
>
> If you'd rather blacklist than whitelist, just manually convert any
> name that you don't want to be mapped to the sympy function in your
> locals dict, like
>
> parse_expr(expression, {'var': Symbol('var')})
>
> (this is also how you hav
This problem has vexed me for awhile, and I finally figured out the
problem. The subs command treats unicode differently than strings, so
unicode matching was giving strange results.
I've been using parse_expr to allow input from entries in a web page. To
allow folks to use strings like 'var'
11, 2013, at 10:58 PM, Duane Nykamp >
> wrote:
>
> Getting closer. With
>
> class UnevaluatedAdd(Expr):
> def _sympystr(self, printer):
> return "%s + %s" % (printer._print(self.args[0]),
> printer._print(self.args[1]))
>
> parse_expr("x+1&q
Aaron Meurer wrote:
>
> On Mon, Mar 11, 2013 at 9:38 PM, Duane Nykamp
> >
> wrote:
> > Thanks for your responses.
> >
> > I was pretty sure parse_expr was secure, given how it tokenizes before
> it
> > uses an eval.
> >
> > The Unevalu
Thanks for your responses.
I was pretty sure parse_expr was secure, given how it tokenizes before it
uses an eval.
The UnevaluatedLog example does exactly what I want for log. However, I
cannot figure out how to extend it to an Add or Mul that I get from a
parsed input. In many of the exam
I just discovered sympy. The parse_expr function is just what I needed to
allow folks to enter mathematics in a web page and have it be turned into
math. Thanks a lot!
I have a newbie question. How does one control the degree of
simplification so that sympy doesn't automatically convert the
69 matches
Mail list logo