7. Root brackets, decreasing logarithms, and singularities¶
This chapter applies the earlier lessons to three situations where the mathematical domain determines what a solver result means. The examples use exact real constants and keep the assertion being checked small enough to inspect independently.
Prerequisites: logarithmic relations, inverse branches, and rational bounds.
Bracket a root on a monotonic interval¶
Suppose you need the principal solution of sin(x) = 1/2. An exact decimal
is unnecessary if the application needs only a certified interval.
Define f(x) = sin(x) - 1/2 and choose the endpoints 1/2 and 3/5.
The program asks whether either of those strict sign conditions fails.
Its unsat result certifies both endpoint inequalities:
var half = tm.mkTerm(Kind.DIVISION, one, two)
var upper = tm.mkTerm(Kind.DIVISION, three, five)
var left_sine = tm.mkTerm(Kind.SINE, half)
var right_sine = tm.mkTerm(Kind.SINE, upper)
solver.assertFormula(tm.mkTerm(Kind.OR,
tm.mkTerm(Kind.GEQ, left_sine, half),
tm.mkTerm(Kind.LEQ, right_sine, half)))
var result = solver.checkSat()
assert_true(result.isUnsat())
print("opposite endpoint signs certified:", result)
Sine is continuous, so the intermediate value theorem gives a root in the
open interval (1/2, 3/5). Sine is strictly increasing throughout this
interval, which lies inside (-π/2, π/2), so that root is unique there.
Consequently the principal inverse sine of one half lies in the bracket.
The familiar exact value π/6 is consistent with the result, but was not
used to construct the query.
There are two distinct parts to this reasoning: the solver certifies the endpoint signs; continuity and strict monotonicity supply the mathematical existence and uniqueness argument. The program does not ask the solver to prove these general theorems or return an exact root model.
Complete root bracket program and expected output
"""Certify opposite signs at the endpoints of a sine root bracket."""
from std.testing import assert_true
from cvc5_mojo import TermManager, Solver, Kind
def main() raises:
var tm = TermManager()
var solver = Solver(tm)
solver.setLogic("QF_NRAT")
solver.setOption("tlimit-per", "5000")
solver.setOption("rlimit-per", "100000")
var one = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(1))
var two = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(2))
var three = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(3))
var five = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(5))
var half = tm.mkTerm(Kind.DIVISION, one, two)
var upper = tm.mkTerm(Kind.DIVISION, three, five)
var left_sine = tm.mkTerm(Kind.SINE, half)
var right_sine = tm.mkTerm(Kind.SINE, upper)
solver.assertFormula(tm.mkTerm(Kind.OR,
tm.mkTerm(Kind.GEQ, left_sine, half),
tm.mkTerm(Kind.LEQ, right_sine, half)))
var result = solver.checkSat()
assert_true(result.isUnsat())
print("opposite endpoint signs certified:", result)
Run from the repository root pixi run --locked mojo run -I src docs/examples/root_bracket.mojo
Output
opposite endpoint signs certified: unsat
Refine the bracket without losing the guarantee¶
For an increasing continuous function with opposite strict signs at a
and b, form the exact rational midpoint m = (a+b)/2. Prove the sign of
f(m) using another counterexample query. If it is negative, replace a
with m; if positive, replace b with m. If equality is established,
you have the root. If the sign query is inconclusive, keep the old bracket.
An unknown result cannot justify discarding either half.
The same approach needs a different uniqueness argument outside a monotonic interval. Opposite endpoint signs alone establish existence, not uniqueness, and equal signs do not rule out roots in between.
Work with a logarithm base below one¶
Change of base gives the following formula on its real domain:
Dividing by the negative denominator reverses an inequality. For the concrete base one half, this yields:
The sign of the denominator is the essential step. This program encodes
base_log = ln(1/2) and rules out a nonnegative value:
var base = tm.mkTerm(Kind.DIVISION, one, two)
var base_log = tm.mkConst(tm.getRealSort(), "base_log")
solver.assertFormula(tm.mkTerm(Kind.EQUAL,
tm.mkTerm(Kind.EXPONENTIAL, base_log), base))
solver.assertFormula(tm.mkTerm(Kind.GEQ, base_log, zero))
var result = solver.checkSat()
assert_true(result.isUnsat())
print("ln(1/2) >= 0:", result)
Complete decreasing-base program and expected output
"""Check the negative logarithm of a base between zero and one."""
from std.testing import assert_true
from cvc5_mojo import TermManager, Solver, Kind
def main() raises:
var tm = TermManager()
var solver = Solver(tm)
solver.setLogic("QF_NRAT")
solver.setOption("tlimit-per", "5000")
solver.setOption("rlimit-per", "100000")
var zero = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(0))
var one = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(1))
var two = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(2))
var base = tm.mkTerm(Kind.DIVISION, one, two)
var base_log = tm.mkConst(tm.getRealSort(), "base_log")
solver.assertFormula(tm.mkTerm(Kind.EQUAL,
tm.mkTerm(Kind.EXPONENTIAL, base_log), base))
solver.assertFormula(tm.mkTerm(Kind.GEQ, base_log, zero))
var result = solver.checkSat()
assert_true(result.isUnsat())
print("ln(1/2) >= 0:", result)
Run from the repository root pixi run --locked mojo run -I src docs/examples/logarithm_base.mojo
Output
ln(1/2) >= 0: unsat
For a threshold of two, use the exact endpoint (1/2)^2 = 1/4, giving
log_(1/2)(x) > 2 precisely when 0 < x < 1/4. The inequality is strict:
x = 1/4 makes the logarithm equal to two. Omitting positivity would
incorrectly admit zero and negative arguments.
If the base is symbolic and may lie on either side of one, split the cases
0 < b < 1 and b > 1, excluding one in both. A single inequality direction
does not cover both cases. For a fixed threshold, a justified rewrite can
also avoid the product of two symbolic terms in the general logarithm
relation. The budget comparison
shows why that can matter computationally.
Keep tangent away from its poles¶
The quotient definition of tangent has an explicit domain:
For a principal-branch application, -π/2 < x < π/2 selects one interval
between poles. When an application also needs a numerical margin from a
pole, use justified stricter endpoints or a bound such as cos(x) >= c
with a fixed positive c. That margin is an additional requirement; it
changes the allowed inputs and should come from the application.
The example includes the nonzero-denominator condition, verifies tangent
at zero, and separately checks that the endpoint π/2 fails the domain:
var sine = tm.mkTerm(Kind.SINE, angle)
var cosine = tm.mkTerm(Kind.COSINE, angle)
solver.assertFormula(tm.mkTerm(Kind.DISTINCT, cosine, zero))
var tangent = tm.mkTerm(Kind.DIVISION, sine, cosine)
solver.assertFormula(tm.mkTerm(Kind.EQUAL, angle, zero))
solver.assertFormula(tm.mkTerm(Kind.DISTINCT, tangent, zero))
var value_result = solver.checkSat()
assert_true(value_result.isUnsat())
print("tan(0) != 0 on its domain:", value_result)
Complete tangent-domain program and expected output
"""Keep cosine nonzero when expressing tangent as a quotient."""
from std.testing import assert_true
from cvc5_mojo import TermManager, Solver, Kind
def main() raises:
var tm = TermManager()
var zero = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(0))
var two = tm.mkTerm(Kind.TO_REAL, tm.mkInteger(2))
var angle = tm.mkConst(tm.getRealSort(), "angle")
var solver = Solver(tm)
solver.setLogic("QF_NRAT")
solver.setOption("tlimit-per", "5000")
solver.setOption("rlimit-per", "100000")
var sine = tm.mkTerm(Kind.SINE, angle)
var cosine = tm.mkTerm(Kind.COSINE, angle)
solver.assertFormula(tm.mkTerm(Kind.DISTINCT, cosine, zero))
var tangent = tm.mkTerm(Kind.DIVISION, sine, cosine)
solver.assertFormula(tm.mkTerm(Kind.EQUAL, angle, zero))
solver.assertFormula(tm.mkTerm(Kind.DISTINCT, tangent, zero))
var value_result = solver.checkSat()
assert_true(value_result.isUnsat())
print("tan(0) != 0 on its domain:", value_result)
var pole_solver = Solver(tm)
pole_solver.setLogic("QF_NRAT")
pole_solver.setOption("tlimit-per", "5000")
pole_solver.setOption("rlimit-per", "100000")
var half_pi = tm.mkTerm(Kind.DIVISION, tm.mkTerm(Kind.PI), two)
pole_solver.assertFormula(tm.mkTerm(Kind.DISTINCT,
tm.mkTerm(Kind.COSINE, half_pi), zero))
var pole_result = pole_solver.checkSat()
assert_true(pole_result.isUnsat())
print("pi/2 satisfies the tangent domain:", pole_result)
Run from the repository root pixi run --locked mojo run -I src docs/examples/tangent_domain.mojo
Output
tan(0) != 0 on its domain: unsat
pi/2 satisfies the tangent domain: unsat
Constructing a division term does not by itself add the classical domain restriction to your problem. Preserve the restriction explicitly when replacing a native function with a quotient. Do not interpret a value at an excluded pole as a value of the ordinary real tangent.
Cross-multiplication also needs care. If cos(x) > 0, then
sin(x)/cos(x) < t is equivalent to sin(x) < t*cos(x). If cos(x) < 0,
reverse the comparison. Merely knowing that the denominator is nonzero
is enough for an equality transformation, but not for choosing the direction
of an inequality.
Exercise: diagnose two invalid rewrites¶
A model replaces log_(1/2)(x) > 0 with x > 1, and replaces
tan(x) < 1 with sin(x) < cos(x) for every angle. What is missing?
Worked answer. The logarithm is decreasing, so the first condition is
0 < x < 1. The tangent rewrite is valid where cosine is positive.
Where cosine is negative the comparison reverses, and cosine zero must be
excluded. A restriction to (-π/2, π/2) justifies the positive case.
Continue with the damped oscillation application, which combines exponential and sine bounds into a complete envelope calculation.