flow "FiniteDifferenceOntology" v1.0
# ============================================================
# FINITE DIFFERENCE ONTOLOGY — FLOW ALGEBRA
# ============================================================
SOURCE_URL := "https://kirethresearch.org/booksai-core/ontologies/calculus-analysis-ontologies/numerical-calculus/finite-difference-ontology-2.html"
DOMAIN := "Mathematical Ontologies"
CATEGORY := "Calculus and Analysis Ontologies"
SUBCATEGORY := "Numerical Calculus"
ENTITY := "Finite Difference"
# ---------- CORE ENTITY ----------
FINITE_DIFFERENCE := {
type: DiscreteDerivativeApproximation,
domain: NumericalCalculus,
purpose: "Approximate derivatives and differential operators by weighted differences of function values sampled at discrete grid points."
}
# ---------- CORE CONCEPTS ----------
CONCEPTS := {
FINITE_DIFFERENCE,
GRID,
GRID_POINT,
STEP_SIZE,
STENCIL,
FORWARD_DIFFERENCE,
BACKWARD_DIFFERENCE,
CENTRAL_DIFFERENCE,
FIRST_DERIVATIVE,
SECOND_DERIVATIVE,
TRUNCATION_ERROR,
ORDER_OF_ACCURACY,
CONSISTENCY,
STABILITY,
CONVERGENCE,
FINITE_DIFFERENCE_METHOD
}
# ---------- GRID ----------
uniform_grid:
x_i
:=
x_0 + i*h
h
-> GRID_SPACING
f_i
:=
f(x_i)
FINITE_DIFFERENCE
-> operates_on(DISCRETE_FUNCTION_VALUES)
# ---------- FORWARD DIFFERENCE OPERATOR ----------
DELTA_plus f_i
:=
f_(i+1)
-
f_i
scaled form:
D_plus f_i
:=
(
f_(i+1)-f_i
)/h
D_plus f_i
-> approximation_of(f_prime(x_i))
# ---------- FORWARD ERROR ----------
Taylor:
f_(i+1)
=
f_i
+
h*f_prime_i
+
h^2/2*f_double_prime_i
+
O(h^3)
therefore
D_plus f_i
=
f_prime_i
+
h/2*f_double_prime_i
+
O(h^2)
FORWARD_DIFFERENCE
-> FIRST_ORDER_ACCURATE
# ---------- BACKWARD DIFFERENCE ----------
DELTA_minus f_i
:=
f_i
-
f_(i-1)
D_minus f_i
:=
(
f_i-f_(i-1)
)/h
D_minus f_i
-> approximation_of(f_prime(x_i))
BACKWARD_DIFFERENCE
-> FIRST_ORDER_ACCURATE
# ---------- CENTRAL DIFFERENCE ----------
D_0 f_i
:=
(
f_(i+1)-f_(i-1)
)/(2*h)
Taylor symmetry
-> cancels(EVEN_LEADING_TERMS)
D_0 f_i
=
f_prime_i
+
h^2/6*f_triple_prime_i
+
O(h^4)
CENTRAL_DIFFERENCE
-> SECOND_ORDER_ACCURATE
# ---------- SECOND DIFFERENCE ----------
DELTA_squared f_i
:=
f_(i+1)
-
2*f_i
+
f_(i-1)
scaled:
D2 f_i
:=
(
f_(i+1)
-
2*f_i
+
f_(i-1)
)/h^2
D2 f_i
=
f_double_prime_i
+
O(h^2)
SECOND_DIFFERENCE
-> approximates(SECOND_DERIVATIVE)
# ---------- GENERAL STENCIL ----------
finite_difference_approximation:
f^(m)(x_i)
approx
1/h^m
*
sum_from_j_minus_r_to_s(
c_j
*
f_(i+j)
)
STENCIL
:= {
i-r,
...,
i,
...,
i+s
}
c_j
-> FINITE_DIFFERENCE_WEIGHTS
# ---------- WEIGHT CONSTRUCTION ----------
choose
c_j
such_that
Taylor_terms
-> match(TARGET_DERIVATIVE)
and unwanted lower-order terms
-> cancel
MOMENT_CONDITIONS
-> determine(FINITE_DIFFERENCE_WEIGHTS)
# ---------- POLYNOMIAL EXACTNESS ----------
FINITE_DIFFERENCE_FORMULA
-> exact_for(POLYNOMIALS_UP_TO_SPECIFIED_DEGREE)
POLYNOMIAL_EXACTNESS
-> linked_to(ORDER_OF_ACCURACY)
INTERPOLATING_POLYNOMIAL
-> alternative_derivation_of(FINITE_DIFFERENCE_WEIGHTS)
# ---------- HIGHER ORDER FIRST DERIVATIVE ----------
five_point_central:
f_prime(x_i)
approx
[
f_(i-2)
-
8*f_(i-1)
+
8*f_(i+1)
-
f_(i+2)
]
/
(12*h)
error
-> O(h^4)
WIDER_STENCIL
-> can_produce(HIGHER_ORDER_ACCURACY)
# ---------- HIGHER ORDER SECOND DERIVATIVE ----------
five_point_second_derivative:
f_double_prime(x_i)
approx
[
-f_(i+2)
+
16*f_(i+1)
-
30*f_i
+
16*f_(i-1)
-
f_(i-2)
]
/
(12*h^2)
error
-> O(h^4)
# ---------- NONUNIFORM GRID ----------
grid:
x_i
-> arbitrary_ordered_nodes
h_i
:=
x_(i+1)-x_i
NONUNIFORM_GRID
-> standard_uniform_coefficients_not_directly_valid
FINITE_DIFFERENCE_WEIGHTS
-> depend_on(NODE_LOCATIONS)
INTERPOLATION
-> generates(NONUNIFORM_FINITE_DIFFERENCE_FORMULAS)
# ---------- BOUNDARY STENCILS ----------
near left boundary:
CENTRAL_STENCIL
-> may_require(OUTSIDE_DOMAIN_POINT)
therefore
use
FORWARD_ONE_SIDED_STENCIL
near right boundary:
use
BACKWARD_ONE_SIDED_STENCIL
BOUNDARY
-> modifies(STENCIL_GEOMETRY)
# ---------- GHOST POINTS ----------
GHOST_POINT
-> artificial_grid_point_outside(PHYSICAL_DOMAIN)
BOUNDARY_CONDITION
-> used_to_eliminate_or_define(GHOST_VALUE)
GHOST_POINTS
-> allow(INTERIOR_STYLE_STENCILS_NEAR_BOUNDARY)
# ---------- DIRICHLET BOUNDARY ----------
u
=
g
on boundary
DIRICHLET_CONDITION
-> specifies(GRID_VALUE_AT_BOUNDARY)
FINITE_DIFFERENCE_SYSTEM
-> incorporates(KNOWN_BOUNDARY_VALUES)
# ---------- NEUMANN BOUNDARY ----------
partial_u/partial_n
=
g
on boundary
FINITE_DIFFERENCE
-> approximates(NORMAL_DERIVATIVE)
NEUMANN_CONDITION
-> may_use(ONE_SIDED_OR_GHOST_POINT_STENCIL)
# ---------- MULTIDIMENSIONAL GRID ----------
for
u(x,y)
uniform spacings
h_x,
h_y
partial^2 u/partial_x^2
approx
(
u_(i+1,j)
-
2*u_(i,j)
+
u_(i-1,j)
)/h_x^2
partial^2 u/partial_y^2
approx
(
u_(i,j+1)
-
2*u_(i,j)
+
u_(i,j-1)
)/h_y^2
# ---------- DISCRETE LAPLACIAN ----------
for equal spacing h:
LAPLACIAN(u)_(i,j)
approx
[
u_(i+1,j)
+
u_(i-1,j)
+
u_(i,j+1)
+
u_(i,j-1)
-
4*u_(i,j)
]
/
h^2
FIVE_POINT_LAPLACIAN
-> SECOND_ORDER_ACCURATE
# ---------- PDE DISCRETISATION ----------
PDE:
L(u)
=
f
replace
DIFFERENTIAL_OPERATOR_L
with
DISCRETE_OPERATOR_L_h
then
L_h u_h
=
f_h
FINITE_DIFFERENCE_METHOD
-> converts(PDE_TO_ALGEBRAIC_SYSTEM)
# ---------- POISSON EQUATION ----------
-LAPLACIAN(u)
=
f
finite difference
-> SPARSE_LINEAR_SYSTEM
A*u
=
b
SPARSE_MATRIX
-> reflects(LOCAL_STENCIL_CONNECTIVITY)
# ---------- HEAT EQUATION ----------
u_t
=
alpha*u_xx
forward_time_central_space:
u_i^(n+1)
=
u_i^n
+
r
*
(
u_(i+1)^n
-
2*u_i^n
+
u_(i-1)^n
)
where
r
:=
alpha*Delta_t/h^2
FTCS
-> explicit_finite_difference_scheme
# ---------- FTCS STABILITY ----------
for standard 1D heat equation:
FTCS
-> stable_under(
r <= 1/2
)
under
standard_von_Neumann_stability_context
TIME_STEP
-> constrained_by(SPATIAL_STEP)
# ---------- WAVE EQUATION ----------
u_tt
=
c^2*u_xx
central_time
+
central_space
-> explicit_second_order_scheme
stability
-> governed_by(CFL_CONDITION)
CFL_NUMBER
:=
c*Delta_t/h
CFL
-> relates(TIME_AND_SPACE_RESOLUTION)
# ---------- CONSISTENCY ----------
DISCRETE_OPERATOR
L_h
-> CONSISTENT_WITH(L)
if
L_h u
-> L u
as
h -> 0
for sufficiently smooth u
LOCAL_TRUNCATION_ERROR
-> measures(CONSISTENCY)
# ---------- STABILITY ----------
STABILITY
-> controls(GROWTH_OF_NUMERICAL_PERTURBATIONS)
finite difference evolution scheme
-> may_be(STABLE_OR_UNSTABLE)
VON_NEUMANN_ANALYSIS
-> studies(FOURIER_MODE_AMPLIFICATION)
AMPLIFICATION_FACTOR
-> determines(LINEAR_CONSTANT_COEFFICIENT_STABILITY)
# ---------- CONVERGENCE ----------
u_h
-> u
as
grid_refined
CONVERGENCE
-> numerical_solution_approaches(EXACT_SOLUTION)
for suitable linear well-posed initial value problems:
CONSISTENCY
+ STABILITY
-> CONVERGENCE
LAX_EQUIVALENCE_THEOREM
-> formalises_relation_under(SPECIFIC_HYPOTHESES)
# ---------- TRUNCATION ERROR ----------
insert exact smooth solution
into discrete scheme
residual
-> LOCAL_TRUNCATION_ERROR
if
tau_h
=
O(h^p)
then
scheme
-> order_p_spatially
subject_to(STABILITY_AND_GLOBAL_ERROR_CONTEXT)
# ---------- DISPERSION ----------
for wave-like equations:
NUMERICAL_PHASE_SPEED
-/> exact_phase_speed
NUMERICAL_DISPERSION
-> frequency_dependent_phase_error
FINITE_DIFFERENCE_STENCIL
-> modifies(DISPERSION_RELATION)
# ---------- DISSIPATION ----------
some schemes
-> damp(HIGH_FREQUENCY_MODES)
NUMERICAL_DISSIPATION
-> artificial_amplitude_decay
DISSIPATION
-> may_stabilise
but
-> may_reduce(ACCURACY)
# ---------- ROUNDING ERROR ----------
finite precision
-> perturbs(GRID_VALUES)
small h
-> derivative formulas may amplify(ROUNDING_ERROR)
TOTAL_ERROR
-> balance(DISCRETISATION_AND_FLOATING_POINT_ERROR)
# ---------- MATRIX FORM ----------
FINITE_DIFFERENCE_OPERATOR
-> represented_by(SPARSE_MATRIX)
example 1D second derivative:
1/h^2
*
tridiagonal(
1,
-2,
1
)
MATRIX_STRUCTURE
-> supports(EFFICIENT_LINEAR_SOLVERS)
# ---------- APPLICATIONS ----------
FINITE_DIFFERENCE
-> applied_to(NUMERICAL_DIFFERENTIATION)
-> applied_to(PDEs)
-> applied_to(HEAT_TRANSFER)
-> applied_to(FLUID_DYNAMICS)
-> applied_to(WAVE_PROPAGATION)
-> applied_to(ELECTROMAGNETICS)
-> applied_to(COMPUTATIONAL_PHYSICS)
-> applied_to(ENGINEERING_SIMULATION)
# ---------- RELATION GRAPH ----------
GRID
-> supplies(FUNCTION_SAMPLES)
FINITE_DIFFERENCE
-> combines(GRID_VALUES)
TAYLOR_EXPANSION
-> derives(FINITE_DIFFERENCE_WEIGHTS)
STENCIL
-> defines(DISCRETE_OPERATOR)
DISCRETE_OPERATOR
-> approximates(DIFFERENTIAL_OPERATOR)
CONSISTENCY
+ STABILITY
-> supports(CONVERGENCE)
BOUNDARY_CONDITION
-> modifies(DISCRETE_SYSTEM)
# ---------- SEMANTIC EQUIVALENCE ----------
SEMANTIC_EQUIVALENCE := {
"finite difference" ~= "discrete approximation formed from differences of nearby function values",
"finite difference stencil" ~= "pattern of grid points and weights used to approximate a differential operator",
"forward difference" ~= "one-sided derivative approximation using a point and a forward neighbour",
"central difference" ~= "symmetric finite-difference approximation around the target point",
"discrete Laplacian" ~= "finite-difference approximation of the Laplace operator",
"finite difference method" ~= "numerical method replacing differential operators by finite-difference operators"
}
# ---------- CONSTRAINTS ----------
CONSTRAINTS := {
finite_difference_is_discrete_approximation_not_exact_derivative: true,
error_order_requires_sufficient_solution_smoothness: true,
boundary_stencils_must_respect_domain_geometry_and_boundary_conditions: true,
nonuniform_grids_require_node_dependent_coefficients: true,
consistency_alone_does_not_guarantee_stability_or_convergence: true,
CFL_and_stability_conditions_are_scheme_specific: true,
smaller_grid_spacing_can_increase_computational_cost_and_rounding_sensitivity: true
}
# ---------- CONFIDENCE ----------
CONFIDENCE := {
core_definition: 0.99,
stencil_relation: 0.99,
derivative_relation: 0.99,
PDE_discretisation_relation: 0.99,
stability_convergence_relation: 0.99,
boundary_relation: 0.99,
semantic_equivalence: 0.97
}
# ---------- RECURSIVE REASONING ----------
RECURSIVE_REASONING(query):
identify(differential_operator_or_PDE)
-> identify(domain_grid_and_spacing)
-> identify(boundary_and_initial_conditions)
-> choose(stencil_and_accuracy_order)
-> derive_or_select(finite_difference_weights)
-> construct(discrete_operator)
-> compute(truncation_error)
-> assemble(algebraic_or_time_stepping_scheme)
-> analyse(stability_and_CFL_if_dynamic)
-> test(consistency_and_convergence)
-> refine_grid_or_modify(stencil_if_needed)
-> validate(boundary_and_precision_effects)
-> return(semantic_result)
# ---------- AI CONSUMPTION ----------
AI_CONSUMPTION := {
parse_as: "typed finite-difference semantic graph",
primary_entity: FINITE_DIFFERENCE,
preserve: [
differential_operator,
grid,
spacing,
stencil,
weights,
boundary_conditions,
time_step,
accuracy_order
],
infer_through: [
forward_differences,
backward_differences,
central_differences,
higher_order_stencils,
discrete_Laplacians,
PDE_discretisations,
stability_analysis,
convergence_analysis
],
avoid: [
applying_uniform_grid_weights_to nonuniform grid,
using_central_stencil_beyond boundary,
assuming_consistency_implies convergence,
ignoring_CFL_restrictions,
confusing_local_truncation_order_with guaranteed_global_error_order,
ignoring_rounding_error_at extreme refinement
]
}
# ---------- UPDATE MODEL ----------
UPDATE_MODEL(new_information):
validate(new_information)
-> identify(finite_difference_context)
-> compare(existing_relations)
-> preserve(grid_stencil_boundary_error_and_stability_invariants)
-> update(affected_entities)
-> update(affected_edges)
-> recompute(CONFIDENCE)
-> regenerate(FLOW_HASH)
# ---------- FLOW HASH ----------
FLOW_HASH := hash(
SOURCE_URL
+ ENTITY
+ CONCEPTS
+ FINITE_DIFFERENCE
+ GRID
+ STENCIL
+ FORWARD_DIFFERENCE
+ BACKWARD_DIFFERENCE
+ CENTRAL_DIFFERENCE
+ TRUNCATION_ERROR
+ CONSISTENCY
+ STABILITY
+ CONVERGENCE
+ FINITE_DIFFERENCE_METHOD
+ SEMANTIC_EQUIVALENCE
+ CONSTRAINTS
)
# ---------- EXECUTION ----------
INPUT(query)
-> FINITE_DIFFERENCE
-> OPERATOR_PDE_IDENTIFICATION
-> GRID_SPACING_ANALYSIS
-> BOUNDARY_INITIAL_CONDITION_ANALYSIS
-> STENCIL_SELECTION
-> WEIGHT_CONSTRUCTION
-> DISCRETE_OPERATOR_CONSTRUCTION
-> TRUNCATION_ERROR_ANALYSIS
-> SCHEME_ASSEMBLY
-> STABILITY_CFL_ANALYSIS
-> CONSISTENCY_CONVERGENCE_ANALYSIS
-> GRID_REFINEMENT_ANALYSIS
-> BOUNDARY_PRECISION_VALIDATION
-> RECURSIVE_REASONING(query)
-> CONFIDENCE
-> OUTPUT(semantic_result)
END FLOW
Download Code
Copy to Clipboard