Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/core/config/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ private Settings(){}
public static boolean cacheDerivatives = true;

/**
* Denotes whether or not to cache Legrende polynomials
* Denotes whether or not to cache Legendre polynomials.
* <p><b>Note:</b> The field name "cacheLegrendePolynomials" contains a historical typo
* (correct spelling: "cacheLegendrePolynomials"). The name is kept unchanged for
* API and configuration file compatibility.
*/
public static boolean cacheLegrendePolynomials = true;

Expand Down
9 changes: 7 additions & 2 deletions src/core/functions/GeneralFunction.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Collections;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Function;
Expand Down Expand Up @@ -52,9 +53,13 @@ public abstract class GeneralFunction implements Evaluable, Differentiable, Simp
};

/**
* Caches derivatives with the key corresponding to the {@code varID} of the derivative
* Caches derivatives with the key corresponding to the {@code varID} of the derivative.
* <p><b>Thread-Safety:</b> Using {@link java.util.concurrent.ConcurrentHashMap} to allow
* concurrent get() and put() operations without explicit locking. Required for parallel
* Jacobian construction (e.g. {@code IntStream.parallel()} in CMDSolver).
* A plain {@code HashMap} would cause race conditions under concurrent access.
*/
protected final Map<String, GeneralFunction> derivatives = new HashMap<>();
protected final Map<String, GeneralFunction> derivatives = new ConcurrentHashMap<>();

/**
* Returns a String representation of this {@link GeneralFunction}
Expand Down
13 changes: 11 additions & 2 deletions src/core/tools/functiongenerators/LegrendePolynomial.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,25 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static java.lang.Math.*;
import static core.tools.MiscTools.*;

/**
* The methods in {@link LegrendePolynomial} deal with <a href="https://en.wikipedia.org/wiki/Legendre_polynomials">Legrende Polynomials</a>.
* The methods in {@link LegrendePolynomial} deal with
* <a href="https://en.wikipedia.org/wiki/Legendre_polynomials">Legendre Polynomials</a>.
* <p><b>Note:</b> The class name "LegrendePolynomial" contains a historical typo
* (correct spelling: "LegendrePolynomial"). The name is kept unchanged for API compatibility.
*/
public class LegrendePolynomial {

private static final Map<Integer, GeneralFunction> cache = new HashMap<>();
/**
* Thread-safe cache using ConcurrentHashMap.
* A plain HashMap would cause race conditions under concurrent access
* (multiple threads calling makeLegrendePolynomial() simultaneously).
*/
private static final Map<Integer, GeneralFunction> cache = new ConcurrentHashMap<>();
private static final String defaultVariable = "\\var";

private static GeneralFunction makeLegrendePolynomial(int n) {
Expand Down
2 changes: 1 addition & 1 deletion src/parsing/LatexReplacer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private LatexReplacer(){}
put(Pattern.compile("\\\\epsilon" + "(?![\\w.'[^\\x00-\\x7F]])"), "ϵ");
put(Pattern.compile("\\\\varepsilon" + "(?![\\w.'[^\\x00-\\x7F]])"), "ε");
put(Pattern.compile("\\\\Zeta" + "(?![\\w.'[^\\x00-\\x7F]])"), "Ζ");
put(Pattern.compile("\\\\zeto" + "(?![\\w.'[^\\x00-\\x7F]])"), "ζ");
put(Pattern.compile("\\\\zeta" + "(?![\\w.'[^\\x00-\\x7F]])"), "ζ"); // Fix: was "\\zeto" (typo)
put(Pattern.compile("\\\\Eta" + "(?![\\w.'[^\\x00-\\x7F]])"), "Η");
put(Pattern.compile("\\\\eta" + "(?![\\w.'[^\\x00-\\x7F]])"), "η");
put(Pattern.compile("\\\\Theta" + "(?![\\w.'[^\\x00-\\x7F]])"), "Θ");
Expand Down