> For example: We have an equation (2+3*(8/2)) and when I solve this
> equation in SageMath it gives the exact answer i.e 14. However, it's
> really interesting to imagine if Sage prints all the steps that how
> they solve the above equation to find its answer like first it print
> this (2+3*4) by solving inner bracket and then it print (2+12) by
> multiplying 3 and 4 and at least it prints the last answer i.e 14.
> This can be done by using BODMAS rule. If by some algorithm or
> logic Sage prints every step of BODMAS operation then Sage have the 
> capability to prints
> all the steps that how they solve the particular equation.

Hi Amritpal,

It sounds to me like you mean "computation of expressions" and not
"solving equations". The difference is that "solving an equation" is
e.g. finding x under the requirement that
  x^2 - 2*x + 1 = 0 ,
i.e. something that contains at least one unknown x. For solving the
above equation in x, one *could* write something like

  x^2 - 2*x + 1 = 0   <=>
  (x-1)^2 = 0 <=>
  x-1 = 0

but more likely, the backend system will just apply the closed formula
for solving a second-degree equation, which would give the somewhat less
enlightening derivation

  x^2 - 2*x + 1 = 0   =>
  x = -(-2)/(2*1) +- sqrt((-2)^2 - 4 * 1 * 1)/(2*1) <=>
  x = 1

In other words, there's two major problems with asking a system like
Sage to write out the derivation in solving an equation:

1) A derivation useful for a computer is often not the most readable or
useful for a human.

2) Most non-obvious computations will be done using complicated
algorithms - not even formulas - whose intermediate steps would not hold
much sense for a human to read.

If we restrict ourselves to "computation of expressions" like what
you're actually writing about, then you seem to basically suggest:

- writing out the BNF form of a computation tree, e.g. (2+3*8/2) could
be written

          +
        2     *
            3    /
                8 2

- The expression should now be computed by simplifying nodes which have
only leaves as children. In the above there is only one choice, namely
the "/".

- After each such simplification, print the new expression (flattening
  the updated BNF back to a string, with the necessary parentheses added).


Since Sage uses various backends for the actual computations, and
simplifies in many different locations, it won't be easy to modify Sage
itself to do this everywhere. I also don't think that would be a
particularly sensible option for Sage.

However, it could be achieved, I think, by working on the level of
strings:

sage: print_computation("2+3*8/2")
2+3*8/2
2+3*4
2+12
14

The print_computation function thus takes a *string*, and it has
complete control over when the computations should take place. The
print_computation function could be implemented by scanning over the
string, emulating (or using?) the Python parser, and constructing the
BNF expression tree. The print_computation would then itself carry out
the computation step-wise and printing every time, instead of hacking
into the rest of Sage.

Note that this should be extendable to also allow more complicated Sage
objects to be printed:

sage: M = matrix(ZZ, [ 1, 2, 3, 4])
sage: print_computation('(3 * M) * M')
     [1 2]      [1 2]
(3 * [3 4] ) *  [3 4]

[3  6] * [1 2]
[9 12]   [3 4]

[21 30]
[45 66]

(it could probably be typeset better, though)

However, I'm not convinced such a functionality is really super-cool and
important to have in Sage? As Ralf pointed out, at this level, you could
achieve it manually without too much trouble, so why should Sage offer
the functionality internally -- how often will it be used?

A related, and mathematically quite important feature, is that of
"certificates": that a function returns together with its output a
certificate, a kind of proof, that output is really correct. For
instance, say I call M.rank() on a matrix M. How do I know that the
output 5 is correct? It would be nice to have a proof that I could
check, possibly in a probabilistic way, and preferably much faster than
the rank computation itself, to be certain that 5 is indeed the rank of
M. Making fast algorithms that also output certificates is an active
area of research and would be a cool addition to Sage. (I wouldn't be
able to mentor such a project though: I don't know much about
certificates, and I will likely be mentoring another project).

Best,
Johan

-- 
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.

Reply via email to