
(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 6 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 (- (* 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
(if (<= x -17000000.0)
(* x z)
(if (<= x 1.25e-23)
(- z)
(if (<= x 3.2e+24) (* x y) (if (<= x 5.2e+238) (* x z) (* x y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -17000000.0) {
tmp = x * z;
} else if (x <= 1.25e-23) {
tmp = -z;
} else if (x <= 3.2e+24) {
tmp = x * y;
} else if (x <= 5.2e+238) {
tmp = x * 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 <= (-17000000.0d0)) then
tmp = x * z
else if (x <= 1.25d-23) then
tmp = -z
else if (x <= 3.2d+24) then
tmp = x * y
else if (x <= 5.2d+238) then
tmp = x * 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 <= -17000000.0) {
tmp = x * z;
} else if (x <= 1.25e-23) {
tmp = -z;
} else if (x <= 3.2e+24) {
tmp = x * y;
} else if (x <= 5.2e+238) {
tmp = x * z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -17000000.0: tmp = x * z elif x <= 1.25e-23: tmp = -z elif x <= 3.2e+24: tmp = x * y elif x <= 5.2e+238: tmp = x * z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -17000000.0) tmp = Float64(x * z); elseif (x <= 1.25e-23) tmp = Float64(-z); elseif (x <= 3.2e+24) tmp = Float64(x * y); elseif (x <= 5.2e+238) tmp = Float64(x * z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -17000000.0) tmp = x * z; elseif (x <= 1.25e-23) tmp = -z; elseif (x <= 3.2e+24) tmp = x * y; elseif (x <= 5.2e+238) tmp = x * z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -17000000.0], N[(x * z), $MachinePrecision], If[LessEqual[x, 1.25e-23], (-z), If[LessEqual[x, 3.2e+24], N[(x * y), $MachinePrecision], If[LessEqual[x, 5.2e+238], N[(x * z), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -17000000:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{-23}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{+24}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{+238}:\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1.7e7 or 3.1999999999999997e24 < x < 5.1999999999999999e238Initial program 97.9%
Taylor expanded in x around inf 99.5%
+-commutative99.5%
Simplified99.5%
Taylor expanded in z around inf 63.7%
if -1.7e7 < x < 1.2500000000000001e-23Initial program 100.0%
Taylor expanded in x around 0 69.9%
mul-1-neg69.9%
Simplified69.9%
if 1.2500000000000001e-23 < x < 3.1999999999999997e24 or 5.1999999999999999e238 < x Initial program 100.0%
Taylor expanded in y around inf 73.2%
Final simplification67.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -2e-11) (not (<= x 3.8e-25))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2e-11) || !(x <= 3.8e-25)) {
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 <= (-2d-11)) .or. (.not. (x <= 3.8d-25))) 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 <= -2e-11) || !(x <= 3.8e-25)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2e-11) or not (x <= 3.8e-25): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2e-11) || !(x <= 3.8e-25)) 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 <= -2e-11) || ~((x <= 3.8e-25))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2e-11], N[Not[LessEqual[x, 3.8e-25]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-11} \lor \neg \left(x \leq 3.8 \cdot 10^{-25}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.99999999999999988e-11 or 3.7999999999999998e-25 < x Initial program 98.3%
Taylor expanded in x around inf 97.4%
+-commutative97.4%
Simplified97.4%
if -1.99999999999999988e-11 < x < 3.7999999999999998e-25Initial program 100.0%
Taylor expanded in x around 0 70.9%
mul-1-neg70.9%
Simplified70.9%
Final simplification83.2%
(FPCore (x y z) :precision binary64 (if (or (<= y -5.2e+72) (not (<= y 5.5e-16))) (* x (+ y z)) (- (* x z) z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+72) || !(y <= 5.5e-16)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - 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 ((y <= (-5.2d+72)) .or. (.not. (y <= 5.5d-16))) then
tmp = x * (y + z)
else
tmp = (x * z) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -5.2e+72) || !(y <= 5.5e-16)) {
tmp = x * (y + z);
} else {
tmp = (x * z) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -5.2e+72) or not (y <= 5.5e-16): tmp = x * (y + z) else: tmp = (x * z) - z return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -5.2e+72) || !(y <= 5.5e-16)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * z) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -5.2e+72) || ~((y <= 5.5e-16))) tmp = x * (y + z); else tmp = (x * z) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -5.2e+72], N[Not[LessEqual[y, 5.5e-16]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+72} \lor \neg \left(y \leq 5.5 \cdot 10^{-16}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot z - z\\
\end{array}
\end{array}
if y < -5.19999999999999963e72 or 5.49999999999999964e-16 < y Initial program 98.3%
Taylor expanded in x around inf 76.8%
+-commutative76.8%
Simplified76.8%
if -5.19999999999999963e72 < y < 5.49999999999999964e-16Initial program 100.0%
Taylor expanded in y around 0 89.6%
*-commutative89.6%
distribute-lft-out--89.6%
*-rgt-identity89.6%
Simplified89.6%
Final simplification83.7%
(FPCore (x y z) :precision binary64 (if (<= x -3.8e-11) (* x y) (if (<= x 2.1e-26) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.8e-11) {
tmp = x * y;
} else if (x <= 2.1e-26) {
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 <= (-3.8d-11)) then
tmp = x * y
else if (x <= 2.1d-26) 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 <= -3.8e-11) {
tmp = x * y;
} else if (x <= 2.1e-26) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.8e-11: tmp = x * y elif x <= 2.1e-26: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.8e-11) tmp = Float64(x * y); elseif (x <= 2.1e-26) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.8e-11) tmp = x * y; elseif (x <= 2.1e-26) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.8e-11], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.1e-26], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-11}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-26}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -3.7999999999999998e-11 or 2.10000000000000008e-26 < x Initial program 98.3%
Taylor expanded in y around inf 47.8%
if -3.7999999999999998e-11 < x < 2.10000000000000008e-26Initial program 100.0%
Taylor expanded in x around 0 70.9%
mul-1-neg70.9%
Simplified70.9%
Final simplification60.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 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 39.9%
mul-1-neg39.9%
Simplified39.9%
Final simplification39.9%
herbie shell --seed 2023196
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))