mathematical-expression 实现 数学表达式解析 Java 篇(最新版本)

news2025/1/27 7:01:00

在这里插入图片描述

mathematical-expression (MAE)

  • 切换至 中文文档

Community QQ group

访问链接进行交流信息的获取:https://diskmirror.lingyuzhao.top/DiskMirrorBackEnd/FsCrud/downLoad/18/Binary?fileName=Article/Image/-56202138/1734319937274.jpg

🫠 Important Notice

✅【commonly】 *
PS, please try to use version 1.3.1 and above as much as possible. This will help you use a more stable version and
fix all known bugs in 1.2.x
*

⚠️【important】 The content of

versions 1.3.7

and 1.4.0 is completely consistent, with the only
difference being the
change in the package module. ** Please note that we will refactor the package name
to io.github.beardedManZhao.mathematicalExpression in versions 1.4.0 and all subsequent versions to avoid
conflicting
package names in Java’s various dependencies~**

To avoid any compatibility issues caused by package updates, we have provided version 1.3.7. You can continue to use
the old package name, but we strongly recommend using the new version, as the new package name has been updated to ’
io.
github. beardedManZhao. mathematicalExpression’. If you have any questions or suggestions about changing the package
name or updating, please contact us in a timely manner!!

introduce

This framework is an effective tool for mathematical formula analysis. It can analyze mathematical formulas including
nested functions, including functions, and step accumulation of series. The return value is a numerical result object.
At the same time, it can also be used for comparison operations. When comparing again, the return value is a Boolean
result object.

  • Maven depends on coordinates

    You can directly use Maven to import this framework into the project and use it effectively


<dependencies>
    <dependency>
        <groupId>io.github.BeardedManZhao</groupId>
        <artifactId>mathematical-expression</artifactId>
      <version>1.4.7</version>
    </dependency>
</dependencies>

You can also directly load “mathematical expression” into your framework through gradle, and use the following
dependencies.

dependencies {
    implementation 'io.github.BeardedManZhao:mathematical-expression:1.4.7'
}

Historical version

You can check in the https://github.com/BeardedManZhao/mathematical-expression/tree/main/update Detailed change reports
for all published versions were found in.

Why choose mathematical expression

Mathematical expression has advantages such as simplicity, speed, ease of use, and support for a wide range of
languages. It has almost the same API usage as the C Java Python version.

Easy to use API

Calling the library is very simple, and you can use the following code for calculation. Of course, if you don’t need to
check, you can also compress the calculation code below
into System.out.println(Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2).calculation("(1+2)*3"));
Can effectively reduce code load!

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {

    public static void main(String[] args) throws WrongFormat {
        final Calculation instance = Mathematical_Expression.getInstance(
                // Select the different computing components you want to use here
                Mathematical_Expression.bracketsCalculation2
        );
        // If you ensure the correctness of the expression, you can skip checking
        instance.check("(1+2)*3");
        System.out.println(instance.calculation("(1+2)*3"));
    }
}

Superb functionality, capable of handling numerous functions

Are you unfamiliar with programming? It’s simple, you can completely customize functions using mathematical expressions,
and we also have many built-in functions that are unified
in function.io.github.beardedManZhao.mathematicalExpression.core.calculationFunctionPackage
In class!!

// Import necessary classes and packages for mathematical calculations and functions

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.FunctionPackage;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

// Define a class 'MAIN' with a function that calculates the factorial of x plus 1
@Functions("f(x) = x! + 1")
public class MAIN {
  public static void main(String[] args) throws WrongFormat {
    // Import built-in functions like 'sum' for use
    // Register the math function library
    Mathematical_Expression.register_function(FunctionPackage.MATH);

    // Alternatively, register custom functions, e.g., a function adding two numbers
    Mathematical_Expression.register_function("fTwo(x, y) = x + y");

    // Register all annotated functions in the 'MAIN' class for use
    Mathematical_Expression.register_function(MAIN.class);

    // Initialize the calculation component
    final Calculation instance = Mathematical_Expression.getInstance(Mathematical_Expression.functionFormulaCalculation2);

    // Perform a simple check on the expression
    instance.check("1 + sum(1,2,3,4) + f(3) * fTwo(1, 2)");

    // Calculate the expression, which can include functions
    final CalculationResults calculation = instance.calculation("1 + sum(1,2,3,4) + f(3) * fTwo(1, 2)");

    // Print the result
    System.out.println(calculation.getResult());
  }
}

Not enough support for calculating symbols? Don’t worry, this library supports a wide variety of operators, and you can
see all the operators here!

Symbol NameSymbolic syntax (n represents operands)Supported versionsSymbolic significance
Addition operatorn + n1.0.0Add two operands
Subtraction operatorn - n1.0.0Subtracting two operands
Multiplication operatorn * n1.0.0Multiplying two operands
Division operatorn / n1.0.0Dividing two operands
Remainder operatorn % n1.0.0Perform remainder operation on two operands
Factorial operatorn!1.3.2Performing factorial operations on operands
Power operatorn ^ n1.3.5Exponentiation operands

You can also achieve calculation operations with precision and caching operations by adjusting settings!

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationResults;

import java.math.BigDecimal;

/**
 * This is the main entry point for the application, demonstrating mathematical expression parsing and evaluation.
 */
public class MAIN {
    public static void main(String[] args) {
        // Obtain an instance of the calculation component, which supports parentheses handling.
        final Calculation calculationInstance = Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2);
        // Define a sample mathematical expression to evaluate.
        final String inputExpression = "0.3 * 3";
        // Enable caching to improve performance.
        Mathematical_Expression.Options.setUseCache(true);

        // Enable BigDecimal for more accurate results.
        Mathematical_Expression.Options.setUseBigDecimal(true);
        // Evaluate the expression and print the result.
        System.out.println(calculationInstance.calculation(inputExpression));

        // Disable BigDecimal for faster performance.
        Mathematical_Expression.Options.setUseBigDecimal(false);
        // Evaluate the expression and print the result.
        final CalculationResults calculation = calculationInstance.calculation(inputExpression);
        System.out.println(calculation);

        // Can extract different numerical objects
        System.out.println("Can extract different numerical objects!");
        final double result = (double) calculation.getResult();
        final BigDecimal bigDecimalResult = calculation.getBigDecimalResult();
        System.out.println(result);
        System.out.println(bigDecimalResult);
    }
}

A wide variety of computing components

In mathematical expression, we provide various computing components, and you can choose different computing components
according to your needs to achieve different functions while maintaining the same API calling method.

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

// Prepare a mathematical function x factorial+1
@Functions("f(x) = x! + 1")
public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Register and use the main annotated function
        Mathematical_Expression.register_function(MAIN.class);
        final Calculation instance = Mathematical_Expression.getInstance(
                // Select the function calculation component here
                Mathematical_Expression.functionFormulaCalculation2
        );
        // If you ensure the correctness of the expression, you can skip checking
        instance.check("f(1 + 2) - 3");
        System.out.println(instance.calculation("f(1 + 2) - 3"));

        /*----------------------------------*/

        // You can also use the quick calculation component to calculate the sum between intervals [1+2, 30]
        final Calculation instance1 = Mathematical_Expression.getInstance(
                // Select the quick sum calculation component here, and the API will be the same as above
                Mathematical_Expression.fastSumOfIntervalsBrackets
        );
        instance1.check("1 + 2, 30");
        System.out.println(instance1.calculation("1 + 2, 30"));
    }
}

Ultra-high flexibility

The functions required in any step of it, as well as any calculated object, can be individually obtained for the desired
operation. For example, a mathematical function is a complex object, and after its compilation is successful, you can
directly obtain its function object, which is not limited to the following
Used in mathematical expression!

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

// Prepare a mathematical function x factorial+1
@Functions("f(x) = x! + 1")
public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Register and use the main annotated function
        Mathematical_Expression.register_function(MAIN.class);
        // Extract f (x)=x+ We know that the name of the function object of 1 is f
        final ManyToOneNumberFunction f = Mathematical_Expression.getFunction("f");
        // Calculate using f alone
        final double run = f.run(3);
        System.out.println(run);
    }
}

Detailed execution records

In some calculation components, you can use the ‘explain’ function to calculate expressions. This function can fully
plot the calculation process of the calculation component as a log result object, which can be plotted as a graph. The
following are the supported components and usage examples.

Calculation component nameDoes it support explainWhen did support startRelated knowledge
io.github.beardedManZhao.mathematicalExpression.core.calculation.PrefixExpressionOperationyesv1.3.5click this
io.github.beardedManZhao.mathematicalExpression.core.calculation.BracketsCalculation2yesv1.3.5click this
io.github.beardedManZhao.mathematicalExpression.core.calculation.CumulativeCalculationyesv1.3.6click this
io.github.beardedManZhao.mathematicalExpression.core.calculation.FunctionFormulaCalculation2yesv1.3.6click this
Introducing a flowchart code generation library

You only need to import the dependency coordinates below to automatically import the relevant components. This library
will help you draw a flowchart of the calculation process of computational components.

<!-- If your mathematicalExpression version is greater than 1.4.2, there is no need to introduce this dependency! -->
<dependency>
    <groupId>io.github.BeardedManZhao</groupId>
    <artifactId>varFormatter</artifactId>
    <version>1.0.4</version>
</dependency>
开始进行生成

After importing the library, we can generate a flowchart as shown below.

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.LogResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;
import top.lingyuzhao.varFormatter.core.VarFormatter;

/**
 * This is the main entry point for the application, demonstrating mathematical expression parsing and evaluation.
 */
public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Obtain an instance of the calculation component, which supports parentheses handling.
        final Calculation calculationInstance = Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2);

        // Define a sample mathematical expression to evaluate.
        final String inputExpression = "1 + 2 ^ (2 + (10 - 7)) * 3 + 2";

        // Check the input expression for correct formatting.
        calculationInstance.check(inputExpression);

        // Explain the execution process, which returns a log object containing the result.
        final LogResults explanation = calculationInstance.explain(inputExpression, true);
        System.out.println("计算结果: " + explanation.getResult());

        // The LogResults object is primarily used for visualizing the execution flow.
        // Disable name joining when outputting the visualization, as multiple variables need to be associated.
        explanation.setNameJoin(false);

        // Format the visualization using the VarFormatter in MERMAID syntax.
        System.out.println("graph LR");
        System.out.println(explanation.explain(VarFormatter.MERMAID));
    }
}

The result after running the program is as follows.

计算结果:99.0
graph LR
f_-1523352178("1 + 2 ^ (2 + (10 - 7)) * 3 + 2")
f_-1523352178==Map>Map==>f_1563255009
f_1563255009("2 + (10 - 7)")
f_1563255009==Map>Map==>f_1448155011
f_1448155011("10 - 7")
f_1448155011==Map>Map==>f_1507337
f_1507337("10-7+0")
f_1507337==Map>Map==>f_1507337_优先

f_1507337_优先==Map>Map==>f_1571371271_计算
f_1571371271("10.0 - 7.0")
f_1571371271_计算==Map>String/Number==>f_1571371271
f_1571371271--Map>value-->f_1571371271v{"3.0"}
f_1571371271_计算==Map>Map==>f_1507337_最终

f_1507337_最终==Map>Map==>f_1481348562_计算
f_1481348562("3.0 + 0.0")
f_1481348562_计算==Map>String/Number==>f_1481348562
f_1481348562--Map>value-->f_1481348562v{"3.0"}
f_1563255009==Map>Map==>f_47507548
f_47507548("2+3.0+0")
f_47507548==Map>Map==>f_47507548_优先

f_47507548_优先==Map>Map==>f_-1006161388_计算
f_-1006161388("2.0 + 3.0")
f_-1006161388_计算==Map>String/Number==>f_-1006161388
f_-1006161388--Map>value-->f_-1006161388v{"5.0"}
f_-1006161388_计算==Map>Map==>f_47507548_最终

f_47507548_最终==Map>Map==>f_-2133560364_计算
f_-2133560364("5.0 + 0.0")
f_-2133560364_计算==Map>String/Number==>f_-2133560364
f_-2133560364--Map>value-->f_-2133560364v{"5.0"}
f_-1523352178==Map>Map==>f_-418786079
f_-418786079("1+2^5.0*3+2+0")
f_-418786079==Map>Map==>f_-418786079_优先

f_-418786079_优先==Map>Map==>f_-959059895_计算
f_-959059895("2.0 ^ 5.0")
f_-959059895_计算==Map>String/Number==>f_-959059895
f_-959059895--Map>value-->f_-959059895v{"32.0"}
f_-959059895_计算==Map>Map==>f_1855628224_计算
f_1855628224("32.0 * 3.0")
f_1855628224_计算==Map>String/Number==>f_1855628224
f_1855628224--Map>value-->f_1855628224v{"96.0"}
f_1855628224_计算==Map>Map==>f_2037586494_计算
f_2037586494("96.0 + 2.0")
f_2037586494_计算==Map>String/Number==>f_2037586494
f_2037586494--Map>value-->f_2037586494v{"98.0"}
f_2037586494_计算==Map>Map==>f_-418786079_最终

f_-418786079_最终==Map>Map==>f_-929530109_计算
f_-929530109("1.0 + 98.0")
f_-929530109_计算==Map>String/Number==>f_-929530109
f_-929530109--Map>value-->f_-929530109v{"99.0"}
f_-929530109_计算==Map>String/Number==>result
result--Map>value-->resultv{"99.0"}

After the program runs, there is a graph code for ‘mermaid’ in the result, which we will display below for everyone to
watch!

After version 1.4.6, the visualization effect of ‘explain’ has been optimized. Here is the visualization effect of the
new version, which you can see in
the update record

Map>Map
Map>Map
Map>Map
Map>Map
Map>Map
Map>String/Number
Map>value
Map>Map
Map>Map
Map>String/Number
Map>value
Map>Map
Map>Map
Map>Map
Map>String/Number
Map>value
Map>Map
Map>Map
Map>String/Number
Map>value
Map>Map
Map>Map
Map>Map
Map>String/Number
Map>value
Map>Map
Map>String/Number
Map>value
Map>Map
Map>String/Number
Map>value
Map>Map
Map>Map
Map>String/Number
Map>value
Map>String/Number
Map>value
1 + 2 ^ (2 + (10 - 7)) * 3 + 2
2 + (10 - 7)
10 - 7
10-7+0
f_1507337_优先
f_1571371271_计算
10.0 - 7.0
3.0
f_1507337_最终
f_1481348562_计算
3.0 + 0.0
3.0
2+3.0+0
f_47507548_优先
f_-1006161388_计算
2.0 + 3.0
5.0
f_47507548_最终
f_-2133560364_计算
5.0 + 0.0
5.0
1+2^5.0*3+2+0
f_-418786079_优先
f_-959059895_计算
2.0 ^ 5.0
32.0
f_1855628224_计算
32.0 * 3.0
96.0
f_2037586494_计算
96.0 + 2.0
98.0
f_-418786079_最终
f_-929530109_计算
1.0 + 98.0
99.0
result
99.0

Framework

Obtain and calculate the calculation components directly through the mathematical-expression library

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Build two expressions to be evaluated
        String s1 = "1 + 20 - 2 + 4", s2 = "1 + 20 - (2 + 4)";
        // Obtain the calculation component for calculating the expression without parentheses through the library
        Calculation prefixExpressionOperation = Mathematical_Expression.getInstance(
                Mathematical_Expression.prefixExpressionOperation, "prefixExpressionOperation"
        );
        // Obtain the calculation component for calculating bracketed expressions through the library
        Calculation bracketsCalculation2 = Mathematical_Expression.getInstance(
                Mathematical_Expression.bracketsCalculation2, "bracketsCalculation2"
        );
        // Pass the first formula to the calculation component of an expression without parentheses
        prefixExpressionOperation.check(s1);
        CalculationResults calculation1 = prefixExpressionOperation.calculation(s1);
        // Print the calculation result of the first expression
        System.out.println("计算层数:" + calculation1.getResultLayers() + "\n计算结果:" + calculation1.getResult() +
                "\n计算来源:" + calculation1.getCalculationSourceName());


        // Pass the second formula to the calculation component of the parenthesis expression
        bracketsCalculation2.check(s2);
        CalculationResults calculation2 = bracketsCalculation2.calculation(s2);
        // Print the calculation result of the second expression
        System.out.println("计算层数:" + calculation2.getResultLayers() + "\n计算结果:" + calculation2.getResult() +
                "\n计算来源:" + calculation2.getCalculationSourceName());
    }
}
  • Running results

    By importing packages, the module objects of each computing component can be obtained, which can effectively reduce
    the amount of code imported into the package.

计算层数:1
计算结果:23.0
计算来源:prefixExpressionOperation
计算层数:2
计算结果:15.0
计算来源:bracketsCalculation2

Calculation Manager

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.manager.CalculationManagement

  • introduce:

    The manager is a component designed to use both singletons and dynamic objects. The existence of the manager enables
    each component to be obtained by name. Components with the same name have the same storage address in memory, avoiding
    the use of redundant components. At the same time, for components that need to use dynamic members, a new component
    can also be obtained by a new name.

  • API Usage Example

import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FunctionFormulaCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.PrefixExpressionOperation;
import io.github.beardedManZhao.mathematicalExpression.core.manager.CalculationManagement;

public class MAIN {
    public static void main(String[] args) {
        // Instantiate three components
        // TODO getInstance will be automatically obtained from the manager. 
        //  If it is not obtained, it will be created and registered, and then the data will be returned. 
        //  This method can be used to create or access the manager
        PrefixExpressionOperation a = PrefixExpressionOperation.getInstance("a");
        FunctionFormulaCalculation b = FunctionFormulaCalculation.getInstance("b");
        PrefixExpressionOperation a1 = PrefixExpressionOperation.getInstance("a1");
        // Register a bracketed expression calculation component with the name:"a"
        CalculationManagement.register(a);
        // Register a function expression calculation component named:"b"
        CalculationManagement.register(b);
        // Register a bracketed expression calculation component with the name:"a1"
        CalculationManagement.register(a1);
        // Print whether the memory data of the component we instantiated is consistent with that obtained from the manager
        System.err.println(a + "  " + CalculationManagement.getCalculationByName("a"));
        System.err.println(b + "  " + CalculationManagement.getCalculationByName("b"));
        System.err.println(a1 + "  " + CalculationManagement.getCalculationByName("a1"));
    }
}
  • Running results

    The last three lines are the comparison of memory data. The instantiated components are the same as the components in
    the manager, but the components with different names are different.

[INFO][Calculation Management][24-05-15:11]] : +============================== Welcome to [mathematical expression] ==============================+
[INFO][Calculation Management][24-05-15:11]] : + 	Start time Wed May 15 11:29:32 CST 2024
[INFO][Calculation Management][24-05-15:11]] : + 	version: 1.37
[INFO][Calculation Management][24-05-15:11]] : + 	Calculation component manager initialized successfully
[INFO][Calculation Management][24-05-15:11]] : + 	For more information, see: https://github.com/BeardedManZhao/mathematical-expression.git
[INFO][Calculation Management][24-05-15:11]] : +--------------------------------------------------------------------------------------------------+
[INFO][Calculation Management][24-05-15:11]] : A computing component is registered prefixExpressionOperation
[INFO][Calculation Management][24-05-15:11]] : A computing component is registered PrefixExpressionOperation
[INFO][Calculation Management][24-05-15:11]] : A computing component is registered bracketsCalculation2
计算层数:1
计算结果:23.0
计算来源:prefixExpressionOperation
计算层数:1
计算结果:15.0
计算来源:PrefixExpressionOperation

Calculation component introduce

NotBracketedExpression

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.PrefixExpressionOperation

  • introduce

    This component is designed for a mathematical expression without parentheses, but with operations such as addition,
    subtraction, multiplication, division and remainder. This component can realize the function with priority
    calculation, in which the prefix expression is used to parse and calculate, and the operand and operator are stored on
    the stack together with the calculation priority comparison If the current priority is low, first operate the previous
    operand and operator with the current operand to form a new value, and then put it on the stack.

  • API Usage Example

    The operators supported by this component are: a+b a-b a*b a/b a%b a^b

import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.PrefixExpressionOperation;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Gets the calculation component of a function that evaluates an expression without parentheses
        PrefixExpressionOperation prefixExpressionOperation = PrefixExpressionOperation.getInstance("p");
        // Create an expression
        String s = "1 + 2 + 4 * 10 - 3";
        // Check the expression for errors
        prefixExpressionOperation.check(s);
        // Start calculating results
        CalculationNumberResults calculation = prefixExpressionOperation.calculation(s);
        // Print result value
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\n计算结果:" + calculation.getResult() +
                        "\n计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results

    In the API call, the Running results of the function are printed. It can be seen that the returned value calculated by
    the component is a result set object, in which a lot of information about the calculation results is stored.

计算层数:2
计算结果:40.0
计算来源:p

NestedParenthesisExpression

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.BracketsCalculation2

  • introduce:

    Nested parenthesis expression parsing component, which can parse and calculate the results of mathematical expressions
    with multiple parentheses, and parse and calculate the priority of nested parentheses. This component relies on “core.
    calculation. number. PrefixExpressionOperation”, and uses recursion to parse parentheses in this component, Then
    provide the innermost expression to “core. calculation. number. PrefixExpressionOperation” for calculation.

  • API Usage Example

    The operators supported by this component are:a+b a-b a*b a/b a%b a^b ( ) a!

import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.BracketsCalculation2;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Get a calculation component that evaluates nested parenthesis expressions
        BracketsCalculation2 bracketsCalculation = BracketsCalculation2.getInstance("BracketsCalculation");
        // Create an expression
        String s = "1 + 2 + 4 * (10 - 3)";
        // Check the expression for errors
        bracketsCalculation.check(s);
        // Start calculating results
        CalculationNumberResults calculation = bracketsCalculation.calculation(s);
        // Print result value
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\n计算结果:" + calculation.getResult() +
                        "\n计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results

    In the API call, the calculation result of the expression is printed. It can be seen that the return value of the
    component calculation is a numerical result object, in which a lot of information about the calculation result is
    stored.

计算层数:2
计算结果:31.0
计算来源:BracketsCalculation

Mathematical comparison expression

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.bool.BooleanCalculation2

  • introduce

    A component that uses the comparison operator to determine whether two parenthesis expressions are mutually valid. The
    return value is a Boolean result object. This component can compare the size of two numeric values, or the
    relationship between two expressions, depending on the component “core. calculation. bool. BooleanCalculation2”

  • API Usage Example

    The operators supported by this component are shown in the API


import io.github.beardedManZhao.mathematicalExpression.core.calculation.bool.BooleanCalculation2;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationBooleanResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // 获取一个计算数学比较表达式的组件
        BooleanCalculation2 booleanCalculation2 = BooleanCalculation2.getInstance("Bool");
        // 创建3个表达式
        String s1 = "1 + 2 + 4 * (10 - 3)";
        String s2 = "2 + 30 + (2 * 3) - 1";
        String s3 = "1 + 3 * 10";
        extracted(booleanCalculation2, s1 + " > " + s2);// false
        extracted(booleanCalculation2, s1 + " < " + s2);// true
        extracted(booleanCalculation2, s1 + " = " + s3);// true
        extracted(booleanCalculation2, s1 + " == " + s3);// true
        extracted(booleanCalculation2, s1 + " != " + s3);// false
        extracted(booleanCalculation2, s1 + " <> " + s3);// false
        extracted(booleanCalculation2, s1 + " <= " + s3);// true
        extracted(booleanCalculation2, s1 + " >= " + s3);// true
        extracted(booleanCalculation2, s1 + " != " + s2);// true
        extracted(booleanCalculation2, s1 + " <> " + s2);// true
    }

    private static void extracted(BooleanCalculation2 booleanCalculation2, String s) throws WrongFormat {
        // Check the expression for errors
        booleanCalculation2.check(s);
        // Start calculating results
        CalculationBooleanResults calculation = booleanCalculation2.calculation(s);
        // Print result value
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\t计算结果:" + calculation.getResult() +
                        "\t计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results
计算层数:2	计算结果:false	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool
计算层数:2	计算结果:false	计算来源:Bool
计算层数:2	计算结果:false	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool
计算层数:2	计算结果:true	计算来源:Bool

IntervalAccumulationExpression

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.CumulativeCalculation

  • introduce

    In mathematical expressions, there is often such a formula. The content of the formula is shown in the following
    figure. You can see the number sequence operations that need to be accumulated.

    Then, you can use the Full class name above to achieve the purpose you need.

    img_1

  • API Usage Example

    The syntax level is almost the same as that of other components. The calculation example of the mathematical
    expression written in the component is shown below. What is shown here is the calculation of an accumulative
    mathematical formula.


import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.CumulativeCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Get a component that calculates the cumulative mathematical expression
        CumulativeCalculation cumulativeCalculation = CumulativeCalculation.getInstance("zhao");
        // Construct a mathematical expression. Here, "n [1,10,1]" is similar to the accumulation symbol in mathematics. N will increase continuously in this interval. Every increase will be brought into the formula for calculation
        // Wherein, the last 1 in [1,10,1] represents the increase step, which can realize the accumulation of different equal difference values in the interval
        String s = "n[1,10,1] 2 * (n + 1)";
        // Check mathematical expressions
        cumulativeCalculation.check(s);
        // Calculation results
        CalculationNumberResults calculation = cumulativeCalculation.calculation(s);
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\t计算结果:" + calculation.getResult() +
                        "\t计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results
计算层数:21	计算结果:130.0	计算来源:zhao

FunctionOperationExpression

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FunctionFormulaCalculation

  • introduce

    The framework also supports the operation of some functions. You can use the above classes to write mathematical
    expressions that require functions. It should be noted that all functions used in expressions need to be logically
    registered in “Calculation Management” so that functions can be accessed during calculation

  • API Usage Example


import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FunctionFormulaCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.core.manager.CalculationManagement;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Instantiate a function named DoubleValue to multiply a value by 2
        ManyToOneNumberFunction myFunction = new ManyToOneNumberFunction("DoubleValue") {
            /**
             * 函数的运行逻辑实现
             *
             * @param numbers 这里是函数的数据输入对象,由框架向这里传递数据输入参数
             * @return 这里是数据经过函数转换之后的数据
             */
            @Override
            public double run(double... numbers) {
                // Among the parameters here, the first parameter is the parameter passed in by FunctionFormulaCalculation
                return numbers[0] * 2;
            }
        };
        // Register function to manager
        CalculationManagement.register(myFunction);
        // Get a component that calculates the cumulative mathematical expression
        FunctionFormulaCalculation functionFormulaCalculation = FunctionFormulaCalculation.getInstance("zhao");
        // Build a mathematical expression that uses the function DoubleValue
        String s = "2 * DoubleValue(2 + 3) + 1";
        // Check mathematical expressions
        functionFormulaCalculation.check(s);
        // Calculation results
        CalculationNumberResults calculation = functionFormulaCalculation.calculation(s);
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\t计算结果:" + calculation.getResult() +
                        "\t计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results
[INFO][zhao][22-11-14:11]] : Find and prepare the startup function: DoubleValue
计算层数:1	计算结果:21.0	计算来源:BracketsCalculation2

Multi parameter function operation expression

  • Full class name: io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FunctionFormulaCalculation2

  • 介绍

    For some expression calculations that use functions in expressions, the above class can be used for operations. It is
    an upgraded version of the “core. calculation. number. FunctionFormulaCalculation” class, which has appeared since
    version 1.1, is also an extended implementation of its subclass.

    Compared with the parent class, this component makes up for the deficiency that the parent class can only parse the
    function expression with one parameter. In this component, you can use many real parameters for function operations,
    such as sum (1,2,3)

    This type of function is a multi parameter function. Next, let’s look at the API usage example, in which the
    calculation and results of the multi parameter function expression are shown.


import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FunctionFormulaCalculation2;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.core.manager.CalculationManagement;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Implement a sum function
        ManyToOneNumberFunction manyToOneNumberFunction = new ManyToOneNumberFunction("sum") {
            @Override
            public double run(double... numbers) {
                double res = 0;
                for (double number : numbers) {
                    res += number;
                }
                return res;
            }
        };
        // Register this function to the administrator
        CalculationManagement.register(manyToOneNumberFunction);
        // Get the new version of function calculation component
        FunctionFormulaCalculation2 functionFormulaCalculation2 = FunctionFormulaCalculation2.getInstance("zhao");
        // Build the formula we need to calculate
        // TODO The function sum parameter in this expression is not only one, but also a multi parameter function
        String s = "2 * (200 - sum(1 + 10.1, 2, 3)) + sum(10, 20)";
        // Enabling the shared pool can speed up the calculation. The more complex the calculation formula is, the more significant the effect of the shared pool is
        functionFormulaCalculation2.setStartSharedPool(true);
        // Check the formula for errors
        functionFormulaCalculation2.check(s);
        // Get the calculation results
        CalculationNumberResults calculation = functionFormulaCalculation2.calculation(s);
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\t计算结果:" + calculation.getResult() +
                        "\t计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • 运行结果
计算层数:2	计算结果:397.8	计算来源:BracketsCalculation2
Mathematical function expression registration

You can directly use the mathematical expression of a function to register a function. The format of the function
expression is’ function name (parameter 1, parameter 2, parameter 3)=function logical expression, such as parameter
1+parameter 2 '. Below is a registration example

This registered function can also be directly used in mathematical expressions!


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.manager.ConstantRegion;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        System.out.println(ConstantRegion.VERSION);
        // Start registering TODO. We have registered a function called mySum here, which takes in two parameters and outputs the sum of the two parameters
        if (Mathematical_Expression.register_function("mySum(a, b) = a + b")) {
            System.out.println("函数注册成功!");
        }
    }
}

Fast interval sum calculation component (based on parenthesis expression)

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FastSumOfIntervalsBrackets

  • introduce

    The new product of version 1.15, the interval fast sum component, is a fast component that sums all elements of an
    interval with an equal difference of 1. It logically simulates an interval into a mathematical sequence and quickly
    sums it through the sum formula.

    This component implements the shared pool computing function. It will check, calculate, and record the results of the
    last time, which can speed up computing. The specific API calls are shown below.


import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FastSumOfIntervalsBrackets;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Get the quick sum calculation component of the interval
        FastSumOfIntervalsBrackets fast = FastSumOfIntervalsBrackets.getInstance("fast");
        // Build an expression to be calculated.
        // The following expression represents that the result of adding 11=(1+10) to 13=(20 - (5+2)) should be 36
        String s = "1 + 10, 20 - (5 + 2)";
        // Check the expression. The shared pool has been enabled by default since version 1.2! No need to set manually
        // fast.setStartSharedPool(true);
        fast.check(s);
        // After version 1.2, the accumulation component supports setting step parameters, and since version 1.2.1, it officially supports the summation of step intervals
        fast.step = 2;
        // Start calculation
        CalculationNumberResults calculation = fast.calculation(s);
        // Print calculation results
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\t计算结果:" + calculation.getResult() +
                        "\t计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results

    From the above code, we can see that the formula for fast interval summation is composed of two parentheses separated
    by commas.

计算层数:3	计算结果:24.0	计算来源:fast

Fast interval cumulative calculation component (based on parenthesis expression)

  • Full class
    name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FastMultiplyOfIntervalsBrackets

  • Introduction

    A new product of version 1.1.5, the interval fast accumulation component, is a fast component that accumulates all
    elements of an interval with an equal difference of n. It logically simulates an interval into a mathematical sequence
    and performs fast accumulation through the sum formula.

    This component implements the shared pool computing function. It will check, calculate, and record the results of the
    last time, which can speed up computing. The specific API calls are shown below.


import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.FastMultiplyOfIntervalsBrackets;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationNumberResults;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {
    public static void main(String[] args) throws WrongFormat {
        // Get the quick Multiply calculation component of the interval
        FastMultiplyOfIntervalsBrackets fast = FastMultiplyOfIntervalsBrackets.getInstance("fast");
        // Build an expression to be calculated.
        // The following expression indicates that the result of multiplying 11=(1+10) by 13=(20 - (5+2)) should be 143
        // The result should be 11 * 13=143
        String s = "1 + 10, 20 - (5 + 2)";
        // Check the expression. The shared pool has been enabled by default since version 1.2! No need to set manually
        // fast.setStartSharedPool(true);
        fast.check(s);
        // After version 1.2, the accumulation component supports setting step parameters, and since version 1.2.1, it officially supports the summation of step intervals
        fast.step = 2;
        // Start calculation
        CalculationNumberResults calculation = fast.calculation(s);
        // Print calculation results
        System.out.println(
                "计算层数:" + calculation.getResultLayers() + "\t计算结果:" + calculation.getResult() +
                        "\t计算来源:" + calculation.getCalculationSourceName()
        );
    }
}
  • Running results

    From the above code, we can see that the formula for fast interval summation is composed of two parentheses separated
    by commas

计算层数:3	计算结果:143.0	计算来源:fast

Complex calculation component

  • Full class name:io.github.beardedManZhao.mathematicalExpression.core.calculation.number.ComplexCalculation
  • Starting from version 1.4.5, we have implemented a calculation component for complex calculation expressions. It can
    calculate a mathematical expression such as (3 * 2-1)+2 * 3+f (10,5) i and return its object. We can use the
    returned object to perform a series of operations. Here is an example!
import io.github.beardedManZhao.algorithmStar.operands.ComplexNumber;
import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.ComplexCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.CalculationComplexResults;
import io.github.beardedManZhao.mathematicalExpression.core.container.ComplexExpression;
import io.github.beardedManZhao.mathematicalExpression.core.container.FunctionExpression;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

@Functions({
        "f(x, y) = x - y"
})
public class MAIN {
  public static void main(String[] args) throws WrongFormat {
    Mathematical_Expression.register_function(MAIN.class);
    // 将一个复数编译为计算表达式对象
    final ComplexCalculation instance = (ComplexCalculation) Mathematical_Expression.getInstance(Mathematical_Expression.complexCalculation);
    final String s = "3 * 2 - 1 + 2*3 + f(10, 5)i";
    instance.check(s);
    final ComplexExpression compile = instance.compile(s, true);

    // 我们还可以直接获取到复数的实部 和 虚部的表达式对象!
    final FunctionExpression real = compile.getFunctionExpression1();
    final FunctionExpression imaginary = compile.getFunctionExpression2();
    System.out.println(real.getExpressionStr());
    System.out.println(imaginary.getExpressionStr());

    // 直接计算出复数的结果
    final CalculationComplexResults calculation = compile.calculationCache(false);
    // 查看结果
    System.out.println(compile);
    System.out.println(calculation);
    // 获取到复数对象
    final ComplexNumber complexNumber = calculation.toComplexNumber();
    // 直接 使用科学计算库 参与共轭计算
    final ComplexNumber conjugate = complexNumber.conjugate();
    System.out.println(conjugate);
    // 还可以参与加法等运算 在这里是 自己 + 自己
    final ComplexNumber add = complexNumber.add(conjugate);
    System.out.println(add);

  }
}
  • Running results
3*2
-1+2*3+f(10,5)
io.github.beardedManZhao.mathematicalExpression.core.container.ComplexExpression@2698dc7
6.0 - 10.0i
6.0 + 10.0i
12.0 + 0.0i

Advanced Operations

Registration and calculation of mathematical functions


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {

    public static void main(String[] args) throws WrongFormat {
        // 将 f 函数注册进来
        Mathematical_Expression.register_function("f(x) = x * x");
        // 准备要计算的表达式
        final String data = "1 + f(20) + 3";
        // 获取到计算组件
        final Calculation instance = Mathematical_Expression.getInstance(Mathematical_Expression.functionFormulaCalculation2);
        // 检查与计算
        instance.check(data);
        System.out.println(instance.calculation(data));
    }
}
  • Running results
CalculationNumberResults{result=404.0, source='BracketsCalculation2'}

Registering anonymous implemented functions for computation


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

public class MAIN {

    public static void main(String[] args) throws WrongFormat {
        // 将 f 函数注册进来
        Mathematical_Expression.register_function(new ManyToOneNumberFunction("f") {
            @Override
            public double run(double... numbers) {
                return numbers[0] * numbers[0];
            }
        });
        // 准备要计算的表达式
        final String data = "1 + f(20) + 3";
        // 获取到计算组件
        final Calculation instance = Mathematical_Expression.getInstance(Mathematical_Expression.functionFormulaCalculation2);
        // 检查与计算
        instance.check(data);
        System.out.println(instance.calculation(data));
    }
}
  • Running results
CalculationNumberResults{result=404.0, source='BracketsCalculation2'}

Annotation based implementation of function registration and calculation



import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.Calculation;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

@Functions({
        // 这里是需要被注册的两个函数 在这里标记一下
        "f(x) = x * x",
        "ff(x) = f(x) + 1"
})
public class MAIN {

    public static void main(String[] args) throws WrongFormat {
        // 将 MAIN 类中标记的所有函数注册
        if (Mathematical_Expression.register_function(MAIN.class)) {
            // 构建需要计算的表达式
            final String string = "1 + ff(1 + 2) * 2";
            // 获取到函数计算组件
            Calculation calculation = Mathematical_Expression.getInstance(Mathematical_Expression.functionFormulaCalculation2);
            // 开始进行计算
            calculation.check(string);
            System.out.println(calculation.calculation(string));
        }
    }
}

Here are the calculation results

CalculationNumberResults{result=21.0, source='functionFormulaCalculation2'}

Directly Acquiring Function Objects and Saving Function Objects to Files

All function objects can be extracted, and functions registered based on “mathematical expression” can be saved to
files. We can directly perform serialization operations to save them. Below, we will show some examples.

Extracting Function Objects for Individual Computation

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

@Functions({
        // 这里是需要被注册的两个函数 在这里标记一下 分别是 f 和 ff 两个函数
        "f(x) = x * x",
        "ff(x) = f(x) + 1"
})
public class MAIN {

    public static void main(String[] args) throws WrongFormat {
        // 将 MAIN 类中标记的所有函数注册
        if (Mathematical_Expression.register_function(MAIN.class)) {
            // 获取到 ff 函数
            final ManyToOneNumberFunction ff = Mathematical_Expression.getFunction("ff");
            // 计算出结果
            final double run = ff.run(1024);
            System.out.println(run);
        }
    }
}

下面就是计算结果

1048577.0
Extracting Function Objects and Saving Them to Files

Note that if your saved function uses other functions, e.g., ff(x) = f(x) + 1, you need to save f(x) = x * x to the
file as well. The following demonstrates how to save a single function:


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ExpressionFunction;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;

@Functions({
        // 这里是需要被注册的两个函数 在这里标记一下 分别是 f 和 ff 两个函数
        "f(x) = x * x",
        "ff(x) = f(x) + 1"
})
public class MAIN {

    public static void main(String[] args) throws WrongFormat, IOException {
        // 将 MAIN 类中标记的所有函数注册
        if (Mathematical_Expression.register_function(MAIN.class)) {
            // 获取到 ff 函数
            final ManyToOneNumberFunction ff = Mathematical_Expression.getFunction("f");
            // 保存到文件 TODO ExpressionFunction 的函数是可以被保存到文件中的
            try (final ObjectOutputStream objectOutput = new ObjectOutputStream(Files.newOutputStream(Paths.get("C:\\Users\\zhao\\Desktop\\fsdownload\\f.me")))) {
                // 将 ff 保存到数据流中
                ((ExpressionFunction) ff).saveTo(objectOutput);
            }
        }
    }
}

In fact, you can also save multiple function objects to a single file, which helps resolve function dependency issues!


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;

import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ExpressionFunction;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

@Functions({
        // 这里是需要被注册的两个函数 在这里标记一下 分别是 f 和 ff 两个函数
        "f(x) = x * x",
        "ff(x) = f(x) + 1"
})
public class MAIN {

    public static void main(String[] args) throws WrongFormat, IOException {
        // 将 MAIN 类中标记的所有函数注册
        if (Mathematical_Expression.register_function(MAIN.class)) {
            // 获取到 ff 函数 以及 f 函数
            final ManyToOneNumberFunction ff = Mathematical_Expression.getFunction("ff");
            final ManyToOneNumberFunction f = Mathematical_Expression.getFunction("f");
            // 保存到文件 TODO ExpressionFunction 的函数是可以被保存到文件中的
            try (final ObjectOutputStream objectOutput = new ObjectOutputStream(Files.newOutputStream(Paths.get("C:\\Users\\zhao\\Desktop\\fsdownload\\f.me")))) {
                // 将 ff 和 f 保存到数据流中
                ((ExpressionFunction) ff).saveTo(objectOutput);
                ((ExpressionFunction) f).saveTo(objectOutput);
            }
        }
    }
}

Loading Function Objects Saved in Files into the Library

Functions can be serialized and, consequently, deserialized. After deserialization, you can either register them back
into the library or use them directly!!!

package utils;

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import function.io.github.beardedManZhao.mathematicalExpression.core.calculationExpressionFunction;
import function.io.github.beardedManZhao.mathematicalExpression.core.calculationManyToOneNumberFunction;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

public class MAIN {

    public static void main(String[] args) throws IOException {
        ManyToOneNumberFunction function;
        try (final ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(Paths.get("C:\\Users\\zhao\\Desktop\\fsdownload\\f.me")))) {
            // 在这里读取到函数对象
            function = ExpressionFunction.readFrom(objectInputStream);
        }
        // 把函数注册回 Mathematical_Expression
        Mathematical_Expression.register_function(function);
        // 也可以直接使用它
        final double run = function.run(1024);
        System.out.println(run);
    }
}

Deserialization also supports loading multiple function objects. Here’s an example:

package utils;

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import function.io.github.beardedManZhao.mathematicalExpression.core.calculationExpressionFunction;
import function.io.github.beardedManZhao.mathematicalExpression.core.calculationManyToOneNumberFunction;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.nio.file.Files;
import java.nio.file.Paths;

public class MAIN {

    public static void main(String[] args) throws IOException {
        ManyToOneNumberFunction ff, f;
        try (final ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(Paths.get("C:\\Users\\zhao\\Desktop\\fsdownload\\f.me")))) {
            // 在这里读取到函数对象(要注意这里和保存时的顺序一致哦!!)
            // 如果要是不确定顺序,可以读取直接读取出来注册到库里 库会自动将函数的名称解析出来
            ff = ExpressionFunction.readFrom(objectInputStream);
            f = ExpressionFunction.readFrom(objectInputStream);
        }
        // 把函数注册回 Mathematical_Expression
        Mathematical_Expression.register_function(ff);
        Mathematical_Expression.register_function(f);
        // 也可以直接使用它
        final double run = ff.run(1024);
        System.out.println(run);
    }
}

Batch Serialization/Registration of Functions

Starting from version 1.3.4, you can directly serialize/register functions using data streams within the
Mathematical_Expression class, which simplifies the code. Here’s an example:


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.Functions;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

import java.io.FileOutputStream;
import java.io.IOException;

@Functions({
        // 这里是需要被注册的两个函数 在这里标记一下 分别是 f 和 ff 以及 fff 几个函数
        "f(x) = x * x",
        "ff(x) = f(x) + 1",
        "fff(x) = x! + ff(x) + f(x)"
})
public class MAIN {

    public static void main(String[] args) throws IOException, WrongFormat {
        // 将函数注册一下
        Mathematical_Expression.register_function(MAIN.class);
        // 获取到 几个函数 的对象
        ManyToOneNumberFunction f = Mathematical_Expression.getFunction("f");
        ManyToOneNumberFunction ff = Mathematical_Expression.getFunction("ff");
        ManyToOneNumberFunction fff = Mathematical_Expression.getFunction("fff");
        // 直接将这几个函数输出到文件中
        try (final FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\zhao\\Desktop\\fsdownload\\f.ME")) {
            Mathematical_Expression.saveFunction(fileOutputStream, f, ff, fff);
        }
    }
}

Next, we can manually read the file into memory and use it, demonstrating the deserialization operation in
Mathematical_Expression.


import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.function.ManyToOneNumberFunction;
import io.github.beardedManZhao.mathematicalExpression.exceptional.WrongFormat;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;

public class MAIN {

    public static void main(String[] args) throws WrongFormat, IOException {
        // 将函数注册一下
        try (final FileInputStream fileInputStream = new FileInputStream("C:\\Users\\zhao\\Desktop\\fsdownload\\f.ME")) {
            // 直接在这里使用数据流来进行反序列化操作,这个数据流对应的文件包含的函数都会开始尝试注册
            final Map.Entry<Integer, Integer> integerIntegerEntry = Mathematical_Expression.register_function(fileInputStream);
            // 注册完毕之后在这里就可以查看到结果
            System.out.println("注册成功的数量:" + integerIntegerEntry.getKey());
            System.out.println("注册失败的数量:" + integerIntegerEntry.getValue());
        }
        // 然后我们就可以开始使用了 在这里的数据流中 包含的三个函数分别是 f ff fff
        final ManyToOneNumberFunction f = Mathematical_Expression.getFunction("f");
        final ManyToOneNumberFunction ff = Mathematical_Expression.getFunction("ff");
        final ManyToOneNumberFunction fff = Mathematical_Expression.getFunction("fff");
        System.out.println(f.run(10));
        System.out.println(ff.run(10));
        System.out.println(fff.run(10));
    }
}

Below are the calculation results:

[INFO][Calculation Management][24-03-22:01]] : A computing component is registered PrefixExpressionOperation
[INFO][Calculation Management][24-03-22:01]] : A computing component is registered BracketsCalculation2
[INFO][Calculation Management][24-03-22:01]] : A function is registered f
[INFO][Calculation Management][24-03-22:01]] : A function is registered ff
[INFO][Calculation Management][24-03-22:01]] : A function is registered fff
注册成功的数量:3
注册失败的数量:0
[INFO][Calculation Management][24-03-22:01]] : Get a function component from the manager. => f
[INFO][Calculation Management][24-03-22:01]] : Get a function component from the manager. => ff
[INFO][Calculation Management][24-03-22:01]] : Get a function component from the manager. => fff
[INFO][functionFormulaCalculation_temp][24-03-22:01]] : Use shared pool data. The identity of the data is: functionFormulaCalculation_temp(10.0*10.0)
100.0
[INFO][functionFormulaCalculation_temp][24-03-22:01]] : No Use shared pool: functionFormulaCalculation_temp(f(10.0) + 1)
[INFO][Calculation Management][24-03-22:01]] : Get a function component from the manager. => f
[INFO][functionFormulaCalculation_temp][24-03-22:01]] : Use shared pool data. The identity of the data is: functionFormulaCalculation_temp(10.0*10.0)
101.0
[INFO][functionFormulaCalculation_temp][24-03-22:01]] : No Use shared pool: functionFormulaCalculation_temp(10.0! + ff(10.0) + f(10.0))
[INFO][Calculation Management][24-03-22:01]] : Get a function component from the manager. => f
[INFO][functionFormulaCalculation_temp][24-03-22:01]] : Use shared pool data. The identity of the data is: functionFormulaCalculation_temp(10.0*10.0)
[INFO][Calculation Management][24-03-22:01]] : Get a function component from the manager. => ff
[INFO][functionFormulaCalculation_temp][24-03-22:01]] : Use shared pool data. The identity of the data is: functionFormulaCalculation_temp(f(10.0) + 1)
3629001.0

Mathematical expression compilation

Math expression compilation functionality translates a mathematical expression into an Expression object. All
calculation components that
implement io.github.beardedManZhao.mathematicalExpression.core.calculation.CompileCalculation can compile a
mathematical expression!
This operation enables users to store mathematical expressions or defer the computation time, allowing for features like
expression storage or deferring calculations. For expressions that need to be computed repeatedly, using a compiled
expression can save significant computation time!

PS: The support for io.github.beardedManZhao.mathematicalExpression.core.calculation.CompileCalculation will
gradually increase as the version increases!

Basic usage examples

The case demonstrated here is based on version 1.4.2, so you need to ensure that the version you are using is greater
than or equal to 1.4.2 before you can use it! The usage in version 1.4.1 is similar, but some features are not
supported!

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.PrefixExpressionOperation;
import io.github.beardedManZhao.mathematicalExpression.core.container.Expression;

public class MAIN {

  public static void main(String[] args) {
    // 获取到计算表达式组件
    final PrefixExpressionOperation instance = (PrefixExpressionOperation) Mathematical_Expression.getInstance(Mathematical_Expression.prefixExpressionOperation);
    // 将表达式 3*0.3 编译为一个表达式对象,我们在 1.4.1 版本中新增了compile & compileBigDecimal 方法,他们可以将表达式编译为对象,方便我们进行使用。
    final Expression compile = instance.compile("3 * 0.3", true);
    // 获取到计算结果 在这里有一个参数,设置为 false 性能会好些!设置为 true 功能会多些
    System.out.println(compile.calculationCache(true));
    // 我们可以使用这个表达式重复的计算,对于表达式对象来说 多次调用 calculationCache 的效率会很高
    // 除了第一次 calculationCache,其余调用 calculationCache 的复杂度皆为 O(1)
    System.out.println(compile.calculationCache(false));
    // 值得注意的是,在编译对象中,我们还提供了一个 calculationBigDecimalsCache 函数
    // 当我们在编译的时候 如果是使用 compile 编译出来的就需要使用 calculationCache 计算
    // 如果是使用 compileBigDecimal 编译出来的就需要使用 calculationBigDecimalsCache 计算
    if (compile.isBigDecimal()) {
      // 我们可以使用 isBigDecimal 函数来判断它是什么类型的计算模式
      System.out.println(compile.calculationBigDecimalsCache(false));
    }
  }
}

You can also manually adjust the calculation mode. Here is an example!

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.CompileCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.Expression;

public class MAIN {

  public static void run(Expression expression) {
    if (expression.isBigDecimal()) {
      // 代表支持高精度的计算 TODO 这里使用的是不带 cache 的计算 这是为了测试效果,事实上 在此案例之外,我们建议您使用 cache 的计算!
      System.out.println("高精度计算结果:" + expression.calculationBigDecimals(true).getResult());
    }
    if (expression.isUnBigDecimal()) {
      // 代表支持非高精度的计算
      System.out.println("非精度计算结果:" + expression.calculation(true).getResult());
    }
  }

  public static void main(String[] args) {
    // 获取到计算表达式组件
    final CompileCalculation instance = (CompileCalculation) Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2);
    // 将表达式 3*0.3 编译为一个表达式对象,我们在 1.4.1 版本中新增了compile & compileBigDecimal 方法,他们可以将表达式编译为对象,方便我们进行使用。
    final Expression compile = instance.compile("1 + (3 * 0.3)", true);
    // 运行表达式 这里第一次计算的时候 它因为 compile 的编译,只支持使用 非精度计算模式
    System.out.println("--------");
    run(compile);
    if (compile.isAvailable()) {
      // TODO 此函数需要确保您在 calculationCache or calculationBigDecimalsCache 调用时没有设置为 false
      //  我们可以通过 compile.isAvailable() 方法来判断是否支持多精度计算模块的启用 启用之后 您可以随意调用 calculationCache or calculationBigDecimalsCache
      // 将表达式的多精度支持模式启用 请注意 此操作仅可以对表达式的最后一层计算起作用!
      // 例如 1 + (3*0.3) 最后一层就是 1 + 0.899999(compile编译的) 或者 1 + 0.9(compileBigDecimal 编译的)
      compile.convertToMultiPrecisionSupported();
      // 运行表达式 TODO 这样操作之后 我们会发现它可以在两种模式中进行计算了
      System.out.println("--------");
      run(compile);
    }
  }
}
Serializing an expression object

The expression object inherits the ‘Java. io. Serializable’ interface, so you can use ‘Java. io. Object OutputStream’
and ‘Java. io. Object Input Stream’`
Serialize an expression object!

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.CompileCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.container.NameExpression;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class MAIN {
  public static void main(String[] args) throws IOException, ClassNotFoundException {
    // 获取到计算组件
    final CompileCalculation instance = (CompileCalculation) Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2);
    // 准备一个路径对象
    final Path path = Paths.get("C:\\Users\\zhao\\Downloads\\表达式.me");

    // 将表达式对象保存到磁盘
    try (final ObjectOutputStream objectOutputStream = new ObjectOutputStream(Files.newOutputStream(path))) {
      // 编译一个表达式对象
      final NameExpression compile = instance.compile(" 1 + (20 * 3 - 3 + (10 -4)) + (30 -2)  /2 + 10", true);
      // 将表达式对象输出到磁盘
      objectOutputStream.writeObject(compile);
    }

    // 再将表达式从磁盘读取进来
    try (final ObjectInputStream objectInputStream = new ObjectInputStream(Files.newInputStream(path))) {
      // 从磁盘中将表达式重新加载到内存
      final NameExpression expression = (NameExpression) objectInputStream.readObject();
      // 查看表达式的信息
      System.out.println("表达式来源:" + expression.getCalculationName());
      System.out.println("表达式的格式:" + expression.getExpressionStr());
      System.out.println("表达式支持的模式:" + (expression.isBigDecimal() ? "【高精度 √】 " : "【高精度 ×】 ") + (expression.isUnBigDecimal() ? "【非精度 √】 " : "【非精度 ×】 "));
      System.out.println(">>> 开始为表达式对象添加多精度支持");
      expression.convertToMultiPrecisionSupported();
      System.out.println("表达式支持的模式:" + (expression.isBigDecimal() ? "【高精度 √】 " : "【高精度 ×】 ") + (expression.isUnBigDecimal() ? "【非精度 √】 " : "【非精度 ×】 "));
      System.out.println("计算结果:" + expression.calculation(false));
    }
  }
}

Mathematical_Expression.Options

We allow you to use Mathematical_Expression.Options is used to configure some patterns of the calculation components
of mathematical expressions, and the configured options will change the behavior of the calculation components.

Set cache calculation mode setUseCache

The cache computation mode is a mode that sacrifices memory but improves computation speed. It is worth noting that
cache operations will accompany all of your subexpressions, which means that even if your expression is modified, as
long as it contains some computed expressions, it can still be used with cache. You can enable it by following the steps
below.

import io.github.beardedManZhao.mathematicalExpression.core.Mathematical_Expression;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.CompileCalculation;
import io.github.beardedManZhao.mathematicalExpression.core.calculation.number.BracketsCalculation2;
import io.github.beardedManZhao.mathematicalExpression.core.container.Expression;

public class MAIN {

  // 准备一个用于进行基准测试的表达式
  private static String s = "1 + 30 + (20 / 10)";

  static {
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += '+' + s;
    s += "+ 100000";
    System.out.println("您要计算的表达式:" + s);
  }

  public static void main(String[] args) {
    // 获取到计算表达式组件
    final BracketsCalculation2 instance = (BracketsCalculation2) Mathematical_Expression.getInstance(Mathematical_Expression.bracketsCalculation2);
    // 预热
    final Expression compile0 = instance.compileBigDecimal(s, true);
    System.out.println(compile0.calculationBigDecimalsCache(false));
    System.out.println("-------");

    // 开启缓存时非常快,能够有多快,取决于您的表达式中重复的子表达式的数量,数量越多 效果越明显
    Mathematical_Expression.Options.setUseCache(true);
    run(instance);
    System.out.println("-------");

    // 不开启缓存的计算速度就慢了许多
    Mathematical_Expression.Options.setUseCache(false);
    run(instance);
  }

  /**
   * 基准测试函数
   *
   * @param instance 需要使用的计算组件
   */
  public static void run(CompileCalculation instance) {
    final long l = System.currentTimeMillis();
    // 第一次进行编译
    final Expression compile = instance.compileBigDecimal(s, true);
    System.out.println(compile.calculationBigDecimalsCache(false));

    final long l1 = System.currentTimeMillis();
    System.out.println("第一次计算所用时间:" + (l1 - l));

    // 再一次进行编译 为了结果严谨,这里再次计算 且第二次表达式有所改动 整体除2
    final Expression compile1 = instance.compileBigDecimal('(' + s + ") / 2", true);
    System.out.println(compile1.calculationBigDecimalsCache(false));

    System.out.println("第二次计算所用时间:" + (System.currentTimeMillis() - l1));
  }
}

Java API Structure Chart

在这里插入图片描述

More information

  • 切换至 中文文档
  • mathematical-expression-py
  • mathematical-expression-JS
  • mathematical-expression-C++

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2283283.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

MVCC底层原理实现

MVCC的实现原理 了解实现原理之前&#xff0c;先理解下面几个组件的内容 1、 当前读和快照读 先普及一下什么是当前读和快照读。 当前读&#xff1a;读取数据的最新版本&#xff0c;并对数据进行加锁。 例如&#xff1a;insert、update、delete、select for update、 sele…

WPF实战案例 | C# WPF实现计算器源码

WPF实战案例 | C# WPF实现计算器源码 一、设计来源计算器应用程序讲解1.1 主界面1.2 计算界面 二、效果和源码2.1 界面设计&#xff08;XAML&#xff09;2.2 代码逻辑&#xff08;C#&#xff09;2.3 实现步骤总结 源码下载更多优质源码分享 作者&#xff1a;xcLeigh 文章地址&a…

vulnhub靶场【kioptrix-3】靶机

前言 靶机&#xff1a;kioptrix-3&#xff0c;IP地址为192.168.1.74 攻击&#xff1a;kali&#xff0c;IP地址为192.168.1.16 都采用虚拟机&#xff0c;网卡为桥接模式 文章中涉及的靶机&#xff0c;来源于vulnhub官网&#xff0c;想要下载&#xff0c;可自行访问官网下载&a…

无人机 PX4 飞控 | PX4源码添加自定义参数方法并用QGC显示与调整

无人机 PX4 飞控 | PX4源码添加自定义参数方法并用QGC显示与调整 0 前言 之前文章添加了一个自定义的模块&#xff0c;本篇文章在之前的自定义模块中&#xff0c;添加两个自定义参数 使用QGC显示出来&#xff0c;并通过QGC调整参数值&#xff0c;代码实现参数更新 新增的参…

【Linux】华为服务器使用U盘安装统信操作系统

目录 一、准备工作 1.1 下载UOS官方系统 &#xff11;.&#xff12;制作启动U盘 1.3 服务器智能管理系统iBMC 二、iBMC设置U盘启动 一、准备工作 1.1 下载UOS官方系统 服务器CPU的架构是x86-64还是aarch64&#xff09;,地址&#xff1a;统信UOS生态社区 - 打造操作系统创…

npm常见报错整理

npm install时报UNMET PEER DEPENDENCY 现象 npm install时报UNMET PEER DEPENDENCY,且执行npm install好几遍仍报这个。 原因 不是真的缺少某个包,而是安装的依赖版本不对,警告你应该安装某一个版本。 真的缺少某个包。 解决 看了下package.json文件,我的react是有的…

在宝塔安装部署mindoc

MinDoc简介 MinDoc 是一款针对IT团队开发的简单好用的文档管理系统。 MinDoc 的前身是 SmartWiki 文档系统。SmartWiki 是基于 PHP 框架 laravel 开发的一款文档管理系统。因 PHP 的部署对普通用户来说太复杂&#xff0c;所以改用 Golang 开发。可以方便用户部署和实用。 开…

蓝桥杯练习日常|递归-进制转换

蓝桥云课760数的计算 一、递归 题目&#xff1a; 我的解题代码&#xff1a; #include <iostream> using namespace std; int sum0; int main() {// 请在此输入您的代码int n;cin>>n;int fun(int n);fun(n); cout<<sum<<\n;return 0; } // void fu…

什么是CIDR技术? 它是如何解决路由缩放问题的

什么是CIDR技术&#xff1f; 它是如何解决路由缩放问题的 一. 什么是 CIDR&#xff1f;二. CIDR 是如何工作的&#xff1f;1. 高效地址分配2. 路由聚合&#xff08;Route Aggregation&#xff09;3. 精确满足需求 三. CIDR 的计算详解1. 子网掩码计算2. 地址范围计算3. 可用 IP…

单片机内存管理剖析

一、概述 在单片机系统中&#xff0c;内存资源通常是有限的&#xff0c;因此高效的内存管理至关重要。合理地分配和使用内存可以提高系统的性能和稳定性&#xff0c;避免内存泄漏和碎片化问题。单片机的内存主要包括程序存储器&#xff08;如 Flash&#xff09;和数据存储器&a…

Qt简单迷宫游戏

目录 你将学到你将准备你将改变你将设计你将编程开始界面游玩界面胜利界面其它bug修复 你可扩展下一篇博客要说的东西 你将学到 Qt中QKeySequence对象的基本创建Qt中QShortcut对象的基本应用Qt中QSoundEffect对象的基本应用 你将准备 在开始制作Qt简单迷宫游戏之前&#xff…

Ansys Thermal Desktop 概述

介绍 Thermal Desktop 是一种用于热分析和流体分析的通用工具。它可用于组件或系统级分析。 来源&#xff1a;CRTech 历史 Thermal Desktop 由 C&R Technologies (CR Tech) 开发。它采用了 SINDA/FLUINT 求解器。SINDA/FLUINT 最初由 CR Tech 的创始人为 NASA 的约翰逊航…

WPF基础 | WPF 基础概念全解析:布局、控件与事件

WPF基础 | WPF 基础概念全解析&#xff1a;布局、控件与事件 一、前言二、WPF 布局系统2.1 布局的重要性与基本原理2.2 常见布局面板2.3 布局的测量与排列过程 三、WPF 控件3.1 控件概述与分类3.2 常见控件的属性、方法与事件3.3 自定义控件 四、WPF 事件4.1 路由事件概述4.2 事…

西门子【Library of General Functions (LGF) for SIMATIC S7-1200 / S7-1500】

文章目录 概要整体架构流程技术名词解释技术细节小结 概要 通用函数库 (LGF) 扩展了 TIA Portal 中用于 PLC 编程的 STEP 7 指令&#xff08;数学函数、时间、计数器 等&#xff09;。该库可以不受限制地使用&#xff0c;并包含 FIFO 、搜索功能、矩阵计算、 astro 计…

Android实战经验篇-AndroidScrcpyClient投屏一

系列文章转如下链接&#xff1a; Android Display Graphics系列文章-汇总 Android实战经验篇-系列文章汇总 本文主要包括部分&#xff1a; 一、方案说明 1.1 适用场景 1.2 方案框架 二、功能演示 2.1 环境准备 2.2 演示 一、方案说明 1.1 适用场景 优秀的开源的scrc…

从 Spark 到 StarRocks:实现58同城湖仓一体架构的高效转型

作者&#xff1a;王世发&#xff0c;吴艳兴等&#xff0c;58同城数据架构部 导读&#xff1a; 本文介绍了58同城在其数据探查平台中引入StarRocks的实践&#xff0c;旨在提升实时查询性能。在面对传统Spark和Hive架构的性能瓶颈时&#xff0c;58同城选择StarRocks作为加速引擎&…

wangEditor富文本编辑器,Laravel上传图片配置和使用

文章目录 前言步骤1. 构造好前端模版2. 搭建后端存储3. 调试 前言 由于最近写项目需要使用富文本编辑器&#xff0c;使用的是VUE3.0版本所以很多不兼容&#xff0c;实际测试以后推荐使用wangEditor 步骤 构造好前端模版搭建后端存储调试 1. 构造好前端模版 安装模版 模版安…

【MySQL】我在广州学Mysql 系列——MySQL用户管理详解

ℹ️大家好&#xff0c;我是练小杰&#xff0c;本博客是春节前最后一篇了&#xff0c;在此感谢大佬们今年的支持&#xff01;&#xff01;&#x1f64f;&#x1f64f; 接下来将学习MYSQL用户管理的相关概念以及命令~~ 回顾&#xff1a;&#x1f449;【MYSQL触发器的使用】 数据…

2025年数学建模美赛 A题分析(3)楼梯使用方向偏好模型

2025年数学建模美赛 A题分析&#xff08;1&#xff09;Testing Time: The Constant Wear On Stairs 2025年数学建模美赛 A题分析&#xff08;2&#xff09;楼梯磨损分析模型 2025年数学建模美赛 A题分析&#xff08;3&#xff09;楼梯使用方向偏好模型 2025年数学建模美赛 A题分…

Spring Security(maven项目) 3.0.2.7版本

通过实践而发现真理&#xff0c;又通过实践而证实真理和发展真理。从感性认识而能动地发展到理性认识&#xff0c;又从理性认识而能动地指导革命实践&#xff0c;改造主观世界和客观世界。实践、认识、再实践、再认识&#xff0c;这种形式&#xff0c;循环往复以至无穷&#xf…