Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates. #201

Merged
merged 11 commits into from
Aug 25, 2023
Merged
21 changes: 19 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@ jobs:

build:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.21.x', '1.20.x' ]

steps:
- uses: actions/checkout@v3
with:
lfs: 'true'

- name: Set up Go
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: '1.21'
go-version: ${{ matrix.go-version }}

- name: Run golangci-lint
uses: golangci/golangci-lint-action@v3.7.0

- name: Check that `go generate ./...` has been run.
run: go install github.com/go-bindata/go-bindata/... && go generate ./expreduce/builtin.go && git diff --quiet

- name: Build
run: go build -v ./...

Expand All @@ -34,3 +41,13 @@ jobs:

- name: Test concurrency
run: go test -v -race ./... -run Concurrency

- name: GoReleaser Action
uses: goreleaser/goreleaser-action@v4.4.0
# Run only on new tag.
if: startsWith(github.ref, 'refs/tags/')
with:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ __debug_bin
.idea/vcs.xml

.idea/workspace.xml

dist/
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ builds:
- linux
goarch:
- amd64
- arm64
39 changes: 0 additions & 39 deletions .travis.yml

This file was deleted.

5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ This screenshot demonstrates the Jupyter notebook interface for Expreduce. This

[DOWNLOAD HERE](https://github.com/corywalker/expreduce/releases/latest)

If you just want to get started, you can download a binary release and run the software without any downloading Go or compiling. Head over to the [latest release](https://github.com/corywalker/expreduce/releases/latest) and download the correct package for your OS.
If you just want to get started, you can download a binary release and run the software without any downloading Go or compiling. Head over to the [latest release](https://github.com/corywalker/expreduce/releases/latest) and download the correct package for your OS/architecture.

## From source

You must have the [Git Large File Storage](https://git-lfs.github.com/) client (`git-lfs`) installed before cloning the repository.

```
$ go get github.com/corywalker/expreduce
$ expreduce
Expand Down Expand Up @@ -129,6 +127,7 @@ go generate ./...
go test ./...
# Or to test some important parts with helpful information printed:
go test -v github.com/corywalker/expreduce/expreduce -count=1
# To exit early, press Ctrl-\
```

The use of `go generate` might require the download of additional dependencies, for example `go install github.com/go-bindata/go-bindata/...@latest`.
3 changes: 3 additions & 0 deletions expreduce/builtin_arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func getArithmeticDefinitions() (defs []Definition) {
if params.Form == "TeXForm" {
return true, fmt.Sprintf("%v\\frac{%v}{%v}", prefix, numStr, denStr)
}
if params.Form == "FullForm" {
return false, ""
}
return true, fmt.Sprintf("%v(%v)/(%v)", prefix, numStr, denStr)
}
ok, res := toStringInfix(num.GetParts()[1:], delim, "System`Times", params)
Expand Down
19 changes: 17 additions & 2 deletions expreduce/builtin_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,8 +491,19 @@ func getSystemDefinitions() (defs []Definition) {

lhs, lhsIsExpr := this.GetParts()[1].(expreduceapi.ExpressionInterface)
if lhsIsExpr {
for i := range lhs.GetParts() {
lhs.GetParts()[i] = es.Eval(lhs.GetParts()[i])
headSym, headIsSym := &atoms.Symbol{}, false
if len(lhs.GetParts()) > 0 {
headSym, headIsSym = lhs.GetParts()[0].(*atoms.Symbol)
}
attrs := expreduceapi.Attributes{}
if headIsSym {
attrs = headSym.Attrs(es.GetDefinedMap())
}

if !(attrs.HoldAll || attrs.HoldAllComplete) {
for i := range lhs.GetParts() {
lhs.GetParts()[i] = es.Eval(lhs.GetParts()[i])
}
}
es.Define(lhs, this.GetParts()[2])
}
Expand Down Expand Up @@ -549,6 +560,10 @@ func getSystemDefinitions() (defs []Definition) {
&SameTest{"bar[m, 2]", "foo[m, 2]"},
&SameTest{"Null", "fizz[m_, k_] := buzz[m, k]"},
&SameTest{"buzz[m, 2]", "fizz[m, 2]"},

// Test with HoldAll. We should not evaluate the arguments even
// when setting.
&SameTest{"Attributes[holdTest]= {HoldAll};holdTest[1+1]:=\"pass\";holdTest[1+1]", "\"pass\""},
},
})
defs = append(defs, Definition{
Expand Down
21 changes: 18 additions & 3 deletions expreduce/resources.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion expreduce/resources/arithmetic.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@
`Sum[expr, {sym, n}]` returns the sum of `expr` evaluated with `sym` = 1 to `n`.

`Sum[expr, {sym, m, n}]` returns the sum of `expr` evaluated with `sym` = `m` to `n`.";
Attributes[Sum] = {HoldAll, ReadProtected, Protected};
Sum[i_Symbol, {i_Symbol, 0, n_Integer}] := 1/2*n*(1 + n);
Sum[i_Symbol, {i_Symbol, 1, n_Integer}] := 1/2*n*(1 + n);
Sum[i_Symbol, {i_Symbol, end_}] := 1/2*end*(1 + end);
Sum[i_Symbol, {i_Symbol, 0, n_Symbol}] := 1/2*n*(1 + n);
Sum[i_Symbol, {i_Symbol, 1, n_Symbol}] := 1/2*n*(1 + n);
Attributes[Sum] = {HoldAll, ReadProtected, Protected};
(* Infinite series *)
Sum[i_Symbol^(-2), {i_Symbol, 1, Infinity}] := Pi^2/6;
Sum[num_/(i_Symbol^2), {i_Symbol, 1, Infinity}] := num * Pi^2/6;
Tests`Sum = {
ESimpleExamples[
ESameTest[45, Sum[i, {i, 5, 10}]],
Expand All @@ -109,6 +112,10 @@
ESameTest[b+c+d+e, Sum[a, {a, {b, c, d, e}}]],
ESameTest[b g + c g + d g + e g + b h + c h + d h + e h, Sum[a*f, {a, {b, c, d, e}}, {f, {g, h}}]],
ESameTest[25 n (1 + 50 n), Sum[i, {i, n*50}]],
], ETests[
ESameTest[Sum[1/(n^2), {n, 1, Infinity}], Pi^2/6],
ESameTest[Sum[n^-2, {n, 1, Infinity}], Pi^2/6],
ESameTest[Sum[6/(n^2), {n, 1, Infinity}], Pi^2],
]
};

Expand Down
9 changes: 9 additions & 0 deletions expreduce/resources/power.m
Original file line number Diff line number Diff line change
Expand Up @@ -904,3 +904,12 @@
ESameTest[-2^(1/3)-I 2^(1/3) Sqrt[3], ComplexExpand[(-2)^(4/3)]],
]
};

Exp::usage = "`Exp[x]` returns the exponential of `x`.";
Attributes[Exp] = {Listable, NumericFunction, Protected, ReadProtected};
Exp[x_] := E^x;
Tests`Exp = {
ESimpleExamples[
ESameTest[Simplify[Exp[x] * Exp[y] == Exp[x + y]], True],
]
};
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ require (
github.com/blend/go-sdk v1.20220411.3 // indirect
github.com/chzyer/test v1.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible // indirect
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/image v0.11.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/corywalker/mathbigext v0.0.0-20181030033443-6dc8c7f3bee3 h1:Qj2F5FibC
github.com/corywalker/mathbigext v0.0.0-20181030033443-6dc8c7f3bee3/go.mod h1:VQijXw3k1MP2eHh/2nujf2MKurdAFSK77VnjqyoFxBw=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/kavehmz/prime v1.0.0 h1:7nwQQWxmw/DYw5/fQdphqkmgWmoln6zcvYav1v29Bo0=
Expand Down
10 changes: 10 additions & 0 deletions utils/precommit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set -e

echo "Generating files..."
go generate expreduce/builtin.go
echo "Running lint..."
golangci-lint run
echo "Running tests..."
go test -v ./...
go test -v -race ./... -run Concurrency
echo "SUCCESS!"