linear_combination Tactic #
In this file, the linear_combination
tactic is created. This tactic, which
works over ring
s, attempts to simplify the target by creating a linear combination
of a list of equalities and subtracting it from the target. This file also includes a
definition for linear_combination_config
. A linear_combination_config
object can be passed into the tactic, allowing the user to specify a
normalization tactic.
Implementation Notes #
This tactic works by creating a weighted sum of the given equations with the given coefficients. Then, it subtracts the right side of the weighted sum from the left side so that the right side equals 0, and it does the same with the target. Afterwards, it sets the goal to be the equality between the lefthand side of the new goal and the lefthand side of the new weighted sum. Lastly, calls a normalization tactic on this target.
References #
Lemmas #
Configuration #
Part 1: Multiplying Equations by Constants and Adding Them Together #
Part 2: Simplifying #
Part 3: Matching the Linear Combination to the Target #
Part 4: Completed Tactic #
linear_combination
attempts to simplify the target by creating a linear combination
of a list of equalities and subtracting it from the target.
The tactic will create a linear
combination by adding the equalities together from left to right, so the order
of the input hypotheses does matter. If the normalize
field of the
configuration is set to false, then the tactic will simply set the user up to
prove their target using the linear combination instead of normalizing the subtraction.
Users may provide an optional with { exponent := n }
. This will raise the goal to the power n
before subtracting the linear combination.
Note: The left and right sides of all the equalities should have the same
type, and the coefficients should also have this type. There must be
instances of has_mul
and add_group
for this type.
- Input:
-
input
: the linear combination of proofs of equalities, given as a sum/difference of coefficients multiplied by expressions. The coefficients may be arbitrary pre-expressions; if a coefficient is an application of+
or-
it should be surrounded by parentheses. The expressions can be arbitrary proof terms proving equalities. Most commonly they are hypothesis namesh1, h2, ...
.If a coefficient is omitted, it is taken to be
1
. -
config
: alinear_combination_config
, which determines the tactic used for normalization; by default, this value is the standard configuration for a linear_combination_config. In the standard configuration,normalize
is set to tt (meaning this tactic is set to use normalization), andnormalization_tactic
is set toring_nf SOP
.
-
Example Usage:
example (x y : ℤ) (h1 : x*y + 2*x = 1) (h2 : x = y) :
x*y = -2*y + 1 :=
by linear_combination 1*h1 - 2*h2
example (x y : ℤ) (h1 : x*y + 2*x = 1) (h2 : x = y) :
x*y = -2*y + 1 :=
by linear_combination h1 - 2*h2
example (x y : ℤ) (h1 : x*y + 2*x = 1) (h2 : x = y) :
x*y = -2*y + 1 :=
begin
linear_combination -2*h2,
/- Goal: x * y + x * 2 - 1 = 0 -/
end
example (x y z : ℝ) (ha : x + 2*y - z = 4) (hb : 2*x + y + z = -2)
(hc : x + 2*y + z = 2) :
-3*x - 3*y - 4*z = 2 :=
by linear_combination ha - hb - 2*hc
example (x y : ℚ) (h1 : x + y = 3) (h2 : 3*x = 7) :
x*x*y + y*x*y + 6*x = 3*x*y + 14 :=
by linear_combination x*y*h1 + 2*h2
example (x y : ℤ) (h1 : x = -3) (h2 : y = 10) :
2*x = -6 :=
begin
linear_combination 2*h1 with {normalize := ff},
simp,
norm_cast
end
example (x y z : ℚ) (h : x = y) (h2 : x * y = 0) : x + y*z = 0 :=
by linear_combination (-y * z ^ 2 + x) * h + (z ^ 2 + 2 * z + 1) * h2 with { exponent := 2 }
constants (qc : ℚ) (hqc : qc = 2*qc)
example (a b : ℚ) (h : ∀ p q : ℚ, p = q) : 3*a + qc = 3*b + 2*qc :=
by linear_combination 3 * h a b + hqc
```