
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
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)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(y));
}
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)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
return (x * sin(y)) + (cos(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)) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (Math.cos(y) * z);
}
def code(x, y, z): return (x * math.sin(y)) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + \cos y \cdot z
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* (cos y) z)))
(if (<= y -2e+87)
t_0
(if (<= y -0.02)
t_1
(if (<= y 0.0019)
(+ z (* y x))
(if (or (<= y 6.4e+55) (and (not (<= y 1.35e+165)) (<= y 5.5e+260)))
t_1
t_0))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = cos(y) * z;
double tmp;
if (y <= -2e+87) {
tmp = t_0;
} else if (y <= -0.02) {
tmp = t_1;
} else if (y <= 0.0019) {
tmp = z + (y * x);
} else if ((y <= 6.4e+55) || (!(y <= 1.35e+165) && (y <= 5.5e+260))) {
tmp = t_1;
} else {
tmp = t_0;
}
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 = x * sin(y)
t_1 = cos(y) * z
if (y <= (-2d+87)) then
tmp = t_0
else if (y <= (-0.02d0)) then
tmp = t_1
else if (y <= 0.0019d0) then
tmp = z + (y * x)
else if ((y <= 6.4d+55) .or. (.not. (y <= 1.35d+165)) .and. (y <= 5.5d+260)) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.sin(y);
double t_1 = Math.cos(y) * z;
double tmp;
if (y <= -2e+87) {
tmp = t_0;
} else if (y <= -0.02) {
tmp = t_1;
} else if (y <= 0.0019) {
tmp = z + (y * x);
} else if ((y <= 6.4e+55) || (!(y <= 1.35e+165) && (y <= 5.5e+260))) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = math.cos(y) * z tmp = 0 if y <= -2e+87: tmp = t_0 elif y <= -0.02: tmp = t_1 elif y <= 0.0019: tmp = z + (y * x) elif (y <= 6.4e+55) or (not (y <= 1.35e+165) and (y <= 5.5e+260)): tmp = t_1 else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(cos(y) * z) tmp = 0.0 if (y <= -2e+87) tmp = t_0; elseif (y <= -0.02) tmp = t_1; elseif (y <= 0.0019) tmp = Float64(z + Float64(y * x)); elseif ((y <= 6.4e+55) || (!(y <= 1.35e+165) && (y <= 5.5e+260))) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); t_1 = cos(y) * z; tmp = 0.0; if (y <= -2e+87) tmp = t_0; elseif (y <= -0.02) tmp = t_1; elseif (y <= 0.0019) tmp = z + (y * x); elseif ((y <= 6.4e+55) || (~((y <= 1.35e+165)) && (y <= 5.5e+260))) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -2e+87], t$95$0, If[LessEqual[y, -0.02], t$95$1, If[LessEqual[y, 0.0019], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 6.4e+55], And[N[Not[LessEqual[y, 1.35e+165]], $MachinePrecision], LessEqual[y, 5.5e+260]]], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := \cos y \cdot z\\
\mathbf{if}\;y \leq -2 \cdot 10^{+87}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.02:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 0.0019:\\
\;\;\;\;z + y \cdot x\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+55} \lor \neg \left(y \leq 1.35 \cdot 10^{+165}\right) \land y \leq 5.5 \cdot 10^{+260}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.9999999999999999e87 or 6.4000000000000005e55 < y < 1.35e165 or 5.49999999999999961e260 < y Initial program 99.7%
Taylor expanded in x around inf 62.3%
if -1.9999999999999999e87 < y < -0.0200000000000000004 or 0.0019 < y < 6.4000000000000005e55 or 1.35e165 < y < 5.49999999999999961e260Initial program 99.7%
Taylor expanded in x around 0 69.5%
if -0.0200000000000000004 < y < 0.0019Initial program 100.0%
Taylor expanded in y around 0 99.7%
+-commutative99.7%
Simplified99.7%
Final simplification82.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -7.5e+86) (not (<= z 4.6e+153))) (* (cos y) z) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e+86) || !(z <= 4.6e+153)) {
tmp = cos(y) * z;
} else {
tmp = z + (x * sin(y));
}
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) :: tmp
if ((z <= (-7.5d+86)) .or. (.not. (z <= 4.6d+153))) then
tmp = cos(y) * z
else
tmp = z + (x * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7.5e+86) || !(z <= 4.6e+153)) {
tmp = Math.cos(y) * z;
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7.5e+86) or not (z <= 4.6e+153): tmp = math.cos(y) * z else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7.5e+86) || !(z <= 4.6e+153)) tmp = Float64(cos(y) * z); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7.5e+86) || ~((z <= 4.6e+153))) tmp = cos(y) * z; else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7.5e+86], N[Not[LessEqual[z, 4.6e+153]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.5 \cdot 10^{+86} \lor \neg \left(z \leq 4.6 \cdot 10^{+153}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -7.4999999999999997e86 or 4.6000000000000003e153 < z Initial program 99.8%
Taylor expanded in x around 0 91.2%
if -7.4999999999999997e86 < z < 4.6000000000000003e153Initial program 99.9%
Taylor expanded in y around 0 89.0%
Final simplification89.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e-6) (not (<= y 9.5e+30))) (* x (sin y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-6) || !(y <= 9.5e+30)) {
tmp = x * sin(y);
} else {
tmp = z + (y * x);
}
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) :: tmp
if ((y <= (-5.2d-6)) .or. (.not. (y <= 9.5d+30))) then
tmp = x * sin(y)
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e-6) || !(y <= 9.5e+30)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e-6) or not (y <= 9.5e+30): tmp = x * math.sin(y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e-6) || !(y <= 9.5e+30)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.2e-6) || ~((y <= 9.5e+30))) tmp = x * sin(y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e-6], N[Not[LessEqual[y, 9.5e+30]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{-6} \lor \neg \left(y \leq 9.5 \cdot 10^{+30}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -5.20000000000000019e-6 or 9.5000000000000003e30 < y Initial program 99.7%
Taylor expanded in x around inf 51.8%
if -5.20000000000000019e-6 < y < 9.5000000000000003e30Initial program 100.0%
Taylor expanded in y around 0 97.6%
+-commutative97.6%
Simplified97.6%
Final simplification75.6%
(FPCore (x y z) :precision binary64 (if (<= z -1e-58) z (if (<= z 1e-105) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1e-58) {
tmp = z;
} else if (z <= 1e-105) {
tmp = y * x;
} else {
tmp = 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
real(8) :: tmp
if (z <= (-1d-58)) then
tmp = z
else if (z <= 1d-105) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1e-58) {
tmp = z;
} else if (z <= 1e-105) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1e-58: tmp = z elif z <= 1e-105: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1e-58) tmp = z; elseif (z <= 1e-105) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1e-58) tmp = z; elseif (z <= 1e-105) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1e-58], z, If[LessEqual[z, 1e-105], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1 \cdot 10^{-58}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 10^{-105}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1e-58 or 9.99999999999999965e-106 < z Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 53.1%
if -1e-58 < z < 9.99999999999999965e-106Initial program 99.8%
Taylor expanded in x around inf 73.5%
Taylor expanded in y around 0 34.0%
Final simplification46.0%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 53.2%
+-commutative53.2%
Simplified53.2%
Final simplification53.2%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
+-commutative99.9%
*-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Taylor expanded in y around 0 40.2%
Final simplification40.2%
herbie shell --seed 2023308
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))