Trying to simplify a valid code used in all rows of a long table

Hello. CL beginner here.

I’m replicating this graph on the calculator

for a Desmos activity to investigate the convergence of the integral of a tetration tending to an infinite power tower in the interval where it converges (between 0 and e^(1/e)). I’m doing this because in calculator, when I display the results in a table, they appear with fewer significant digits than in the cell where they were calculated. Googling, I discovered that in an activity I can create tables where non-integer numbers are displayed with the full precision used by the tool. So, I started this one:

And it really does :slight_smile:

The idea is to manually change the value of n in the first table and, when the values ​​are finally calculated, copy and paste the first 4 into the second table in the appropriate row, leaving the last 2 values ​​to be automatically calculated.

Eventually, I will try to automatically fill (with something that replaces the loop, because I already discovered that this concept was not implemented in CL) the initial cells of the second table of values ​​for several n with the result of “running” the graph for those n, but that is for the future.

For now, I have this code, valid for a specific row of the 20-row table:

I_1 = this.cellNumericValue(1,2)
I_2 = this.cellNumericValue(1,3)
I_3 = this.cellNumericValue(1,4)
I_4 = this.cellNumericValue(1,5)
I_5 = numericValue("${I_1}+${I_2}+${I_3}")
I_6 = numericValue("${I_5}+${I_4}")
cellContent(1,6): when isDefined(I_1) and isDefined(I_2) and isDefined(I_3) "${I_5}" otherwise ""
cellContent(1,7): when isDefined(I_5) and isDefined(I_4) "${I_6}" otherwise ""

Now I’m trying to write something smarter, perhaps leaner, and most importantly, valid for all 20 lines. After a lot of research, I’ve put together ideas that seem like they would work, but don’t:

sum = simpleFunction( "when isDefined(a) and isDefined(b) and isDefined(c) a+b+c otherwise ''", "a", "b", "c" )
cellContent(row,6): sum.evaluateAt( this.cellNumericValue(row,2), this.cellNumericValue(row,3), this.cellNumericValue(row,4) )
cellContent(row,7): sum.evaluateAt( this.cellNumericValue(row,6), this.cellNumericValue(row,5), 0 )

Even replacing row with a number (1, for example), it doesn’t work.
I saw here some old questions about the same problem: valid code for multiple rows in a table, but no really good solution, apparently.

Can I solve the problem without cramming a bunch of code over and over again?

Extra problem 1: I just resynchronized the activity graph with the calculator graph where I now calculate, using Newton’s method, the minimum of the “even” tetration (even number of iterated powers) and discovered that apparently the recursion that determines the x coordinate of the minimum cannot be executed by the activity, even though it shows a preview of the graph when I am editing it :face_with_diagonal_mouth:

Extra problem 2: the width of the component to accommodate the table across its entire width without scroll bars even when the screen is large enough is another “problem” that doesn’t seem to have a satisfactory solution :slightly_frowning_face:

Thank you in advance for any considerations.

Welcome! I’ve had the same problem.

You can do this. I’m not sure if this is EXACTLY what you want but it gives you the idea.

list = sum.map((e) => evaluateAt(this.cellNumericValue(row, e)) 
cellContent(row, 1): list[1] #etc.

to list out everything.

You still need to list out all the sinks, but it will save you a lot of typing.
Also, this is every function you can use with a list.

If you have experience in languages like Python you can think e like the control variable, and .map the loop, and list (sum) the iterable.

1 Like

Unfortunately, you cannot use variables to define the cellContent. Coordinates need to be explicitly named, as do arguments in some other sinks and sources (e.g. .isSelected()). You can simplify some code, as @NTMDev noted, by using lists.

Also note that conditionals can be done inside latex or strings, but they need to be contained in ${}, but you would not be able to use the variables as part of those conditions as you’re attempting in your sum function. Using the lists we can get around that though. Screen 1 I’ve provided one approach.

I’m not sure what is going on with the graph. I’m wondering if the recursive functions are too much computation and it’s (partially?) crashing it somehow. I found if I explicitly define n as 4 rather than the table cell value (before looking in the graph) it seems to display fine, but as soon as I update to anything else the graph malfunctions (i.e. even editing inside the graph is not showing a normal state). Maybe try rebuilding the graph? Something definitely isn’t functioning correctly. I even tried to make it a full Graphing Calculator component and it shows n=4, but the slider (and all the expression types) disappears.

There is not currently a way to expand the total width of the table to remove the scroll bars. Alternatives would be faking a table in a graph where you can control width and text size.

1 Like