
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
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
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (/ (* x (/ (sin y) y)) z))
double code(double x, double y, double z) {
return (x * (sin(y) / y)) / z;
}
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
public static double code(double x, double y, double z) {
return (x * (Math.sin(y) / y)) / z;
}
def code(x, y, z): return (x * (math.sin(y) / y)) / z
function code(x, y, z) return Float64(Float64(x * Float64(sin(y) / y)) / z) end
function tmp = code(x, y, z) tmp = (x * (sin(y) / y)) / z; end
code[x_, y_, z_] := N[(N[(x * N[(N[Sin[y], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
\begin{array}{l}
\\
\frac{x \cdot \frac{\sin y}{y}}{z}
\end{array}
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= y 2e-8) (/ x z) (* (sin y) (/ x (* y z)))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (y <= 2e-8) {
tmp = x / z;
} else {
tmp = sin(y) * (x / (y * z));
}
return tmp;
}
NOTE: y should be positive before calling this 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) :: tmp
if (y <= 2d-8) then
tmp = x / z
else
tmp = sin(y) * (x / (y * z))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if (y <= 2e-8) {
tmp = x / z;
} else {
tmp = Math.sin(y) * (x / (y * z));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if y <= 2e-8: tmp = x / z else: tmp = math.sin(y) * (x / (y * z)) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if (y <= 2e-8) tmp = Float64(x / z); else tmp = Float64(sin(y) * Float64(x / Float64(y * z))); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 2e-8) tmp = x / z; else tmp = sin(y) * (x / (y * z)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[y, 2e-8], N[(x / z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * N[(x / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{-8}:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \frac{x}{y \cdot z}\\
\end{array}
\end{array}
if y < 2e-8Initial program 96.5%
associate-*l/98.4%
times-frac83.8%
*-commutative83.8%
associate-*r/81.3%
*-commutative81.3%
Simplified81.3%
Taylor expanded in y around 0 77.0%
if 2e-8 < y Initial program 92.5%
associate-*l/91.9%
times-frac97.0%
*-commutative97.0%
associate-*r/97.2%
*-commutative97.2%
Simplified97.2%
Final simplification82.8%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x (* (/ y (sin y)) z)))
y = abs(y);
double code(double x, double y, double z) {
return x / ((y / sin(y)) * z);
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / ((y / sin(y)) * z)
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / ((y / Math.sin(y)) * z);
}
y = abs(y) def code(x, y, z): return x / ((y / math.sin(y)) * z)
y = abs(y) function code(x, y, z) return Float64(x / Float64(Float64(y / sin(y)) * z)) end
y = abs(y) function tmp = code(x, y, z) tmp = x / ((y / sin(y)) * z); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / N[(N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{\frac{y}{\sin y} \cdot z}
\end{array}
Initial program 95.3%
associate-/l*98.0%
Simplified98.0%
clear-num97.8%
associate-/r/97.9%
clear-num98.0%
Applied egg-rr98.0%
Final simplification98.0%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= y 0.0255) (/ x z) (* x (/ (/ 6.0 z) (* y y)))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (y <= 0.0255) {
tmp = x / z;
} else {
tmp = x * ((6.0 / z) / (y * y));
}
return tmp;
}
NOTE: y should be positive before calling this 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) :: tmp
if (y <= 0.0255d0) then
tmp = x / z
else
tmp = x * ((6.0d0 / z) / (y * y))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if (y <= 0.0255) {
tmp = x / z;
} else {
tmp = x * ((6.0 / z) / (y * y));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if y <= 0.0255: tmp = x / z else: tmp = x * ((6.0 / z) / (y * y)) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if (y <= 0.0255) tmp = Float64(x / z); else tmp = Float64(x * Float64(Float64(6.0 / z) / Float64(y * y))); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 0.0255) tmp = x / z; else tmp = x * ((6.0 / z) / (y * y)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[y, 0.0255], N[(x / z), $MachinePrecision], N[(x * N[(N[(6.0 / z), $MachinePrecision] / N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0255:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{\frac{6}{z}}{y \cdot y}\\
\end{array}
\end{array}
if y < 0.0254999999999999984Initial program 96.5%
associate-*l/98.4%
times-frac83.9%
*-commutative83.9%
associate-*r/81.4%
*-commutative81.4%
Simplified81.4%
Taylor expanded in y around 0 76.8%
if 0.0254999999999999984 < y Initial program 92.4%
associate-/l*96.9%
Simplified96.9%
clear-num96.9%
associate-/r/96.9%
clear-num97.0%
Applied egg-rr97.0%
Taylor expanded in y around 0 32.0%
*-commutative32.0%
unpow232.0%
Simplified32.0%
Taylor expanded in y around inf 32.0%
associate-*r/32.0%
unpow232.0%
associate-*l*32.1%
Simplified32.1%
Taylor expanded in x around 0 32.0%
associate-*r/32.0%
*-commutative32.0%
unpow232.0%
times-frac32.0%
associate-*l/31.9%
associate-*r/32.0%
Simplified32.0%
Final simplification64.0%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (if (<= y 0.0255) (/ x z) (* (/ x y) (/ 6.0 (* y z)))))
y = abs(y);
double code(double x, double y, double z) {
double tmp;
if (y <= 0.0255) {
tmp = x / z;
} else {
tmp = (x / y) * (6.0 / (y * z));
}
return tmp;
}
NOTE: y should be positive before calling this 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) :: tmp
if (y <= 0.0255d0) then
tmp = x / z
else
tmp = (x / y) * (6.0d0 / (y * z))
end if
code = tmp
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
double tmp;
if (y <= 0.0255) {
tmp = x / z;
} else {
tmp = (x / y) * (6.0 / (y * z));
}
return tmp;
}
y = abs(y) def code(x, y, z): tmp = 0 if y <= 0.0255: tmp = x / z else: tmp = (x / y) * (6.0 / (y * z)) return tmp
y = abs(y) function code(x, y, z) tmp = 0.0 if (y <= 0.0255) tmp = Float64(x / z); else tmp = Float64(Float64(x / y) * Float64(6.0 / Float64(y * z))); end return tmp end
y = abs(y) function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 0.0255) tmp = x / z; else tmp = (x / y) * (6.0 / (y * z)); end tmp_2 = tmp; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := If[LessEqual[y, 0.0255], N[(x / z), $MachinePrecision], N[(N[(x / y), $MachinePrecision] * N[(6.0 / N[(y * z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
y = |y|\\
\\
\begin{array}{l}
\mathbf{if}\;y \leq 0.0255:\\
\;\;\;\;\frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y} \cdot \frac{6}{y \cdot z}\\
\end{array}
\end{array}
if y < 0.0254999999999999984Initial program 96.5%
associate-*l/98.4%
times-frac83.9%
*-commutative83.9%
associate-*r/81.4%
*-commutative81.4%
Simplified81.4%
Taylor expanded in y around 0 76.8%
if 0.0254999999999999984 < y Initial program 92.4%
associate-/l*96.9%
Simplified96.9%
clear-num96.9%
associate-/r/96.9%
clear-num97.0%
Applied egg-rr97.0%
Taylor expanded in y around 0 32.0%
*-commutative32.0%
unpow232.0%
Simplified32.0%
Taylor expanded in y around inf 32.0%
associate-*r/32.0%
unpow232.0%
associate-*l*32.1%
Simplified32.1%
*-commutative32.1%
times-frac32.1%
*-commutative32.1%
Applied egg-rr32.1%
Final simplification64.0%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x (* z (+ 1.0 (* (* y y) 0.16666666666666666)))))
y = abs(y);
double code(double x, double y, double z) {
return x / (z * (1.0 + ((y * y) * 0.16666666666666666)));
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / (z * (1.0d0 + ((y * y) * 0.16666666666666666d0)))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / (z * (1.0 + ((y * y) * 0.16666666666666666)));
}
y = abs(y) def code(x, y, z): return x / (z * (1.0 + ((y * y) * 0.16666666666666666)))
y = abs(y) function code(x, y, z) return Float64(x / Float64(z * Float64(1.0 + Float64(Float64(y * y) * 0.16666666666666666)))) end
y = abs(y) function tmp = code(x, y, z) tmp = x / (z * (1.0 + ((y * y) * 0.16666666666666666))); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / N[(z * N[(1.0 + N[(N[(y * y), $MachinePrecision] * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{z \cdot \left(1 + \left(y \cdot y\right) \cdot 0.16666666666666666\right)}
\end{array}
Initial program 95.3%
associate-/l*98.0%
Simplified98.0%
clear-num97.8%
associate-/r/97.9%
clear-num98.0%
Applied egg-rr98.0%
Taylor expanded in y around 0 67.5%
*-commutative67.5%
unpow267.5%
Simplified67.5%
Final simplification67.5%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x (* z (+ 1.0 (* y (* y -0.16666666666666666))))))
y = abs(y);
double code(double x, double y, double z) {
return x / (z * (1.0 + (y * (y * -0.16666666666666666))));
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / (z * (1.0d0 + (y * (y * (-0.16666666666666666d0)))))
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / (z * (1.0 + (y * (y * -0.16666666666666666))));
}
y = abs(y) def code(x, y, z): return x / (z * (1.0 + (y * (y * -0.16666666666666666))))
y = abs(y) function code(x, y, z) return Float64(x / Float64(z * Float64(1.0 + Float64(y * Float64(y * -0.16666666666666666))))) end
y = abs(y) function tmp = code(x, y, z) tmp = x / (z * (1.0 + (y * (y * -0.16666666666666666)))); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / N[(z * N[(1.0 + N[(y * N[(y * -0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{z \cdot \left(1 + y \cdot \left(y \cdot -0.16666666666666666\right)\right)}
\end{array}
Initial program 95.3%
associate-/l*98.0%
Simplified98.0%
clear-num97.8%
associate-/r/97.9%
clear-num98.0%
Applied egg-rr98.0%
Taylor expanded in y around 0 67.5%
*-commutative67.5%
unpow267.5%
Simplified67.5%
expm1-log1p-u67.5%
expm1-udef67.5%
log1p-udef67.5%
add-exp-log67.5%
+-commutative67.5%
add-sqr-sqrt67.5%
sqrt-unprod67.5%
swap-sqr67.5%
metadata-eval67.5%
metadata-eval67.5%
swap-sqr67.5%
associate-*r*67.5%
associate-*r*67.5%
sqrt-unprod25.0%
add-sqr-sqrt67.8%
fma-def67.8%
Applied egg-rr67.8%
fma-udef67.8%
associate--l+67.8%
metadata-eval67.8%
Simplified67.8%
Final simplification67.8%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ 1.0 (/ z x)))
y = abs(y);
double code(double x, double y, double z) {
return 1.0 / (z / x);
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 1.0d0 / (z / x)
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return 1.0 / (z / x);
}
y = abs(y) def code(x, y, z): return 1.0 / (z / x)
y = abs(y) function code(x, y, z) return Float64(1.0 / Float64(z / x)) end
y = abs(y) function tmp = code(x, y, z) tmp = 1.0 / (z / x); end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(1.0 / N[(z / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{1}{\frac{z}{x}}
\end{array}
Initial program 95.3%
associate-/l*98.0%
Simplified98.0%
clear-num96.9%
associate-/r/97.7%
clear-num98.1%
associate-/l/90.9%
*-commutative90.9%
Applied egg-rr90.9%
Taylor expanded in y around 0 58.8%
associate-*l/59.0%
*-un-lft-identity59.0%
clear-num59.1%
Applied egg-rr59.1%
Final simplification59.1%
NOTE: y should be positive before calling this function (FPCore (x y z) :precision binary64 (/ x z))
y = abs(y);
double code(double x, double y, double z) {
return x / z;
}
NOTE: y should be positive before calling this function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x / z
end function
y = Math.abs(y);
public static double code(double x, double y, double z) {
return x / z;
}
y = abs(y) def code(x, y, z): return x / z
y = abs(y) function code(x, y, z) return Float64(x / z) end
y = abs(y) function tmp = code(x, y, z) tmp = x / z; end
NOTE: y should be positive before calling this function code[x_, y_, z_] := N[(x / z), $MachinePrecision]
\begin{array}{l}
y = |y|\\
\\
\frac{x}{z}
\end{array}
Initial program 95.3%
associate-*l/96.5%
times-frac87.6%
*-commutative87.6%
associate-*r/85.9%
*-commutative85.9%
Simplified85.9%
Taylor expanded in y around 0 59.0%
Final simplification59.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ y (sin y))) (t_1 (/ (* x (/ 1.0 t_0)) z)))
(if (< z -4.2173720203427147e-29)
t_1
(if (< z 4.446702369113811e+64) (/ x (* z t_0)) t_1))))
double code(double x, double y, double z) {
double t_0 = y / sin(y);
double t_1 = (x * (1.0 / t_0)) / z;
double tmp;
if (z < -4.2173720203427147e-29) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x / (z * t_0);
} else {
tmp = t_1;
}
return tmp;
}
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) :: t_1
real(8) :: tmp
t_0 = y / sin(y)
t_1 = (x * (1.0d0 / t_0)) / z
if (z < (-4.2173720203427147d-29)) then
tmp = t_1
else if (z < 4.446702369113811d+64) then
tmp = x / (z * t_0)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = y / Math.sin(y);
double t_1 = (x * (1.0 / t_0)) / z;
double tmp;
if (z < -4.2173720203427147e-29) {
tmp = t_1;
} else if (z < 4.446702369113811e+64) {
tmp = x / (z * t_0);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = y / math.sin(y) t_1 = (x * (1.0 / t_0)) / z tmp = 0 if z < -4.2173720203427147e-29: tmp = t_1 elif z < 4.446702369113811e+64: tmp = x / (z * t_0) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(y / sin(y)) t_1 = Float64(Float64(x * Float64(1.0 / t_0)) / z) tmp = 0.0 if (z < -4.2173720203427147e-29) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = Float64(x / Float64(z * t_0)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = y / sin(y); t_1 = (x * (1.0 / t_0)) / z; tmp = 0.0; if (z < -4.2173720203427147e-29) tmp = t_1; elseif (z < 4.446702369113811e+64) tmp = x / (z * t_0); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(y / N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(x * N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, If[Less[z, -4.2173720203427147e-29], t$95$1, If[Less[z, 4.446702369113811e+64], N[(x / N[(z * t$95$0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{\sin y}\\
t_1 := \frac{x \cdot \frac{1}{t_0}}{z}\\
\mathbf{if}\;z < -4.2173720203427147 \cdot 10^{-29}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;z < 4.446702369113811 \cdot 10^{+64}:\\
\;\;\;\;\frac{x}{z \cdot t_0}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
herbie shell --seed 2023252
(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))