0

I'm playing with manim and I'd like to create an animation with an elliptic curve. This is my code, in the file functions.py:

from manim import *

class EllipticCurve(Scene):

    def construct(self):
        basic_ec = FunctionGraph(
           lambda x: x**1.5 - x**0.5 + 19**0.5
        )

        self.play(Create(basic_ec))

When I execute this command manim -pql functions.py EllipticCurve, I get the following error:

ValueError: array must not contain infs or NaNs

I believe the the method FunctionGraph expects a function, instead of a curve, but how can I animate and plot an elliptic curve? Is there any other method? Am I missing something?

Hyperion
  • 156
  • 11

2 Answers2

0

You are passing the function to FunctionGraph correctly, the problem is that if you don't explicitly specify a x_range for the plot, Manim will choose the range [-config.frame_x_radius, config.frame_x_radius] (that is, it spans over the entire width of the frame; by default from -7.11 to +7.11).

Plugging in negative values in your function is problematic, and so Manim complains. Either pass x_range=[0, 7] to FunctionGraph, or check out ImplicitFunction (which to me seems more useful for working with elliptic curves).

And one final hint: It can be a bit tricky to get sane scaling for FunctionGraph, you might want to consider creating an Axes mobject and then use the corresponding Axes.plot or Axes.plot_implicit methods.

Benjamin Hackl
  • 1,011
  • 2
  • 8
  • Thank you for the answer. I’d need to plot negative values too. Is there any way to plot the EC with its Weierstrass form: `y^2 = x^3 - x + 19` ? – Hyperion May 12 '22 at 12:34
  • 1
    @Alejandro Yes, this is what the linked [`ImplicitFunction`](https://docs.manim.community/en/stable/reference/manim.mobject.graphing.functions.ImplicitFunction.html?highlight=ImplicitFunction#manim.mobject.graphing.functions.ImplicitFunction) does. – Benjamin Hackl May 12 '22 at 13:20
0

The following worked for me:

#!/usr/bin/env python
"""
# python -m manim --quality l simple_ec.py EllipticCurve1 -p
"""
from manim import *

class EllipticCurve(Scene):
    def construct(self):
        ax = Axes(x_range=[-3.2, 6.2, 1], y_range=[-21, 21, 10]
                  , x_length=14         , y_length=7.5
                  , color=BLUE
                  , x_axis_config={"numbers_to_include": range(-3, 6 + 1, 1),
                                   "font_size": 24,}
                  , y_axis_config={"numbers_to_include": range(-20, 20 + 10, 10),
                                   "font_size": 24,}
                  , tips=False)
        
        a = ax.plot_implicit_curve(lambda x, y: -y**2 + x**3 - x + 19
                                   , color=YELLOW)

        plane = NumberPlane(x_range=[-3.2, 6.2, 1], y_range=[-21, 21, 10]
                            , x_length=14         , y_length=7.5
                            , color=GRAY)

        self.add(ax, a, plane)
        self.wait(5)
        

It uses an implicit plot, the method plot_implicit_curve of the axes object ax, and is producing:

elliptic curve yy = xxx - x + 19

Note: The wanted elliptic curve was extracted from the comments. It is the curve y² = x³ - x + 19 . (Of course, we cannot isolate y by extracting the square root "termwise" from the R.H.S. - whatever the signs of the terms may be...) The curve (seen over the rationals) has no torsion points, its rank is one, and a generator is (2, 5).

dan_fulea
  • 541
  • 3
  • 5