-1

I'm looking for a library but I'm not sure what to search for because I'm not sure what to call the task I want to do (in such a way that it's searchable).

Example of functionality

I have a number of matrix equations involving a single operation (multiplication), with some common elements in them, for example:

result_1 = a * b * c * e
result_2 = b * c
result_3 = c * e * f

There are no unknowns here; we're just calculating the result_n items.

These multiplications are expensive to perform so I'm wanting a library that lets me set up the equations and the values of a, b, etc, then retrieve the result items.

Most crucially, I also need to then be able to say "I am updating values (for example) a and f", and have the library not do any unnecessary calcualtion; it would not bother recalculating result_2 (as the answer won't change), and it wouldn't not bother recalculating sub-terms b * c * e (in result_1) or c * e (in result_3) as these parts will be not different either.

Is there a good name for this kind of facility?

Ideally it would also be able to handle different operators (e.g. binary * and unary transpose) and you could specify properties of operators, e.g. "* does not commute, but is associative". Knowing these properties would allow the lib to sometimes do a more efficient job.

occulus
  • 16,959
  • 6
  • 53
  • 76
  • If you're looking for a word to search for, how about "spreadsheet". – Mr Lister Mar 18 '17 at 09:59
  • Your question was discussed on meta: [Off-topic requests for assistance](https://meta.stackoverflow.com/questions/345592/off-topic-requests-for-assistance) – user000001 Mar 18 '17 at 14:49
  • @MrLister I was looking for a lib - a library - not a spreadsheet. Something I could call from python, or Golang, etc – occulus Jan 16 '20 at 22:51

1 Answers1

1

Unless you were working with really big numbers, I would advise you to stick with the standard libraries. Multiplying numbers in C++ is probably as bare minimum as one could get besides using assembly code, even then i doubt you would see significant improvements.

I personally say you are fine, if you were using Python then YES I would definitely advise you to use Python's math library but since this is C++, you really don't need to worry about it.

Why do you need to optimize it if i may ask? Have you tried flagging your compiler with optimizations? Are the numbers you are working with big?

honk
  • 9,137
  • 11
  • 75
  • 83
Kevin Duarte
  • 424
  • 1
  • 4
  • 13
  • 1
    Thanks for your answer! You're right that in C++ it's probably not worth it in a lot of situations. However, I'm interested in both "is there a proper name for this?" and "is there a lib that does this sort of thing?" - it could feasibly be used in different languages by me – occulus Feb 25 '17 at 10:39
  • @occulus After rereading your response `These multiplications are expensive to perform so I'm wanting a library that lets me set up the equations and the values of a, b, etc, then retrieve the result items.` This actually sounds like operation overloading with a return of a vector. It would be a little tricky to set up though! – Kevin Duarte Feb 25 '17 at 20:16