
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x y) (* (- x 1.0) z)))
double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * 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 * y) + ((x - 1.0d0) * z)
end function
public static double code(double x, double y, double z) {
return (x * y) + ((x - 1.0) * z);
}
def code(x, y, z): return (x * y) + ((x - 1.0) * z)
function code(x, y, z) return Float64(Float64(x * y) + Float64(Float64(x - 1.0) * z)) end
function tmp = code(x, y, z) tmp = (x * y) + ((x - 1.0) * z); end
code[x_, y_, z_] := N[(N[(x * y), $MachinePrecision] + N[(N[(x - 1.0), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y + \left(x - 1\right) \cdot z
\end{array}
(FPCore (x y z) :precision binary64 (fma x (+ y z) (- z)))
double code(double x, double y, double z) {
return fma(x, (y + z), -z);
}
function code(x, y, z) return fma(x, Float64(y + z), Float64(-z)) end
code[x_, y_, z_] := N[(x * N[(y + z), $MachinePrecision] + (-z)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + z, -z\right)
\end{array}
Initial program 99.2%
*-commutative99.2%
sub-neg99.2%
distribute-rgt-in99.2%
associate-+r+99.2%
distribute-lft-out100.0%
fma-def100.0%
metadata-eval100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y z) :precision binary64 (if (<= x -3.3e+55) (* x z) (if (<= x -2.9e-42) (* x y) (if (<= x 1.0) (- z) (* x z)))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e+55) {
tmp = x * z;
} else if (x <= -2.9e-42) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else {
tmp = x * 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 (x <= (-3.3d+55)) then
tmp = x * z
else if (x <= (-2.9d-42)) then
tmp = x * y
else if (x <= 1.0d0) then
tmp = -z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e+55) {
tmp = x * z;
} else if (x <= -2.9e-42) {
tmp = x * y;
} else if (x <= 1.0) {
tmp = -z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.3e+55: tmp = x * z elif x <= -2.9e-42: tmp = x * y elif x <= 1.0: tmp = -z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.3e+55) tmp = Float64(x * z); elseif (x <= -2.9e-42) tmp = Float64(x * y); elseif (x <= 1.0) tmp = Float64(-z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.3e+55) tmp = x * z; elseif (x <= -2.9e-42) tmp = x * y; elseif (x <= 1.0) tmp = -z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.3e+55], N[(x * z), $MachinePrecision], If[LessEqual[x, -2.9e-42], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.0], (-z), N[(x * z), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+55}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -2.9 \cdot 10^{-42}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.3e55 or 1 < x Initial program 98.3%
Taylor expanded in x around inf 99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in z around inf 59.1%
if -3.3e55 < x < -2.9000000000000003e-42Initial program 100.0%
Taylor expanded in y around inf 59.2%
if -2.9000000000000003e-42 < x < 1Initial program 100.0%
Taylor expanded in x around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
Final simplification67.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.08e-42) (not (<= x 3.7e-13))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.08e-42) || !(x <= 3.7e-13)) {
tmp = x * (y + z);
} 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 ((x <= (-1.08d-42)) .or. (.not. (x <= 3.7d-13))) then
tmp = x * (y + z)
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.08e-42) || !(x <= 3.7e-13)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.08e-42) or not (x <= 3.7e-13): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.08e-42) || !(x <= 3.7e-13)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.08e-42) || ~((x <= 3.7e-13))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.08e-42], N[Not[LessEqual[x, 3.7e-13]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.08 \cdot 10^{-42} \lor \neg \left(x \leq 3.7 \cdot 10^{-13}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.07999999999999996e-42 or 3.69999999999999989e-13 < x Initial program 98.6%
Taylor expanded in x around inf 96.1%
+-commutative96.1%
Simplified96.1%
if -1.07999999999999996e-42 < x < 3.69999999999999989e-13Initial program 100.0%
Taylor expanded in x around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e-42) (not (<= x 1.2))) (* x (+ y z)) (* z (+ x -1.0))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-42) || !(x <= 1.2)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.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) :: tmp
if ((x <= (-5.5d-42)) .or. (.not. (x <= 1.2d0))) then
tmp = x * (y + z)
else
tmp = z * (x + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e-42) || !(x <= 1.2)) {
tmp = x * (y + z);
} else {
tmp = z * (x + -1.0);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e-42) or not (x <= 1.2): tmp = x * (y + z) else: tmp = z * (x + -1.0) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e-42) || !(x <= 1.2)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(z * Float64(x + -1.0)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -5.5e-42) || ~((x <= 1.2))) tmp = x * (y + z); else tmp = z * (x + -1.0); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e-42], N[Not[LessEqual[x, 1.2]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(z * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{-42} \lor \neg \left(x \leq 1.2\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if x < -5.5e-42 or 1.19999999999999996 < x Initial program 98.6%
Taylor expanded in x around inf 96.8%
+-commutative96.8%
Simplified96.8%
if -5.5e-42 < x < 1.19999999999999996Initial program 100.0%
Taylor expanded in y around 0 77.1%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (<= x -5.1e-42) (* x y) (if (<= x 7e-18) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -5.1e-42) {
tmp = x * y;
} else if (x <= 7e-18) {
tmp = -z;
} else {
tmp = 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 (x <= (-5.1d-42)) then
tmp = x * y
else if (x <= 7d-18) then
tmp = -z
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -5.1e-42) {
tmp = x * y;
} else if (x <= 7e-18) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -5.1e-42: tmp = x * y elif x <= 7e-18: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -5.1e-42) tmp = Float64(x * y); elseif (x <= 7e-18) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -5.1e-42) tmp = x * y; elseif (x <= 7e-18) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -5.1e-42], N[(x * y), $MachinePrecision], If[LessEqual[x, 7e-18], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.1 \cdot 10^{-42}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 7 \cdot 10^{-18}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -5.1e-42 or 6.9999999999999997e-18 < x Initial program 98.6%
Taylor expanded in y around inf 46.1%
if -5.1e-42 < x < 6.9999999999999997e-18Initial program 100.0%
Taylor expanded in x around 0 77.6%
mul-1-neg77.6%
Simplified77.6%
Final simplification60.1%
(FPCore (x y z) :precision binary64 (- (* x (+ y z)) z))
double code(double x, double y, double z) {
return (x * (y + z)) - 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 * (y + z)) - z
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) - z;
}
def code(x, y, z): return (x * (y + z)) - z
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) - z) end
function tmp = code(x, y, z) tmp = (x * (y + z)) - z; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(y + z\right) - z
\end{array}
Initial program 99.2%
*-commutative99.2%
sub-neg99.2%
distribute-rgt-in99.2%
associate-+r+99.2%
metadata-eval99.2%
mul-1-neg99.2%
unsub-neg99.2%
distribute-lft-out100.0%
Simplified100.0%
Final simplification100.0%
(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 Float64(-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.2%
Taylor expanded in x around 0 37.3%
mul-1-neg37.3%
Simplified37.3%
Final simplification37.3%
herbie shell --seed 2023195
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))