
(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 (+ (+ 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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -3.2e+147)
t_0
(if (<= z -3.5e+51)
(+ x z)
(if (<= z -1.6e+30)
t_0
(if (<= z -8.8e-221)
(+ z (+ x y))
(if (<= z 1.15e+112) (+ x z) t_0)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -3.2e+147) {
tmp = t_0;
} else if (z <= -3.5e+51) {
tmp = x + z;
} else if (z <= -1.6e+30) {
tmp = t_0;
} else if (z <= -8.8e-221) {
tmp = z + (x + y);
} else if (z <= 1.15e+112) {
tmp = x + z;
} 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 <= (-3.2d+147)) then
tmp = t_0
else if (z <= (-3.5d+51)) then
tmp = x + z
else if (z <= (-1.6d+30)) then
tmp = t_0
else if (z <= (-8.8d-221)) then
tmp = z + (x + y)
else if (z <= 1.15d+112) then
tmp = x + z
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 <= -3.2e+147) {
tmp = t_0;
} else if (z <= -3.5e+51) {
tmp = x + z;
} else if (z <= -1.6e+30) {
tmp = t_0;
} else if (z <= -8.8e-221) {
tmp = z + (x + y);
} else if (z <= 1.15e+112) {
tmp = x + z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -3.2e+147: tmp = t_0 elif z <= -3.5e+51: tmp = x + z elif z <= -1.6e+30: tmp = t_0 elif z <= -8.8e-221: tmp = z + (x + y) elif z <= 1.15e+112: tmp = x + z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -3.2e+147) tmp = t_0; elseif (z <= -3.5e+51) tmp = Float64(x + z); elseif (z <= -1.6e+30) tmp = t_0; elseif (z <= -8.8e-221) tmp = Float64(z + Float64(x + y)); elseif (z <= 1.15e+112) tmp = Float64(x + z); 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 <= -3.2e+147) tmp = t_0; elseif (z <= -3.5e+51) tmp = x + z; elseif (z <= -1.6e+30) tmp = t_0; elseif (z <= -8.8e-221) tmp = z + (x + y); elseif (z <= 1.15e+112) tmp = x + z; 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, -3.2e+147], t$95$0, If[LessEqual[z, -3.5e+51], N[(x + z), $MachinePrecision], If[LessEqual[z, -1.6e+30], t$95$0, If[LessEqual[z, -8.8e-221], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.15e+112], N[(x + z), $MachinePrecision], t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -3.2 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -3.5 \cdot 10^{+51}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -1.6 \cdot 10^{+30}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -8.8 \cdot 10^{-221}:\\
\;\;\;\;z + \left(x + y\right)\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+112}:\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -3.19999999999999979e147 or -3.5e51 < z < -1.59999999999999986e30 or 1.15e112 < z Initial program 99.8%
+-commutative99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in z around inf 91.8%
if -3.19999999999999979e147 < z < -3.5e51 or -8.80000000000000005e-221 < z < 1.15e112Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 75.5%
+-commutative75.5%
Simplified75.5%
if -1.59999999999999986e30 < z < -8.80000000000000005e-221Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 66.9%
+-commutative66.9%
+-commutative66.9%
associate-+l+66.9%
Simplified66.9%
Final simplification78.2%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* z (cos y))))
(if (<= z -6.5e+147)
t_0
(if (<= z -4.5e+51)
(+ x z)
(if (or (<= z -18.0) (not (<= z 3e+95))) t_0 (+ x (sin y)))))))
double code(double x, double y, double z) {
double t_0 = z * cos(y);
double tmp;
if (z <= -6.5e+147) {
tmp = t_0;
} else if (z <= -4.5e+51) {
tmp = x + z;
} else if ((z <= -18.0) || !(z <= 3e+95)) {
tmp = t_0;
} else {
tmp = 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) :: t_0
real(8) :: tmp
t_0 = z * cos(y)
if (z <= (-6.5d+147)) then
tmp = t_0
else if (z <= (-4.5d+51)) then
tmp = x + z
else if ((z <= (-18.0d0)) .or. (.not. (z <= 3d+95))) then
tmp = t_0
else
tmp = x + sin(y)
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 <= -6.5e+147) {
tmp = t_0;
} else if (z <= -4.5e+51) {
tmp = x + z;
} else if ((z <= -18.0) || !(z <= 3e+95)) {
tmp = t_0;
} else {
tmp = x + Math.sin(y);
}
return tmp;
}
def code(x, y, z): t_0 = z * math.cos(y) tmp = 0 if z <= -6.5e+147: tmp = t_0 elif z <= -4.5e+51: tmp = x + z elif (z <= -18.0) or not (z <= 3e+95): tmp = t_0 else: tmp = x + math.sin(y) return tmp
function code(x, y, z) t_0 = Float64(z * cos(y)) tmp = 0.0 if (z <= -6.5e+147) tmp = t_0; elseif (z <= -4.5e+51) tmp = Float64(x + z); elseif ((z <= -18.0) || !(z <= 3e+95)) tmp = t_0; else tmp = Float64(x + sin(y)); end return tmp end
function tmp_2 = code(x, y, z) t_0 = z * cos(y); tmp = 0.0; if (z <= -6.5e+147) tmp = t_0; elseif (z <= -4.5e+51) tmp = x + z; elseif ((z <= -18.0) || ~((z <= 3e+95))) tmp = t_0; else tmp = x + sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -6.5e+147], t$95$0, If[LessEqual[z, -4.5e+51], N[(x + z), $MachinePrecision], If[Or[LessEqual[z, -18.0], N[Not[LessEqual[z, 3e+95]], $MachinePrecision]], t$95$0, N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := z \cdot \cos y\\
\mathbf{if}\;z \leq -6.5 \cdot 10^{+147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq -4.5 \cdot 10^{+51}:\\
\;\;\;\;x + z\\
\mathbf{elif}\;z \leq -18 \lor \neg \left(z \leq 3 \cdot 10^{+95}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;x + \sin y\\
\end{array}
\end{array}
if z < -6.5e147 or -4.5e51 < z < -18 or 2.99999999999999991e95 < z Initial program 99.8%
+-commutative99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in z around inf 87.2%
if -6.5e147 < z < -4.5e51Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 77.4%
+-commutative77.4%
Simplified77.4%
if -18 < z < 2.99999999999999991e95Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in z around 0 92.1%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (if (or (<= z -3.1e+146) (not (<= z 1.5e+107))) (* z (cos y)) (+ (+ x (sin y)) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+146) || !(z <= 1.5e+107)) {
tmp = z * cos(y);
} else {
tmp = (x + sin(y)) + 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 <= (-3.1d+146)) .or. (.not. (z <= 1.5d+107))) then
tmp = z * cos(y)
else
tmp = (x + sin(y)) + z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -3.1e+146) || !(z <= 1.5e+107)) {
tmp = z * Math.cos(y);
} else {
tmp = (x + Math.sin(y)) + z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.1e+146) or not (z <= 1.5e+107): tmp = z * math.cos(y) else: tmp = (x + math.sin(y)) + z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.1e+146) || !(z <= 1.5e+107)) tmp = Float64(z * cos(y)); else tmp = Float64(Float64(x + sin(y)) + z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.1e+146) || ~((z <= 1.5e+107))) tmp = z * cos(y); else tmp = (x + sin(y)) + z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.1e+146], N[Not[LessEqual[z, 1.5e+107]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x + N[Sin[y], $MachinePrecision]), $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.1 \cdot 10^{+146} \lor \neg \left(z \leq 1.5 \cdot 10^{+107}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\left(x + \sin y\right) + z\\
\end{array}
\end{array}
if z < -3.1000000000000002e146 or 1.50000000000000012e107 < z Initial program 99.8%
+-commutative99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in z around inf 91.1%
if -3.1000000000000002e146 < z < 1.50000000000000012e107Initial program 100.0%
Taylor expanded in y around 0 94.2%
Final simplification93.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -4e+20) (not (<= y 6.2e-19))) (+ x z) (+ z (+ x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+20) || !(y <= 6.2e-19)) {
tmp = x + z;
} else {
tmp = z + (x + 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 ((y <= (-4d+20)) .or. (.not. (y <= 6.2d-19))) then
tmp = x + z
else
tmp = z + (x + y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -4e+20) || !(y <= 6.2e-19)) {
tmp = x + z;
} else {
tmp = z + (x + y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -4e+20) or not (y <= 6.2e-19): tmp = x + z else: tmp = z + (x + y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -4e+20) || !(y <= 6.2e-19)) tmp = Float64(x + z); else tmp = Float64(z + Float64(x + y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -4e+20) || ~((y <= 6.2e-19))) tmp = x + z; else tmp = z + (x + y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -4e+20], N[Not[LessEqual[y, 6.2e-19]], $MachinePrecision]], N[(x + z), $MachinePrecision], N[(z + N[(x + y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{+20} \lor \neg \left(y \leq 6.2 \cdot 10^{-19}\right):\\
\;\;\;\;x + z\\
\mathbf{else}:\\
\;\;\;\;z + \left(x + y\right)\\
\end{array}
\end{array}
if y < -4e20 or 6.1999999999999998e-19 < y Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 48.5%
+-commutative48.5%
Simplified48.5%
if -4e20 < y < 6.1999999999999998e-19Initial program 100.0%
+-commutative100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 98.1%
+-commutative98.1%
+-commutative98.1%
associate-+l+98.1%
Simplified98.1%
Final simplification73.1%
(FPCore (x y z) :precision binary64 (if (<= x -2.55e-8) x (if (<= x 3.7e-48) z x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.55e-8) {
tmp = x;
} else if (x <= 3.7e-48) {
tmp = z;
} else {
tmp = 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 (x <= (-2.55d-8)) then
tmp = x
else if (x <= 3.7d-48) then
tmp = z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.55e-8) {
tmp = x;
} else if (x <= 3.7e-48) {
tmp = z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.55e-8: tmp = x elif x <= 3.7e-48: tmp = z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.55e-8) tmp = x; elseif (x <= 3.7e-48) tmp = z; else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.55e-8) tmp = x; elseif (x <= 3.7e-48) tmp = z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.55e-8], x, If[LessEqual[x, 3.7e-48], z, x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.55 \cdot 10^{-8}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-48}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.55e-8 or 3.6999999999999998e-48 < x Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 74.2%
if -2.55e-8 < x < 3.6999999999999998e-48Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in z around inf 56.8%
Taylor expanded in y around 0 38.2%
Final simplification58.0%
(FPCore (x y z) :precision binary64 (+ x z))
double code(double x, double y, double z) {
return x + 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 + z
end function
public static double code(double x, double y, double z) {
return x + z;
}
def code(x, y, z): return x + z
function code(x, y, z) return Float64(x + z) end
function tmp = code(x, y, z) tmp = x + z; end
code[x_, y_, z_] := N[(x + z), $MachinePrecision]
\begin{array}{l}
\\
x + z
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 67.9%
+-commutative67.9%
Simplified67.9%
Final simplification67.9%
(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%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 46.6%
Final simplification46.6%
herbie shell --seed 2024053
(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))))