| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 13632 |
\[\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)}
\]

(FPCore (x y z t) :precision binary64 (* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))
(FPCore (x y z t) :precision binary64 (* (- (* x 0.5) y) (sqrt (* 2.0 (* z (exp (* t t)))))))
double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0));
}
double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * sqrt((2.0 * (z * exp((t * t)))));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = (((x * 0.5d0) - y) * sqrt((z * 2.0d0))) * exp(((t * t) / 2.0d0))
end function
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = ((x * 0.5d0) - y) * sqrt((2.0d0 * (z * exp((t * t)))))
end function
public static double code(double x, double y, double z, double t) {
return (((x * 0.5) - y) * Math.sqrt((z * 2.0))) * Math.exp(((t * t) / 2.0));
}
public static double code(double x, double y, double z, double t) {
return ((x * 0.5) - y) * Math.sqrt((2.0 * (z * Math.exp((t * t)))));
}
def code(x, y, z, t): return (((x * 0.5) - y) * math.sqrt((z * 2.0))) * math.exp(((t * t) / 2.0))
def code(x, y, z, t): return ((x * 0.5) - y) * math.sqrt((2.0 * (z * math.exp((t * t)))))
function code(x, y, z, t) return Float64(Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(z * 2.0))) * exp(Float64(Float64(t * t) / 2.0))) end
function code(x, y, z, t) return Float64(Float64(Float64(x * 0.5) - y) * sqrt(Float64(2.0 * Float64(z * exp(Float64(t * t)))))) end
function tmp = code(x, y, z, t) tmp = (((x * 0.5) - y) * sqrt((z * 2.0))) * exp(((t * t) / 2.0)); end
function tmp = code(x, y, z, t) tmp = ((x * 0.5) - y) * sqrt((2.0 * (z * exp((t * t))))); end
code[x_, y_, z_, t_] := N[(N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(z * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[(t * t), $MachinePrecision] / 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_, t_] := N[(N[(N[(x * 0.5), $MachinePrecision] - y), $MachinePrecision] * N[Sqrt[N[(2.0 * N[(z * N[Exp[N[(t * t), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot e^{t \cdot t}\right)}
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 99.5% |
|---|---|
| Target | 99.5% |
| Herbie | 99.8% |
Initial program 99.5%
Simplified99.8%
[Start]99.5% | \[ \left(\left(x \cdot 0.5 - y\right) \cdot \sqrt{z \cdot 2}\right) \cdot e^{\frac{t \cdot t}{2}}
\] |
|---|---|
associate-*l* [=>]99.8% | \[ \color{blue}{\left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot e^{\frac{t \cdot t}{2}}\right)}
\] |
exp-sqrt [=>]99.8% | \[ \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \color{blue}{\sqrt{e^{t \cdot t}}}\right)
\] |
Applied egg-rr75.4%
[Start]99.8% | \[ \left(x \cdot 0.5 - y\right) \cdot \left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)
\] |
|---|---|
expm1-log1p-u [=>]98.6% | \[ \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)\right)}
\] |
expm1-udef [=>]75.4% | \[ \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\left(e^{\mathsf{log1p}\left(\sqrt{z \cdot 2} \cdot \sqrt{e^{t \cdot t}}\right)} - 1\right)}
\] |
sqrt-unprod [=>]75.4% | \[ \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\color{blue}{\sqrt{\left(z \cdot 2\right) \cdot e^{t \cdot t}}}\right)} - 1\right)
\] |
associate-*l* [=>]75.4% | \[ \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\sqrt{\color{blue}{z \cdot \left(2 \cdot e^{t \cdot t}\right)}}\right)} - 1\right)
\] |
exp-prod [=>]75.4% | \[ \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\sqrt{z \cdot \left(2 \cdot \color{blue}{{\left(e^{t}\right)}^{t}}\right)}\right)} - 1\right)
\] |
Simplified99.9%
[Start]75.4% | \[ \left(x \cdot 0.5 - y\right) \cdot \left(e^{\mathsf{log1p}\left(\sqrt{z \cdot \left(2 \cdot {\left(e^{t}\right)}^{t}\right)}\right)} - 1\right)
\] |
|---|---|
expm1-def [=>]98.6% | \[ \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{z \cdot \left(2 \cdot {\left(e^{t}\right)}^{t}\right)}\right)\right)}
\] |
expm1-log1p [=>]99.9% | \[ \left(x \cdot 0.5 - y\right) \cdot \color{blue}{\sqrt{z \cdot \left(2 \cdot {\left(e^{t}\right)}^{t}\right)}}
\] |
*-commutative [=>]99.9% | \[ \left(x \cdot 0.5 - y\right) \cdot \sqrt{\color{blue}{\left(2 \cdot {\left(e^{t}\right)}^{t}\right) \cdot z}}
\] |
associate-*l* [=>]99.9% | \[ \left(x \cdot 0.5 - y\right) \cdot \sqrt{\color{blue}{2 \cdot \left({\left(e^{t}\right)}^{t} \cdot z\right)}}
\] |
*-commutative [<=]99.9% | \[ \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \color{blue}{\left(z \cdot {\left(e^{t}\right)}^{t}\right)}}
\] |
exp-prod [<=]99.9% | \[ \left(x \cdot 0.5 - y\right) \cdot \sqrt{2 \cdot \left(z \cdot \color{blue}{e^{t \cdot t}}\right)}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 13632 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.3% |
| Cost | 14152 |
| Alternative 3 | |
|---|---|
| Accuracy | 90.0% |
| Cost | 8776 |
| Alternative 4 | |
|---|---|
| Accuracy | 90.2% |
| Cost | 8644 |
| Alternative 5 | |
|---|---|
| Accuracy | 86.4% |
| Cost | 7620 |
| Alternative 6 | |
|---|---|
| Accuracy | 86.1% |
| Cost | 7488 |
| Alternative 7 | |
|---|---|
| Accuracy | 86.7% |
| Cost | 7488 |
| Alternative 8 | |
|---|---|
| Accuracy | 84.9% |
| Cost | 7360 |
| Alternative 9 | |
|---|---|
| Accuracy | 57.2% |
| Cost | 6976 |
herbie shell --seed 2023263
(FPCore (x y z t)
:name "Data.Number.Erf:$cinvnormcdf from erf-2.0.0.0, A"
:precision binary64
:herbie-target
(* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (pow (exp 1.0) (/ (* t t) 2.0)))
(* (* (- (* x 0.5) y) (sqrt (* z 2.0))) (exp (/ (* t t) 2.0))))