Hi
I was working on the other parts of the sympy code, to understand the much
part of it so that i can have ideas for this project that how we can reduce
new step_eval functions to implement step-by-step expressions. I have come
up with new ideas and different kind of implementations.
1. In sympy we have different kind of implementations for different kind of
functions. In integration we already have the list of the steps. For
example: If I evaluate
integrate(asin(x) *log(x), x), we get the integral_steps
PartsRule(u=log(x), dv=asin(x), v_step=PartsRule(u=asin(x), dv=1,
v_step=ConstantRule(constant=1, context=1, symbol=x), second_step=
URule(u_var=_u, u_func=-x**2 + 1,constant=1/2, substep=
ConstantTimesRule(constant=1/2, other=-1/sqrt(_u), substep
=ConstantTimesRule(constant=-1, other=1/sqrt(_u), substep=
PowerRule(base=_u, exp=-1/2, context=1/sqrt(_u), symbol=_u),
context=-1/sqrt(_u), symbol=_u), context=-1/sqrt(_u), symbol=x),
context=x/sqrt(-x**2 + 1), symbol=x), context=asin(x), symbol=x),
second_step=RewriteRule(rewritten=asin(x) + sqrt(-x**2 + 1)/x,
substep=AddRule(substeps=[PartsRule(u=asin(x), dv=1, v_step=
ConstantRule(constant=1, context=1, symbol=x), second_step=
URule(u_var=_u, u_func=-x**2 + 1, constant=1/2, substep=
ConstantTimesRule(constant=1/2, other=-1/sqrt(_u), substep
=ConstantTimesRule(constant=-1, other=1/sqrt(_u), substep=
PowerRule(base=_u, exp=-1/2, context=1/sqrt(_u), symbol=_u),
context=-1/sqrt(_u), symbol=_u), context=-1/sqrt(_u), symbol=x),
context=x/sqrt(-x**2 + 1), symbol=x), context=asin(x), symbol=x),
DontKnowRule(context=sqrt(-x**2 + 1)/x, symbol=x)],
context=asin(x) + sqrt(-x**2 + 1)/x, symbol=x),
context=(x*asin(x) + sqrt(-x**2 + 1))/x, symbol=x),
context=log(x)*asin(x), symbol=x)
For such a big parts like integral, we can just parse this output and
change this into a tree to get the whole hierarchy and then we can print
the steps which are taken to do this integral.
In Integrations, different algorithms have been used, we can use these
steps and it can be used to explain the algorithms to the users. Say if a
user want to know about risch algorithm , we can use these steps to explain
the algorithm by taking one example of any function.
2. For derivations, I had already implemented tree structures for having
step by step expressions, as you can see in the commits.
For the optimizations and addition of less functions, we can
````traceback```` for some functions and get the inputs and outputs of the
called function and put that in a tree like
def goto_child(self, infunc):
if len(infunc.args) == 0:
return infunc
temp = infunc
infunc = list(infunc.args)
for i in range(len(infunc)):
if isinstance(infunc[i], Derivative):
infunc[i] = diff(infunc[i].expr, infunc[i].args[-1],
evaluate=True, step=True)
else:
infunc[i] = self.goto_child(infunc[i])
at = tuple(infunc)
return temp.func(*at)
def tracefunc(frame, event, arg, indent=[0]):
if event == "call":
if frame.f_code.co_name == "_eval_derivative":
# make a parent with 'arg' and the send the child to the
next call
elif event == "return":
# store the resturn result and then go to next level of tree
return tracefunc
This implementation will be same for many functions which have the standard
call for doit() or for _eval_derivative(). Same can be done for the basic
classes.
According to me, if we use traceback, there is a need of step_derivation
function at the end of for some parent classes, because sympy code is very
vast and if in future some change happens, then we may have to change this
parser for traceback functions .
Conclusive thought which i have is, We can use traceback to form string of
steps for every called functions (similar to shown in integration ) and
then we make parser for the main function( like Integrate() ) and since for
every function we can get the input argument and output argument, we can
make a tree and then we output the results.
Benefits: Very Less addition of new functions, parser will be able to parse
for every function including both simple and complex. Easy Implementation.
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/6334e79b-0d97-4bed-92f9-61214bb88217%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.