top | item 46234734

Show HN: I made a spreadsheet where formulas also update backwards

252 points| fouronnes3 | 2 months ago |victorpoughon.github.io

Hello HN! I'm happy to release this project today. It's a bidirectional calculator (hence the name bidicalc).

I've been obsessed with the idea of making a spreadsheet where you can update both inputs and outputs, instead of regular spreadsheets where you can only update inputs.

Please let me know what you think! Especially if you find bugs or good example use cases.

116 comments

order
[+] pedrozieg|2 months ago|reply
The interesting thing here isn’t “spreadsheet, but backwards” so much as “spreadsheet as a constraint system”. Classic spreadsheets are basically DAGs: data flows one way and a lot of UX assumptions (and people’s intuition) rely on that. As soon as you allow arbitrary cells to be solved for, you’re in “which variables are free?” land, and most of the confusion in this thread is really about degrees of freedom, not about the math.

One way to make this less surprising might be to flip the default: treat all cells as fixed unless explicitly marked as solver variables, and give a lightweight visualization of “these are the cells that will move if you edit this one.” That keeps the power of a general constraint solver while preserving the mental model spreadsheet users already have, and it opens the door to more serious use cases (financial models, physics, scheduling) without feeling like spooky action at a distance.

[+] fouronnes3|2 months ago|reply
That's great feedback, thanks! I agree with you, but I don't want to flip the default because this is an experiment I made for fun, and the whole point is to lean in to the chaos a little bit. In a serious product the UX would definitely need a lot more work though.
[+] willrshansen|2 months ago|reply
The first example on the main page has a formula with two variables being updated from changing one value. The immediate question I have is if I change the output, where does the extra degree of freedom come from on the inputs? Does one stay locked in place? Unclear.

I am a huge fan of the concept though. It's been bugging me for years that my spreadsheet doesn't allow editing text fields after filtering and sorting them down to the subset I want. I have to go all the way back to the mess of unsorted input rows to actually edit them.

[+] rahimnathwani|2 months ago|reply

  Does one stay locked in place? Unclear.
If you set C1=A1+B1 then, when you set a value for C1, A1 and B1 are each half of that value, even if they started off unbalanced.
[+] ximm|2 months ago|reply
100% this. When I reached the end of that page I felt pranked because the obvious question was never answered. How are these cases resolved? Is it possible to fix some inputs and only update others? What if I sometimes want to change input A, and other times I want to update input B? All this should be explained as early as possible.
[+] areyousure|2 months ago|reply
I have wanted one general application of this idea in a spreadsheet. Specifically, I track some of my running, including speed (pace), distance, and time. Under different circumstances, I have exactly two of the three available and I want the third to be computed, but it varies which. I have found it fairly difficult to implement this kind of data entry in Google Spreadsheets and Excel, even know conceptually it's a very simple constraint "a*b=c" where I know some two variables.

As a more substantive comment: You may find the thesis "Propagation networks : a flexible and expressive substrate for computation" by Alexey Radul interesting. https://dspace.mit.edu/handle/1721.1/54635

[+] fainpul|2 months ago|reply
You could create a table with 3 columns: distance, time, pace. Set the display format for time and pace to "Duration".

Enter these formulas:

  distance = time / pace
  time = distance * pace
  pace = time / distance
Drag fill everything down. At this point you get reference errors, but once you enter any two values (thereby overwriting the formulas in those cells), you get your result.
[+] culi|2 months ago|reply
You just need two spreadsheet tabs. One for the "raw" input and one with a formula that either takes the input if it exists or falls back to the calculated version
[+] davexunit|2 months ago|reply
Came here to see if anyone mentioned propagators. That thesis is excellent. I second the recommendation.
[+] SoftTalker|2 months ago|reply
Can you enter an RSA key and have it produce two prime numbers?
[+] spiderice|2 months ago|reply
A random tool like this would be the most entertaining possible way for something like that to be unleashed on the world
[+] fainpul|2 months ago|reply
In Prolog you can write rules (similar to functions in other languages) so that they work "both ways". Let's say you have this rule that defines how pace ("runner's speed") relates to distance and time:

  :- use_module(library(clpr)).

  pace(Km, Minutes, Pace) :-
    { Minutes = Km * Pace }.

Even though the rule only specifies how Minutes are calculated, Prolog can now also calculate the other values.

You can query it, giving unknowns an uppercase `Name`, and it will give you the possible values for it:

  pace(5, 24.5, Pace)
  pace(40, Min, 5)
  pace(Km, 24.5, 5)
  pace(Km, Time, 5)
  
You can try it here: https://swish.swi-prolog.org/

So if you had a rule that defines RSA key calculation this way, you could enter a key and get all valid solutions for the primes. But of course complex calculations still take a long time. I assume it's similar to a brute force attack in that way (Prolog has clever strategies to explore the solution space though).

Disclaimer: I'm not an expert in Prolog or cryptography, so this might not be 100% accurate.

[+] rvba|2 months ago|reply
I always thought the government has it, perhaps in a form of a rainbow table
[+] yonatan8070|2 months ago|reply
Or enter a public key + some encrypted data to get the private key
[+] b-karl|2 months ago|reply
In Excel you have goal seek for this functionality. I believe it does some form of numerical solving of the equation system.

Good for every situation when you need to solve equations!

In the context of using spreadsheets I think about solving simple financial or maybe construction/mechanical design problems where you don’t want to solve it manually or program it and a spreadsheet is a quick and useful interface.

[+] graemep|2 months ago|reply
This is very different in practice, because it is pervasive rather than something you have to set up for particular cases.

If this was usual it would help a lot with people's tendency to hard code the correct answer rather than fix formulae. Just that aspect of it would be a huge improvement. People do this all the time with simple financial problem, for example.

A lot of what people use spreadsheets for is not all that simple. Again, especially with financial applications. People manage huge amounts of money using horribly complex models implemented in Excel.

[+] moron4hire|2 months ago|reply
It does not. It perturbates the variables and uses a hill-climbing algorithm.
[+] thomastay|2 months ago|reply
This is really cool! It's like Excel's goal seek but can also handle the case of arbitrary input cells. Goal seeek can only handle one input and one output cell.

But how do you handle the case where multiple variables can be changed? If multiple input cells is the key difference from Goal seek, i think some more rigor should be placed into the algorithm here

e.g. setting A1 + B1 and wanting the result to be 5. Currently it bumps both A1 and B1 equally. What's the thought process behind this?

[+] fragmede|2 months ago|reply
Yeah. The UI could have a lock icon to set, eg B1 should stay fixed and then only A1 would change.
[+] adonovan|2 months ago|reply
“Formulas that update backwards” is the main idea behind neural networks such as LLMs: the computation network produces a value, the error in this value is computed, and then the error quantity is pushed backward through the network; this relies on the differentiability of the function computed at each node in the network.
[+] big-chungus4|2 months ago|reply
"Formulas that update backwards" isn't really the main idea behind neural networks. It's an efficient way of computing gradients, but there are other ways. For example forward propagation would compute a jacobian-matrix product of input wrt output with an identity matrix. Backpropagation is similar to bidi-calc to the same extent as it is similar to many other algorithms which traverse some graph backward.

I think you should be able to use bidi-calc to train a neural net, altough I haven't tried. You'd define a neural net, and then change it's random output to what you want it to output. However as I understand it, it won't find a good solution. It might find a least squares solution to the last layer, then you'd want previous layer to output something that reduces error of the last layer, but bidi-calc will no longer consider last layer at all.

[+] uoaei|2 months ago|reply
All those words and you forget to provide people the breadcrumbs to learn more for themselves.

The term of interest is "backpropagation".

[+] jsax|2 months ago|reply
This is pretty cool.

This functionality is called ‘break back’ in a lot of enterprise modelling software. See [IBM TM1](https://www.ibm.com/docs/en/cognos-planning/10.2.1?topic=bre...) and [Anaplan](https://help.anaplan.com/breakback-1b7aa87d-aa13-49f6-8f7d-d...). They generally work in terms of scaling the inputs to match the new output though, which is a bit more basic than this approach.

[+] fouronnes3|2 months ago|reply
Interesting, thanks! I had never heard of this. Yes, bidicalc is much more advanced. You can update any value of an arbitrary dependency graph of cells.
[+] Animats|2 months ago|reply
Somebody did this back in the DOS era. The program was sometimes called "the crooked accountant's spreadsheet", because you could start with the outputs you wanted and get the input numbers adjusted to fit.

Anyone remember?

[+] kccqzy|2 months ago|reply
I think the concept is solid. I’ve only had a few minutes of playing with it, but I have the opinion is that from a UX perspective constants are more common than variables. So perhaps a cell containing a constant should not have a #, but a variable should.
[+] satvikpendem|2 months ago|reply
Ah, two way data binding. If you've used any frameworks before React (and a couple earlier ones with the same philosophy) you'll understand how it becomes a spaghetti mess over time.
[+] culi|2 months ago|reply
Not necessarily if you're following best practices. Modern angular is quite scalable and uses two way data binding
[+] remywang|2 months ago|reply
A bidirectional formula is also known as an integrity constraint in databases (plus some triggers for restoring the constraint upon updates)!
[+] penteract|2 months ago|reply
This is great.

Since you've asked about bugs, I tried pushing the limits and found the following:

    A1: 100          B1: =100-A1
    A2: =A1*(100-A1)
    A3: =A1*B1
A2 can be successfully set to anything reasonable (up to 2500)

However, setting A3 to exactly 100 doesn't work, even though setting it to 101 or 99 (or even 100.000001) does work.

Another limit:

    A1: 100          B1: 100
    A2: =A1+B1
    A3: =A1*B1
    A4: =abs(A2-100) + abs(A3-100)
Setting A4 to zero (or anything below 80) doesn't work. This doesn't improve if the constants in the A4 formula are moved a short distance away from 100.

In case you can't tell from that last example, I think being able to fix the intended values of multiple outputs simultaneously would be interesting. If you were to give more details about the solver's internals, I'd be keen to hear them.

[+] zkmon|2 months ago|reply
The idea is very interesting. As a default strategy you could preserve the ratio of inputs by scaling them to match the scaling of the output, instead of making them equal (for addition). Similarly, for multiplication, you could preserve the ratio of inputs as well, by scaling them by nth root of the scaling factor of the output.
[+] fouronnes3|2 months ago|reply
Currently the solver does not use the previous values of inputs at all when solving. But it could use it in some cases as a heuristic I guess, yes!
[+] d--b|2 months ago|reply
The examples are great and these bidirectional calculators are something that people would love to have in traditional spreadsheets.

So much so that Credit Suisse, which basically was running everything on heavily modded Excel, created a full language whose outputs were Excel spreadsheets capable of doing that. That thing called “paradise” was a total monstrosity but showed how much people wanted this.

That said, you really need a way to set which cells are fixed and which cells are allowed to move if you want to move past basic examples.

Most times you know what you want to do. like => if the user modifies that cell, find a solution for those specific ones.

If you can enter that info, then you have a lot more constrains for your solver and will avoid a lot of edge cases where everything goes to 0, and you can check that the calculation entered is indeed reversible or not, or if it could have multiple solutions, and so on.

[+] amelius|2 months ago|reply
> and these bidirectional calculators are something that people would love to have in traditional spreadsheets

People want them in general programming languages too. I can't count the number of times I had to implement the same function multiple times, but backwards in various ways.

[+] fouronnes3|2 months ago|reply
Constants are supported, use # as a prefix, e.g.; #50.

I'd like to add more constraints in the future like a domain constraint for variables.

[+] nico|2 months ago|reply
Could you build an inverse kinematics solver with this? (I recently watched a youtube video of someone iteratively working out the solutions for a robotic arm, by alternating modifying the inputs and the results)
[+] fouronnes3|2 months ago|reply
That's an interesting example I hadn't thought of. Probably? I'll need to try it. Thank you for the suggestion!

I think one issue will be that trig functions are kinda weird because they are non-injective. So they work but they are awkward (try solving cos(A1) = 0.5). Inverse kinematics is so well studied, you're probably better off using a dedicated algorithm.

[+] amelius|2 months ago|reply
Closed form solutions might be more efficient (in time, energy) and perhaps more numerically stable.
[+] rvba|2 months ago|reply
Spredsheet but no VLOOKUP?