lluisalemanypuig / sycalc

Small symbolic calculator implemented with SWI-Prolog. Performs basic arithmetic operations with multi-variate polynomials.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Sycalc

Sycalc is a small SYmbolic CALCulator implemented with SWI-Prolog. It provides a series of algorithms to perform basic arithmetic operations between multivariate polynomial expressions.

Not only it offers an interactive mode, but it can also be used to make larger programs. Any program can be compiled using the provided code by following the example in this Makefile.

The full documentation in html (generated using DYP) can be found here.

Here are a few basic examples:

  • Compute the product of several polynomials:

      ?- polynomial_expression_evaluation( n*(n - 1)*(n - 2)*(n - 3), R ).
      R = n^4 - 6*n^3 + 11*n^2 - 6*n.
    
  • Compute the integer roots of a univariate polynomial:

      ?- integer_roots_unipolynomial(n^3 - 6*n^2 + 11*n - 6, R).
      R = [1, 2, 3].
    
  • Compute the polynomial that gives the sum of the first n naturals raised to the power 10:

      P(n) = \sum_{i=1}^n i^10
      
      ?- power_sums(10, P).
      P = 1/11*n^11 + 1/2*n^10 + 5/6*n^9 - n^7 + n^5 - 1/2*n^3 + 5/66*n.
    
  • Obtain the polynomial that corresponds to the binomial n choose 7:

      ?- polynomial_expression_evaluation( choose(n,7), B ).
      B = 1/5040*n^7 - 1/240*n^6 + 5/144*n^5 - 7/48*n^4 + 29/90*n^3 - 7/20*n^2 + 1/7*n.
    
  • Compute the square of a multivariate polynomial:

       ?- polynomial_expression_evaluation( (z*q + y - x^2)^2, P ).
       P = -2*q*x^2*z + 2*q*y*z + q^2*z^2 - 2*x^2*y + x^4 + y^2.
    
  • Perform composition of functions:

    • Compose the univariate polynomial P(x) = x^2 with the multivariate polynomial Q(x,y) = 3*x + y, that is, compute P(Q(x,y)):

        ?- P=x^2, Q=3*x + y, polynomial_composition(x,Q, P, C).
        C = 6*x*y + 9*x^2 + y^2.
      
    • Compose the multivariate polynomial P(x,y) = x^2 + y^2 with the multivariate polynomial Q(x,y) = 3*x + y. In particular, compute P(Q(x,y), y) and P(x, Q(x,y))

        ?- P=x^2 + y^2, Q=3*x + y, polynomial_composition(x,Q, P, C).
        C = 6*x*y + 9*x^2 + 2*y^2.
        
        ?- P=x^2 + y^2, Q=3*x + y, polynomial_composition(y,Q, P, C).
        C = 6*x*y + 10*x^2 + y^2.
      

Dependencies

Tools

The user will need to have the SWI-Prolog implementation of the language, and the 'make' tool is needed to execute the necessary commands to compile the project.

Compiling

To compile the interactive version of the calculator, issue the following commands in the project's root directory:

    cd build
    make -f Makefile release

This will create a directory called bin/ with a executable file called sycalc in the project's root directory. In addition to this, one can also compile the tests that look for bugs in the code issuing the following commands:

    cd build
    make -f Makefile debug

About

Small symbolic calculator implemented with SWI-Prolog. Performs basic arithmetic operations with multi-variate polynomials.

License:GNU General Public License v3.0


Languages

Language:Prolog 99.2%Language:Makefile 0.8%