lambdaengine

package module
v0.0.0-...-9305e13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2025 License: MIT Imports: 7 Imported by: 0

README

lambda-calc (engine)

Logical Advanced Mathmatical Backend for Dynamic Analysis of Calculation and Algebra with LaTeX Cuteness

This is a modular version of the lambda-calc project. It is made for the lambda-calc-gui, but should work in any GO-Project. For more information and work in progress features of this project look at the main branch.

It is currently not a go package. So if you want to use it, you will need to but the folder into your project.

Usage

You can add the lambda-calc-engine into your GO-project and import it.

import (
    lambda "lambda-calc-gui/lambda-calc"
)

To initialize the engine you need to call the start function. An initilization parameter that holds all callback functions is passed to the function.

func main() {
    lambda.Start(lambda.InitilizationParameters{
        func(lambda.Variable) {} // Callback, when variables are defined.
        func(lambda.Variable) {} // Callback, when variables are dropped.
    })
}

The Variable struct passed into these callback function holds information about the variable like its name and its value.

type Variable struct {
	Name     string
	Equation string
}

To now calculate the result of an equation you need to call the Input function. The function returns the result of type string and an error. The error contains the whether and error was produced, the error message and an error code.

func main() {
    str := "2 + 2"

    res, err := lambda.Input(str)
    if err.IsError {
        fmt.Printf("Recieved Error: %s", err.Message)
    } else {
        fmt.Printf("Recieved Result: %s", res)
    }
}

Config-File

The config file can be found under config/config.toml. The config file defines the behavior of the math engine.

Options

Currently options are only there to debug the program and trace back at what point an error occured.

[options]
show_debug_process = false
Option - bool Effect
show_debug_process Prints out message about the state of the program during calculation.
Symbols

All symbols used when entering an equation can be configured:

[symbols]
decimal_split = '.'

plus = '+'
minus = '-'
multiply = '*'
divide = '/'

sqrt = 'sqrt'
power = '^'

Currently sqrt is the only multi-character symbol.

Constants

Constants can also be defined in the config file. All constants are declared under the constant struct, with the key being the name of the variable and the value the value of the variable. The value is in a Float64 format. By default these constants are included:

[constants]
pi = 3.14159265
phi = 1.618033988
e = 2.71828182

Documentation

Overview

Package lambdaengine implements a calculation interface based on symbolic expressions and mathmatical simplification.

Index

Constants

View Source
const (
	NUMBER       = iota
	PLUS         = iota
	MINUS        = iota
	MULTIPLY     = iota
	DIVIDE       = iota
	POWER        = iota
	SQRT         = iota
	LPARENTHESES = iota
	RPARENTHESES = iota
	EQUAL        = iota
	VARIABLE     = iota
)
View Source
const (
	UNWIND = 0
	REWIND = 1
	SOLVE  = 2
)

Constant index in rule set

Variables

View Source
var RewindRules = []RewriteRule{
	simplifyAddZero,
	simplifySubZero,
	simplifySingleAdd,
	simplifyMultZero,
	simplifyMultOne,
	simplifyDivOne,
	simplifyZeroDiv,
	simplifyDivSelf,

	simplifyAddCollect,
	simplifyMultCollect,
	simplifyConstantFold,
	simplifyPowZero,
	simplifyMultPow,
	simplifyRefact,
}
View Source
var SolveRules = []RewriteRule{

	simplifyAddZero,
	simplifySubZero,
	simplifyMultZero,
	simplifyMultOne,
	simplifyDivOne,
	simplifyZeroDiv,
	simplifyDivSelf,

	simplifyPowSelf,
	simplifyAddPow,
	simplifyMultPow,

	simplifyConstantFold,
}
View Source
var UnwindRules = []RewriteRule{

	simplifyAddZero,
	simplifySubZero,
	simplifySingleAdd,
	simplifyMultZero,
	simplifyMultOne,
	simplifyDivOne,
	simplifyZeroDiv,
	simplifyDivSelf,

	simplifyPowZero,
	simplifyMultPow,

	simplifyAddCollect,
	simplifyMultCollect,
	simplifyDefact,
	simplifyConstantFold,
}

Functions

func Start

func Start(
	initPrm InitilizationParameters,
) bool

Loads the config and initilizes the callback functions.

Types

type Config

type Config struct {
	Options   map[string]bool
	Symbols   map[string]string
	Constants map[string]float64
}

type Error

type Error struct {
	Message   string
	IsError   bool
	ErrorCode int
}

func Input

func Input(cmd string) (string, Error)

type InitilizationParameters

type InitilizationParameters struct {
	VariableDefinedCallback func(variable Variable)
	VariableDroppedCallback func(variable Variable)
}

Initilization Parameters:

"VariableDefinedCallback": Callback function called when a variable is defined, with Variable being the parameter.

"VariableDroppedCallback": Callback function called when a variable is dropped, with Variable being the parameter.

type Node

type Node struct {
	// contains filtered or unexported fields
}

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

type RewriteRule

type RewriteRule func(*Node) (*Node, bool, error)

type Token

type Token struct {
	// contains filtered or unexported fields
}

type Variable

type Variable struct {
	Name     string
	Equation string
}

The variable struct holds information about a Variable like its name and its underlying equation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL