G
G
grenkin2018-09-17 09:33:08
User interface
grenkin, 2018-09-17 09:33:08

What is the easiest way to write an interface for mathematical calculations?

When developing programs for mathematical calculations, I came to the following problem. You need to set the input data for the program - numbers, elements of enumerated types, vectors, matrices, as well as functions that will be calculated several times within the main program. (In an ordinary configuration file, you can enter the values ​​of variables, but you cannot, say, enter an expression instead of a value that should be calculated.) I write computer programs in C ++.
What software tools can be used to solve this problem? There is an option to write Python or Lua (or possibly Octave) scripts that provide input and/or call a function in the main program, but I don't know if it's possible to pass a function to your C++ program in that case so that it quickly counted. Or I'm thinking of developing my own interpreter with a universal parser that can be useful for different data presentation formats (although there is Boost.Spirit).
Please tell me how best to automate the input of expressions, matrices and functions into your program.
If you need a more specific formulation of the problem - there is, say, a nonlinear differential equation of elliptic type -Δu + f(u) = g, where f, g are given functions. When solving such an equation, it is necessary to calculate the value of the function f several times, which must be fed to the input of my program.
One option is to write a program in any language that takes function arguments as parameters and outputs the function value to standard output - then pass the program path and arguments as configuration file parameters and call this program from the main program. But I want to have a more convenient and versatile interface at hand.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
lz961, 2018-09-17
@grenkin

It may be more expedient to describe the functions f and g in the same C++ in a separate file and rebuild the executable file each time for a specific task, for example, using the script
#/bin/bash
gcc -o $1 -lm -lstdc++ solver.o $1.cpp
./$1
where $1 -- script argument -- file name with the implementation of specific f and g without the extension
solver.o -- precompiled computational kernel

A
Armenian Radio, 2018-09-17
@gbg

I solved the same problem like this (and the equation is elliptic) - the formula was written into a Fortran program, then it was compiled and attached to the program as a shared library. No overhead.
If you are working with a GPU, the expediency and formula to calculate on the GPU

S
Sergey Tikhonov, 2018-09-17
@tumbler

Run a separate process each time to calculate one number - it will cost like a Crimean bridge.
The fastest descending methods: a program for the GPU, calculating a vector of values ​​from a matrix of input parameters, a library with the implementation of the desired function.
As for convenience, it obviously depends on the problem statement, because the universal calculator is a compiler. You can also look at code compilation at runtime (JIT), there are implementations for different languages.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question