| Alternative 1 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 6980 |
\[\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathbf{if}\;x \leq 3.5 \cdot 10^{-77}:\\
\;\;\;\;\frac{t_0}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot t_0}{z}\\
\end{array}
\]

(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
(FPCore (x y z) :precision binary64 (let* ((t_0 (/ (sin y) y))) (if (<= x 3.5e-77) (/ t_0 (/ z x)) (/ (* x t_0) z))))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
double code(double x, double y, double z) {
double t_0 = sin(y) / y;
double tmp;
if (x <= 3.5e-77) {
tmp = t_0 / (z / x);
} else {
tmp = (x * t_0) / z;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * (sin(y) / y)) / z
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = sin(y) / y
if (x <= 3.5d-77) then
tmp = t_0 / (z / x)
else
tmp = (x * t_0) / z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
public static double code(double x, double y, double z) {
double t_0 = Math.sin(y) / y;
double tmp;
if (x <= 3.5e-77) {
tmp = t_0 / (z / x);
} else {
tmp = (x * t_0) / z;
}
return tmp;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
def code(x, y, z): t_0 = math.sin(y) / y tmp = 0 if x <= 3.5e-77: tmp = t_0 / (z / x) else: tmp = (x * t_0) / z return tmp
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function code(x, y, z) t_0 = Float64(sin(y) / y) tmp = 0.0 if (x <= 3.5e-77) tmp = Float64(t_0 / Float64(z / x)); else tmp = Float64(Float64(x * t_0) / z); end return tmp end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
function tmp_2 = code(x, y, z) t_0 = sin(y) / y; tmp = 0.0; if (x <= 3.5e-77) tmp = t_0 / (z / x); else tmp = (x * t_0) / z; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]}, If[LessEqual[x, 3.5e-77], N[(t$95$0 / N[(z / x), $MachinePrecision]), $MachinePrecision], N[(N[(x * t$95$0), $MachinePrecision] / z), $MachinePrecision]]]
\frac{x \cdot \frac{\sin y}{y}}{z}
\begin{array}{l}
t_0 := \frac{\sin y}{y}\\
\mathbf{if}\;x \leq 3.5 \cdot 10^{-77}:\\
\;\;\;\;\frac{t_0}{\frac{z}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{x \cdot t_0}{z}\\
\end{array}
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 96.3% |
|---|---|
| Target | 99.6% |
| Herbie | 97.4% |
if x < 3.50000000000000013e-77Initial program 94.7%
Simplified87.9%
[Start]94.7% | \[ \frac{x \cdot \frac{\sin y}{y}}{z}
\] |
|---|---|
associate-*l/ [<=]98.0% | \[ \color{blue}{\frac{x}{z} \cdot \frac{\sin y}{y}}
\] |
times-frac [<=]80.0% | \[ \color{blue}{\frac{x \cdot \sin y}{z \cdot y}}
\] |
*-commutative [=>]80.0% | \[ \frac{\color{blue}{\sin y \cdot x}}{z \cdot y}
\] |
associate-*r/ [<=]87.9% | \[ \color{blue}{\sin y \cdot \frac{x}{z \cdot y}}
\] |
*-commutative [=>]87.9% | \[ \sin y \cdot \frac{x}{\color{blue}{y \cdot z}}
\] |
Applied egg-rr97.9%
[Start]87.9% | \[ \sin y \cdot \frac{x}{y \cdot z}
\] |
|---|---|
associate-*r/ [=>]80.0% | \[ \color{blue}{\frac{\sin y \cdot x}{y \cdot z}}
\] |
associate-/r* [=>]79.6% | \[ \color{blue}{\frac{\frac{\sin y \cdot x}{y}}{z}}
\] |
associate-*l/ [<=]94.7% | \[ \frac{\color{blue}{\frac{\sin y}{y} \cdot x}}{z}
\] |
associate-/l* [=>]97.9% | \[ \color{blue}{\frac{\frac{\sin y}{y}}{\frac{z}{x}}}
\] |
if 3.50000000000000013e-77 < x Initial program 99.8%
Final simplification98.6%
| Alternative 1 | |
|---|---|
| Accuracy | 97.4% |
| Cost | 6980 |
| Alternative 2 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 13764 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.3% |
| Cost | 13764 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.7% |
| Cost | 7113 |
| Alternative 5 | |
|---|---|
| Accuracy | 95.6% |
| Cost | 7112 |
| Alternative 6 | |
|---|---|
| Accuracy | 95.8% |
| Cost | 6848 |
| Alternative 7 | |
|---|---|
| Accuracy | 66.3% |
| Cost | 968 |
| Alternative 8 | |
|---|---|
| Accuracy | 66.5% |
| Cost | 968 |
| Alternative 9 | |
|---|---|
| Accuracy | 65.7% |
| Cost | 841 |
| Alternative 10 | |
|---|---|
| Accuracy | 65.7% |
| Cost | 840 |
| Alternative 11 | |
|---|---|
| Accuracy | 65.6% |
| Cost | 840 |
| Alternative 12 | |
|---|---|
| Accuracy | 65.7% |
| Cost | 840 |
| Alternative 13 | |
|---|---|
| Accuracy | 66.2% |
| Cost | 840 |
| Alternative 14 | |
|---|---|
| Accuracy | 66.2% |
| Cost | 704 |
| Alternative 15 | |
|---|---|
| Accuracy | 58.4% |
| Cost | 192 |
herbie shell --seed 2023272
(FPCore (x y z)
:name "Linear.Quaternion:$ctanh from linear-1.19.1.3"
:precision binary64
:herbie-target
(if (< z -4.2173720203427147e-29) (/ (* x (/ 1.0 (/ y (sin y)))) z) (if (< z 4.446702369113811e+64) (/ x (* z (/ y (sin y)))) (/ (* x (/ 1.0 (/ y (sin y)))) z)))
(/ (* x (/ (sin y) y)) z))