28
$\begingroup$

As some of you might know, I'm working with Albert Rich to improve the accessibility of his Rubi package for rule-based integration. I'm almost done with a first version that contains several improvements, but for the current task, I'd like to ask for input from the community.

One major strength of Rubi is that it can provide all steps and intermediate results of an integration. This, however, was a bit broken since the intermediate output was not overwritten when you evaluate an integration again. I reworked this completely and now the big question is how to format rules and intermediate results in the most stunning way.

A "step" can either be a RubiRule or a RubiIntermediateResult and I get them as

RubiRule[conditionString,
         HoldComplete[leftHandSide],
         HoldComplete[rightHandSide],
         ruleNumber]

RubiIntermediateResult[HoldComplete[expression]]

The conditionString and the ruleNumber is not always there, but often we have this information.

Question: Who can come up with the most stunning display of these two types of expressions? Go crazy with Style, Panel, Grid, etc. but in the end, we need a nice looking output for both types.

I have prepared a small notebook that contains an example list of steps in the last portion of the Reap result. This notebook is not meant to be evaluated since you obviously don't have my development version of Rubi.m, but you can use the output that I provided to implement and test pretty-printing for RubiRule and RubiIntermediateResult.

Import["http://halirutan.github.io/Mathematica-SE-Tools/decode.m"]["https://i.sstatic.net/K0wqL.png"]

At the moment, it looks like this in Rubi

output

$\endgroup$
7
  • 1
    $\begingroup$ Looks like Rubi.m file is missing. $\endgroup$ Commented Jun 13, 2018 at 9:28
  • $\begingroup$ Is it possible to get the conditions as expressions, rather than strings? $\endgroup$
    – Lukas Lang
    Commented Jun 13, 2018 at 9:29
  • $\begingroup$ @AnjanKumar Yes, it is missing because this version currently only available on my machine. I wanted to give people a complete list of Rubi steps which you can just copy from the output that is also in the notebook. I'm making this clear again in the question. $\endgroup$
    – halirutan
    Commented Jun 13, 2018 at 9:31
  • $\begingroup$ @LukasLang At the moment not. The code which creates this string is from Albert and didn't want to throw everything overboard. So I re-used his complete code of extracting conditions, rules, and results and simply changed the code so that these expressions are not printed but returned. The condition string contains "If" and "let" which is created in deeply nested code that inspects the DownValues of the definitions for Rubi's Int function. I didn't dare to touch this for now. $\endgroup$
    – halirutan
    Commented Jun 13, 2018 at 9:35
  • 1
    $\begingroup$ @halirutan Ok, fair enough $\endgroup$
    – Lukas Lang
    Commented Jun 13, 2018 at 9:37

2 Answers 2

17
$\begingroup$

To give you an idea of what I had in mind, I created something that I don't hate completely. Working with Grid, Column is a pain when you want to align and size everything to your needs, but it does the job.

img

Intermediate results can be copied by clicking on them. Here is the code that was used as a basis for the above (I changed some small things later). The final list was wrapped in Column and I riffled some down-arrows in between.

Format[RubiIntermediateResult[HoldComplete[expr_]]] :=
 Tooltip[
  Button[
   Deploy@Panel[Row[
      {Style["Intermediate Result:", "Label", Gray],
       Style[HoldForm[expr], ColorData[99, 2]]
       }, Spacer[10]],
     FrameMargins -> 5
     ], CopyToClipboard[Defer[expr]], Appearance -> None], 
  "Click to copy as input"
  ]

Format[RubiRule[cond_, HoldComplete[lhs_], HoldComplete[rhs_], 
   rule_: "General"]] :=
 Deploy@Panel[
   Grid[{
     {
      Style["Rubi Rule:", "Label", Gray],
      Style[rule, "Label"]},
     {
      Style["Condition:", "Label", Gray],
      Style[If[cond === "", "None", cond], ColorData[99, 3]]
      },
     {
      Style["Transformation:", "Label", Gray],
      Row[{
        Style[TraditionalForm@HoldForm[lhs], ColorData[99, 1]],
        Style["\[DoubleLongRightArrow]", 14, ColorData[99, 1]],
        Style[TraditionalForm@HoldForm[rhs], ColorData[99, 1]]
        }, Spacer[10], Alignment -> Center
       ]
      }
     },
    Alignment -> {{Right, Left}, {Center, Center, Center}},
    Spacings -> {1, 1},
    Dividers -> {False, {2 -> LightGray, 3 -> LightGray}}
    ]
   ]

Update

Although no one posted a solution, I got feedback and was able to partially include it. I discussed things with Albert and we decided to a simple left/right scheme. I took the suggestion from Kuba to make the rules closable and show only the transformation rule initially. With the help of the answers here, I was able to make the layout render in the same font size as the rest! Thank you for that.

If you like, you can try it out yourself. People with Mathematica version 11.3 can install Rubi directly from GitHub

PacletInstall[
  "https://github.com/RuleBasedIntegration/Rubi/releases/download/4.16/Rubi-4.16.paclet"
];

$LoadShowSteps = True;
<< Rubi`
Steps@Int[((125 - x^3)^(1/3))^2, x]

Mathematica graphics

The suggestion of @b3m2a1 went into the display of the integration statistics which uses a BoxForm`ArrangeSummeryBox

Mathematica graphics

$\endgroup$
6
$\begingroup$

Unlike the official implements of Rubi`Steps, usually we care about the result only instead of rules, as we don't write rules for hand-writing formulae.

So I wrote a new RubiSteps`ShowIntSteps, which supports more for hand-writing formula generation. The code is a bit long so I provide it at github.

BUG issues are welcomed.

Implementation Details

RubiSteps`ShowIntSteps does not use the output from Rubi`Steps, but is implemented as a new function.

Rubi`Steps sets Rubi`Private`$ShowSteps = True and then use FixedPoint to evaluate step by step and Sow held results.

RubiSteps`ShowIntSteps uses two nested FixedPoints. The inner one evaluate and Sow everything except Rubi`Subst which stands for substituting operation. When the inner one find no replacing can be performed, the outer FixedPoint function is applied for doing substitutions.

Then ShowIntSteps uses a Reap to collect results. Note that substitutions in these results are not performed, so this information can be used for typesetting.

Finally it does trivial(but need 80% code) conversions for the result.

Advice for Rubi developer

I've noticed the usage of Defer and HoldComplete in Steps is just Inactive and HoldForm. The latter may be more canonical.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.