
(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.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* (cos y) z)))
(if (<= y -1.16e+67)
t_0
(if (<= y -0.028)
t_1
(if (<= y 0.00039)
(+ z (+ (* -0.5 (* z (pow y 2.0))) (* y x)))
(if (<= y 4.1e+88) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = cos(y) * z;
double tmp;
if (y <= -1.16e+67) {
tmp = t_0;
} else if (y <= -0.028) {
tmp = t_1;
} else if (y <= 0.00039) {
tmp = z + ((-0.5 * (z * pow(y, 2.0))) + (y * x));
} else if (y <= 4.1e+88) {
tmp = 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 = x * sin(y)
t_1 = cos(y) * z
if (y <= (-1.16d+67)) then
tmp = t_0
else if (y <= (-0.028d0)) then
tmp = t_1
else if (y <= 0.00039d0) then
tmp = z + (((-0.5d0) * (z * (y ** 2.0d0))) + (y * x))
else if (y <= 4.1d+88) then
tmp = 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 = x * Math.sin(y);
double t_1 = Math.cos(y) * z;
double tmp;
if (y <= -1.16e+67) {
tmp = t_0;
} else if (y <= -0.028) {
tmp = t_1;
} else if (y <= 0.00039) {
tmp = z + ((-0.5 * (z * Math.pow(y, 2.0))) + (y * x));
} else if (y <= 4.1e+88) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = math.cos(y) * z tmp = 0 if y <= -1.16e+67: tmp = t_0 elif y <= -0.028: tmp = t_1 elif y <= 0.00039: tmp = z + ((-0.5 * (z * math.pow(y, 2.0))) + (y * x)) elif y <= 4.1e+88: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(cos(y) * z) tmp = 0.0 if (y <= -1.16e+67) tmp = t_0; elseif (y <= -0.028) tmp = t_1; elseif (y <= 0.00039) tmp = Float64(z + Float64(Float64(-0.5 * Float64(z * (y ^ 2.0))) + Float64(y * x))); elseif (y <= 4.1e+88) tmp = t_0; else tmp = t_1; 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 <= -1.16e+67) tmp = t_0; elseif (y <= -0.028) tmp = t_1; elseif (y <= 0.00039) tmp = z + ((-0.5 * (z * (y ^ 2.0))) + (y * x)); elseif (y <= 4.1e+88) tmp = t_0; else tmp = t_1; 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, -1.16e+67], t$95$0, If[LessEqual[y, -0.028], t$95$1, If[LessEqual[y, 0.00039], N[(z + N[(N[(-0.5 * N[(z * N[Power[y, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(y * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.1e+88], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := \cos y \cdot z\\
\mathbf{if}\;y \leq -1.16 \cdot 10^{+67}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -0.028:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 0.00039:\\
\;\;\;\;z + \left(-0.5 \cdot \left(z \cdot {y}^{2}\right) + y \cdot x\right)\\
\mathbf{elif}\;y \leq 4.1 \cdot 10^{+88}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -1.15999999999999994e67 or 3.89999999999999993e-4 < y < 4.10000000000000028e88Initial program 99.7%
Taylor expanded in x around inf 63.5%
if -1.15999999999999994e67 < y < -0.0280000000000000006 or 4.10000000000000028e88 < y Initial program 99.6%
Taylor expanded in x around 0 64.5%
if -0.0280000000000000006 < y < 3.89999999999999993e-4Initial program 100.0%
Taylor expanded in y around 0 100.0%
Final simplification82.6%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (sin y))) (t_1 (* (cos y) z)))
(if (<= y -4e+66)
t_0
(if (<= y -5.5e-8)
t_1
(if (<= y 0.00043) (+ z (* y x)) (if (<= y 3.1e+88) t_0 t_1))))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double t_1 = cos(y) * z;
double tmp;
if (y <= -4e+66) {
tmp = t_0;
} else if (y <= -5.5e-8) {
tmp = t_1;
} else if (y <= 0.00043) {
tmp = z + (y * x);
} else if (y <= 3.1e+88) {
tmp = 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 = x * sin(y)
t_1 = cos(y) * z
if (y <= (-4d+66)) then
tmp = t_0
else if (y <= (-5.5d-8)) then
tmp = t_1
else if (y <= 0.00043d0) then
tmp = z + (y * x)
else if (y <= 3.1d+88) then
tmp = 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 = x * Math.sin(y);
double t_1 = Math.cos(y) * z;
double tmp;
if (y <= -4e+66) {
tmp = t_0;
} else if (y <= -5.5e-8) {
tmp = t_1;
} else if (y <= 0.00043) {
tmp = z + (y * x);
} else if (y <= 3.1e+88) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) t_1 = math.cos(y) * z tmp = 0 if y <= -4e+66: tmp = t_0 elif y <= -5.5e-8: tmp = t_1 elif y <= 0.00043: tmp = z + (y * x) elif y <= 3.1e+88: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) t_1 = Float64(cos(y) * z) tmp = 0.0 if (y <= -4e+66) tmp = t_0; elseif (y <= -5.5e-8) tmp = t_1; elseif (y <= 0.00043) tmp = Float64(z + Float64(y * x)); elseif (y <= 3.1e+88) tmp = t_0; else tmp = t_1; 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 <= -4e+66) tmp = t_0; elseif (y <= -5.5e-8) tmp = t_1; elseif (y <= 0.00043) tmp = z + (y * x); elseif (y <= 3.1e+88) tmp = t_0; else tmp = t_1; 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, -4e+66], t$95$0, If[LessEqual[y, -5.5e-8], t$95$1, If[LessEqual[y, 0.00043], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.1e+88], t$95$0, t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
t_1 := \cos y \cdot z\\
\mathbf{if}\;y \leq -4 \cdot 10^{+66}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-8}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 0.00043:\\
\;\;\;\;z + y \cdot x\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+88}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if y < -3.99999999999999978e66 or 4.29999999999999989e-4 < y < 3.1000000000000001e88Initial program 99.7%
Taylor expanded in x around inf 63.5%
if -3.99999999999999978e66 < y < -5.5000000000000003e-8 or 3.1000000000000001e88 < y Initial program 99.6%
Taylor expanded in x around 0 65.7%
if -5.5000000000000003e-8 < y < 4.29999999999999989e-4Initial program 100.0%
Taylor expanded in y around 0 99.5%
*-commutative99.5%
Simplified99.5%
Final simplification82.3%
(FPCore (x y z) :precision binary64 (if (or (<= y -42000.0) (not (<= y 0.00175))) (* x (sin y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -42000.0) || !(y <= 0.00175)) {
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 <= (-42000.0d0)) .or. (.not. (y <= 0.00175d0))) 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 <= -42000.0) || !(y <= 0.00175)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -42000.0) or not (y <= 0.00175): tmp = x * math.sin(y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -42000.0) || !(y <= 0.00175)) 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 <= -42000.0) || ~((y <= 0.00175))) tmp = x * sin(y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -42000.0], N[Not[LessEqual[y, 0.00175]], $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 -42000 \lor \neg \left(y \leq 0.00175\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -42000 or 0.00175000000000000004 < y Initial program 99.7%
Taylor expanded in x around inf 52.2%
if -42000 < y < 0.00175000000000000004Initial program 100.0%
Taylor expanded in y around 0 97.9%
*-commutative97.9%
Simplified97.9%
Final simplification76.1%
(FPCore (x y z) :precision binary64 (if (<= z -1.2e-82) z (if (<= z 4e-172) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.2e-82) {
tmp = z;
} else if (z <= 4e-172) {
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 <= (-1.2d-82)) then
tmp = z
else if (z <= 4d-172) 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 <= -1.2e-82) {
tmp = z;
} else if (z <= 4e-172) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.2e-82: tmp = z elif z <= 4e-172: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.2e-82) tmp = z; elseif (z <= 4e-172) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.2e-82) tmp = z; elseif (z <= 4e-172) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.2e-82], z, If[LessEqual[z, 4e-172], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.2 \cdot 10^{-82}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 4 \cdot 10^{-172}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.20000000000000004e-82 or 4.0000000000000002e-172 < z Initial program 99.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 46.3%
if -1.20000000000000004e-82 < z < 4.0000000000000002e-172Initial program 99.9%
Taylor expanded in y around 0 58.2%
*-commutative58.2%
Simplified58.2%
Taylor expanded in z around 0 44.6%
Final simplification45.7%
(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.8%
Taylor expanded in y around 0 54.4%
*-commutative54.4%
Simplified54.4%
Final simplification54.4%
(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.8%
+-commutative99.8%
*-commutative99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 36.5%
Final simplification36.5%
herbie shell --seed 2023311
(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))))