
(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 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
associate-+r+98.0%
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 (<= y -2.3e+94)
(* x y)
(if (<= y -3.3e+14)
(- z)
(if (<= y -2.55e-10)
(* x y)
(if (<= y -7.9e-153)
(* x z)
(if (<= y 1.32e-139)
(- z)
(if (<= y 3.1e-55) (* x z) (if (<= y 3.1e-42) (- z) (* x y)))))))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.3e+94) {
tmp = x * y;
} else if (y <= -3.3e+14) {
tmp = -z;
} else if (y <= -2.55e-10) {
tmp = x * y;
} else if (y <= -7.9e-153) {
tmp = x * z;
} else if (y <= 1.32e-139) {
tmp = -z;
} else if (y <= 3.1e-55) {
tmp = x * z;
} else if (y <= 3.1e-42) {
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 (y <= (-2.3d+94)) then
tmp = x * y
else if (y <= (-3.3d+14)) then
tmp = -z
else if (y <= (-2.55d-10)) then
tmp = x * y
else if (y <= (-7.9d-153)) then
tmp = x * z
else if (y <= 1.32d-139) then
tmp = -z
else if (y <= 3.1d-55) then
tmp = x * z
else if (y <= 3.1d-42) 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 (y <= -2.3e+94) {
tmp = x * y;
} else if (y <= -3.3e+14) {
tmp = -z;
} else if (y <= -2.55e-10) {
tmp = x * y;
} else if (y <= -7.9e-153) {
tmp = x * z;
} else if (y <= 1.32e-139) {
tmp = -z;
} else if (y <= 3.1e-55) {
tmp = x * z;
} else if (y <= 3.1e-42) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.3e+94: tmp = x * y elif y <= -3.3e+14: tmp = -z elif y <= -2.55e-10: tmp = x * y elif y <= -7.9e-153: tmp = x * z elif y <= 1.32e-139: tmp = -z elif y <= 3.1e-55: tmp = x * z elif y <= 3.1e-42: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.3e+94) tmp = Float64(x * y); elseif (y <= -3.3e+14) tmp = Float64(-z); elseif (y <= -2.55e-10) tmp = Float64(x * y); elseif (y <= -7.9e-153) tmp = Float64(x * z); elseif (y <= 1.32e-139) tmp = Float64(-z); elseif (y <= 3.1e-55) tmp = Float64(x * z); elseif (y <= 3.1e-42) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.3e+94) tmp = x * y; elseif (y <= -3.3e+14) tmp = -z; elseif (y <= -2.55e-10) tmp = x * y; elseif (y <= -7.9e-153) tmp = x * z; elseif (y <= 1.32e-139) tmp = -z; elseif (y <= 3.1e-55) tmp = x * z; elseif (y <= 3.1e-42) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.3e+94], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.3e+14], (-z), If[LessEqual[y, -2.55e-10], N[(x * y), $MachinePrecision], If[LessEqual[y, -7.9e-153], N[(x * z), $MachinePrecision], If[LessEqual[y, 1.32e-139], (-z), If[LessEqual[y, 3.1e-55], N[(x * z), $MachinePrecision], If[LessEqual[y, 3.1e-42], (-z), N[(x * y), $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+94}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.3 \cdot 10^{+14}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq -2.55 \cdot 10^{-10}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -7.9 \cdot 10^{-153}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;y \leq 1.32 \cdot 10^{-139}:\\
\;\;\;\;-z\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-55}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{-42}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.3e94 or -3.3e14 < y < -2.54999999999999998e-10 or 3.1000000000000003e-42 < y Initial program 96.6%
*-commutative96.6%
sub-neg96.6%
distribute-rgt-in96.6%
associate-+r+96.6%
metadata-eval96.6%
mul-1-neg96.6%
unsub-neg96.6%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 94.3%
Taylor expanded in y around inf 85.4%
if -2.3e94 < y < -3.3e14 or -7.8999999999999998e-153 < y < 1.31999999999999995e-139 or 3.09999999999999997e-55 < y < 3.1000000000000003e-42Initial program 98.7%
*-commutative98.7%
sub-neg98.7%
distribute-rgt-in98.8%
associate-+r+98.8%
metadata-eval98.8%
mul-1-neg98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 57.3%
mul-1-neg57.3%
Simplified57.3%
if -2.54999999999999998e-10 < y < -7.8999999999999998e-153 or 1.31999999999999995e-139 < y < 3.09999999999999997e-55Initial program 99.9%
*-commutative99.9%
sub-neg99.9%
distribute-rgt-in99.9%
associate-+r+99.9%
metadata-eval99.9%
mul-1-neg99.9%
unsub-neg99.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 73.4%
Taylor expanded in x around inf 44.6%
Final simplification67.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.45e+43) (not (<= z 6.5e+147))) (- (* x z) z) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e+43) || !(z <= 6.5e+147)) {
tmp = (x * z) - z;
} else {
tmp = (x * 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 <= (-1.45d+43)) .or. (.not. (z <= 6.5d+147))) then
tmp = (x * z) - z
else
tmp = (x * y) - z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.45e+43) || !(z <= 6.5e+147)) {
tmp = (x * z) - z;
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.45e+43) or not (z <= 6.5e+147): tmp = (x * z) - z else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.45e+43) || !(z <= 6.5e+147)) tmp = Float64(Float64(x * z) - z); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.45e+43) || ~((z <= 6.5e+147))) tmp = (x * z) - z; else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.45e+43], N[Not[LessEqual[z, 6.5e+147]], $MachinePrecision]], N[(N[(x * z), $MachinePrecision] - z), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.45 \cdot 10^{+43} \lor \neg \left(z \leq 6.5 \cdot 10^{+147}\right):\\
\;\;\;\;x \cdot z - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if z < -1.4500000000000001e43 or 6.5e147 < z Initial program 96.2%
*-commutative96.2%
sub-neg96.2%
distribute-rgt-in96.2%
associate-+r+96.2%
metadata-eval96.2%
mul-1-neg96.2%
unsub-neg96.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 87.7%
if -1.4500000000000001e43 < z < 6.5e147Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.9%
associate-+r+98.9%
metadata-eval98.9%
mul-1-neg98.9%
unsub-neg98.9%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 88.2%
Final simplification88.1%
(FPCore (x y z) :precision binary64 (if (<= y -2.5e+94) (* x y) (if (<= y 6.8e-180) (- z) (* x y))))
double code(double x, double y, double z) {
double tmp;
if (y <= -2.5e+94) {
tmp = x * y;
} else if (y <= 6.8e-180) {
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 (y <= (-2.5d+94)) then
tmp = x * y
else if (y <= 6.8d-180) 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 (y <= -2.5e+94) {
tmp = x * y;
} else if (y <= 6.8e-180) {
tmp = -z;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -2.5e+94: tmp = x * y elif y <= 6.8e-180: tmp = -z else: tmp = x * y return tmp
function code(x, y, z) tmp = 0.0 if (y <= -2.5e+94) tmp = Float64(x * y); elseif (y <= 6.8e-180) tmp = Float64(-z); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -2.5e+94) tmp = x * y; elseif (y <= 6.8e-180) tmp = -z; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -2.5e+94], N[(x * y), $MachinePrecision], If[LessEqual[y, 6.8e-180], (-z), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+94}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-180}:\\
\;\;\;\;-z\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.50000000000000005e94 or 6.79999999999999963e-180 < y Initial program 97.1%
*-commutative97.1%
sub-neg97.1%
distribute-rgt-in97.1%
associate-+r+97.1%
metadata-eval97.1%
mul-1-neg97.1%
unsub-neg97.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 88.9%
Taylor expanded in y around inf 76.4%
if -2.50000000000000005e94 < y < 6.79999999999999963e-180Initial program 99.1%
*-commutative99.1%
sub-neg99.1%
distribute-rgt-in99.1%
associate-+r+99.1%
metadata-eval99.1%
mul-1-neg99.1%
unsub-neg99.1%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 48.7%
mul-1-neg48.7%
Simplified48.7%
Final simplification63.5%
(FPCore (x y z) :precision binary64 (if (<= z 3.8e+154) (- (* x y) z) (* x z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 3.8e+154) {
tmp = (x * y) - 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 (z <= 3.8d+154) then
tmp = (x * y) - z
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 3.8e+154) {
tmp = (x * y) - z;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 3.8e+154: tmp = (x * y) - z else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 3.8e+154) tmp = Float64(Float64(x * y) - z); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 3.8e+154) tmp = (x * y) - z; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 3.8e+154], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision], N[(x * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 3.8 \cdot 10^{+154}:\\
\;\;\;\;x \cdot y - z\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < 3.7999999999999998e154Initial program 98.2%
*-commutative98.2%
sub-neg98.2%
distribute-rgt-in98.2%
associate-+r+98.2%
metadata-eval98.2%
mul-1-neg98.2%
unsub-neg98.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 82.5%
if 3.7999999999999998e154 < z Initial program 96.2%
*-commutative96.2%
sub-neg96.2%
distribute-rgt-in96.2%
associate-+r+96.2%
metadata-eval96.2%
mul-1-neg96.2%
unsub-neg96.2%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around 0 96.2%
Taylor expanded in x around inf 64.7%
Final simplification80.7%
(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 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
associate-+r+98.0%
metadata-eval98.0%
mul-1-neg98.0%
unsub-neg98.0%
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 98.0%
*-commutative98.0%
sub-neg98.0%
distribute-rgt-in98.0%
associate-+r+98.0%
metadata-eval98.0%
mul-1-neg98.0%
unsub-neg98.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in x around 0 30.7%
mul-1-neg30.7%
Simplified30.7%
Final simplification30.7%
herbie shell --seed 2023240
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))