Git Product home page Git Product logo

diophantine's Introduction

Maxima program to solve diophantine equations of the form ax^2+bxy+cy^2+dx+ey+f=0 with a,b,c,d,e,f constant integers. Based on Dario Alpern's solution/code found at https://www.alpertron.com.ar/QUAD.HTM

Installing
Usage
Limitations
Tests
Graphical examples

Install

Put the source in some folder, and in maxima do the following:

	(%i1) diophantine_source_dir:"<some-folder>"$
	(%i2) push(sconcat(diophantine_source_dir, "$$$.mac"), file_search_maxima)$
	(%i3) push(sconcat(diophantine_source_dir, "$$$.lisp"), file_search_lisp)$

Putting these lines in your maxima-init.mac saves you from having to type this in every new maxima session.

Alternatively, if you're using Robert Dodier's asdf loader, you can do the following:

	(%i1) install_github("sdemarre", "diophantine", "master")$
	(%i2) asdf_load_source("diophantine")$

Usage

	(%i1) load(diophantine)$

	(%i2) diophantine_solve(-9*x+11*y=5);
	(%o2) [[x = 11*%z1 - 3,y = 9*%z1 - 2]]

The result is always a (possibly empty) list of solutions. When there are infinitely many solutions, solutions use a parameter %z1 or %n1, which means "any integer" or "any natural number" respectively. Some equations have several sets of those, e.g.

	(%i3) diophantine_solve(18*y^2-24*x*y+7*y+8*x^2+5*x+16);
	(%o3) [[x = (-174*%z1^2)+17*%z1-2,y = (-116*%z1^2)+21*%z1-2],
	       [x = (-174*%z1^2)+41*%z1-4,y = (-116*%z1^2)+37*%z1-4]]

Generating some specific values when the solution contains such a parameter can be done like this

	(%i4) diophantine_solve(3*x+2*y-8);
	(%o4) [[x=2*%z1+2,y=1-3*%z1]]

	(%i5) diophantine_instantiate_solutions(%o4,-3,3);
	(%o5) [[x = - 4, y = 10], [x = - 2, y = 7], [x = 0, y = 4], [x = 2, y = 1],
	      	  [x = 4, y = - 2], [x = 6, y = - 5], [x = 8, y = - 8]]

Limitations

The test file (rtest_diophantine.mac) contains possibly interesting examples and examples that show the following issues:

  • Even apparently simple equations can take a very long time to solve.

Tests

There is a file with tests available, run it like this:

	(%i6) batch(rtest_diophantine, test);

Graphical examples:

	(%i7) load(diophantine_draw)$
	(%i8) dio_draw_example();

Graphical example

	(%i9) dio_draw_example2();

Graphical example 2

	(%i10) dio_draw_example3();

Graphical example 3

	(%i11) dio_draw_example4();

Graphical example 4

In general, you can use dio_draw() to draw the equation with (some of) its solutions:

	(%i17) dio_draw(x^2-7*y^2=-3);

diophantine's People

Contributors

sdemarre avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.