Top
Best
New

Posted by fouronnes3 4 days ago

Show HN: I made a spreadsheet where formulas also update backwards(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.

248 points | 113 commentspage 2
penteract 1 day ago|
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.

kccqzy 3 days ago||
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.
thomastay 3 days ago||
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 3 days ago|
Yeah. The UI could have a lock icon to set, eg B1 should stay fixed and then only A1 would change.
tkzed49 3 days ago||
It supports this. If you type # before a number, like #5, it's made constant.
PaulHoule 3 days ago||
Wow! See the classic https://en.wikipedia.org/wiki/TK_Solver
RachelF 2 days ago|
and Borland's Eureka solver https://nagodede.github.io/eureka/
remywang 3 days ago||
A bidirectional formula is also known as an integrity constraint in databases (plus some triggers for restoring the constraint upon updates)!
zkmon 2 days ago||
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 days ago|
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 days ago||
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 days ago||
> 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 days ago||
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 days ago||
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 days ago||
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 days ago||
Closed form solutions might be more efficient (in time, energy) and perhaps more numerically stable.
hallole 2 days ago||
Phenomenal! This is a solid prototype, clean execution. I've had exactly this idea, too: I've already given the spreadsheet the relationships between these values, why can't it just work backwards when values change? That premise hides a ton of complexity, though, I'm sure. Lots of scary matrices.
fouronnes3 2 days ago|
Thanks! Yes I loved the ratio of apparent simplicity to underlying complexity of this project. I have filled around 120 pages of draft and notes just for the math of the solver :)
deckar01 2 days ago|
Sympy can (often) solve under constrained systems in terms of the free variables. The problem I run into is discrete constraints that make solving less closed form and more combinatorial search. When textbook amplifier formulas significantly diverge from physical reality I model the errors as linear correction factors and use gradient descent to correct it in a few experiments, but I’m curious if there is software that has solved this problem.
More comments...