
(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}
\\
\left(x + \sin y\right) + 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}
\\
\left(x + \sin y\right) + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (+ (sin y) (fma z (cos y) x)))
double code(double x, double y, double z) {
return sin(y) + fma(z, cos(y), x);
}
function code(x, y, z) return Float64(sin(y) + fma(z, cos(y), x)) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin y + \mathsf{fma}\left(z, \cos y, x\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (+ (sin y) x)))
double code(double x, double y, double z) {
return (z * cos(y)) + (sin(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 * cos(y)) + (sin(y) + x)
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (Math.sin(y) + x);
}
def code(x, y, z): return (z * math.cos(y)) + (math.sin(y) + x)
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(sin(y) + x)) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (sin(y) + x); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + \left(\sin y + x\right)
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -1.8e+71)
t_0
(if (<= z -4.9e-84)
(+ y (+ z x))
(if (<= z 3.5e-81) (+ (sin y) x) (if (<= z 2.55e+95) (+ z x) t_0))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -1.8e+71) {
tmp = t_0;
} else if (z <= -4.9e-84) {
tmp = y + (z + x);
} else if (z <= 3.5e-81) {
tmp = sin(y) + x;
} else if (z <= 2.55e+95) {
tmp = z + x;
} 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) :: tmp
t_0 = z * cos(y)
if (z <= (-1.8d+71)) then
tmp = t_0
else if (z <= (-4.9d-84)) then
tmp = y + (z + x)
else if (z <= 3.5d-81) then
tmp = sin(y) + x
else if (z <= 2.55d+95) then
tmp = z + x
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = z * Math.cos(y);
double tmp;
if (z <= -1.8e+71) {
tmp = t_0;
} else if (z <= -4.9e-84) {
tmp = y + (z + x);
} else if (z <= 3.5e-81) {
tmp = Math.sin(y) + x;
} else if (z <= 2.55e+95) {
tmp = z + x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -1.8e+71: tmp = t_0 elif z <= -4.9e-84: tmp = y + (z + x) elif z <= 3.5e-81: tmp = math.sin(y) + x elif z <= 2.55e+95: tmp = z + x else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -1.8e+71) tmp = t_0; elseif (z <= -4.9e-84) tmp = Float64(y + Float64(z + x)); elseif (z <= 3.5e-81) tmp = Float64(sin(y) + x); elseif (z <= 2.55e+95) tmp = Float64(z + x); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -1.8e+71) tmp = t_0; elseif (z <= -4.9e-84) tmp = y + (z + x); elseif (z <= 3.5e-81) tmp = sin(y) + x; elseif (z <= 2.55e+95) tmp = z + x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -1.8e+71], t$95$0, If[LessEqual[z, -4.9e-84], N[(y + N[(z + x), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 3.5e-81], N[(N[Sin[y], $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 2.55e+95], N[(z + x), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -1.8 \cdot 10^{+71}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;z \leq -4.9 \cdot 10^{-84}:\\
\;\;\;\;y + \left(z + x\right)\\
\mathbf{elif}\;z \leq 3.5 \cdot 10^{-81}:\\
\;\;\;\;\sin y + x\\
\mathbf{elif}\;z \leq 2.55 \cdot 10^{+95}:\\
\;\;\;\;z + x\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if z < -1.8e71 or 2.55000000000000001e95 < z Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
fma-udef99.8%
associate-+r+99.8%
+-commutative99.8%
associate-+l+99.8%
flip-+26.5%
clear-num26.5%
*-un-lft-identity26.5%
associate-/l*26.5%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in z around inf 92.8%
if -1.8e71 < z < -4.8999999999999998e-84Initial program 99.8%
+-commutative99.8%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 84.9%
+-commutative84.9%
Simplified84.9%
*-un-lft-identity84.9%
*-commutative84.9%
associate-+r+85.0%
+-commutative85.0%
+-commutative85.0%
Applied egg-rr85.0%
if -4.8999999999999998e-84 < z < 3.49999999999999986e-81Initial program 100.0%
+-commutative100.0%
associate-+l+100.0%
+-commutative100.0%
fma-def100.0%
Simplified100.0%
Taylor expanded in z around 0 96.1%
if 3.49999999999999986e-81 < z < 2.55000000000000001e95Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
associate-+r+99.9%
+-commutative99.9%
associate-+l+99.9%
flip-+68.8%
clear-num68.7%
*-un-lft-identity68.7%
associate-/l*68.7%
flip-+99.4%
+-commutative99.4%
associate-+r+99.4%
fma-udef99.4%
Applied egg-rr99.4%
Taylor expanded in y around 0 85.4%
Final simplification91.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e+71) (not (<= z 1.56e+96))) (* z (cos y)) (+ (sin y) (+ z x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e+71) || !(z <= 1.56e+96)) {
tmp = z * cos(y);
} else {
tmp = sin(y) + (z + 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 ((z <= (-2.6d+71)) .or. (.not. (z <= 1.56d+96))) then
tmp = z * cos(y)
else
tmp = sin(y) + (z + x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e+71) || !(z <= 1.56e+96)) {
tmp = z * Math.cos(y);
} else {
tmp = Math.sin(y) + (z + x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e+71) or not (z <= 1.56e+96): tmp = z * math.cos(y) else: tmp = math.sin(y) + (z + x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e+71) || !(z <= 1.56e+96)) tmp = Float64(z * cos(y)); else tmp = Float64(sin(y) + Float64(z + x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.6e+71) || ~((z <= 1.56e+96))) tmp = z * cos(y); else tmp = sin(y) + (z + x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e+71], N[Not[LessEqual[z, 1.56e+96]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] + N[(z + x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.6 \cdot 10^{+71} \lor \neg \left(z \leq 1.56 \cdot 10^{+96}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y + \left(z + x\right)\\
\end{array}
\end{array}
if z < -2.59999999999999991e71 or 1.5599999999999999e96 < z Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
fma-udef99.8%
associate-+r+99.8%
+-commutative99.8%
associate-+l+99.8%
flip-+26.5%
clear-num26.5%
*-un-lft-identity26.5%
associate-/l*26.5%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in z around inf 92.8%
if -2.59999999999999991e71 < z < 1.5599999999999999e96Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 95.6%
Final simplification94.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -8.5e+71) (not (<= z 2.15e+97))) (* z (cos y)) (+ z x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e+71) || !(z <= 2.15e+97)) {
tmp = z * cos(y);
} else {
tmp = z + 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 ((z <= (-8.5d+71)) .or. (.not. (z <= 2.15d+97))) then
tmp = z * cos(y)
else
tmp = z + x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -8.5e+71) || !(z <= 2.15e+97)) {
tmp = z * Math.cos(y);
} else {
tmp = z + x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -8.5e+71) or not (z <= 2.15e+97): tmp = z * math.cos(y) else: tmp = z + x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -8.5e+71) || !(z <= 2.15e+97)) tmp = Float64(z * cos(y)); else tmp = Float64(z + x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -8.5e+71) || ~((z <= 2.15e+97))) tmp = z * cos(y); else tmp = z + x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -8.5e+71], N[Not[LessEqual[z, 2.15e+97]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -8.5 \cdot 10^{+71} \lor \neg \left(z \leq 2.15 \cdot 10^{+97}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x\\
\end{array}
\end{array}
if z < -8.4999999999999996e71 or 2.1499999999999999e97 < z Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
fma-udef99.8%
associate-+r+99.8%
+-commutative99.8%
associate-+l+99.8%
flip-+26.5%
clear-num26.5%
*-un-lft-identity26.5%
associate-/l*26.5%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in z around inf 92.8%
if -8.4999999999999996e71 < z < 2.1499999999999999e97Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
associate-+r+99.9%
+-commutative99.9%
associate-+l+99.9%
flip-+72.7%
clear-num72.3%
*-un-lft-identity72.3%
associate-/l*72.4%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 76.9%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (<= z -5.5e+33) z (if (<= z 3.1e+106) x z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+33) {
tmp = z;
} else if (z <= 3.1e+106) {
tmp = 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 <= (-5.5d+33)) then
tmp = z
else if (z <= 3.1d+106) then
tmp = x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.5e+33) {
tmp = z;
} else if (z <= 3.1e+106) {
tmp = x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.5e+33: tmp = z elif z <= 3.1e+106: tmp = x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.5e+33) tmp = z; elseif (z <= 3.1e+106) tmp = x; else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.5e+33) tmp = z; elseif (z <= 3.1e+106) tmp = x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.5e+33], z, If[LessEqual[z, 3.1e+106], x, z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.5 \cdot 10^{+33}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 3.1 \cdot 10^{+106}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -5.5000000000000006e33 or 3.0999999999999999e106 < z Initial program 99.8%
+-commutative99.8%
associate-+l+99.8%
+-commutative99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 65.4%
+-commutative65.4%
Simplified65.4%
Taylor expanded in z around inf 57.1%
if -5.5000000000000006e33 < z < 3.0999999999999999e106Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
associate-+r+99.9%
+-commutative99.9%
associate-+l+99.9%
flip-+72.9%
clear-num72.6%
*-un-lft-identity72.6%
associate-/l*72.6%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 63.8%
Final simplification61.4%
(FPCore (x y z) :precision binary64 (+ z x))
double code(double x, double y, double z) {
return z + 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 + x
end function
public static double code(double x, double y, double z) {
return z + x;
}
def code(x, y, z): return z + x
function code(x, y, z) return Float64(z + x) end
function tmp = code(x, y, z) tmp = z + x; end
code[x_, y_, z_] := N[(z + x), $MachinePrecision]
\begin{array}{l}
\\
z + x
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
associate-+r+99.9%
+-commutative99.9%
associate-+l+99.9%
flip-+57.9%
clear-num57.7%
*-un-lft-identity57.7%
associate-/l*57.7%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in y around 0 72.7%
Final simplification72.7%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
+-commutative99.9%
associate-+l+99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
fma-udef99.9%
associate-+r+99.9%
+-commutative99.9%
associate-+l+99.9%
flip-+57.9%
clear-num57.7%
*-un-lft-identity57.7%
associate-/l*57.7%
flip-+99.6%
+-commutative99.6%
associate-+r+99.6%
fma-udef99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 45.4%
Final simplification45.4%
herbie shell --seed 2023301
(FPCore (x y z)
:name "Graphics.Rasterific.Svg.PathConverter:segmentToBezier from rasterific-svg-0.2.3.1, C"
:precision binary64
(+ (+ x (sin y)) (* z (cos y))))