Skip to content

Commit

Permalink
identified an issue with multiple-inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
quffaro committed Jun 10, 2024
1 parent 57ff35d commit 8e10590
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 55 deletions.
2 changes: 0 additions & 2 deletions src/stdlib/models/twosorted.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,3 @@ end
@withmodel RMatricesTwo() (e, i, , zero, unit, *, +, -, ) begin
i(2rand(2,2) rand(2,2))
end
# @time -1*(2*rand(2,2) + rand(2,2))

49 changes: 5 additions & 44 deletions src/stdlib/theories/algebra.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export ThEmpty, ThSet, ThMagma, ThSemiGroup, ThMonoid, ThGroup, ThCMonoid, ThAb, ThSemiRing, ThRing, ThCRing, ThDiffRing, ThBooleanRing, ThDivisionRing, ThField, ThCRig, ThElementary, ThPreorder, ThLeftModule, ThRightModule, ThBiModule, ThModule, ThCommRModule
export ThEmpty, ThSet, ThMagma, ThSemiGroup, ThMonoid, ThGroup, ThCMonoid, ThAb, ThSemiRing, ThRing, ThCommRing, ThDiffRing, ThBooleanRing, ThDivisionRing, ThCRig, ThElementary, ThPreorder, ThLeftModule, ThRightModule, ThModule, ThCommRModule

import Base: +, *, zero, one

Expand Down Expand Up @@ -122,7 +122,7 @@ Examples:
-
"""
@theory ThCRing begin
@theory ThCommRing begin
using ThRing
x * y == y * x [x,y]
end
Expand All @@ -131,7 +131,7 @@ end
A commutative ring equipped with a *derivation* operator `d` which fulfills linearity and the Leibniz product rule.
"""
@theory ThDiffRing begin
using ThCRing
using ThCommRing
d(x) :: default [x::default]
d(x + y) == d(x) + d(y) [x::default, y::default]
d(x*y) == d(x)*y + x*d(y) [x::default, y::default]
Expand All @@ -144,7 +144,7 @@ Examples:
"""
@theory ThBooleanRing begin
using ThCRing
using ThCommRing
x * x == x [x]
end

Expand All @@ -160,41 +160,13 @@ end
x * i(x) == one() [x]
end

# TODO: how to handle cases where RHS of axiom must be a different sort (e.g., nonzero) than those on the LHS (e.g., default)? Can we define a sort which inherits axioms defined on another sort (default)?
""" The theory of a commutative ring where multiplication by nonzero elements is nonzero
-
"""
# @theory ThIntegralDomain begin
# using ThCRing
# nonzero::TYPE
# # using ThCRing: default as nonzero
# x * y == z ⊣ [x::nonzero, y::nonzero, z::nonzero]
# end

# using two theories which overlap considerably, we can still add unique elem
# best to export default as K or something
""" The theory of a commutative division ring
- The rational numbers ℚ and algebraic extensions, i.e. ℚ[√2]
- The real numbers ℝ and its algebraic completion, the complex numbers ℂ
-
"""
@theory ThField begin
using ThDivisionRing
using ThCRing
end
# TODO user needs to define inv as 0 when 0

@theory ThCRig begin
using ThRig
a * b == b * a [a,b]
end

@theory ThElementary begin
using ThCRing
using ThCommRing
sin(x) [x]
cos(x) [x]
tan(x) [x]
Expand Down Expand Up @@ -285,17 +257,6 @@ end
# 1.b: it does not exist in the old theory
# 2. ThBiModule contributes both Left and Right Modules. Since the scalars are being renamed (to the same name), they are checked if they have new

# TODO we do not change the idents, so M and Scalar show
# @theory __ThModule begin
# using ThLeftModule
# using ThRightModule
# end

@theory ThVectorSpace begin
using ThModule
using ThField: default as Scalar, i as inv
end

# TODO Fix axioms
@theory ThCommRModule begin
using ThModule
Expand Down
7 changes: 7 additions & 0 deletions src/stdlib/theories/dec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ end
ap x) == α ap(x) [x::DomVector]
end

# TODO current implementation of multiple-inheritance does not overload the axioms in Form1 and Form2 Modules, so they are treated as the same and therefore eliminated.
#
# @theory _CoChains begin
# using Module: M as Form0
# using Module: M as Form1
# using Module: M as Form2
# end
@theory CoChains begin
using Module: Vector as Form0
using Module: Vector as Form1
Expand Down
11 changes: 2 additions & 9 deletions src/syntax/TheoryInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ function rename_impl(newname, body, __module__)
#
lines = Any[]
newnames = Symbol[]

## XXX "for binding in segment" was "... in newsegment", and I wrapped this
## in a for-loop for segments. This was done to debug an issue with ModelInterface
## where the `default` function was not being declared.
##
## owen: this should be in newsegment as before

for segment in newtheory.segments.scopes
for binding in segment
judgment = getvalue(binding)
Expand Down Expand Up @@ -258,9 +253,7 @@ function theory_impl(head, body, __module__)

theory = fromexpr(parent, body, GAT; name, current_module=fqmn(__module__))


newsegment = theory.segments.scopes[end]
# @info "NEWSEGMENT" newsegment
# newsegment = theory.segments.scopes[end]
docstr = repr(theory)

lines = Any[]
Expand Down

0 comments on commit 8e10590

Please sign in to comment.