
(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 (- (* 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.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
(FPCore (x y z)
:precision binary64
(if (<= x -3.3e+74)
(* x z)
(if (<= x -1.02e-105)
(* x y)
(if (<= x 1.15e-75)
(- z)
(if (or (<= x 3.5e+97) (not (<= x 4e+168))) (* x y) (* x z))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.3e+74) {
tmp = x * z;
} else if (x <= -1.02e-105) {
tmp = x * y;
} else if (x <= 1.15e-75) {
tmp = -z;
} else if ((x <= 3.5e+97) || !(x <= 4e+168)) {
tmp = x * y;
} 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+74)) then
tmp = x * z
else if (x <= (-1.02d-105)) then
tmp = x * y
else if (x <= 1.15d-75) then
tmp = -z
else if ((x <= 3.5d+97) .or. (.not. (x <= 4d+168))) then
tmp = x * y
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+74) {
tmp = x * z;
} else if (x <= -1.02e-105) {
tmp = x * y;
} else if (x <= 1.15e-75) {
tmp = -z;
} else if ((x <= 3.5e+97) || !(x <= 4e+168)) {
tmp = x * y;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.3e+74: tmp = x * z elif x <= -1.02e-105: tmp = x * y elif x <= 1.15e-75: tmp = -z elif (x <= 3.5e+97) or not (x <= 4e+168): tmp = x * y else: tmp = x * z return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.3e+74) tmp = Float64(x * z); elseif (x <= -1.02e-105) tmp = Float64(x * y); elseif (x <= 1.15e-75) tmp = Float64(-z); elseif ((x <= 3.5e+97) || !(x <= 4e+168)) tmp = Float64(x * y); else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.3e+74) tmp = x * z; elseif (x <= -1.02e-105) tmp = x * y; elseif (x <= 1.15e-75) tmp = -z; elseif ((x <= 3.5e+97) || ~((x <= 4e+168))) tmp = x * y; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.3e+74], N[(x * z), $MachinePrecision], If[LessEqual[x, -1.02e-105], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.15e-75], (-z), If[Or[LessEqual[x, 3.5e+97], N[Not[LessEqual[x, 4e+168]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(x * z), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.3 \cdot 10^{+74}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;x \leq -1.02 \cdot 10^{-105}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.15 \cdot 10^{-75}:\\
\;\;\;\;-z\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{+97} \lor \neg \left(x \leq 4 \cdot 10^{+168}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if x < -3.3000000000000002e74 or 3.5000000000000001e97 < x < 3.9999999999999997e168Initial program 97.1%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in z around inf 68.3%
*-commutative68.3%
Simplified68.3%
if -3.3000000000000002e74 < x < -1.0200000000000001e-105 or 1.15e-75 < x < 3.5000000000000001e97 or 3.9999999999999997e168 < x Initial program 99.0%
Taylor expanded in y around inf 66.1%
if -1.0200000000000001e-105 < x < 1.15e-75Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 77.9%
neg-mul-177.9%
Simplified77.9%
Final simplification70.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.55e+25) (not (<= x 7e-15))) (* x (+ y z)) (- (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.55e+25) || !(x <= 7e-15)) {
tmp = x * (y + 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 ((x <= (-1.55d+25)) .or. (.not. (x <= 7d-15))) then
tmp = x * (y + 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 ((x <= -1.55e+25) || !(x <= 7e-15)) {
tmp = x * (y + z);
} else {
tmp = (x * y) - z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.55e+25) or not (x <= 7e-15): tmp = x * (y + z) else: tmp = (x * y) - z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.55e+25) || !(x <= 7e-15)) tmp = Float64(x * Float64(y + z)); else tmp = Float64(Float64(x * y) - z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.55e+25) || ~((x <= 7e-15))) tmp = x * (y + z); else tmp = (x * y) - z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.55e+25], N[Not[LessEqual[x, 7e-15]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{+25} \lor \neg \left(x \leq 7 \cdot 10^{-15}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - z\\
\end{array}
\end{array}
if x < -1.5499999999999999e25 or 7.0000000000000001e-15 < x Initial program 97.8%
Taylor expanded in x around inf 99.1%
+-commutative99.1%
Simplified99.1%
if -1.5499999999999999e25 < x < 7.0000000000000001e-15Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 99.4%
Final simplification99.2%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-105) (not (<= x 3e-76))) (* x (+ y z)) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-105) || !(x <= 3e-76)) {
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.05d-105)) .or. (.not. (x <= 3d-76))) 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.05e-105) || !(x <= 3e-76)) {
tmp = x * (y + z);
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-105) or not (x <= 3e-76): tmp = x * (y + z) else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-105) || !(x <= 3e-76)) 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.05e-105) || ~((x <= 3e-76))) tmp = x * (y + z); else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-105], N[Not[LessEqual[x, 3e-76]], $MachinePrecision]], N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-105} \lor \neg \left(x \leq 3 \cdot 10^{-76}\right):\\
\;\;\;\;x \cdot \left(y + z\right)\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.05e-105 or 3.00000000000000024e-76 < x Initial program 98.2%
Taylor expanded in x around inf 92.5%
+-commutative92.5%
Simplified92.5%
if -1.05e-105 < x < 3.00000000000000024e-76Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 77.9%
neg-mul-177.9%
Simplified77.9%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.05e-105) (not (<= x 7.2e-76))) (* x y) (- z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-105) || !(x <= 7.2e-76)) {
tmp = x * y;
} 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.05d-105)) .or. (.not. (x <= 7.2d-76))) then
tmp = x * y
else
tmp = -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.05e-105) || !(x <= 7.2e-76)) {
tmp = x * y;
} else {
tmp = -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.05e-105) or not (x <= 7.2e-76): tmp = x * y else: tmp = -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.05e-105) || !(x <= 7.2e-76)) tmp = Float64(x * y); else tmp = Float64(-z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.05e-105) || ~((x <= 7.2e-76))) tmp = x * y; else tmp = -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.05e-105], N[Not[LessEqual[x, 7.2e-76]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-z)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-105} \lor \neg \left(x \leq 7.2 \cdot 10^{-76}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-z\\
\end{array}
\end{array}
if x < -1.05e-105 or 7.2000000000000001e-76 < x Initial program 98.2%
Taylor expanded in y around inf 57.1%
if -1.05e-105 < x < 7.2000000000000001e-76Initial program 100.0%
*-commutative100.0%
sub-neg100.0%
distribute-rgt-in100.0%
metadata-eval100.0%
neg-mul-1100.0%
associate-+r+100.0%
unsub-neg100.0%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 77.9%
neg-mul-177.9%
Simplified77.9%
Final simplification64.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.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 75.9%
Taylor expanded in x around 0 31.8%
neg-mul-131.8%
Simplified31.8%
(FPCore (x y z) :precision binary64 0.0)
double code(double x, double y, double z) {
return 0.0;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = 0.0d0
end function
public static double code(double x, double y, double z) {
return 0.0;
}
def code(x, y, z): return 0.0
function code(x, y, z) return 0.0 end
function tmp = code(x, y, z) tmp = 0.0; end
code[x_, y_, z_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 98.8%
*-commutative98.8%
sub-neg98.8%
distribute-rgt-in98.8%
metadata-eval98.8%
neg-mul-198.8%
associate-+r+98.8%
unsub-neg98.8%
distribute-lft-out100.0%
Simplified100.0%
Taylor expanded in y around inf 75.9%
Taylor expanded in x around 0 31.8%
neg-mul-131.8%
Simplified31.8%
add-sqr-sqrt17.8%
sqrt-unprod17.1%
sqr-neg17.1%
sqrt-unprod1.3%
add-log-exp3.4%
add-sqr-sqrt9.9%
add-sqr-sqrt9.9%
sqrt-unprod9.9%
*-un-lft-identity9.9%
exp-prod9.9%
add-sqr-sqrt3.4%
sqrt-unprod4.2%
sqr-neg4.2%
sqrt-unprod0.8%
add-sqr-sqrt1.7%
exp-prod1.7%
*-un-lft-identity1.7%
exp-neg1.6%
rgt-mult-inverse2.5%
metadata-eval2.5%
metadata-eval2.5%
Applied egg-rr2.5%
herbie shell --seed 2024172
(FPCore (x y z)
:name "Graphics.Rendering.Chart.Drawing:drawTextsR from Chart-1.5.3"
:precision binary64
(+ (* x y) (* (- x 1.0) z)))