Skip to content

Usage Guide

This guide demonstrates how to use lesslines in various scenarios, along with code examples.

Basic Workflow

Importing lesslines

Start by importing the package and exploring its basic functionality:

from lesslines.misc import info

print(info.description())

# explore python with less lines of code

Example: Vector Operations

lesslines simplifies vector operations like addition, substraction, and cross product:

from lesslines.math.vector import Vect3

a = Vect3(1, 2, 3)
print(a)
# { "x": 1, "y": 2, "z": 3 }

b = Vect3(2, -1, 3)
print(b)
# { "x": 2, "y": -1, "z": 3 }

c = a + b
print(c)
# { "x": 3, "y": 1, "z": 6 }

d = a - b
print(d)
# { "x": -1, "y": 3, "z": 0 }

e = a * b
print(e)
# { "x": 9, "y": 3, "z": -5 }

Example: Numerical Differentiation and Integration with Polynomial

lesslines simplifies operations like diffentiantion and integration for polynomial function:

from lesslines.math.polynomial import Polynomial

p1 = Polynomial([4, -1, 3])
print(p1)
# 4 - x + 3x^2

p2 = p1.integrate(-10)
print(p2)
# -10 + 4.0x - 0.5x^2 + x^3

p3 = p2.differentiate()
print(p3)
# 4.0 - 1.0x + 3.0x^2

p4 = p3.differentiate()
print(p4)
# -1.0 + 6.0x

Example: Using Data Generator

lesslines includes data generator to produce artificial data:

from lesslines.data.generated import parametric as prm

x, y2 = prm.polynomial([0.25, 1, -1])

plt.plot(x, y2, 'o--')
plt.show()

The equation is

\[\tag{1} y = \tfrac14 + x - x^2, \]

where \(x\) is along horizontal axis and \(y\) along vertical axis.

Advanced Usage (currently not applicable)

Custom Functions

You can extend lesslines functionality by creating custom wrappers for your own workflows:

from lesslines.core import custom_function

result = custom_function(lambda x: x**3, [1, 2, 3])
print("Custom function results:", result)

Integrating with NumPy and SciPy

lesslines plays nicely with other popular libraries:

import numpy as np
from lesslines.core import transform

array = np.array([1, 2, 3, 4])
transformed_array = transform(array)
print("Transformed array:", transformed_array)

Next Steps

  • Explore the API reference (coming soon) for detailed information about available functions.
  • Check out the examples folder in the repository for real-world use cases.