File: rational.py

package info (click to toggle)
mpsolve 3.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,100 kB
  • sloc: ansic: 25,748; sh: 4,925; cpp: 3,155; makefile: 914; python: 407; yacc: 158; lex: 85; xml: 41
file content (24 lines) | stat: -rwxr-xr-x 497 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Try to set some integer/rational coefficients

import mpsolve


def rootsofunity():
    """Solve the polynomial x^n - 1 using rational 
    input for MPSolve"""
    ctx = mpsolve.Context()
    poly = mpsolve.MonomialPoly(ctx, 8)

    poly.set_coefficient (0, "-1")
    poly.set_coefficient (8, "1")

    print( "Roots of x^8 - 1 = %s" % ( "  ".join (map (str, ctx.solve (poly)))))

if __name__ == "__main__":
    rootsofunity()